How can I insert the return of DELETE into INSERT in postgresql?

后端 未结 5 2182
闹比i
闹比i 2021-02-07 02:23

I am trying to delete a row from one table and insert it with some additional data into another. I know this can be done in two separate commands, one to delete and another to i

5条回答
  •  清酒与你
    2021-02-07 03:09

    You cannot do this before PostgreSQL 9.1, which is not yet released. And then the syntax would be

    WITH foo AS (DELETE FROM a WHERE id = 1 RETURNING one, two, 5)
        INSERT INTO b (one, two, num) SELECT * FROM foo;
    

提交回复
热议问题