function MergeTest::testMergeSelectExpression

Tests a native merge with a select subquery as expression.

File

core/modules/pgsql/tests/src/Kernel/pgsql/MergeTest.php, line 129

Class

MergeTest
Tests the native MERGE implementation of the PostgreSQL driver.

Namespace

Drupal\Tests\pgsql\Kernel\pgsql

Code

public function testMergeSelectExpression() : void {
  $select = $this->connection
    ->select('test', 't')
    ->condition('t.name', 'Ringo');
  $select->addExpression('[t].[age]');
  $result = $this->connection
    ->merge('test_people')
    ->key('job', 'Speaker')
    ->insertFields([
    'name' => 'Tiffany',
  ])
    ->expression('age', $select)
    ->execute();
  $this->assertSame(Merge::STATUS_UPDATE, $result);
  $age = $this->connection
    ->query('SELECT [age] FROM {test_people} WHERE [job] = :job', [
    ':job' => 'Speaker',
  ])
    ->fetchField();
  // Ringo's age in the sample data of the test table.
  $this->assertEquals(28, $age);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.