Re: order by - Mailing list pgsql-general

From Vijaykumar Jain
Subject Re: order by
Date
Msg-id CAM+6J94_t9Vu33qbAtA14jJAm4eC5NXuWeDwyUscSiLFqfLEqw@mail.gmail.com
Whole thread Raw
In response to order by  (Luca Ferrari <fluca1978@gmail.com>)
Responses Re: order by  (Luca Ferrari <fluca1978@gmail.com>)
List 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)



pgsql-general by date:

Previous
From: Luca Ferrari
Date:
Subject: order by
Next
From: Luca Ferrari
Date:
Subject: Re: order by