Lists: | pgsql-general |
---|
From: | Victor Spång Arthursson <scooterbabe(at)home(dot)se> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | ORDER BY 'DK', 'DE', DESC? |
Date: | 2004-05-11 08:46:59 |
Message-ID: | C3D41FDA-A327-11D8-99EA-00039344A3C4@home.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hi!
I would like to know if it's possible to give a priority order of how
to sort the returning rows?
Like for example to order every row with a field language = DK first,
then the rows with field language = *DE' and last the other languages,
ordered alphabetically…?
Sincerely
Victor
From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | Victor Spång Arthursson <scooterbabe(at)home(dot)se> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: ORDER BY 'DK', 'DE', DESC? |
Date: | 2004-05-20 17:20:44 |
Message-ID: | 20040520101818.E17153@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Tue, 11 May 2004, [ISO-8859-1] Victor Spång Arthursson wrote:
> Hi!
>
> I would like to know if it's possible to give a priority order of how
> to sort the returning rows?
>
> Like for example to order every row with a field language = DK first,
> then the rows with field language = *DE' and last the other languages,
> ordered alphabetically…?
Well, I think you can do something like:
ORDER BY (language = 'DK'), (language = 'DE'), language
(or you could possibly condense the first two into one with case)
From: | Adam Ruth <aruth(at)intercation(dot)com> |
---|---|
To: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org, Victor Spång Arthursson <scooterbabe(at)home(dot)se> |
Subject: | Re: ORDER BY 'DK', 'DE', DESC? |
Date: | 2004-05-20 18:02:00 |
Message-ID: | CAC8998B-AA87-11D8-9F90-000A959D1424@intercation.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On May 20, 2004, at 11:20 AM, Stephan Szabo wrote:
> On Tue, 11 May 2004, [ISO-8859-1] Victor Spång Arthursson wrote:
>
>> Hi!
>>
>> I would like to know if it's possible to give a priority order of how
>> to sort the returning rows?
>>
>> Like for example to order every row with a field language = DK first,
>> then the rows with field language = *DE' and last the other languages,
>> ordered alphabetically…?
>
> Well, I think you can do something like:
>
> ORDER BY (language = 'DK'), (language = 'DE'), language
>
> (or you could possibly condense the first two into one with case)
Due to the sorting of boolean values, you'd need:
ORDER BY language = 'DK' desc, language like '%DE' desc, language;
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo(at)postgresql(dot)org
>
From: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
---|---|
To: | Adam Ruth <aruth(at)intercation(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org, Victor Spång Arthursson <scooterbabe(at)home(dot)se> |
Subject: | Re: ORDER BY 'DK', 'DE', DESC? |
Date: | 2004-05-20 18:19:36 |
Message-ID: | 20040520111840.G18583@megazone.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On Thu, 20 May 2004, Adam Ruth wrote:
>
> On May 20, 2004, at 11:20 AM, Stephan Szabo wrote:
>
> > On Tue, 11 May 2004, [ISO-8859-1] Victor Spång Arthursson wrote:
> >
> >> Hi!
> >>
> >> I would like to know if it's possible to give a priority order of how
> >> to sort the returning rows?
> >>
> >> Like for example to order every row with a field language = DK first,
> >> then the rows with field language = *DE' and last the other languages,
> >> ordered alphabetically…?
> >
> > Well, I think you can do something like:
> >
> > ORDER BY (language = 'DK'), (language = 'DE'), language
> >
> > (or you could possibly condense the first two into one with case)
>
> Due to the sorting of boolean values, you'd need:
>
> ORDER BY language = 'DK' desc, language like '%DE' desc, language;
Yep, someday I'll remember that 0 is less than 1. ;)
From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: ORDER BY 'DK', 'DE', DESC? |
Date: | 2004-05-20 22:10:48 |
Message-ID: | 8765aqsqaf.fsf@stark.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Adam Ruth <aruth(at)intercation(dot)com> writes:
> Due to the sorting of boolean values, you'd need:
>
> ORDER BY language = 'DK' desc, language like '%DE' desc, language;
Personally I find something like this clearer:
ORDER BY (CASE WHEN language = 'DK' THEN 1
WHEN language like '%DE' THEN 2
WHEN ...
ELSE 5
END
)
--
greg
From: | Adam Ruth <aruth(at)intercation(dot)com> |
---|---|
To: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org, Victor Spång Arthursson <scooterbabe(at)home(dot)se> |
Subject: | Re: ORDER BY 'DK', 'DE', DESC? |
Date: | 2004-05-21 13:57:10 |
Message-ID: | C0DDCF42-AB2E-11D8-B784-000A959D1424@intercation.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On May 20, 2004, at 12:19 PM, Stephan Szabo wrote:
>
> On Thu, 20 May 2004, Adam Ruth wrote:
>
>>
>> On May 20, 2004, at 11:20 AM, Stephan Szabo wrote:
>>
>>> On Tue, 11 May 2004, [ISO-8859-1] Victor Spång Arthursson wrote:
>>>
>>>> Hi!
>>>>
>>>> I would like to know if it's possible to give a priority order of
>>>> how
>>>> to sort the returning rows?
>>>>
>>>> Like for example to order every row with a field language = DK
>>>> first,
>>>> then the rows with field language = *DE' and last the other
>>>> languages,
>>>> ordered alphabetically…?
>>>
>>> Well, I think you can do something like:
>>>
>>> ORDER BY (language = 'DK'), (language = 'DE'), language
>>>
>>> (or you could possibly condense the first two into one with case)
>>
>> Due to the sorting of boolean values, you'd need:
>>
>> ORDER BY language = 'DK' desc, language like '%DE' desc, language;
>
> Yep, someday I'll remember that 0 is less than 1. ;)
>
I only remember it after I try it once and wonder why my trues are at
the bottom!
Adam Ruth