Re: Sort question - Fractions, Metric etc

From: "Gogala, Mladen" <gogala(dot)mladen(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Sort question - Fractions, Metric etc
Date: 2021-08-14 19:51:06
Message-ID: 702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guyren Howe 2021-08-14 20:13:21 Re: Sort question - Fractions, Metric etc
Previous Message Adrian Klaver 2021-08-14 17:41:28 Re: Understaning postgresql instance vs database