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.
This has now been improved in 15.9.0 release. Thing should be better now if you use AS keyword to declare aliases. Without the AS, there will still be problems though.
Activity
nene commentedon Nov 14, 2024
Thanks for reporting.
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:
However this syntax is valid in DB2, where one can even write:
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.
[-][FORMATTING] Reserved words can't be used as aliases[/-][+]Reserved words used as aliases cause a crash[/+]Treat a reserved word after AS as an alias
Address review: narrow isAsKeyword, move tests to shared helpers
nene commentedon Sep 23, 2026
This has now been improved in 15.9.0 release. Thing should be better now if you use
ASkeyword to declare aliases. Without theAS, there will still be problems though.