Hello,
Below is the definition of the table from schema public of our database and also the view inherited from the table:
create table public.sp
(
id uuid default uuid_generate_v4() not null primary key,
provid uuid not null,
surgid uuid not null,
role_group_type varchar(255) not null,
role_group_name varchar(255) not null,
first_name varchar(255),
last_name varchar(255),
gef_code varchar(255),
role varchar(255),
overridden_role varchar(255),
gam_code varchar(255),
adeli_code varchar(9),
rpps_code varchar(11),
billing_identifier varchar(255),
is_main boolean not null,
created timestamp not null,
modified timestamp not null,
attendance_times jsonb
);
create index ix_sp_surgid
on public.sp (surgid);
create index ix_sp_provid
on public.sp (provid);
create index ix_sp_provid_surgid
on public.sp (provid, surgid);
create index ix_sp_firstname
on public.sp (first_name);
create index ix_sp_lastname
on public.sp (last_name);
create index ix_sp_adelicode
on public.sp (adeli_code);
create index ix_sp_rppscode
on public.sp (rpps_code);
create index ix_sp_isoperator
on public.sp (role_group_type)
where ((role_group_type)::text = 'OPERATOR'::text);
create index ix_sp_ismain
on public.sp (is_main)
where (is_main = true);
create index ix_sp_isanesthetist
on public.sp (role_group_type)
where ((role_group_type)::text = 'ANESTHETIST'::text);
create index ix_sp_iscoordinator
on public.sp (role_group_type)
where ((role_group_type)::text = 'COORDINATOR'::text);
create index ix_sp_attendancetimes
on public.sp using gin (attendance_times);
create index ix_sp_rolegrouptype
on public.sp (role_group_type);
create view public.sp_attendance_time
(provid, surgid, sp_attendance_time_id, begin_date_time, end_date_time) as
SELECT sp.provid,
sp.surgid,
(spat.value ->> 'resourceId'::text)::uuid AS sp_attendance_time_id,
(spat.value ->> 'beginDateTime'::text)::timestamp WITH TIME ZONE AS begin_date_time,
(spat.value ->> 'endDateTime'::text)::timestamp WITH TIME ZONE AS end_date_time
FROM sp sp,
LATERAL JSONB_ARRAY_ELEMENTS(sp.attendance_times) spat(value);
Thanks for the help