Re: order by question

From: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: order by question
Date: 2009-07-06 09:51:12
Message-ID: puhbxqywa7.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


> I agree with Scott, if your application generate IN condition, could create
> CASE too, looks like this

> SELECT id, product_id FROM your_table
>    WHERE product_id IN (6, 3, 4, 10, 7)
>     ORDER BY
>       CASE
>         WHEN product_id = 6  THEN 1
>         WHEN product_id = 3  THEN 2
>         WHEN product_id = 4  THEN 3
>         WHEN product_id = 10 THEN 4
>         WHEN product_id = 7  THEN 5
>       END;

A shorter solution would be

ORDER BY product_id != 6,
product_id != 3,
product_id != 4,
product_id != 10,
product_id != 7,
product_id

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Peter Eisentraut 2009-07-06 12:35:11 Re: Make the primary key a multilingual value
Previous Message Andy Shellam 2009-07-05 22:38:10 Re: Compile errors when building 32-bit on 64-bit system