In the following statement (PostgreSQL 11):
=> SELECT c cost FROM tt;
ERROR: syntax error at or near "cost"
LINE 1: SELECT c cost FROM tt;
I get an error. Adding parenthesis around the field expression doesn't help (SELECT (c) cost FROM tt;
). But adding the AS
keyword fixes it.
=> SELECT c AS cost FROM tt;
cost
------
1
...
I realize that cost
is a keyword, but my impression is that the AS
keyword is optional.
From a language perspective, why is the AS
keyword required (or helpful) here? Is the PostgreSQL behavior here standard or documented somewhere?
Are there any other cases when the AS
keyword is required?