Skip to content

feat(PostgreSQL dialect): always quote identifier if it is a reserved word - #8935

Closed
jmarton wants to merge 1 commit into
sequelize:masterfrom
jmarton:postgres-quote-reserverd-words
Closed

jmarton wants to merge 1 commit into
sequelize:masterfrom
jmarton:postgres-quote-reserverd-words

Conversation

@jmarton

@jmarton jmarton commented Jan 22, 2018 •

Copy link
Copy Markdown

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions? (edit: not applicable)
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? (edit: not applicable)
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Having reserved words generated in the PostgreSQL queries came up a few times, e.g. in #3528, and in these situations, it was the only possible solution to re-enable quoting.

After this change, reserved words are always quoted, even if quoteIdentifiers is set to false.

This makes it possible to have case-insensitive identifiers in PostgreSQL when certain queries had table aliases generated, which turn out to be PostgreSQL reserved words.

e.g. for the model Users, sometimes, User is the generated table alias, which must be quoted to avoid naming problems.

@jmarton jmarton changed the title PostgreSQL dialect: always quote identifier if it is a reserved word feat(PostgreSQL dialect): always quote identifier if it is a reserved word Jan 22, 2018
@jmarton
jmarton force-pushed the postgres-quote-reserverd-words branch from 34945c2 to 85f270d Compare January 22, 2018 23:25
@codecov

codecov Bot commented Jan 22, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #8935 into master will not change coverage.
The diff coverage is 100%.

@jmarton

jmarton commented Jan 27, 2018

Copy link
Copy Markdown
Author

@mickhansen may I ask you for some advice on how to move forward with this?

For the missing checks:

  • I didn't add new tests because some old tests requirred modification and they cover this enhancement
  • no API was changed, so I didn't include any docs

@jmarton

jmarton commented Feb 2, 2018

Copy link
Copy Markdown
Author

@sushantdhiman may I ask you for some advice on how to move forward with this?

@sushantdhiman

Copy link
Copy Markdown
Contributor

Seems like a good idea and actually this will allow users to use sequelize properly when identifiers are not quoted. But this needs some work, I will tackle that in my attempt to refactor query generator https://github.com/sequelize/sequelize/blob/refactor/lib/dialects/abstract/query-generator/helpers/quote.js#L46

@sushantdhiman sushantdhiman self-assigned this Feb 5, 2018
@sushantdhiman sushantdhiman added this to the 5.0 milestone Feb 8, 2018
@sushantdhiman sushantdhiman mentioned this pull request Mar 24, 2018
4 of 5 tasks
@sushantdhiman

Copy link
Copy Markdown
Contributor

This fix was included to v5 #9236, will be released in next beta release

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

Successfully merging this pull request may close these issues.

2 participants