Re: RETURNING, CTEs and TRANSACTION ISOLATION levels...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pól Ua Laoínecháin <linehanp(at)tcd(dot)ie>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: RETURNING, CTEs and TRANSACTION ISOLATION levels...
Date: 2021-05-14 15:40:07
Message-ID: 1885899.1621006807@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

=?UTF-8?B?UMOzbCBVYSBMYW/DrW5lY2jDoWlu?= <linehanp(at)tcd(dot)ie> writes:
> I was trying to do this:

> DELETE FROM t
> WHERE id IN
> INSERT INTO t_archiv
> (
> SELECT *
> FROM t
> WHERE EXTRACT(EPOCH FROM NOW()) - epok > 15613200
> )
> RETURNING id;

Try putting the INSERT ... RETURNING in a CTE (WITH clause).
We don't support putting RETURNING into any random place
where a sub-select can appear, because the semantics would
be too unpredictable. But a WITH has guaranteed evaluate-once
semantics, so DML with RETURNING is OK there.

(Maybe something more specific than a syntax error would
be nice ...)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-05-14 16:00:47 Re: RETURNING, CTEs and TRANSACTION ISOLATION levels...
Previous Message Pól Ua Laoínecháin 2021-05-14 15:33:04 RETURNING, CTEs and TRANSACTION ISOLATION levels...