Ordering by IN

From: Hadley Willan <hadley(dot)willan(at)deeperdesign(dot)co(dot)nz>
To: PGSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Ordering by IN
Date: 2004-08-25 06:18:56
Message-ID: 1093414736.2365.203.camel@atlas.sol.deeper.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I was wondering if it's possible to order the result set by some of
the set contained in an IN clause.

For example.
SELECT * FROM v_fol_unit_pub_utmpt WHERE folder_folder_object = 100120
AND unit IN ( 90072, 90005, 90074, 90075 ) AND unit_pub_type IN ( 2 )
AND utmpt IN ( 1 );

Results in.

folder_folder_object | unit | unit_type | unit_quantity |
unit_pub_type | utmpt
----------------------+-------+-----------+---------------+---------------+-------
100120 | 90005 | 101 | 1 |
2 | 1
100120 | 90072 | 101 | 1 |
2 | 1
100120 | 90074 | 101 | 1 |
2 | 1

When ideally I'd like to maintain the order as per ordered list of unit
ids passed in as the parameters.
Like so;

folder_folder_object | unit | unit_type | unit_quantity |
unit_pub_type | utmpt
----------------------+-------+-----------+---------------+---------------+-------
100120 | 90072 | 101 | 1 |
2 | 1
100120 | 90005 | 101 | 1 |
2 | 1
100120 | 90074 | 101 | 1 |
2 | 1

Is this even possible?

Thanks

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Hallgren 2004-08-25 06:46:51 Re: Unsupported 3rd-party solutions (Was: Few questions
Previous Message Carlos Moreno 2004-08-25 04:14:56 Re: Deadlocks caused by referential integrity checks