Re: getGeneratedKeys method - Mailing list pgsql-jdbc

From Sven Köhler
Subject Re: getGeneratedKeys method
Date
Msg-id 42177A2A.5000304@upb.de
Whole thread Raw
In response to Re: getGeneratedKeys method  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-jdbc
> Yes, this is correct, there is no functionality in postgres to get the
> generated keys.

That's sad.

> This is because the keys are generated using a sequence which can be any
> of the columns in the row, there is no apriori knowledge of the column
> that is being generated.

First, we have to define what a "generated key" is! If you define it as
a value generated by a sequence, than this is hard to find out.

Simply take the following definition:
A column in the primary key is a "generated key", iff a value for the
columns hasn't been given in the INSERT and if the column has a default
value.

With this definition, is should be easy for the server to find the
generated keys.

> 2) get the key after the insert leaving the key value out of the insert,
> or inserting a null there. select currval('sequence_name');

but you have to know the sequence name for that. That's really bad!


pgsql-jdbc by date:

Previous
From: Sven Köhler
Date:
Subject: How to get generated primary key?
Next
From: Michael Barker
Date:
Subject: [Patch] JDBC3 Blob support