FEATURE: Make Keyword an Identifier when it is used before "AS"
In a SQL query we have a keyword as identifier for a CTE:
WITH data AS (
SELECT *
FROM table
WHERE id < 100
)
SELECT * FROM data
It would be nice to mark a keyword conditionally on the context. In this case do not mark it as a keyword if it is used before the AS token.
Hey @JCZuurmond , were you able to find a solution/workaround to this? It seems that as of sqlparse 0.4.3, this remains unsolved.
Nope, I decided to not do SQL parsing
DATA is recognized as a keyword since the beginning of sqlparse. But it seems to be a keyword only in certain dialects liek DB2 or Terradata. Version 0.5.0 will introduce some changes in the current behavior that allows us to remove DATA as a default keyword.
For my later self... This might be a good guide for deciding which keyword belongs to which dialect: https://en.wikipedia.org/wiki/List_of_SQL_reserved_words
@andialbrecht Thanks very much for your response. Although you are correct about DATA appearing as a keyword in only a few dialects of SQL, the solution proposed by the questioner is different.
It may be better to parse the name occurring after WITH as an alias/identifier, despite it being a keyword in any dialect of SQL.