|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36681 pgsql: Deferred constraints do not raise an exception on commit
Submitted: 2006-03-10 14:32 UTC Modified: 2006-09-19 15:46 UTC
Avg. Score:4.4 ± 1.2
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: ce at netage dot bg Assigned:
Status: Closed Package: PDO related
PHP Version: 5.1.2 OS: Linux & Windows
Private report: No CVE-ID: None
 [2006-03-10 14:32 UTC] ce at netage dot bg
When using deferred constraints in postgresql, the commit statement doesn't raise exception on constraint violation

Reproduce code:
create table parent (id integer not null primary key);
create table child (parent integer not null references parent(id) deferrable);

$dbh = new PDO('pgsql:dbname=test;host=localhost');

$dbh->exec('insert into child VALUES (1)');

Expected result:
PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23503]: Foreign key violation: 7 ERROR:  insert or update on table "child" violates foreign key constraint "child_parent_fkey"

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-10 17:52 UTC]
I'm reproducing the bug on Windows XP with PHP 5.1.2.
 [2006-04-09 08:24 UTC]
My guess is that this patch will fix this issue, but I haven't tried it:

Index: pgsql_driver.c
RCS file: /repository/php-src/ext/pdo_pgsql/pgsql_driver.c,v
retrieving revision
diff -u -p -r1.53.2.14 pgsql_driver.c
--- pgsql_driver.c      9 Apr 2006 08:17:50 -0000
+++ pgsql_driver.c      9 Apr 2006 08:23:52 -0000
@@ -470,6 +470,7 @@ static int pdo_pgsql_transaction_cmd(con

        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
                ret = 0;
+               pdo_pgsql_error(dbh, PQresultStatus(res), pdo_pgsql_sqlstate(res));


 [2006-04-09 13:46 UTC] ce at netage dot bg
I tested it against 5.1.2. It looks to me as if it works! :-)
 [2006-09-19 15:46 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 13:03:31 2021 UTC