Re: Sort question - Fractions, Metric etc

2021-08-15 Thread Pól Ua Laoínecháin
> I have a table with metric, imperial, fraction columns. Have "metric_equivalent_magnitude" and "metric_equivalent_unit" columns and do all your sorting via those columns. Use the relatively new generated (or computed/calculated) columns to calculate these. That way, you get the conversion

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Adrian Klaver
On 8/14/21 4:05 PM, Gavan Schneider wrote: On 15 Aug 2021, at 7:47, Bret Stern wrote: I will say this business has been behind in the attributes game. Plus there are many "artsy" vendors who can hardly speak in these terms, and don't publish to us, so we do the best we can. Getting

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Gavan Schneider
On 15 Aug 2021, at 7:47, Bret Stern wrote: > I will say this business has been behind in the attributes game. Plus there > are many "artsy" vendors who can hardly speak in these terms, and don't > publish to us, so we do the best we can. > > Getting vendors to supply the basic values is a

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Adrian Klaver
On 8/14/21 2:47 PM, Bret Stern wrote: On 8/14/2021 2:13 PM, Adrian Klaver wrote: On 8/14/21 2:04 PM, Bret Stern wrote: Vendors supply dimensions, depending on where in the world the product comes from, could be metric, imperial or fraction Yes, nominal dimensions. That is what I'm

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Bret Stern
On 8/14/2021 2:13 PM, Adrian Klaver wrote: On 8/14/21 2:04 PM, Bret Stern wrote: Yep, I provide the UI for the user to select the vendor supplied unit value from the list. I should have been more specific, does the vendor do all the conversions and supply them to you? Vendors supply

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Adrian Klaver
On 8/14/21 2:04 PM, Bret Stern wrote: Yep, I provide the UI for the user to select the vendor supplied unit value from the list. I should have been more specific, does the vendor do all the conversions and supply them to you? I don't want anyone entering (manually) any value, they must

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Bret Stern
Yep, I provide the UI for the user to select the vendor supplied unit value from the list. I don't want anyone entering (manually) any value, they must select from my list (fed from a PG table). (and since some units don't translate exactly, they pick the one that is closest). It's Tile

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Adrian Klaver
On 8/14/21 1:24 PM, Bret Stern wrote: Here's the clip of the UI. The user selects whatever value the vendor provides for unit thickness. The data entry So the vendors supply the measurements in all the various units for a given item? people aren't comfortable converting. At this point

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Guyren Howe
You might define new types for temperature, length, whatever, with suitable conversion, operation and creation functions. You’d be able to define how the new types participate in indexes, support directly sorting on them, so you package up this complexity and forget about it. Either normalize

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Gogala, Mladen
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

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread bret_st...@machinemanagement.com
@lists.postgresql.org Subject: Re: Sort question - Fractions, Metric etc On Sat, 14 Aug 2021 at 19:03, Tom Lane wrote:Adrian Klaver writes: > On 8/14/21 9:37 AM, Bret Stern wrote: >> I haven't explored doing this with numeric types, but some columns >> needed alpha chars eg 13mm.

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Adrian Klaver
On 8/14/21 10:19 AM, Sándor Daku wrote: I'm not sure, but maybe a kind of cast function that cast everything into a reasonable common unit(Khm... millimeters) and sort on that? It seems relatively simple to pick up the value and unit from a string with a regexp. Admittedly the data would

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Sándor Daku
On Sat, 14 Aug 2021 at 19:03, Tom Lane wrote: > Adrian Klaver writes: > > On 8/14/21 9:37 AM, Bret Stern wrote: > >> I haven't explored doing this with numeric types, but some columns > >> needed alpha chars eg 13mm. > > > Two columns: > > > data_val(numeric) data_unit(varchar) > > 13

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Tom Lane
Adrian Klaver writes: > On 8/14/21 9:37 AM, Bret Stern wrote: >> I haven't explored doing this with numeric types, but some columns >> needed alpha chars eg 13mm. > Two columns: > data_val(numeric) data_unit(varchar) > 13mm It sounds like your data is a completely

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Bret Stern
I like that idea On 8/14/2021 9:46 AM, Adrian Klaver wrote: On 8/14/21 9:37 AM, Bret Stern wrote: Strings; I haven't explored doing this with numeric types, but some columns needed alpha chars eg 13mm. Two columns: data_val(numeric)    data_unit(varchar) 13    mm Although I

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Adrian Klaver
On 8/14/21 9:37 AM, Bret Stern wrote: Strings; I haven't explored doing this with numeric types, but some columns needed alpha chars eg 13mm. Two columns: data_val(numeric) data_unit(varchar) 13 mm Although I could have front ended this UI with mm nomenclature

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Bret Stern
Strings; I haven't explored doing this with numeric types, but some columns needed alpha chars eg 13mm. Although I could have front ended this UI with mm nomenclature I did not. I'll put a table together with appropriate numeric types and see if the sort will behave. On 8/14/2021 9:21

Re: Sort question - Fractions, Metric etc

2021-08-14 Thread Adrian Klaver
On 8/14/21 9:14 AM, 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) Alright how is this different from metric or fraction? I can sort of see fraction if you mean as 1/3, 1/20, etc.

Sort question - Fractions, Metric etc

2021-08-14 Thread Bret Stern
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