From: | Vijaykumar Jain <vijaykumarjain(dot)github(at)gmail(dot)com> |
---|---|
To: | Luca Ferrari <fluca1978(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: order by <tablename> |
Date: | 2021-06-10 08:15:28 |
Message-ID: | CAM+6J94_t9Vu33qbAtA14jJAm4eC5NXuWeDwyUscSiLFqfLEqw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> Any hint?
you can run an explain analyze to check what is going on,
when you provide a table in query in the order by clause, it is
ordered by cols of that table in that order.
create table t(id int, value int);
postgres=# explain (analyze,verbose) select * from t order by t;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Sort (cost=158.51..164.16 rows=2260 width=40) (actual
time=0.005..0.006 rows=0 loops=1)
Output: id, value, t.*
Sort Key: t.*
Sort Method: quicksort Memory: 25kB
-> Seq Scan on public.t (cost=0.00..32.60 rows=2260 width=40)
(actual time=0.002..0.002 rows=0 loops=1)
Output: id, value, t.*
Planning Time: 0.033 ms
Execution Time: 0.044 ms
(8 rows)
postgres=# truncate table t;
TRUNCATE TABLE
postgres=# insert into t values (100, 1);
INSERT 0 1
postgres=# insert into t values (50, 2);
INSERT 0 1
postgres=# select * from t order by t;
id | value
-----+-------
50 | 2
100 | 1
(2 rows)
postgres=# select * from t order by t.id, t.value;
id | value
-----+-------
50 | 2
100 | 1
(2 rows)
From | Date | Subject | |
---|---|---|---|
Next Message | Luca Ferrari | 2021-06-10 08:39:59 | Re: order by <tablename> |
Previous Message | Luca Ferrari | 2021-06-10 08:03:11 | order by <tablename> |