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

From Adrian Klaver
Subject Re: Overriding natural order of query results for a subset
Date
Msg-id 9d147c65-6476-2e15-7f57-6b3f2967532a@aklaver.com
Whole thread Raw
In response to Re: Overriding natural order of query results for a subset  (Laura Smith <n5d9xq3ti233xiyif2vp@protonmail.ch>)
Responses Re: Overriding natural order of query results for a subset
List pgsql-general
On 5/29/21 9:00 AM, Laura Smith wrote:
> I did try "nulls last" but will give it another go, maybe I messed up on the ordering of clauses.

Unless the fields you are ordering on contain NULLs I'm not sure how 
this is going to deal with your issue.

> 
> Sent with ProtonMail Secure Email.
> 
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Saturday, 29 May 2021 15:23, Michael van der Kolff <mvanderkolff@gmail.com> wrote:
> 
>> Have you considered use of the "nulls last" option in order by
(https://www.postgresql.org/docs/13/queries-order.html)?
>>
>> Alternatively, you could write your own type, with its own ordering primitive 😉
>>
>> On Sun, 30 May 2021, 12:15 am Laura Smith, <n5d9xq3ti233xiyif2vp@protonmail.ch> wrote:
>>
>>> Hi
>>>
>>> I've got a bit of a puzzle that I'm not quite sure how to approach.
>>>
>>> Let's say I've got a table of bios, so :
>>>
>>> create table bios (
>>> first_name text not null,
>>> last_name text not null,
>>> person_title text,
>>> person_short_bio text
>>> );
>>>
>>> Now, the "natural order" would be a standard "select * from bios order by last_name".  Basic stuff, no problem.
>>>
>>> The problem is that my use-case calls for a scenario where due to protocol certain people may be designated as
"VIP"and therefore need to appear at the top.  In addition, protocol may dictate that those "VIP" people themselves may
(sometimesbut not always) need to be ordered in a specific manner.
 
>>>
>>> Bear in mind that there may be a large enough number of people in this table that the naïve approach of manually
assigningeveryone an order is neither practical or desirable.  Hence the need for an "override" which would mean only a
subsetof people would need specific parameters.
 
>>>
>>> Any ideas ?
>>>
>>> Thanks !
>>>
>>> Laura
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com



pgsql-general by date:

Previous
From: Laura Smith
Date:
Subject: Re: Overriding natural order of query results for a subset
Next
From: Adrian Klaver
Date:
Subject: Re: AWS forcing PG upgrade from v9.6 a disaster