Unix Technical Forum

Support for RETURNING xxx INTO yyy for INSERT and UPDATE?

This is a discussion on Support for RETURNING xxx INTO yyy for INSERT and UPDATE? within the pgsql Novice forums, part of the PostgreSQL category; --> Does anyone know if Postgres supports some form of: insert into mytable(column1,column2) values ('a','b') returning mytable_pk into :new_mytable_pk Where ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 08:31 PM
John Napiorkowski
 
Posts: n/a
Default Support for RETURNING xxx INTO yyy for INSERT and UPDATE?

Does anyone know if Postgres supports some form of:

insert into mytable(column1,column2)
values ('a','b')
returning mytable_pk into :new_mytable_pk

Where 'mytable_pk' is defaulted to type of SERIAL?

I am really used to having this on Oracle, but can't
seem to find anything about it in the documentation or
searching around the mailing lists.

If not, what methods can I use to reliable and
efficiently return new primary keys from inserts? I
am thinking I could use a function, but then I would
need to create one for each table in the database,
which seems really messy to me.

Sorry if this question has been answered somewhere
else. I figure it must have been, since this seems
like such a basic thing to me, but I just can't find
it

--john



__________________________________
Do you Yahoo!?
Yahoo! Sports - Sign up for Fantasy Baseball.
http://baseball.fantasysports.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 08:31 PM
Michael Fuhr
 
Posts: n/a
Default Re: Support for RETURNING xxx INTO yyy for INSERT and UPDATE?

On Tue, Feb 22, 2005 at 10:11:24PM -0800, John Napiorkowski wrote:

> what methods can I use to reliable and efficiently return new
> primary keys from inserts?


See "How do I get the value of a SERIAL insert?" in the FAQ:

http://www.postgresql.org/files/docu...AQ.html#4.11.2

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:25 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com