pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Carl.Weierstrass <carl.weierstrass@googlemail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: bug or feature
Date: Mon, 05 Oct 2026 16:12:35 +0200
Message-ID: <1ceec3736795f744417d6467796bad12e836ad1c.camel@cybertec.at> (raw)
In-Reply-To: <d93e2d28-c230-4c3f-9f46-d1d44fbe46a6@gmail.com>
References: <d93e2d28-c230-4c3f-9f46-d1d44fbe46a6@gmail.com>

On Mon, 2026-10-05 at 10:26 +0200, Carl.Weierstrass wrote:
> I want to delete some data from table test1 und protocol the deleted 
> data in table test2:
> 
> The solution with two statements
> 
> begin;
> insert into test2
> select * from test1
> where 1 = 1;
> 
> delete from test1
> where 1 = 1
> returning *;   -- show deleted lines
> commit;
> 
> works fine, but the more elegant version in one single statement results 
> in a syntax error
> 
> begin;
> insert into test2
> delete from test1
> where 1 = 1
> returning *;  --return deleted lines
> commit;
> 
> psql:test.sql:32: FEHLER:  Syntaxfehler bei »delete«
> ZEILE 2: delete from test1
> 
> Is this a bug or a feature?

That's incorrect syntax.

Try

  WITH cte AS (
     DELETE FROM test1
     RETURNING *
  )
  INSERT INTO test2
  SELECT * FROM cte;

Yours,
Laurenz Albe






view thread (7+ messages)  latest in thread

Message-ID: <1ceec3736795f744417d6467796bad12e836ad1c.camel@cybertec.at>
Permalink:  ../1ceec3736795f744417d6467796bad12e836ad1c.camel@cybertec.at/
Also on:    postgresql.org/message-id/1ceec3736795f744417d6467796bad12e836ad1c.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, carl.weierstrass@googlemail.com
  Subject: Re: bug or feature
  In-Reply-To: <1ceec3736795f744417d6467796bad12e836ad1c.camel@cybertec.at>
  References: <d93e2d28-c230-4c3f-9f46-d1d44fbe46a6@gmail.com> <1ceec3736795f744417d6467796bad12e836ad1c.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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