Re: RETURNING, CTEs and TRANSACTION ISOLATION levels... - Mailing list pgsql-general

From Tom Lane
Subject Re: RETURNING, CTEs and TRANSACTION ISOLATION levels...
Date
Msg-id 1885899.1621006807@sss.pgh.pa.us
Whole thread Raw
In response to RETURNING, CTEs and TRANSACTION ISOLATION levels...  (Pól Ua Laoínecháin <linehanp@tcd.ie>)
List pgsql-general
=?UTF-8?B?UMOzbCBVYSBMYW/DrW5lY2jDoWlu?= <linehanp@tcd.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



pgsql-general by date:

Previous
From: Pól Ua Laoínecháin
Date:
Subject: RETURNING, CTEs and TRANSACTION ISOLATION levels...
Next
From: "David G. Johnston"
Date:
Subject: Re: RETURNING, CTEs and TRANSACTION ISOLATION levels...