Unix Technical Forum

Re: How I can read-back a serial value just inserted?

This is a discussion on Re: How I can read-back a serial value just inserted? within the Pgsql General forums, part of the PostgreSQL category; --> If it's a recent PG: select lastval() See this: http://www.postgresql.org/docs/8.2/i...-sequence.html -----Original Message----- From: pgsql-general-owner@postgresql.org [mailto gsql-general-owner@postgresql.org] On Behalf Of ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 01:27 PM
Adam Rich
 
Posts: n/a
Default Re: How I can read-back a serial value just inserted?


If it's a recent PG:

select lastval()

See this:

http://www.postgresql.org/docs/8.2/i...-sequence.html


-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailtogsql-general-owner@postgresql.org] On Behalf Of dfx
Sent: Monday, January 01, 2007 11:46 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] How I can read-back a serial value just inserted?


Dear Sirs,

my question is very simple:
when I insert a row whith a serial field, a value is automatically
generated; how can I know this value, strictly of my row, without the
risk
of to read the value of another subsequent insertion?

Thank you.

Domenico



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


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 01:27 PM
Robert Treat
 
Posts: n/a
Default Re: How I can read-back a serial value just inserted?

On Thursday 18 January 2007 00:57, Adam Rich wrote:
> If it's a recent PG:
>
> select lastval()
>
> See this:
>
> http://www.postgresql.org/docs/8.2/i...-sequence.html
>


probably more important that you see this:
http://people.planetpostgresql.org/x...tval-evil.html

:-)

--
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 01:27 PM
Russ Brown
 
Posts: n/a
Default Re: How I can read-back a serial value just inserted?

Robert Treat wrote:
> On Thursday 18 January 2007 00:57, Adam Rich wrote:
>> If it's a recent PG:
>>
>> select lastval()
>>
>> See this:
>>
>> http://www.postgresql.org/docs/8.2/i...-sequence.html
>>

>
> probably more important that you see this:
> http://people.planetpostgresql.org/x...tval-evil.html
>
> :-)
>


lastval's main benefit is in aiding the port of MySQL apps (being a
drop-in replacement for LAST_INSERT_ID()). without lastval such ports
can be really difficult.

So it does have its place.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 01:27 PM
Devrim GUNDUZ
 
Posts: n/a
Default Re: How I can read-back a serial value just inserted?

Hi,

On Thu, 2007-01-18 at 10:01 -0600, Russ Brown wrote:
> lastval's main benefit is in aiding the port of MySQL apps (being a
> drop-in replacement for LAST_INSERT_ID()). without lastval such ports
> can be really difficult.


I think one can also use INSERT/UPDATE...RETURNING that appeared in 8.2.

Regards,

--
The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBFr5rupme12CBXnxERAmjAAJwI2is/sMB/Cf//r368EfnbKzHE6gCfRgmC
MvZJSviJgj428XZpmnL+0rU=
=i1yy
-----END PGP SIGNATURE-----

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 09:25 AM.


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