pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedLast_Inserted Value
5+ messages / 3 participants
[nested] [flat]
* Last_Inserted Value
@ 2002-03-28 08:06 Andre Schubert <andre.schubert@km3.de>
2002-03-28 11:11 ` Re: Last_Inserted Value Marin Dimitrov <marin.dimitrov@sirma.bg>
2002-03-28 14:40 ` Re: Last_Inserted Value Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 5+ messages in thread
From: Andre Schubert @ 2002-03-28 08:06 UTC (permalink / raw)
To: pgsql-admin
Hi all,
i have a little question on getting the last inserted value from a
table.
Lets say i have a transaction which does the following.
insert into foo values(1);
insert into bar values(2);
insert into foobar values(3);
All three tables use the same sequence to increment their id.
I want to know if it is possible to find the id of the inserted value of
foo.
Can i do a select id from foo order by id desc limit 1 before the end of
the transaction,
does this return exactly the row i inserted for this transaction?
Thanks in advance
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Last_Inserted Value
2002-03-28 08:06 Last_Inserted Value Andre Schubert <andre.schubert@km3.de>
@ 2002-03-28 11:11 ` Marin Dimitrov <marin.dimitrov@sirma.bg>
2002-03-28 12:37 ` Re: Last_Inserted Value Andre Schubert <andre.schubert@km3.de>
1 sibling, 1 reply; 5+ messages in thread
From: Marin Dimitrov @ 2002-03-28 11:11 UTC (permalink / raw)
To: Andre Schubert <andre.schubert@km3.de>; pgsql-admin
----- Original Message -----
From: "Andre Schubert"
>
> Can i do a select id from foo order by id desc limit 1 before the end of
> the transaction,
> does this return exactly the row i inserted for this transaction?
>
only if u use SERIALIZABLE transaction isolation level - then the
transactions committed from other users *while* your transaction was in
progress are not visible
in the default READ COMMITED level other committed transactions will
interfere with the "select id from foo order by id desc limit 1" you'll
issue before the end of your transaction
take a look at "Read Committed and Serializable Isolation Levels" from
"PostgreSQL: Introduction and Concepts"
hth,
Marin
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Last_Inserted Value
2002-03-28 08:06 Last_Inserted Value Andre Schubert <andre.schubert@km3.de>
2002-03-28 11:11 ` Re: Last_Inserted Value Marin Dimitrov <marin.dimitrov@sirma.bg>
@ 2002-03-28 12:37 ` Andre Schubert <andre.schubert@km3.de>
0 siblings, 0 replies; 5+ messages in thread
From: Andre Schubert @ 2002-03-28 12:37 UTC (permalink / raw)
To: Marin Dimitrov <marin.dimitrov@sirma.bg>; +Cc: pgsql-admin
Marin Dimitrov schrieb:
>
> ----- Original Message -----
> From: "Andre Schubert"
>
> >
> > Can i do a select id from foo order by id desc limit 1 before the end of
> > the transaction,
> > does this return exactly the row i inserted for this transaction?
> >
>
> only if u use SERIALIZABLE transaction isolation level - then the
> transactions committed from other users *while* your transaction was in
> progress are not visible
Oh thanks for your advice, i exactly use this transaction isolation
level.
>
> in the default READ COMMITED level other committed transactions will
> interfere with the "select id from foo order by id desc limit 1" you'll
> issue before the end of your transaction
>
> take a look at "Read Committed and Serializable Isolation Levels" from
> "PostgreSQL: Introduction and Concepts"
>
> hth,
>
> Marin
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Last_Inserted Value
2002-03-28 08:06 Last_Inserted Value Andre Schubert <andre.schubert@km3.de>
@ 2002-03-28 14:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-04-02 04:52 ` Re: Last_Inserted Value Andre Schubert <andre.schubert@km3.de>
1 sibling, 1 reply; 5+ messages in thread
From: Tom Lane @ 2002-03-28 14:40 UTC (permalink / raw)
To: Andre Schubert <andre.schubert@km3.de>; +Cc: pgsql-admin
Andre Schubert <andre.schubert@km3.de> writes:
> All three tables use the same sequence to increment their id.
> I want to know if it is possible to find the id of the inserted value of
> foo.
Try "currval".
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Last_Inserted Value
2002-03-28 08:06 Last_Inserted Value Andre Schubert <andre.schubert@km3.de>
2002-03-28 14:40 ` Re: Last_Inserted Value Tom Lane <tgl@sss.pgh.pa.us>
@ 2002-04-02 04:52 ` Andre Schubert <andre.schubert@km3.de>
0 siblings, 0 replies; 5+ messages in thread
From: Andre Schubert @ 2002-04-02 04:52 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin
Tom Lane schrieb:
>
> Andre Schubert <andre.schubert@km3.de> writes:
> > All three tables use the same sequence to increment their id.
> > I want to know if it is possible to find the id of the inserted value of
> > foo.
>
> Try "currval".
I think i cant use it. because all three tables use the same sequence,
and currval
gives me the id from the insert of the last table, not of the first one.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2002-04-02 04:52 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-03-28 08:06 Last_Inserted Value Andre Schubert <andre.schubert@km3.de>
2002-03-28 11:11 ` Marin Dimitrov <marin.dimitrov@sirma.bg>
2002-03-28 12:37 ` Andre Schubert <andre.schubert@km3.de>
2002-03-28 14:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-04-02 04:52 ` Andre Schubert <andre.schubert@km3.de>
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