On Wednesday 14 January 2009 10:29, Gareth Bult wrote: > This function would be required regardless of the underlying DB .. so > what't the PG equivalent ?
By looking at the sqlite docs, I'm guessing last_insert_rowid() is their equivalent, but I only have MySQL installed so I can't test it. But some DB engines don't even have auto-incrementing fields, let alone a function to return the last inserted ID. Google tells me CURRVAL(pg_get_serial_sequence('my_tbl_name','id_col_name')) is the Postgres equivalent, but if it uses sequences, I think that's different than what we know as autoincrement fields. With Firebird, you can approximate the functionality with generators, like this: -- before inserting any rows into table CREATE GENERATOR generator_id; -- then, as part of each insert statement INSERT INTO tablename (keycolumn, ...) VALUES (gen_id(generator_id, 1), ...); -- after all that, here's the LAST_INSERT_ID() equivalent SELECT gen_id(generator_id, 0); I have no idea whether this is safe to use with multiple connections (like MySQL's is) or anything like that. I also don't think there's any standard ODBC mechanism to do this. Rob ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user