Catching errors with Perl DBI

From: stan <stanb(at)panix(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Catching errors with Perl DBI
Date: 2020-07-02 15:03:37
Message-ID: 20200702150337.GA18581@panix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How can I catch the errors generated whne I call an INSERT that violates a
constraint? I have coded like this:

my $sth = $dbh->prepare($stmt);
my $rv = $sth->execute() or die $DBI::errstr;
if ( $rv < 0 ) {
print $DBI::errstr;
}

But, if the INSERT violates a constraint, it never gets the the evaluation
of the $rv

Is this a setting for the DBI?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Anders Steinlein 2020-07-02 15:06:24 Re: Different results from identical matviews
Previous Message Anders Steinlein 2020-07-02 14:57:18 Re: Different results from identical matviews