Problem/Motivation

If you do something like:

    $database->insert('table_with_serial_id')->from(
      $database->select('table_with_serial_id_backup')->fields('table_with_serial_id_backup')
    )->execute();
    $database->insert('table_with_serial_id')->fields([
      'value' => 'Foob bar,
    ])->execute()

Where table_with_serial_id_backup contains a couple of rows - PostgreSQL will error on the second insert because \Drupal\pgsql\Driver\Database\pgsql\Insert::execute() has not update the sequence like it would for an insert not using a fromQuery.

See https://git.drupalcode.org/issue/drupal-3561800/-/jobs/7571540#L2892 for the failing test case.

Proposed resolution

Always update sequences if the fromQuery includes the serial field.

Remaining tasks

User interface changes

None

Introduced terminology

N/a

API changes

None

Data model changes

None

Release notes snippet

N/a

Issue fork drupal-3561800

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Status: Active » Needs review
smustgrave’s picture

So test-only is passing should it be failing?

alexpott’s picture

@smustgrave it is not passing on PostgreSQL. - sure it passes on MySQL and SQLite. But they don't have the bug :)

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Sorry for the noise, I opened an MR with just the tests and ran postgreSql with 8.5, I did get a test failure in https://git.drupalcode.org/issue/drupal-3561800/-/jobs/7648408

So fix addresses the problem.

longwave’s picture

Version: 11.x-dev » 10.6.x-dev
Component: database system » postgresql db driver
Status: Reviewed & tested by the community » Fixed

Patch applies to 10.6.x so let's backport it there as well.

Committed and pushed a0acc2c1005 to main and cbb23a2aebd to 11.x and 9ebef38a847 to 11.3.x and 96912dd3a82 to 10.6.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed 96912dd3 on 10.6.x
    fix: #3561800 Using \Drupal\Core\Database\Query\Insert::from() on...

  • longwave committed 9ebef38a on 11.3.x
    fix: #3561800 Using \Drupal\Core\Database\Query\Insert::from() on...

  • longwave committed cbb23a2a on 11.x
    fix: #3561800 Using \Drupal\Core\Database\Query\Insert::from() on...

  • longwave committed a0acc2c1 on main
    fix: #3561800 Using \Drupal\Core\Database\Query\Insert::from() on...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.