Re: way to custom sort column by fixed strings, then by field's content

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: way to custom sort column by fixed strings, then by field's content
Date: 2014-02-03 20:36:38
Message-ID: 52EFFDD6.8020508@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/03/2014 01:22 PM, Adrian Klaver wrote:
> On 02/03/2014 12:01 PM, Susan Cassidy wrote:
>
> CCing the list.
>
>> This didn't sort the way I want. It ended up as:
>> description | description
>> -------------------+-------------
>> 18 cm long wrench | Scene 1
>> absolute root |
>> blue screwdriver | Scene 1
>> red toolbox | Scene 1
>> root 3 | Scene 1
>> root 4 | Scene 2
>> root 6 | Scene 3
>> small wrench | Scene 1
>> tire | Scene 2
>>
>>
>> The first column is the one I want sorted.
>
> Probably best to show us a made up sample of what you want.
>
>>
>> Also note that I made it a left outer join\
>
> Where?
>
>>
>> Susan
>>
>
>
>

Is this what you're after?
select s.s1, s.s2, ( CASE
when (s.s1 = 'absolute root'::text) then 1
when (s.s1 ~* '^root%') then 2
else 3
END) as v
from scripts as s
order by v,s1;
s1 | s2 | v
-------------------+---------+---
absolute root | | 1
18 cm long wrench | Scene 1 | 3
blue screwdriver | Scene 1 | 3
red toolbox | Scene 1 | 3
root 3 | Scene 1 | 3
root 4 | Scene 2 | 3
root 6 | Scene 3 | 3
small wrench | Scene 1 | 3
tire | Scene 2 | 3
(9 rows)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2014-02-03 20:39:39 Re: way to custom sort column by fixed strings, then by field's content
Previous Message Jeff Janes 2014-02-03 20:35:25 Re: Server hanging with high CPU wait -- Checkpoint issue?