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

From: salah jubeh <s_jubeh(at)yahoo(dot)com>
To: Susan Cassidy <susan(dot)cassidy(at)decisionsciencescorp(dot)com>, "pgsql-general(at)postgresql(dot)org" <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 19:23:21
Message-ID: 1391455401.3351.YahooMailNeo@web164806.mail.gq1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hello ,

The case Syntax is not correct , have a look here
http://www.postgresql.org/docs/current/static/functions-conditional.html

Furthermore; I think,  this will not ensure the order of root 3, root 4 and root 5 as well as scene1,...

Regards

On Monday, February 3, 2014 7:55 PM, Susan Cassidy <susan(dot)cassidy(at)decisionsciencescorp(dot)com> wrote:

I have a column that contains items like
'absolute root'
'root 3'
'root 4'
'root 5'

'scene 1'
'scene 2'
'scene 3'

and I would like them to sort in that order.

I tried:
select sti.description, sc.description from scene_thing_instances sti join scenes sc on sti.scene_id = sc.scene_id
  order by CASE sc.description
            when (sc.description = 'absolute root'::text) then 1
            when (sc.description ilike 'root%') then  2
            else 3
           END;

I was starting with this, and was going to add perhaps another case statement.

But it gives me:
ERROR:  operator does not exist: text = boolean
LINE 3:             when (sc.description = 'absolute root'::text) th...
                    ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

I don't understand this because description is a text column, not boolean, and certainly 'absolute root'::text is a text string.

This is 9.2.

Ideas, anyone?

Thanks,
Susan

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Susan Cassidy 2014-02-03 20:01:53 Re: way to custom sort column by fixed strings, then by field's content
Previous Message George Woodring 2014-02-03 19:16:55 Server hanging with high CPU wait -- Checkpoint issue?