Connection_lastRowId on postgresql

Paul J Stevens paul at nfg.nl
Fri Feb 29 09:35:20 CET 2008


Jan-Henrik Haukeland wrote:
> What command did you use in dbmail to get last insert row id in  
> postgres?

Well, until now we were using a sequence and called "select
curval('sequence_identifier')" after each insert if a last inserted row
id was required.

But I've decided to switch to using the 'RETURNING id' instead to avoid
the additional roundtrip for the extra query. I use executeQuery for the
INSERTs involved, passing the connector and result pointer to my facade
for lastRowId. That call then tries to retrieve the id from the
resultset if lastRowId returns 0 and the resultset is not null. Appears
to work just fine.

Of course 'RETURNING x' is a postgresql construct but I have a framework
in place for dealing with backend specific dialect fragments.

> 
> On 28. feb.. 2008, at 21.55, Paul J Stevens wrote:
> 
>> Jan-Henrik,
>>
>> This call always returns 0 on a postgresql connection. I assume this  
>> is
>> because my tables are without OIDs. Is that intentional? I can work
>> around it. But perhaps a small note in the api docs would be in order?
> 
> --
> To unsubscribe:
> http://www.tildeslash.com/mailman/listinfo/libzdb-general
> 


-- 
  ________________________________________________________________
  Paul Stevens                                      paul at nfg.nl
  NET FACILITIES GROUP                     GPG/PGP: 1024D/11F8CD31
  The Netherlands________________________________http://www.nfg.nl


More information about the libzdb-general mailing list