Re: transactions, serial ids, and JDBC - Mailing list pgsql-general

From Neil Conway
Subject Re: transactions, serial ids, and JDBC
Date
Msg-id 87sn1qe19q.fsf@klamath.dyndns.org
Whole thread Raw
In response to transactions, serial ids, and JDBC  (Gregory Seidman <gss+pg@cs.brown.edu>)
Responses Re: transactions, serial ids, and JDBC  ("Paul Ogden" <pogden@claresco.com>)
List pgsql-general
Gregory Seidman <gss+pg@cs.brown.edu> writes:
> I don't know how to dependably get the id from the last insert. One
> possibility, I suppose, is to call nextval myself and use the value
> explicitly, but if there is a way to do it portably (i.e. not depending on
> PostgreSQL's specific implementation of a self-incrementing id field) I
> would prefer it.

Use currval() to get the last ID produced by a sequence. AFAIK most
databases implement a concept similar to sequences, but it's not
standardized -- i.e. it will be difficult or impossible to use the
same technique with different database systems.

> Oh, one more thing. I'm doing this from JDBC. Can I do transactions with a
> long text string with all of this, or do I need to send each line
> (including BEGIN and END) as a separate Statement?

Either way will work.

Cheers,

Neil

--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC

pgsql-general by date:

Previous
From: Gregory Seidman
Date:
Subject: transactions, serial ids, and JDBC
Next
From: Gregory Seidman
Date:
Subject: Re: transactions, serial ids, and JDBC