pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gogala, Mladen <gogala.mladen@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Sort question - Fractions, Metric etc
Date: Sat, 14 Aug 2021 15:51:06 -0400
Message-ID: <702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com> (raw)
In-Reply-To: <57f60e61-114f-c403-b2e2-820e76f08d64@machinemanagement.com>
References: <57f60e61-114f-c403-b2e2-820e76f08d64@machinemanagement.com>

I would write a stable function converting everything to metric (or 
imperial, depends on your preferences) and sort on the return of the 
function. Since unit conversion functions do not need to modify the 
database and should always return the same values for the same 
arguments, the function can be used within a query (that is the meaning 
of the keyword "STABLE")  and you can use it for sorting stuff

Regards

On 8/14/2021 12:14 PM, Bret Stern wrote:
> I have a table with metric, imperial, fraction columns.
>
> Is there a way to sort correctly using imperial (eg; .125, .375, .437 
> -> 1., 1.125)
>
> Couldn't handle it with ORDER BY ASC, DESC args so I added a 
> sort_column and sorted based
>
> on those values eg; 1,2,3,4,5,6 indicating the value I need to show in 
> which sequence.
>
>
> Just curious what the pro's do
>
> Bret
>
>
-- 
Mladen Gogala
Oracle DBA
Tel: (347) 321-1217
Blog: https://dbwhisperer.wordpress.com





view thread (20+ messages)  latest in thread

Message-ID: <702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com>
Permalink:  ../702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com/
Also on:    postgresql.org/message-id/702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: gogala.mladen@gmail.com
  Subject: Re: Sort question - Fractions, Metric etc
  In-Reply-To: <702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com>
  References: <57f60e61-114f-c403-b2e2-820e76f08d64@machinemanagement.com> <702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox