During an UPSERT query on PostgreSQL it is not obvious which entries of a table has changed (inserted or updated).
Query:
First add an unique constraint for the businessKey:
alter table public."test_table" add constraint "bk_constraint" unique ("businessKey");
INSERT ... ON CONFLICT ... DO UPDATE
INSERT INTO public."test_table" ("first_name","last_name","role", "businessKey")
SELECT
UNNEST(ARRAY['Jon','Anna','Bernhard']),
UNNEST(ARRAY['Doe','Miller','Hill']),
UNNEST(ARRAY['team member','team member','project lead']),
UNNEST(ARRAY['Jon JD','Anna AM','Bernhard AH'])
ON CONFLICT ("businessKey") DO UPDATE
SET "first_name"=EXCLUDED."first_name","last_name"=EXCLUDED."last_name""role"=EXCLUDED."role","businessKey"=EXCLUDED."businessKey";
Now I want to know which entries were inserted or updated for further processing. How can I get this information?