pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedsequence
5+ messages / 5 participants
[nested] [flat]
* sequence
@ 2000-04-18 07:05 Vladimir V. Zolotych <gsmith@eurocom.od.ua>
2000-04-18 16:18 ` Re: sequence Andrew Perrin - Demography <aperrin@demog.berkeley.edu>
0 siblings, 1 reply; 5+ messages in thread
From: Vladimir V. Zolotych @ 2000-04-18 07:05 UTC (permalink / raw)
To: pgsql-admin
Hello all
What is the safe way to add record to a table
and get it id (generated by a sequence) consistently?
E.g.
1) add record (INSERT INTO...) to a table
(the record's id will be generated
automatically due the ``id SERIAL'' column were defined).
2) get the id of a just created record.
Thanks
--
Vladimir Zolotych gsmith@eurocom.od.ua
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: sequence
2000-04-18 07:05 sequence Vladimir V. Zolotych <gsmith@eurocom.od.ua>
@ 2000-04-18 16:18 ` Andrew Perrin - Demography <aperrin@demog.berkeley.edu>
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Perrin - Demography @ 2000-04-18 16:18 UTC (permalink / raw)
To: Vladimir V. Zolotych <gsmith@eurocom.od.ua>; +Cc: pgsql-admin
I figured this out recently with the help of the list - you want either
nextval() or currval(). In my case, I used currval(). Basically:
SELECT currval('table_field_seq');
will return the most recently assigned value to the field *by the current
backend* which means:
- There's no danger of a race condition (another user creating a record in
the time between your creating the record and calling currval); BUT
- You must be using the same backend as you did on the creation.
Hope this helps.
---------------------------------------------------------------------
Andrew J. Perrin - aperrin@demog.berkeley.edu - NT/Unix Admin/Support
Department of Demography - University of California at Berkeley
2232 Piedmont Avenue #2120 - Berkeley, California, 94720-2120 USA
http://demog.berkeley.edu/~aperrin --------------------------SEIU1199
On Tue, 18 Apr 2000, Vladimir V. Zolotych wrote:
> Hello all
>
> What is the safe way to add record to a table
> and get it id (generated by a sequence) consistently?
>
> E.g.
> 1) add record (INSERT INTO...) to a table
> (the record's id will be generated
> automatically due the ``id SERIAL'' column were defined).
>
> 2) get the id of a just created record.
>
> Thanks
>
>
> --
> Vladimir Zolotych gsmith@eurocom.od.ua
>
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* sequence
@ 2003-01-09 01:08 Roberto Benitez <rbenitez22@yahoo.com>
2003-01-11 15:17 ` Re: sequence Artur Pietruk <arturp@plukwa.net>
0 siblings, 1 reply; 5+ messages in thread
From: Roberto Benitez @ 2003-01-09 01:08 UTC (permalink / raw)
To: pgsql-admin
I have a field of serial type. for some reason, the
sequence skips numbers every now and then. does anyone
know why?
--thanks
--roberto c. benitez
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: sequence
2003-01-09 01:08 sequence Roberto Benitez <rbenitez22@yahoo.com>
@ 2003-01-11 15:17 ` Artur Pietruk <arturp@plukwa.net>
0 siblings, 0 replies; 5+ messages in thread
From: Artur Pietruk @ 2003-01-11 15:17 UTC (permalink / raw)
To: Roberto Benitez <rbenitez22@yahoo.com>; +Cc: pgsql-admin
On Wed, Jan 08, 2003 at 05:08:35PM -0800, Roberto Benitez wrote:
> I have a field of serial type. for some reason, the
> sequence skips numbers every now and then. does anyone
> know why?
Canceled/rollbacked transactions?
BR,
--
--- Artur Pietruk, arturp@plukwa.net
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: sequence
@ 2003-01-11 15:23 Artur Pietruk <arturp@plukwa.pdi.net>
0 siblings, 0 replies; 5+ messages in thread
From: Artur Pietruk @ 2003-01-11 15:23 UTC (permalink / raw)
To: pgsql-admin
On Wed, Jan 08, 2003 at 05:08:35PM -0800, Roberto Benitez wrote:
> I have a field of serial type. for some reason, the
> sequence skips numbers every now and then. does anyone
> know why?
Canceled/rollbacked transactions?
BR,
--
--- Artur Pietruk, arturp@plukwa.net
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-01-11 15:23 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-04-18 07:05 sequence Vladimir V. Zolotych <gsmith@eurocom.od.ua>
2000-04-18 16:18 ` Andrew Perrin - Demography <aperrin@demog.berkeley.edu>
2003-01-09 01:08 sequence Roberto Benitez <rbenitez22@yahoo.com>
2003-01-11 15:17 ` Artur Pietruk <arturp@plukwa.net>
2003-01-11 15:23 Re: sequence Artur Pietruk <arturp@plukwa.pdi.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox