Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email firstname.lastname@example.org
Re: Serial type and nextval
From: Gustav Brock (gustavcactus.dk)
Date: Tue Jun 08 2004 - 13:19:11 CDT
Oh, I see - didn't know of the "magic" of currval.
> Date: 2004-06-08 20:03
> Hi Gustav,
> The SQL statement I posted below is a special statement---not merely the
> first column. Given the table definition:
> create table sometable (foo int DEFAULT SERIAL, bar int)
> insert into sometable (bar) VALUES (11)
> If you do:
> select sometable.currval from sometable
> It will return the current value of the serial column. You see, I am not
> merely selecting the column. The result table it returns is a N x 1
> sized result table where N is the number of rows in the table. However,
> each row is identical. Therefore, the most efficient way to get the
> value would be to fetch the first row.
> Gustav Brock wrote:
>>If not wrapped in a transaction, I doubt this will be reliable in a
>>multiuser environment ...
>>And, if truly single-user, wouldn't it be the last row to fetch?
>>>Something like this will work:
>>>select mytable_name.currval from mytable_name
>>>Just fetch the first row.
>>>>If i create a table that have a field of type serial(1) and insert a row
>>>>on it.... how to determine the currval for this field on this table
>>>>when insert new values on a store procedure?
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb