Re: Re: How to convert "output deleted/inserted into" in MySQL to Postgres

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: How to convert "output deleted/inserted into" in MySQL to Postgres
Date: 2015-02-20 22:01:59
Message-ID: 54E7AED7.5080105@illuminatedcomputing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Michael,

> hey, john, i did as you said like:
> update db.user
> set deleted = 1,
> updateterminal = UpdateTerminal,
> updateuser = UpdateUser,
> updatedate = UpdateDate
> returning
> credittypeid,
> creditid,
> amount
> into ReconDeleted
> where deleted = 0
> and clientid = ClientID
> );
>
> I have ERROR: syntax error at or near "into"

I think what you need here is a Postgres CTE, because you need to
separate the UPDATE from the INSERT. You can do your query like this:

WITH changes AS (
update db.user
set deleted = 1,
updateterminal = UpdateTerminal,
updateuser = UpdateUser,
updatedate = UpdateDate
returning
credittypeid,
creditid,
amount
)
INSERT INTO ReconDeleted
SELECT * FROM changes
;

(not tested, but see CTE docs if you have troubles)

Paul

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2015-02-20 22:06:07 Re: How to convert "output deleted/inserted into" in MySQL to Postgres
Previous Message Adrian Klaver 2015-02-20 21:45:29 Re: Re: How to convert "output deleted/inserted into" in MySQL to Postgres