Postgres uses 'oid' as a reference to the last row inserted/updated, which
would compare to MySQLs 'insertid', hence use:
$oid_status = $sth->{pg_oid_status} 

from DBD::Pg' man:
=============================
pg_size 
Returns a reference to an array of integer values for each column. The
integer shows the storage (not display) size of the column in bytes.
Variable length columns are indicated by -1. 
pg_type 
Returns a reference to an array of strings for each column. The string shows
the name of the data type. 
pg_oid_status 
Returns the OID of the last INSERT command. 
pg_cmd_status 
Returns the name of the last command type. Possible types are: INSERT,
DELETE, UPDATE, SELECT. 
===============================





-----Original Message-----
From: Mark Morgan [mailto:[EMAIL PROTECTED]
Sent: 25 June 2003 18:13
To: [EMAIL PROTECTED]
Subject: Re: DBD::Pg - insert_id


Not sure if postgres is similar to oracle, in this respect, but in Oracle,
it's illegal to do a currval call until nextval has been called at least
once on a sequence.  Something that may come to bite you...

Take care,
Mark.

On Mon, 23 Jun 2003, Toby Corkindale wrote:

> Date: Mon, 23 Jun 2003 08:50:41 -0700
> From: Toby Corkindale <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: Re: DBD::Pg - insert_id
>
> On Fri, Jun 20, 2003 at 10:53:47AM +0100, Chisel Wright wrote:
> > One piece of functionality I can't find in the postgres database
> > interface is the equivalent of:
> >
> >   $sth->{'mysql_insertid'}
> >
> > It would just be really nice to be able to do something like:
> >
> >   $sql = q[INSERT INTO foo (foofield1) VALUES (?)];
> >   $sth = $dbh->prepare($sql);
> >   $sth->execute($barbaz);
> >
> >   return $sth->{'pg_insertid'};
> >
> > Can anyone offer some clues?
>
> as above, except then
> return last_inserted_id($tablename);
>
> Note that this is quite safe and the value returned is the current value
for
> YOUR session only; so no need to worry about someone else inserting
something
> or other such race conditions. :)
>
> # Returns the last ID resulting from an INSERT command
> sub last_inserted_id
> {
>     my $self = shift;
>     my $table = shift; #should be safe, but check anyway
>     if ($table =~ /(\w[\w\d\_]+)/) {
>         $table = $1;
>     }
>     else {
>         die("LBHF.pm/last_inserted_id: Invalid table name: $table\n");
>     }
>     my $query = $self->{db}->prepare("SELECT currval('" . $table .
"_id_seq')");    $query->execute
>         or mydie($self, 'SQL Error occured:' . $self->{db}->errstr);
>     return($query->fetchrow_arrayref->[0]);
> }
>
> hope this helps,
>
> Toby
>
> --
> Turning and turning in the widening gyre
> The falcon cannot hear the falconer;
> Things fall apart, the centre cannot hold;
> Mere anarchy is loosed upon the world.
>
>



________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Reply via email to