SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

CREATE TABLE public.table2 (
    id bigint,
    from_datetime timestamp with time zone,
    to_datetime timestamp with time zone
);

COPY public.table2 (id, from_datetime, to_datetime) FROM stdin;
1	2022-03-21 01:00:00+01	2022-03-21 01:59:59+01
\.

create view public.myview as select extract(epoch from scheduled) as id, scheduled, exact_schedule_id, coalesce(v.id, 0) as negative_schedule_id from (select '2022-03-21'::date + '01:00:00'::time as scheduled, 1 as exact_schedule_id) as u left join public.table2 as v on (u.scheduled between v.from_datetime and v.to_datetime)  order by scheduled asc;

SELECT * FROM public.myview where id = 1647824400;
