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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 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 |
| |||
| 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/ |
| |||
| 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 |
| ||||
| 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----- |