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
Here's a more complex example (the error is a bit different):
SELECT id AS srvid,
CASE WHEN id = $1 THEN $2
ELSE
COALESCE(alias, hostname || $3|| port)
END AS alias,
CASE WHEN id = $4 THEN $5 ELSE hostname END as hostname,
CASE WHEN id = $6 THEN $7 ELSE port END AS port,
CASE WHEN id = $8 THEN set.setting
ELSE s.version::text
END AS version
FROMpublic.powa_servers s
LEFT JOIN pg_settings setONset.name = $9ANDs.id= $10
Although this error occurs with other dialects, it's more of a PostgreSQL-specific issue as most SQL dialects don't allow reserved keywords to be used as aliases. PostgreSQL also only allows some, like the following won't work:
SELECTselect.foo FROM settings ASselect;
However this syntax is valid in DB2, where one can even write:
SELECTselectFROMfrom;
Isn't SQL a wonderful language :D
Usually I would recommend checking out prettier-plugin-sql-cst, which does a much better job at formatting PostgreSQL than this library, but turns out that the same issue is also present in there. Though my hopes of fixing this issue in there are much higher than fixing it in here.
Input data
Here's a more complex example (the error is a bit different):
Usage
Tested in the online demo as well.
What SQL language(s) does this apply to?
PostgreSQL, but the first example fails with any dialect with the same error
Which SQL Formatter version are you using?
15.4.6
The text was updated successfully, but these errors were encountered: