Skip to content

Breaking change in queries with duplicate column names #3189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pgarrett-twc opened this issue Apr 3, 2024 · 3 comments
Closed

Breaking change in queries with duplicate column names #3189

pgarrett-twc opened this issue Apr 3, 2024 · 3 comments

Comments

@pgarrett-twc
Copy link

In pg versions prior to 8.11.4, selecting multiple columns with the same name would produce a non-null result if any of the columns were not null. Starting with 8.11.4, query() returns the right-most column of the same name, even if it's null. This is arguably the correct behavior, but it caused a breakage in my application due to a select * outer join query that had multiple columns of the same name from different tables, where some were null and others not.

This appears to have been introduced in da0f5c5.

Reproduction script:

const { Client } = require('pg')

async function main() {
  const client = new Client()
  await client.connect()

  const x = 'Hello, world'
  const res = await client.query(`SELECT $1::text as msg, null as msg`, [x])
  console.dir(res.rows)
  await client.end()
}

main()

8.11.3:

$ npm install [email protected]
...

$ node repro.js
[ { msg: 'Hello, world' } ]

8.11.4:

$ npm install [email protected]
...

$ node repro.js
[ { msg: null } ]

8.11.5:

$ npm install [email protected]
...

$ node repro.js
[ { msg: null } ]
@charmander
Copy link
Collaborator

In pg versions prior to 8.11.4

In 8.11.3 only, which was the unintentional breaking change and reverted. #3062

@charmander charmander closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
@pgarrett-twc
Copy link
Author

I see. I didn't realize we had been on 8.11.3 for as long as we had. Thanks.

@jonesbusy
Copy link

Thanks, we were also relying on this bug without even knowing it.

Adding alias on column names fixes our problems after update from 8.11.3 to 8.11.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants