|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Re: Serial type and nextval
From: John Singleton (jsinglet
johnsingleton.com)
Date: Tue Jun 08 2004 - 13:03:24 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
Cheers,
JLS
Gustav Brock wrote:
>Hi John
>
>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?
>
>/gustav
>
>
>
>
>>Date: 2004-06-08 19:34
>>
>>
>
>
>
>>Hello,
>>
>>
>
>
>
>>Something like this will work:
>>
>>
>
>
>
>>select mytable_name.currval from mytable_name
>>
>>
>
>
>
>>Just fetch the first row.
>>
>>
>
>
>
>>Cheers,
>>JLS
>>
>>
>
>
>
>>maxdb wrote:
>>
>>
>
>
>
>>>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
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]