by chmaynard · 6y ago · 0 comments
Many interpreters let you use a column alias from the select clause in the group and order clauses. This has better readability IMO but I'm not sure it's in the SQL-92 standard, but I believe it is now standardized.
Not sure if it's standardised, but Postgres doesn't let you do this (rather irritatingly).
> An expression used inside a grouping_element can be an input column name, or the name or ordinal number of an output column (SELECT list item), or an arbitrary expression formed from input-column values. [0]
> Each expression can be the name or ordinal number of an output column (SELECT list item), or it can be an arbitrary expression formed from input-column values. [1]
Perhaps you are thinking of trying to use an output column name in a WHERE clause?
[0]: https://www.postgresql.org/docs/current/sql-select.html#SQL-...
[1]: https://www.postgresql.org/docs/current/sql-select.html#SQL-...
Agreed, but the purpose of the example is to demonstrate how to use UPDATE FROM, nothing more. I appreciate how it accomplishes a complex update in a very clear, concise, elegant way.
Edit: Or use subqueries apparently.