Thread: INSERT Return Value?

INSERT Return Value?

From
Greg Lindstrom
Date:
Hello-

I am running Postgres 8.08 on a Linux system.  When I insert data into a
table I generate and store a value in the table via a trigger that fires
after the insert.  Is there a way to retrieve the value that I generate
with the trigger?  In this case, I am generating a broker number and
would like to get it back.  One method would be to grab the sequence
number of the record and then make another query, but I feel there is a
more elegant way to get the field.

Thanks for your help,
--greg

--
Greg Lindstrom               501 975.4859 (office)
Programmer                   501 219-4455 (fax)
NovaSys Health               greg.lindstrom@novasyshealth.com
Little Rock, Arkansas

"We are the music makers, and we are the dreamers of dreams."  W.W.




Re: INSERT Return Value?

From
"A. Kretschmer"
Date:
am  Mon, dem 11.12.2006, um 14:46:08 -0600 mailte Greg Lindstrom folgendes:
> Hello-
>
> I am running Postgres 8.08 on a Linux system.  When I insert data into a
> table I generate and store a value in the table via a trigger that fires
> after the insert.  Is there a way to retrieve the value that I generate
> with the trigger?  In this case, I am generating a broker number and

is this a pl/pgsql-trigger-function? You can RAISE NOTICE the generated
number to the font-end.


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47215,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

Re: INSERT Return Value?

From
"Jaime Casanova"
Date:
On 12/11/06, Greg Lindstrom <greg.lindstrom@novasyshealth.com> wrote:
> Hello-
>
> I am running Postgres 8.08 on a Linux system.  When I insert data into a
> table I generate and store a value in the table via a trigger that fires
> after the insert.  Is there a way to retrieve the value that I generate
> with the trigger?  In this case, I am generating a broker number and
> would like to get it back.  One method would be to grab the sequence
> number of the record and then make another query, but I feel there is a
> more elegant way to get the field.
>

you can migrate to 8.2 and use the new INSERT | UPDATE | DELETE
returning feature

http://www.postgresql.org/docs/8.2/static/sql-insert.html
http://www.postgresql.org/docs/8.2/static/sql-update.html
http://www.postgresql.org/docs/8.2/static/sql-delete.html

--
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
                                       Richard Cook