Re: Overriding natural order of query results for a subset

From: Laura Smith <n5d9xq3ti233xiyif2vp(at)protonmail(dot)ch>
To: Michael van der Kolff <mvanderkolff(at)gmail(dot)com>
Cc: postgre <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Overriding natural order of query results for a subset
Date: 2021-05-29 16:00:32
Message-ID: -SUYhuDsvySdITV3ZKJdoJiEptMDao8UXUhPciG6w44VDFv4Nkf3-PdFh8FGBA1PGox20pS3Z4uXBtWA3VDGdH62_J5ZDGhJH8VjUJqXuxU=@protonmail.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I did try "nulls last" but will give it another go, maybe I messed up on the ordering of clauses.

Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, 29 May 2021 15:23, Michael van der Kolff <mvanderkolff(at)gmail(dot)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(at)protonmail(dot)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 (sometimes but 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 assigning everyone an order is neither practical or desirable.  Hence the need for an "override" which would mean only a subset of people would need specific parameters.
> >
> > Any ideas ?
> >
> > Thanks !
> >
> > Laura

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2021-05-29 16:06:00 Re: Overriding natural order of query results for a subset
Previous Message Vijaykumar Jain 2021-05-29 15:16:44 Re: WAL accumulating, Logical Replication pg 13