Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

could '2' be a column name?

... meaning 'order by 2' would order it by the values in the column named '2', but which wasn't selected.



In PostgreSQL, the grammar does not permit unquoted identifiers to start with a digit. So this is a syntax error:

    SELECT 'val' AS 2
Instead you must escape the identifier with double quotes:

    SELECT 'val' AS "2"
So there is no ambiguity on that front in the ORDER BY clause. Either you have `ORDER BY 2`, which means order by the second column, or you have `ORDER BY "2"`, which means order by the column named "2".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: