pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedinsert on conflict postgres returning distinction
5+ messages / 2 participants
[nested] [flat]
* insert on conflict postgres returning distinction
@ 2020-08-12 14:23 pinker <pinker@onet.eu>
2020-08-12 16:01 ` Re: insert on conflict postgres returning distinction Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 5+ messages in thread
From: pinker @ 2020-08-12 14:23 UTC (permalink / raw)
To: pgsql-general
is there any way to distinct between updated and inserted rows in RETURNING
clause when ON CONFLICT UPDATE was used?
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: insert on conflict postgres returning distinction
2020-08-12 14:23 insert on conflict postgres returning distinction pinker <pinker@onet.eu>
@ 2020-08-12 16:01 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-08-12 16:24 ` Re: insert on conflict postgres returning distinction pinker <pinker@onet.eu>
2020-08-12 18:52 ` Re: insert on conflict postgres returning distinction pinker <pinker@onet.eu>
0 siblings, 2 replies; 5+ messages in thread
From: Adrian Klaver @ 2020-08-12 16:01 UTC (permalink / raw)
To: pinker <pinker@onet.eu>; pgsql-general
On 8/12/20 7:23 AM, pinker wrote:
> is there any way to distinct between updated and inserted rows in RETURNING
> clause when ON CONFLICT UPDATE was used?
Do you want to use that information immediately in the query or store it
somewhere? If the first case I don't think that is possible. For the
second then, I haven't tried it but, maybe a trigger using transition
tables per example here:
https://www.postgresql.org/docs/12/plpgsql-trigger.html
Example 42.7. Auditing with Transition Tables
>
>
>
> --
> Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: insert on conflict postgres returning distinction
2020-08-12 14:23 insert on conflict postgres returning distinction pinker <pinker@onet.eu>
2020-08-12 16:01 ` Re: insert on conflict postgres returning distinction Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-08-12 16:24 ` pinker <pinker@onet.eu>
1 sibling, 0 replies; 5+ messages in thread
From: pinker @ 2020-08-12 16:24 UTC (permalink / raw)
To: pgsql-general
thank you Adrian,
the background of it is that I have already written the python script that
translates Oracle MERGE clause to Postgres INSERT ... ON CONFLICT, but in
order to be able to add DELETE part from MERGE i need to distinct those
operations.
thank you for the idea with trigger, i haven't thought about it at the
beginning, but it does complicate the code a lot :/ not saying about
performance...
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: insert on conflict postgres returning distinction
2020-08-12 14:23 insert on conflict postgres returning distinction pinker <pinker@onet.eu>
2020-08-12 16:01 ` Re: insert on conflict postgres returning distinction Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-08-12 18:52 ` pinker <pinker@onet.eu>
2020-08-12 20:13 ` Re: insert on conflict postgres returning distinction pinker <pinker@onet.eu>
1 sibling, 1 reply; 5+ messages in thread
From: pinker @ 2020-08-12 18:52 UTC (permalink / raw)
To: pgsql-general
how about this solution?
Does it have any caveats?
WITH upsert AS (INSERT INTO GUCIO (ID, NAZWA)
SELECT A.ID, A.NAZWA
FROM ALA A
ON CONFLICT (ID) DO UPDATE SET
nazwa = excluded.nazwa
RETURNING xmax,xmin, *)
select xmax as xmax_value
into txmaxu
from upsert;
delete
from gucio
where xmax = (select xmax_value from txmaxu where xmax_value <> 0 limit 1);
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: insert on conflict postgres returning distinction
2020-08-12 14:23 insert on conflict postgres returning distinction pinker <pinker@onet.eu>
2020-08-12 16:01 ` Re: insert on conflict postgres returning distinction Adrian Klaver <adrian.klaver@aklaver.com>
2020-08-12 18:52 ` Re: insert on conflict postgres returning distinction pinker <pinker@onet.eu>
@ 2020-08-12 20:13 ` pinker <pinker@onet.eu>
0 siblings, 0 replies; 5+ messages in thread
From: pinker @ 2020-08-12 20:13 UTC (permalink / raw)
To: pgsql-general
Od course inside transaction block
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2020-08-12 20:13 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 14:23 insert on conflict postgres returning distinction pinker <pinker@onet.eu>
2020-08-12 16:01 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-08-12 16:24 ` pinker <pinker@onet.eu>
2020-08-12 18:52 ` pinker <pinker@onet.eu>
2020-08-12 20:13 ` pinker <pinker@onet.eu>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox