diff --git includes/database/pgsql/query.inc includes/database/pgsql/query.inc index 8825229..9989d30 100644 --- includes/database/pgsql/query.inc +++ includes/database/pgsql/query.inc @@ -67,7 +67,21 @@ class InsertQuery_pgsql extends InsertQuery { elseif ($options['return'] == Database::RETURN_INSERT_ID) { $options['return'] = Database::RETURN_NULL; } - $last_insert_id = $this->connection->query($stmt, array(), $options); + + try { + $last_insert_id = $this->connection->query($stmt, array(), $options); + } catch(PDOException $e) { + if ($e->getCode() == 55000) { + // The query can fail if a value was inserted into the serial column and + // nextval() was never called. In that case, the last_insert_id is known + // by the caller and NULL is returned. + $last_insert_id = NULL; + } + else { + // If it is a different exception, re-throw it. + throw $e; + } + } // Re-initialize the values array so that we can re-use this query. $this->insertValues = array();