perseas / Pyrseas

Provides utilities for Postgres database schema versioning.
https://perseas.github.io/
BSD 3-Clause "New" or "Revised" License
395 stars 67 forks source link

Quote more keywords in SQL generation #214

Closed rmg closed 4 years ago

rmg commented 4 years ago

Change filter to use any keywords not marked as non-reserved instead of only those marked as reserved. This is necessary due to how certain keywords are classified by Postgres and by the various standards.

Keyword categories (from Postgres src/include/common/keywords.h):

For example, "authorization" is reserved, but may be used as a function name, so it has a catcode of T instead of R, so is not quoted by the original logic.

Docs: https://www.postgresql.org/docs/current/sql-keywords-appendix.html

Closes #212

rmg commented 4 years ago

@jmafc I can switch this to the query you proposed in https://github.com/perseas/Pyrseas/issues/212#issuecomment-561901739 if that helps it get merged.

SELECT word FROM pg_get_keywords() 
WHERE catcode != 'U';
jmafc commented 4 years ago

@rmg Yes, I would prefer the WHERE catcode != 'U', please.

rmg commented 4 years ago

Done. Expanded on the commit message while I was at it (updated PR description to match).