#earlier in SQL CREATE TABLE tbl ( id serial, col2 text, col3 text ); NOTICE: CREATE TABLE will create implicit sequence 'tbl_id_seq' for SERIAL column 'tbl.id' #### my $myid; my $dbh=DBI->connect("DBI:Pg(AutoCommit=>0,RaiseError=>1):dbname=foo"); eval { $dbh->do("INSERT INTO tbl ( col2, col3 ) VALUES ( 'val', 'val3' )"; my $sth=$dbh->prepare("SELECT currval('tbl_id_seq')"); $sth->execute; $sth->bind_columns( \($myid )); $sth->fetch; $dbh->commit; }; if($@) { $dbh->rollback; #enlightening error message goes here } # $myid has your id in it here.