I am trying to implement a statement where I update some timestamps and an active field in before inserting the new row. In case the information is identical, it should not do anything.
My statement looks like this:
with inputdata (id, name, inPrison)
as (
SELECT * FROM (
VALUES (
1, 'egon',TRUE), (2, 'benny',FALSE), (3, 'kjeld',FALSE)) AS t (id,name,inPrison)
)
INSERT INTO public.cdc_test
(id, NAME, inPrison,validfrom,validto,valid)
SELECT inputdata.id, inputdata.NAME, inputdata.inPrison, cdc.start, cdc.end, cdc.active
FROM inputdata
cross JOIN (select now() as start, make_timestamptz(9999, 12, 31, 8, 00, 00) as end, TRUE as active) cdc
ON CONFLICT (id) WHERE md5(row(id,name)::text) != md5(row(public.cdc_test.id,public.cdc_test.name)::text)
DO UPDATE
SET valid = FALSE,
validto = excluded.validfrom
where active = TRUE
and the public.cdc_test table is defined as:
CREATE TABLE public.cdc_test (
id int NOT NULL,
name char(100),
inPrison BOOLEAN,
validfrom DATE,
validto DATE,
valid BOOLEAN
);
I can run my statement without the on conflict, but the on conflict keeps giving me trouble and i feel like I exhausted the ideas I had to make this work.
Can anyone see what i am doing wrong?
When i run it, i get this error:
invalid reference to FROM-clause entry for table "cdc_test"