Re: Sort question - Fractions, Metric etc - Mailing list pgsql-general

From Gogala, Mladen
Subject Re: Sort question - Fractions, Metric etc
Date
Msg-id 702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com
Whole thread Raw
In response to Sort question - Fractions, Metric etc  (Bret Stern <bret_stern@machinemanagement.com>)
Responses Re: Sort question - Fractions, Metric etc
Re: Sort question - Fractions, Metric etc
List 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



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Understaning postgresql instance vs database
Next
From: Guyren Howe
Date:
Subject: Re: Sort question - Fractions, Metric etc