[sf-perl] PostgreSQL DBD ---- repost: sorry, I had the wrong subject in my previous post

David Fetter david at fetter.org
Thu Mar 31 18:44:15 PST 2005


On Thu, Mar 31, 2005 at 06:03:44PM -0800, Shane Hill wrote:
>  Hey folks,
>  
>  I hope all are well.
>  
>  I am using the DBI with postgres and all is good except that when I
>  use the last_insert_id function.  I simply cannot get it work when I
>  use it according to the docs.
>  
>  I am using it in the form :
>  
>  my $id = $self->connection->last_insert_id(undef,undef,$table_name,undef);

Looking at the DBI docs, it says, "For some drivers the $catalog,
$schema, $table, and $field parameters are required (e.g., Pg)..."

Actually, $catalog should be undef (no such concept in Pg), but the
schema is probably 'public' or your username, unless you're using
different schemas.  Anyhow, I'm puzzled, but I have a fix.  After
you've checked whether the INSERT succeeded (you're doing that anyway,
RIGHT?!? ;) just do:

    SELECT currval('the_name_of_the_appropriate_seq');

Not quite as convenient, and I've got a query in to the DBD::Pg dev
team, but it will work.

>  $table_name is defined and assigned.
>  
>  the docs say this is ok,  how am I screwing up?

You're not :)  You're asking for help.

Cheers,
D
-- 
David Fetter david at fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!


More information about the SanFrancisco-pm mailing list