Skip to content
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

[FORMATTING] tsql: odbc keywords and datatypes as column identifiers are incorrectly formatted #819

Closed
rmja opened this issue Jan 2, 2025 · 3 comments
Labels

Comments

@rmja
Copy link

rmja commented Jan 2, 2025

Input data

Which SQL and options did you provide as input?

SELECT Name, Value, 123 as Timestamp FROM Zone zone;

with the following options

const prettierPluginSqlConfig = {
    language: "tsql",
    keywordCase: "upper",
    functionCase: "upper",
    dataTypeCase: "lower",
};

Expected Output

SELECT
    Name,
    Value,
    123 AS Timestamp
FROM
    Zone zone;

Actual Output

SELECT
    Name,
    VALUE,
    123 AS timestamp
FROM
    ZONE ZONE;

Note the incorrect casing of VALUE, timestamp, and ZONE.

Usage

  • How are you calling / using the library? prettier-plugin-sql
  • What SQL language(s) does this apply to? tsql
  • Which SQL Formatter version are you using? master branch
@rmja rmja added the bug label Jan 2, 2025
@nene
Copy link
Collaborator

nene commented Jan 2, 2025

Thanks for reporting.

Looks like there are way too many keywords listed for tsql, a lot of which aren't actual reserved keywords. Cleaning up this list to only leave the actual reserved keywords (as documented in here) should take care of the problem with VALUE and ZONE.

However with TIMESTAMP, which is also a name of a data type, SQL Formatter is unable to distinguish when it's being used as a data type and when it's being used as plain identifier.

nene added a commit that referenced this issue Jan 2, 2025
@nene
Copy link
Collaborator

nene commented Jan 2, 2025

I close this, as I fixed the problem with ODBC keywords (by just throwing them all away), but the problem with TIMESTAMP really can't be fixed within the current architecture of SQL Formatter . My suggestion is simply to not use the dataTypeCase: "lower" option.

@nene nene closed this as completed Jan 2, 2025
@rmja
Copy link
Author

rmja commented Jan 2, 2025

Thank you! Year, I guess I can use AS [Timestamp] as a workaround.

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

No branches or pull requests

2 participants