Re: insert ... returning in plpgsql

From: Willy-Bas Loos <willybas(at)gmail(dot)com>
To: cedric(at)2ndquadrant(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: insert ... returning in plpgsql
Date: 2012-10-02 13:24:02
Message-ID: CAHnozTidmS34-suRpeno-52t3SG4kNxSrDSDS1HN9McL8HODgg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

cool, thanks

On Tue, Oct 2, 2012 at 3:13 PM, Cédric Villemain <cedric(at)2ndquadrant(dot)com>wrote:

> **
>
> Le mardi 2 octobre 2012 15:01:08, Willy-Bas Loos a écrit :
>
> > Hi,
>
> > (postgres 9.1)
>
> > I was doing something like this in a plpgsql function, but i got a Syntax
>
> > Error.
>
> >
>
> > t_var:=(insert into table1(field2) values ('x') returning field1);
>
> >
>
> > Is there no support for using RETURNING in insert, update, delete queries
>
> > to fill a variable in plpgsql?
>
>
>
> Use the following :
>
>
>
> INSERT ... RETURNING expressions INTO [STRICT] target;
>
> UPDATE ... RETURNING expressions INTO [STRICT] target;
>
> DELETE ... RETURNING expressions INTO [STRICT] target;
>
>
>
> http://www.postgresql.org/docs/9.1/static/plpgsql-statements.html
>
>
>
> Else if you have multiple rows do something like:
>
> FOR my_update IN UPDATE ... RETURNING * LOOP
>
>
> --
>
> Cédric Villemain +33 (0)6 20 30 22 52
>
> http://2ndQuadrant.fr/
>
> PostgreSQL: Support 24x7 - Développement, Expertise et Formation
>

--
"Quality comes from focus and clarity of purpose" -- Mark Shuttleworth

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-10-02 14:01:47 Re: strange permission error
Previous Message Merlin Moncure 2012-10-02 13:18:24 Re: What's faster? BEGIN ... EXCEPTION or CREATE TEMP TABLE IF NOT EXISTS?