> -----Original Message-----
> From: Erik Thiele [mailto:[EMAIL PROTECTED]
> Sent: Friday, November 19, 2004 3:42 AM
> To: [EMAIL PROTECTED]
> Subject: [SQL] get sequence value of insert command
> 
> 
> hi
> 
> create sequence mysequence;
> 
> create table foo(
>   id integer default nextval('mysequence'),
>   bla text,
>   wombat integer,
>   foobar date,
>   primary key(id)
> );
> 
> insert into foo (wombat) values (88);
> 
> now how do i know the id of my newly inserted element? and
> how can this be done in a completely concurrency safe way?

CREATE RULE get_pkey_on_insert AS ON INSERT TO foo DO SELECT
currval('mysequence') AS id LIMIT 1;

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

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

Reply via email to