|
Home > Archive > PostgreSQL Discussion > September 2005 > returning the primary key value
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
returning the primary key value
|
|
| Jason Tesser 2005-09-21, 8:23 pm |
| I have a stored proc in which I want to retur the primary key of an insert statement that the stored proc just ran. How can I do that?
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly
| |
| Michael Fuhr 2005-09-22, 3:23 am |
| On Wed, Sep 21, 2005 at 02:22:22PM -0500, Jason Tesser wrote:
> I have a stored proc in which I want to retur the primary key of
> an insert statement that the stored proc just ran. How can I do
> that?
If the primary key is a SERIAL column then see "How do I get the
value of a SERIAL insert?" in the FAQ:
http://www.postgresql.org/docs/faqs.FAQ.html#4.11.2
--
Michael Fuhr
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
| |
| vishal saberwal 2005-09-22, 8:24 pm |
| hi,
If this primary key is a guid or a number that you create as unique, create
it local to your function and then return the same after inserting within
the function.
create or replace function test_insert() returns guid as $$
DECLARE
ret guid;
BEGIN
select into ret newid();
-- ret is the primary key for the table "Table_a"
insert into table_a (ret, "Value1","Value2");
if not found then
...............
end if;
return ret;
END;
$$ language plpgsql;
your question is too abstract, i tink we will nee more information to solve
your problem
vish
On 9/21/05, Michael Fuhr <mike@fuhr.org> wrote:
>
> On Wed, Sep 21, 2005 at 02:22:22PM -0500, Jason Tesser wrote:
>
> If the primary key is a SERIAL column then see "How do I get the
> value of a SERIAL insert?" in the FAQ:
>
> http://www.postgresql.org/docs/faqs.FAQ.html#4.11.2
>
> --
> Michael Fuhr
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
|
|
|
|
|