Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/pg/lib/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Result {
var field = this.fields[i].name
if (rawValue !== null) {
row[field] = this._parsers[i](rawValue)
} else {
row[field] = null
}
}
return row
Expand Down
21 changes: 21 additions & 0 deletions packages/pg/test/integration/gh-issues/3062-tests.js
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()
})