pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: steinbeck@ice.mpg.de
To: pgsql-interfaces@postgreSQL.org
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [INTERFACES] JDBC and getting just assigned serial number
Date: Wed, 22 Sep 1999 17:16:36 +0200
Message-ID: <l03130301b40ea195509c@[147.233.159.109]> (raw)
In-Reply-To: <37DD4E36.830C04BD@ice.mpg.de>
References: <XFMail.990913114903.orsingerc@epg-gw1.lewis.army.mil>

At 21:19 +0200 on 13/09/1999, Christoph Steinbeck wrote:


> I'm thrilled to see that there is some kind of discussion running in the
> C area on the exact equivalent of my very recent JDBC problem.
> I insert a row into a table where one field is a SERIAL. This SERIAL, of
> course, is automatically assigned by PostgreSQL. How do I get this
> number immeadiately after inserting the row? When I issue the command
> with psql I get back some kind of number which presumably is the OID.
> Getting just this one would be fine too because I need it for
> referencing.

I have answered this question several times already on the SQL list. It has
nothing to do with Java or any other interface you are using (except,
maybe, the question about how to get the OID).

Let's make it short.

1) Don't use OIDs for reference. It will only make life harder.

2) If you want to use the OID just to retrieve that last row, make sure
   that the OID column is indexed, otherwise you are in for sequential
   searching. See, I told you not to use it...

3) As for the serial field. "serial" is a shorthand notation for
   creating an PostgreSQL sequence, and taking the next number from
   that sequence. You can see the name of the sequence that was
   created with a quick \ds in psql.

   Now, after inserting a row, use SELECT currval('sequence_name');
   The number returned is the number assigned to the serial number in
   the last INSERT statement of the current session.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





view thread (7+ messages)  latest in thread

Message-ID: <l03130301b40ea195509c@[147.233.159.109]>
Permalink:  ../l03130301b40ea195509c@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03130301b40ea195509c@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: herouth@oumail.openu.ac.il, steinbeck@ice.mpg.de, pgsql-interfaces@postgreSQL.org
  Subject: Re: [INTERFACES] JDBC and getting just assigned serial number
  In-Reply-To: <l03130301b40ea195509c@[147.233.159.109]>
  References: <XFMail.990913114903.orsingerc@epg-gw1.lewis.army.mil> <l03130301b40ea195509c@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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