Re: Overriding natural order of query results for a subset - Mailing list pgsql-general

From Tom Lane
Subject Re: Overriding natural order of query results for a subset
Date
Msg-id 2118122.1622307354@sss.pgh.pa.us
Whole thread Raw
In response to Re: Overriding natural order of query results for a subset  (Michael Nolan <htfoot@gmail.com>)
Responses Re: Overriding natural order of query results for a subset
List pgsql-general
Michael Nolan <htfoot@gmail.com> writes:
> You probably need some kind order by case when .... else .... end clause,
> where the else clause deals with the non-VIPs, probably negating the need
> for a nulls last clause.

The idiomatic way to do this, assuming that you create an "is_vip bool"
field or some other way to identify VIPs accurately, is

    ORDER BY is_vip DESC, last_name, first_name

relying on the fact that bool TRUE > bool FALSE.

            regards, tom lane



pgsql-general by date:

Previous
From: Michael Nolan
Date:
Subject: Re: Overriding natural order of query results for a subset
Next
From: Laura Smith
Date:
Subject: Re: Overriding natural order of query results for a subset