order by - Mailing list pgsql-general

From Luca Ferrari
Subject order by
Date
Msg-id CAKoxK+5uLxLGo3CSeYX41mxiATbUgQ3P-KtU2FrB5X7ju1=QcQ@mail.gmail.com
Whole thread Raw
Responses Re: order by  (Vijaykumar Jain <vijaykumarjain.github@gmail.com>)
Re: order by  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi all,
this could be trivial, but I found as an accident the following:

pgbench=> create table t as select v from generate_series( 1, 2 ) v;
SELECT 2
pgbench=> select * from t order by foo;
ERROR:  column "foo" does not exist
LINE 1: select * from t order by foo;
                                 ^
pgbench=> select * from t order by t;
 v
---
 1
 2
(2 rows)

The ORDER BY rejects non existent columns (right) but accepts the
table itself as an ordering expression.
Reading here <https://www.postgresql.org/docs/12/sql-select.html#SQL-ORDERBY>
I cannot really understand why it is working and which kind of
ordering it is applying at all, I suspect the same ordering as without
ORDER BY at all.

Any hint?

Just for the record, seems that supplying another table name is
rejected too, as I would expect:

pgbench=> select * from t order by pgbench_accounts;
ERROR:  column "pgbench_accounts" does not exist
LINE 1: select * from t order by pgbench_accounts;


Thanks,
Luca



pgsql-general by date:

Previous
From: Vijaykumar Jain
Date:
Subject: Re: PostgreSQL replication lag - Suggestions and questions
Next
From: Vijaykumar Jain
Date:
Subject: Re: order by