List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:November 22 2002 4:55pm
Subject:Re: Fw: Question/Suggestion
View as plain text  
At 11:20 +0200 11/22/02, Mircea LUTIC wrote:
>Question: Can I rely on the following behaviour?
>mysql> create table test(id integer not null auto_increment primary key, t
>mysql> insert into test(t) values (last_insert_id());
>mysql> insert into test(t) values (last_insert_id()+1);
>mysql> select * from test;
>| id | t    |
>|  1 | 0    |
>|  2 | 2    |
>That is - when used in an insert statement the last_insert_id() returns the
>value BEFORE the insert?

No.  You have to generate an AUTO_INCREMENT value before using it.
If you were to refer to it before generating it, what's to guarantee
that you would ever generate it?

>This is useful when storing hierarchical data in a table by using char() to
>store "ancestorid.parentid.objectid."
>Suggestion: Document this behaviour.


Can't document the behavior you suggest, because LAST_INSERT_ID()
behaves the way it's explained in the manual, not the way you suggest

sql, query
Fw: Question/SuggestionMircea LUTIC22 Nov
  • Re: Fw: Question/SuggestionPaul DuBois22 Nov