By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,903 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,903 IT Pros & Developers. It's quick & easy.

serial type vs. sequences

P: n/a
I was wondering if there was a reliable method to get the last id
inserted into a serial column in a table. I believe previous
recommendations given were to use a sequence, have your app get the
nextval for the sequence and then use that in the insert. I was
wondering if things had changed or if that is still the recommended
method.

--
Suchandra Thapa <s-********@alumni.uchicago.edu>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQA/sp8o6nShCjt5AZIRAhNjAJ9mlahGpJ5KZlv/0MoPzjU05UVPmwCfTIee
PJJDf072MsDQL78U1ZEd7F8=
=4zpq
-----END PGP SIGNATURE-----

Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Wed, Nov 12, 2003 at 14:59:33 -0600,
Suchandra Thapa <s-********@alumni.uchicago.edu> wrote:
I was wondering if there was a reliable method to get the last id
inserted into a serial column in a table. I believe previous
recommendations given were to use a sequence, have your app get the
nextval for the sequence and then use that in the insert. I was
wondering if things had changed or if that is still the recommended
method.


It is probably a little better to use currval rather than remembering
what nextval returned in your application.

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

Nov 12 '05 #2

P: n/a
You are accurate.

Suchandra Thapa wrote:
I was wondering if there was a reliable method to get the last id
inserted into a serial column in a table. I believe previous
recommendations given were to use a sequence, have your app get the
nextval for the sequence and then use that in the insert. I was
wondering if things had changed or if that is still the recommended
method.


--
Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC
Postgresql support, programming shared hosting and dedicated hosting.
+1-503-222-2783 - jd@commandprompt.com - http://www.commandprompt.com
Editor-N-Chief - PostgreSQl.Org - http://www.postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #3

P: n/a
Joshua D. Drake wrote:
You are accurate.

Suchandra Thapa wrote:
I was wondering if there was a reliable method to get the last id
inserted into a serial column in a table. I believe previous
recommendations given were to use a sequence, have your app get the
nextval for the sequence and then use that in the insert. I was
wondering if things had changed or if that is still the recommended
method.


If you don't need the value itself in your application, it is safe to
use currval('seqname') in queries following the use of
nextval('seqname'). currval() returns the last value assigned in your
session and is not affected by other concurrent transactions.
Jan

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = Ja******@Yahoo.com #
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.