Unix Technical Forum

returning autogenerated keys

This is a discussion on returning autogenerated keys within the pgsql Interfaces jdbc forums, part of the PostgreSQL category; --> I am trying to use PostgreSQL and while trying to do a prototype, I am getting an error. org.postgresql.util.PSQLException: ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 11:40 PM
Srinivasa_Tata@hud.gov
 
Posts: n/a
Default returning autogenerated keys

I am trying to use PostgreSQL and while trying to do a prototype, I am
getting an error.
org.postgresql.util.PSQLException: Returning autogenerated keys is not
supported.
at
org.postgresql.jdbc3.AbstractJdbc3Statement.execut eUpdate(AbstractJdbc3Statement.java:138)

In the TODO list (INSERT section), it is mentioned that "This is useful
for returning the auto-generated key for an INSERT. One complication is
how to handle rules that run as part of the insert."

Does it mean PostgreSQL does not support returning autogenerated keys? I
am using 803 version.

Thanks In Advance

Srinivas Tata



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2008, 11:40 PM
Adriaan Joubert
 
Posts: n/a
Default Re: returning autogenerated keys

Yes, that is correct, postgres does not support returning auto-generated
keys.

You can get the auto generated keys by calling

SELECT currval('<sequence-name>');

on the same connection. We have remote users and latency is an issue. We
combine the insert and the fetch of the remote keys, which does
everything in a single trip to the database.

sql = "INSERT ....; SELECT currval('<sequence-name>')";
// Prepare the statement
PreparedStatement st = connection.prepareStatement(sql);
// Set the insert values
...
// Insert the row
st.execute();
int nInserted = st.getUpdateCount();
if (nInserted == 1 && st.getMoreResults()) {
ResultSet rs = st.getResultSet();
if (rs.next())
result = rs.get(1);
}

That does everything in one go.

Cheers,

Adriaan



Srinivasa_Tata@hud.gov wrote:

>
>
> I am trying to use PostgreSQL and while trying to do a prototype, I am
> getting an error.
>
> org.postgresql.util.PSQLException: Returning autogenerated keys is not
> supported.
> at
> org.postgresql.jdbc3.AbstractJdbc3Statement.execut eUpdate(AbstractJdbc3Statement.java:138)
>
> In the TODO list (INSERT section), it is mentioned that "This is
> useful for returning the auto-generated key for an INSERT. One
> complication is how to handle rules that run as part of the insert."
>
> Does it mean PostgreSQL does not support returning autogenerated keys?
> I am using 803 version.
>
> Thanks In Advance
>
> Srinivas Tata_
>
> _
>
>




---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:36 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com