On Fri, Aug 09, 2002 at 11:01:30PM +0100, Nigel J. Andrews wrote:
> accepted method of do this sort of thing with sequences is either:
>
> 1. SELECT nextval('seqname');
> 2. Remember the result in variable say currid
> 3. INSERT INTO mytable (idcol, ...) VALUES (<value from currid>, ...)
> 4. Use value from variable currid whereever else it is that you require it
>
> or
>
> 1. INSERT INTO mytable (idcol, ...) VALUES (<value from currid>, ...)
> 2. SELECT curval('seqname');
> 3. Remember the result in variable say currid
> 4. Use value from variable currid whereever else it is that you require it
In the second example, you don't need to get "currid". You can just
do INSERT and then SELECT currval('seqname'). Remember, currval is
defined as sticking _with your connection_, so you don't have to
worry about someone else messing with your currval. (That's also the
reason you can't get a currval() until you have SELECTed nextval(),
either implicitly or explicitly.)
A
--
----
Andrew Sullivan 87 Mowat Avenue
Liberty RMS Toronto, Ontario Canada
<andrew@libertyrms.info> M6K 3E3
+1 416 646 3304 x110