Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mF02S-0001Vz-Qb for pgsql-general@arkaria.postgresql.org; Sat, 14 Aug 2021 20:13:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mF02R-0007NI-KV for pgsql-general@arkaria.postgresql.org; Sat, 14 Aug 2021 20:13:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mF02R-0007N9-8m for pgsql-general@lists.postgresql.org; Sat, 14 Aug 2021 20:13:51 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mF02L-0006U4-DX for pgsql-general@lists.postgresql.org; Sat, 14 Aug 2021 20:13:49 +0000 Received: by mail-pj1-x1035.google.com with SMTP id gz13-20020a17090b0ecdb0290178c0e0ce8bso15166730pjb.1 for ; Sat, 14 Aug 2021 13:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:message-id:in-reply-to:references:subject:mime-version; bh=2hT5PumNMKsKjjyGQvNLQ4bJS7tTqKsgbyALknSfg0w=; b=tx3I5anS4kYY9eVef78upjwGK2mNHT8vt+yLSDNW8MAthvy7FcOhe4FR2p+xyV9Cty dhrBvvpwfXFYYGQB+qwZROpOScyRiCPW1BjQBa9phq4KJiKzauZTnNEVJhhwe3+jQm2F P6jO2ChPz+njsCVeRiLdVyGwVP7T7y917x9eJybG3gZL38JD4qMiv3b17RkTecGQ3cLy S4q5aPOVdynfgdVyXJZDPiarbjgrUKCxFaSeyXoLTJ+a85tdKm/tgMhdKhZReOgeLxy+ whyUYb030TlCxT6OaX6CKzXwa30t8BiX8zwbc6eMurRnUiQI/5gTAUoAtQSfzDcuCb+V hv2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:message-id:in-reply-to:references :subject:mime-version; bh=2hT5PumNMKsKjjyGQvNLQ4bJS7tTqKsgbyALknSfg0w=; b=DAZMUx6FIX2nqTH3RThiW8i9q+HCEy8oJ3MsYqyH1HEItISK+TAoDifUUhVGZRcGFN uDVxE0ElroVTK/h+VTi8BR4GYv9ZPUTO2BDPMXVfHGEcC7AEZVi1NQL+lRMHdUWf1wH+ c8JHjFc77xVxJpVznhGx5Sz+gdJifLRIvd1/ZcrhB1pR4jlxyFQnndmUrq/GjkZ1Oo0n v8yaV017wW/SndB3FtrZDnwEs1t0v+vh/3Z0JHIXQ5GBzuUTKexxWlKauEeGWVfv+QMo JPjyt1k6+ZSp+TDkZlfCLFkTTWias/IBEXHWQyWu2BysqWdIJivq9sda6mbGf0yxVvRS AIrw== X-Gm-Message-State: AOAM530TXmDq1S997U6rKaWic9P0ktlGs1SaeFcj0Q/0MWC5q4DfnuUq qAw0iYg4HJa4rpnFJu/HHewdf8lQBBXHxQ== X-Google-Smtp-Source: ABdhPJwvPFFLOgitKwchJ/ClesRsgrS2rSP32tksrvHx6sGiyXq6pUPV+wmXrP/swiPhnLPaTY6/Qw== X-Received: by 2002:a62:7f09:0:b029:3c8:584:72d with SMTP id a9-20020a627f090000b02903c80584072dmr8425953pfd.80.1628972022720; Sat, 14 Aug 2021 13:13:42 -0700 (PDT) Received: from [2600:8801:8800:5:100::] ([2600:8801:8800:5::3]) by smtp.gmail.com with ESMTPSA id z131sm6721900pfc.159.2021.08.14.13.13.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Aug 2021 13:13:42 -0700 (PDT) Date: Sat, 14 Aug 2021 13:13:21 -0700 From: Guyren Howe To: pgsql-general@lists.postgresql.org, =?utf-8?Q?Gogala=2C_Mladen?= Message-ID: <15d19116-d71c-46f9-a438-2db929f53c9a@Spark> 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> Subject: Re: Sort question - Fractions, Metric etc X-Readdle-Message-ID: 15d19116-d71c-46f9-a438-2db929f53c9a@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="611823f4_1f16e9e8_4c35" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --611823f4_1f16e9e8_4c35 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline You might define new types for temperature, length, whatever, with suitab= le conversion, operation and creation functions. You=E2=80=99d be able to= define how the new types participate in indexes, support directly sortin= g on them, so you package up this complexity and forget about it. Either normalize everything to metric on creation, or have an enumeration= or boolean flag to indicate whether the value is metric or imperial (cho= ose this one if you want values to remember how they were created and thu= s how they will display, and to avoid rounding errors converting back to = imperial for display). Depends how many places you use them whether this is worth it. But it wou= ld be a good way to make this complexity idiot-proof if you=E2=80=99ll be= using it all over. You=E2=80=99d be able to just add and multiply length= s and such without worrying how they were specified. Looks like this might do what you need on cursory examination:=C2=A0https= ://github.com/df7cb/postgresql-unit On Aug 14, 2021, 12:51 -0700, Gogala, Mladen ,= wrote: > 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 =22STABLE=22)=C2=A0 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=5Fcolumn and sorted based > > > > on those values eg; 1,2,3,4,5,6 indicating the value I need to show i= n > > which sequence. > > > > > > Just curious what the pro's do > > > > Bret > > > > > -- > Mladen Gogala > Oracle DBA > Tel: (347) 321-1217 > Blog: https://dbwhisperer.wordpress.com > > --611823f4_1f16e9e8_4c35 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
You might define new types for temperature, length,= whatever, with suitable conversion, operation and creation functions. Yo= u=E2=80=99d be able to define how the new types participate in indexes, s= upport directly sorting on them, so you package up this complexity and fo= rget about it.

Either normalize everything to metric on creation, or have an enumeration= or boolean flag to indicate whether the value is metric or imperial (cho= ose this one if you want values to remember how they were created and thu= s how they will display, and to avoid rounding errors converting back to = imperial for display).

Depends how many places you use them whether this is worth it. But it wou= ld be a good way to make this complexity idiot-proof if you=E2=80=99ll be= using it all over. You=E2=80=99d be able to just add and multiply length= s and such without worrying how they were specified.

Looks like this might do what you need on cursory examination:&=23160;https://github.com/df7cb/postgresql-unit
On Aug 14, 2021, 12:51 -0700, Gogal= a, Mladen <gogala.mladen=40gmail.com>, wrote:
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 =22STABLE=22)&=23160; 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, fract= ion 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=5Fcolumn 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


--611823f4_1f16e9e8_4c35--