[SQL] getting back autonumber just inserted

2005-07-07 Thread mail TechEvolution

hello

i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 
(windowsinstaller) on a xp prof platform


i would like to get back the autonumber from the last record inserted, 
for other SQL db (m$ sql db ...) i could use:

SELECT @@ IDENTITY

can someone help me by informing me what the SQL syntax is to be used 
with PostGreSQL db and get the same result, the last autonumber inserted?


greeTz

wes

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


Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread mail TechEvolution

hi Alvaro Herrera


You use the currval() function, using the name of the involved sequence
as parameter.  There is a pg_get_serial_sequence() function, to which
you give the table name and column name


thx for the information

and is there a function i can use to get the last added autonumber without 
knowing wich table or row? (exactly as select @@ IDENTITY does?) i have read in 
the messages that there must be such a function for version 8.0, but i could 
not find it in the documentation, any idea on it?

greetZ

wes



Alvaro Herrera schreef:


On Thu, Jul 07, 2005 at 07:50:16PM +0200, mail TechEvolution wrote:
 


hello

i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 
(windowsinstaller) on a xp prof platform


i would like to get back the autonumber from the last record inserted, 
for other SQL db (m$ sql db ...) i could use:

SELECT @@ IDENTITY

can someone help me by informing me what the SQL syntax is to be used 
with PostGreSQL db and get the same result, the last autonumber inserted?
   



You use the currval() function, using the name of the involved sequence
as parameter.  There is a pg_get_serial_sequence() function, to which
you give the table name and column name, and it will give you the
sequence name.

 




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


Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread mail TechEvolution

THX to all guys, it is working great !!

greetZ

wes

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])