You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Preserve the quoting (or absence of quoting) of identifiers in the original query
Database Engine
PostgreSQL.
Context
In Postgres, unquoted identifiers are case insensitive. So SELECT mYcoL FROM tEsT and SELECT mycol FROM test are equivalent queries. However, quoted identifiers are case sensitive. So SELECT "MyCol" FROM test is semantically different from the two previous queries.
Since the sqlify() function will always quote identifiers, it will produce SQL that is semantically different from the original, when the original used unquoted identifiers.
To Reproduce
constp=newParser();constast=p.astify(`SELECT MyCol FROM "test"`,{database: 'Postgresql'});constsql=p.sqlify(ast,{database: 'Postgresql'});console.log(sql);
node-sql-parser version 4.11.0
Observed output SELECT "MyCol" FROM "test". "MyCol" is rebuilt with quotes, when the original SQL was unquoted.
Expected output SELECT MyCol FROM "test", the original quoting style is preserved for the two identifiers MyCol (unquoted) and "test" (quoted).
The solution is to track if the original identifier was quoted or not in the AST, and rebuild the SQL based on this additional information. Perhaps an additional quoted property could be added to the AST for a more detailed description of identifiers:
Of course this AST modification will break all the code that expects a string value in the column key. It should probably be considered only in a major release, or sooner with a different AST change that will be backward compatible.
The text was updated successfully, but these errors were encountered:
Describe the bug
Preserve the quoting (or absence of quoting) of identifiers in the original query
Database Engine
PostgreSQL.
Context
In Postgres, unquoted identifiers are case insensitive. So
SELECT mYcoL FROM tEsT
andSELECT mycol FROM test
are equivalent queries. However, quoted identifiers are case sensitive. SoSELECT "MyCol" FROM test
is semantically different from the two previous queries.Since the
sqlify()
function will always quote identifiers, it will produce SQL that is semantically different from the original, when the original used unquoted identifiers.To Reproduce
node-sql-parser version 4.11.0
Observed output
SELECT "MyCol" FROM "test"
. "MyCol" is rebuilt with quotes, when the original SQL was unquoted.Expected output
SELECT MyCol FROM "test"
, the original quoting style is preserved for the two identifiers MyCol (unquoted) and "test" (quoted).The solution is to track if the original identifier was quoted or not in the AST, and rebuild the SQL based on this additional information. Perhaps an additional quoted property could be added to the AST for a more detailed description of identifiers:
Of course this AST modification will break all the code that expects a string value in the column key. It should probably be considered only in a major release, or sooner with a different AST change that will be backward compatible.
The text was updated successfully, but these errors were encountered: