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 1mEzgc-0000wj-7q for pgsql-general@arkaria.postgresql.org; Sat, 14 Aug 2021 19:51:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mEzgZ-0006TC-06 for pgsql-general@arkaria.postgresql.org; Sat, 14 Aug 2021 19:51:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEzgY-0006T4-GG for pgsql-general@lists.postgresql.org; Sat, 14 Aug 2021 19:51:14 +0000 Received: from mail-qv1-xf29.google.com ([2607:f8b0:4864:20::f29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mEzgT-0007o5-B1 for pgsql-general@lists.postgresql.org; Sat, 14 Aug 2021 19:51:13 +0000 Received: by mail-qv1-xf29.google.com with SMTP id q6so4376427qvs.12 for ; Sat, 14 Aug 2021 12:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=7OPfJMVDEiojJU/LfAh8arSIQ4Gdjbf45YmBLnvzSmo=; b=lNey1u2GtvOw6S5mvi5TQBoESYfCT4+I22N7Uqos6RGBZyh8rMU9CTD7Xmzpe+8oTH FFp5E631dZfwvga9X/8saVQA5IZ5VNr+aWc4CPtYlPbWKgF0MsIxuZa7h0oEMYbiwVRG LFaufvfQSynwyxRgQgPh/rjp4O7t+eDYr1Ad4ZxAf7TI+Azs00WNDB7MyC4VoJfNDFQU pcVfstF0XClHPEfAkRxYKlG5f3/L/s7UwSmww0d8rv0Qg0MtyOT4mtfD+AWahZSAyamC +s3uNTt9P+FHoTx54K1ZLLP3/yV+EbmHPQPNbAUssZNxZWB4UubbC2/CeVSQ+pkV0MiG 8hww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=7OPfJMVDEiojJU/LfAh8arSIQ4Gdjbf45YmBLnvzSmo=; b=EDxaEMJvVORzJLewBPP9O2XYjTp7uIrIxJJSPIvETUkZ6cPuK+nH7GveiiJmHX1YL6 DzL8NJyIKKkqX2IDt9XpLfvburmjYGTmw+RQjEGdn6Kqc5Y5M5eoM4Tbskczi/hSDHWZ wPzuxqR4e5NH/YNs9kU53PRjGLuovugQR4Xsb7rrC28gsFIv/FFFQER0a5heDG1bxzwJ pDQCuywRNJB/a7/yI363UA51qBjK6BrSMBcZzSANiu03rLqlYy2+rCv4qg26UAahCdEL qXUtpBXfOroWIu8Fy8jvtm2q61gkJg0pKeEnZoflRdQi+uRO5jtj5gZshg/NwQd2xYYz MZqQ== X-Gm-Message-State: AOAM5320xajp58aYlMi4D3TKaa058GqYC8tK7MysBYt9SrvfNkzJN6Vc uMZX6BLNYpzBUjboQwRaNtN8hmbZ1RM= X-Google-Smtp-Source: ABdhPJypBKfxMP0kNjqqGyaTerVTJ/OxSspRe3uHHW0EVuWzBTbfNextSK22DgnJRNyjdfExccUy0A== X-Received: by 2002:a05:6214:2b09:: with SMTP id jx9mr3553416qvb.54.1628970667622; Sat, 14 Aug 2021 12:51:07 -0700 (PDT) Received: from [172.17.30.110] ([65.196.60.4]) by smtp.gmail.com with ESMTPSA id f17sm3104214qkm.107.2021.08.14.12.51.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Aug 2021 12:51:07 -0700 (PDT) Subject: Re: Sort question - Fractions, Metric etc To: pgsql-general@lists.postgresql.org References: <57f60e61-114f-c403-b2e2-820e76f08d64@machinemanagement.com> From: "Gogala, Mladen" Message-ID: <702e71c6-5091-9c65-87c0-e4599dddd376@gmail.com> Date: Sat, 14 Aug 2021 15:51:06 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <57f60e61-114f-c403-b2e2-820e76f08d64@machinemanagement.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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