SQL function and "UPDATE...RETURNING"

Started by Vincenzo Romanoover 18 years ago2 messagesgeneral
Jump to latest
#1Vincenzo Romano
vincenzo.romano@gmail.com

Hi all.

Is there a way to write an SQL function like this:

create or replace function afunction( recid bigint )
returns bigint as $body$
update atable set afield=0 where recid=$1 returning anotherfield;
$body$ language SQL;

If i write the function this way, postgres will complain that
the update stetement won't return values.

I also understand that by switching to PLPGSQL I would b able to
do write the function. But I'd prefer SQL in this case.

--
Vincenzo Romano
--
Maybe Computer will never become as intelligent as Humans.
For sure they won't ever become so stupid. [VR-1988]

#2Merlin Moncure
mmoncure@gmail.com
In reply to: Vincenzo Romano (#1)
Re: SQL function and "UPDATE...RETURNING"

On 8/2/07, Vincenzo Romano <vincenzo.romano@gmail.com> wrote:

Hi all.

Is there a way to write an SQL function like this:

create or replace function afunction( recid bigint )
returns bigint as $body$
update atable set afield=0 where recid=$1 returning anotherfield;
$body$ language SQL;

If i write the function this way, postgres will complain that
the update stetement won't return values.

I also understand that by switching to PLPGSQL I would b able to
do write the function. But I'd prefer SQL in this case.

It's not really possible to do it that way :(

merlin