-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix get value of last column with same name in result rows (#3063)
* Add failing test for result rows with the same column names * Fix handling of duplicate column names in results to ensure last value is populated Fixes handling of result rows that have the same column name duplicated in the results to ensure that the last value is the one returned to the user. This was the old behavior but unintentionally broken when the pre-built object optimization was added.
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
const helper = require('../test-helper') | ||
var assert = require('assert') | ||
const suite = new helper.Suite() | ||
|
||
// https://github.com/brianc/node-postgres/issues/3062 | ||
suite.testAsync('result fields with the same name should pick the last value', async () => { | ||
const client = new helper.pg.Client() | ||
await client.connect() | ||
|
||
const { rows: [shouldBeNullRow] } = await client.query('SELECT NULL AS test, 10 AS test, NULL AS test') | ||
assert.equal(shouldBeNullRow.test, null) | ||
|
||
const { rows: [shouldBeTwelveRow] } = await client.query('SELECT NULL AS test, 10 AS test, 12 AS test') | ||
assert.equal(shouldBeTwelveRow.test, 12) | ||
|
||
const { rows: [shouldBeAbcRow] } = await client.query(`SELECT NULL AS test, 10 AS test, 12 AS test, 'ABC' AS test`) | ||
assert.equal(shouldBeAbcRow.test, 'ABC') | ||
|
||
await client.end() | ||
}) |