-- Using any database you wish drop schema if exists temp_agg cascade; create schema temp_agg; -- all one part named objects will be in temp_agg by default set search_path to temp_agg; create table emp_temporal ( emp_no int, name text, salary int, project text, emp_row_id bigint not null primary key generated by default as identity, emp_ts timestamptz, emp_te timestamptz ); insert into emp_temporal (emp_no, name, salary, project, emp_ts,emp_te) values (1,'Anne', 4000, 'p11','2023-01-01', '2023-05-01'), (1,'Anne', 4000, 'p15','2023-05-01', 'infinity'), (2,'Esa', 3200, 'p11','2023-04-16', '2023-09-01'), (2,'Esa', 3600, 'p20','2023-01-01', '2023-04-16'), (3,'Eja', 4500, 'p15','2023-01-01', '2023-04-20'), (3,'Eja', 4800, 'p15','2023-04-20', 'infinity'), (4,'Timo', 4800, 'p15','2023-01-01', '2023-06-15'), (4,'Timo', 4800, 'p20','2023-06-15', '2023-07-01'), (4,'Timo', 5000, 'p20','2023-07-01', 'infinity'), (5,'Antti', 3600, 'p11','2023-06-01', '2023-09-01'), (5,'Antti', 3900, 'p11','2023-09-01', 'infinity'), (6,'Merja', 4200, 'p11','2023-01-01', '2023-03-01'), (6,'Merja', 4200, 'p15','2023-03-01', '2023-07-01'), (6,'Merja', 4200, 'p20','2023-07-01', '2023-09-01'), (6,'Merja', 4800, 'p20','2023-09-01', 'infinity'); create table qu ( code text, qu_ts timestamptz, qu_te timestamptz ); insert into qu values ('q1','2023-01-01','2023-04-01'), ('q2','2023-04-01','2023-07-01'), ('q3','2023-07-01','2023-10-01'), ('q4','2023-10-01','2024-01-01');