When inserting zero rows into an empty table (as can happen with INSERT FROM SELECT), the default $options['return']
value of Database::RETURN_INSERT_ID
can cause an error in Postgres after the INSERT
has (successfully) competed:
'SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: currval of sequence "(table)_(column)_seq" is not yet defined in this session'
In particular this can block the taxonomy module's upgrade path: http://drupal.org/node/1759144#comment-6828288 (taxonomy_update_7005() creates a new table and then inserts into it), but it might potentially cause problems elsewhere as well.
Setting an explicit return option of Database::RETURN_NULL
fixes this, and can safely be done everywhere that the return value of the db_insert() is not needed.
Comment | File | Size | Author |
---|---|---|---|
#4 | drupal-db_insert_return_null-1993166-4.patch | 4.15 KB | jweowu |
#3 | drupal-db_insert_return_null-1993166-2.patch | 4.14 KB | jweowu |
#1 | drupal-db_insert_return_null-1993166-1.patch | 4.15 KB | jweowu |
Comments
Comment #1
jweowu CreditAttribution: jweowu commentedThis patch covers all core instances of the text
"->from("
, save for a non-postgres instance in./includes/database/sqlite/schema.inc:386
which I've left alone.Comment #3
jweowu CreditAttribution: jweowu commentedOops, that didn't apply to HEAD. Re-rolling.
Comment #4
jweowu CreditAttribution: jweowu commented...and I managed to get a tab into the indentation as well, so fixing that: