On Thu, Mar 27, 2003 at 06:36:29AM +0100, Thomas Corell wrote:
Lee Daniel Crocker wrote:
(Thomas Corell T.Corell@t-online.de):
Ok, I will try to understand what is the extention they made, first look at the function in the mysql docs did not give me a hint. Possibly I miss at midnight the reason why I need to know this number and what extention is handled with it. But currval(seq-name) must be similar.
The MySQL extension is the availability of auto-increment integer fields. They're handy when you need an integer key value that's guaranteed to be unique, but you don't care what it is. Without the extension, you can do that by keeping a "last used ID" filed value in a separate table and updating it every time you insert. But with MySQL, you just go ahead and do the insert, and then ask it "Oh, by the way, what integer value did you just assign to the auto- increment field of the record I just inserted?"
Oh, they call that an extention. Well. There's a serial/serial8 type in Postgres, which implicitly creates a sequence and you can use the functions nextval() and currval(). So a definition of e.g. "cur_id serial8 PRIMARY KEY" should handle this.
Or just serial, which would be considerably faster than serial8, unless you think that you will end up with more than 2147483648 rows (2^31).