johnf wrote: > On Monday 16 April 2007 14:56, johnf wrote: >> On Monday 16 April 2007 10:28, Ed Leafe wrote: >>> getLastRowID() >> I'll check into it. But as I recall was working. > > The psycopg cursor.lastrowid returns the 'OID' of the record. This is not > the > PK of the record. > > In Larry's case (since we are not using oid's in our tables) returning a '0' > was correct. However, that's not what he was expecting was it. So the > question is what should we be doing with Postgres for Dabo? > > Postgres uses a sequence function to provide unique numbers. In the case of > a > PK a built-in data type "serial" is provided. The data type "serial" is > nothing more than a special sequence function. Some of you might call this > a 'auto increment' field. But the user does not have to use sequences as > PK's. > > I can write a function that returns the last generated number using > Postgres's 'lastval()' if the table uses a sequence. But what happens if the > table does not use a sequence? Or does not have any PK? Or uses some > compound index. >
Firebird also has a sequence type for PKs. If you don't set the pk in the client app, a before insert trigger is used for setting the pk in the new record. I you need the pk in the client app, you have to get a new pk value and do the setting of the pk value before you issue the insert stmt. I think you should do something similar in postgres too. Some databases can get the new pk after the insert was done, but the most databases use the firebird approach as this is more natural. Uwe _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users Searchable Archives: http://leafe.com/archives/search/dabo-users This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]
