Closed samdeanpinknews closed 3 months ago
Thanks for reporting. The problem is with the keyword VALUES
. The same problem happens in this shorter SQL query:
SELECT values.id FROM my_table AS "values"
The formatter expects values
to be the beginning of a VALUES (...)
clause, but here it's used as a table name.
Currently the workaround is to simply quote it.
It's likely something that isn't easy to fix, because it stems from the architectural problems in the formatter.
As you're using PostgreSQL, I can suggest you instead try prettier-plugin-sql-cst, which formats this query just fine. It doesn't yet have full PostgreSQL support, but if you're mainly formatting queries, it should work better than SQL Formatter.
Ah, that makes sense.
It's probably best practice not to use keywords as table names so I think I'll just change the name of that cte :)
I'll close this issue as it's too unlikely that it'll get fixed.
Describe the bug
When running this code:
Where the parameters are
[]
and the query isExpected behavior
The SQL to be formatted, and no error to be thrown
Actual behavior
An error was thrown:
FYI: The character at 43:347 is a
.
, but it's no different to all the other.
s on that line, and the query runs absolutely fine.Usage
How are you calling / using the library? In typescript, node. Installed via npm. The query string is created via TypeORM query builder in NestJS.
What SQL language(s) does this apply to? postgresql
Which SQL Formatter version are you using? 15.2.0