http://www.perlmonks.org?node_id=525563


in reply to Re: Getting ID of last row inserted into database
in thread Getting ID of last row inserted into database

Indeed. I just want to point (for the OP) that support for last_insert_id varies greatly from DBMS to DBMS, and not all DBD's implement it in a reasonable way. Caveat selector.

Replies are listed 'Best First'.
Re^3: Getting ID of last row inserted into database
by lima1 (Curate) on Jan 25, 2006 at 21:04 UTC
    yes...had some problems with that, but with this parameter combination:
    $self->db->dbh->last_insert_id(undef, undef, 'tablename', 'id_name');
    SQLite, MySQL 4.0 and PostgreSQL 8.1 all pass my tests. I think SERIAL UNIQUE NOT NULL was also necessary for Pg, but not sure.
Re^3: Getting ID of last row inserted into database
by Yendor (Pilgrim) on Jan 26, 2006 at 15:20 UTC

    Aye. Reading the DBI docs that Corion pointed me to were a great help. I ended up with the following as my call to last_insert_id:

    my $LastID = $dbh->last_insert_id(undef, 'public', 'CUSTOMER_INFORMATION', 'ID');