- Previous thread: Weird Error
- Next thread: expired mysql connection ?
- Threads sorted by date: mysql 200905
I don't think its possible to do what you want in a single statement. Since
LAST_INSERT_ID() is set to the last insert id of the connection... and the
row you are inserting doesn't exist.. well.. until you create it, it will
always either be zero or the record BEFORE your next insert, ie:
INSERT INTO testtable(NULL,LAST_INSERT_ID());
INSERT INTO testtable(NULL,LAST_INSERT_ID());
would produce
ID CRC32ID
1 0
2 1
You could run an update immediately after the insert to set the CRC32
column:
UPDATE testtable SET id-crc=CRC32(LAST_INSERT_ID()) WHERE
id=LAST_INSERT_ID();
Not quite sure why you need the CRC32 value of the ID, will it not always be
the same value for the given ID number? Wouldn't it be easier to do it on
the select side of the equation?
SELECT id,CRC32(id) AS id-crc... FROM testtable...
-jw
On Sun, May 3, 2009 at 7:16 AM, thunder@isfahan.at wrote:
> Hello,
> I have a questions and I hope, that is possible in MySQL.
>
> I have the following short Table.
> CREATE TABLE IF NOT EXISTS `testtable` (
> `id` bigint(20) unsigned NOT NULL auto_increment,
> `id-crc` bigint(20) unsigned NOT NULL,
> PRIMARY KEY (`id`),
> UNIQUE KEY `id-crc` (`id-crc`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
>
>
> `id` is the unique autoincrement
>
> in `id-crc` I would like save the CRC32 from `id` (the coloumn is unique)
>
> E.G.
>
> id id-crc
> --------------------
> 1 2212294583 --> CRC32('1')
> 2 450215437 --> CRC32('2')
> 3 1842515611 --> CRC32('3')
>
> I would like insert the CRC32 directly when I make a new Insert. E.G.
>
> INSERT INTO `db283796092`.`testtable` (
> `id` , `id-crc`
> )
> VALUES (
> NULL , LAST_INSERT_ID()
> );
>
> But LAST_INSERT_ID() is 0!!!! How can I make that, that he use the actual
> INSERT-ID?
>
> Best regards
>
> Thunder
>
>
>
>
>
>
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=johnny@pixelated.net
>
>
--
-----------------------------
Johnny Withers
601.209.4985
johnny@pixelated.net
LAST_INSERT_ID() is set to the last insert id of the connection... and the
row you are inserting doesn't exist.. well.. until you create it, it will
always either be zero or the record BEFORE your next insert, ie:
INSERT INTO testtable(NULL,LAST_INSERT_ID());
INSERT INTO testtable(NULL,LAST_INSERT_ID());
would produce
ID CRC32ID
1 0
2 1
You could run an update immediately after the insert to set the CRC32
column:
UPDATE testtable SET id-crc=CRC32(LAST_INSERT_ID()) WHERE
id=LAST_INSERT_ID();
Not quite sure why you need the CRC32 value of the ID, will it not always be
the same value for the given ID number? Wouldn't it be easier to do it on
the select side of the equation?
SELECT id,CRC32(id) AS id-crc... FROM testtable...
-jw
On Sun, May 3, 2009 at 7:16 AM, thunder@isfahan.at wrote:
> Hello,
> I have a questions and I hope, that is possible in MySQL.
>
> I have the following short Table.
> CREATE TABLE IF NOT EXISTS `testtable` (
> `id` bigint(20) unsigned NOT NULL auto_increment,
> `id-crc` bigint(20) unsigned NOT NULL,
> PRIMARY KEY (`id`),
> UNIQUE KEY `id-crc` (`id-crc`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
>
>
> `id` is the unique autoincrement
>
> in `id-crc` I would like save the CRC32 from `id` (the coloumn is unique)
>
> E.G.
>
> id id-crc
> --------------------
> 1 2212294583 --> CRC32('1')
> 2 450215437 --> CRC32('2')
> 3 1842515611 --> CRC32('3')
>
> I would like insert the CRC32 directly when I make a new Insert. E.G.
>
> INSERT INTO `db283796092`.`testtable` (
> `id` , `id-crc`
> )
> VALUES (
> NULL , LAST_INSERT_ID()
> );
>
> But LAST_INSERT_ID() is 0!!!! How can I make that, that he use the actual
> INSERT-ID?
>
> Best regards
>
> Thunder
>
>
>
>
>
>
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=johnny@pixelated.net
>
>
--
-----------------------------
Johnny Withers
601.209.4985
johnny@pixelated.net
Conversations: LAST_INSERT_ID and CRC32
- LAST_INSERT_ID and CRC32 by thunder@isfahan.at on 2009-05-03T12:16:26+00:00
- Re: LAST_INSERT_ID and CRC32 by Johnny Withers on 2009-05-03T17:09:01+00:00
- Re: LAST_INSERT_ID and CRC32 by thunder@isfahan.at on 2009-05-03T17:41:26+00:00
- Re: LAST_INSERT_ID and CRC32 by thunder@isfahan.at on 2009-05-03T17:43:59+00:00
- Re: LAST_INSERT_ID and CRC32 by Johnny Withers on 2009-05-03T22:48:37+00:00
- Re: LAST_INSERT_ID and CRC32 by Thomas Pundt on 2009-05-05T15:23:10+00:00
- Re: LAST_INSERT_ID and CRC32 by Johnny Withers on 2009-05-06T02:54:51+00:00
- Re: LAST_INSERT_ID and CRC32 by thunder@isfahan.at on 2009-05-06T06:14:17+00:00
Related Threads
- I need your help. - debian
- [HACKERS] ALTER DATABASE SET TABLESPACE vs crash safety - pgsql
- Mlk day of service - Free - python
- minimal mirror for lenny net install - debian
- [PHP] mySQL query question - php
- [PATCH v5, middle end]: Committed: Fix PR 37908, thinko with atomic NAND operation - gcc
- [GENERAL] lo data type - pgsql
- Sending username password to a webpage - python
- PyMei - Python Media Interface - python
- [Bug middle-end/38336] New: fold_builtin_memory_op generates invalid GIMPLE - gcc