Re: sort output per alpha-numeric?

From: Gavan Schneider <list(dot)pg(dot)gavan(at)pendari(dot)org>
To: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Cc: Sbob <sbob(at)quadratum-braccas(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Subject: Re: sort output per alpha-numeric?
Date: 2021-12-01 23:35:26
Message-ID: 3ADA4F64-1223-44EF-97E1-0BCA1D9A643F@pendari.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 2 Dec 2021, at 9:50, David G. Johnston wrote:

> On Wed, Dec 1, 2021 at 3:38 PM Sbob <sbob(at)quadratum-braccas(dot)com>
> wrote:
>
>> I want the displayed print\_size to be ordered by size (8x10, then
>> 11x14, etc)
>>
>> Is there an easy way to do this?
>
>
> You can sort by an expression. For the data as shown the following
> should
>
A little more heavy handed might be to convert the two numbers into a
single integer for ranking, e.g.,

CREATE OR REPLACE FUNCTION image_size_rank ( spec TEXT )
RETURNS INTEGER
LANGUAGE SQL
AS
$$
SELECT
1000 * substring( spec from '^([0-9]+)x.*' )::INTEGER
+ substring( spec from '^[0-9]+x([0-9]+)$' )::INTEGER
;
$$;

so —

pendari=# SELECT image_size_rank ('19x14');
image_size_rank
-----------------
19014
(1 row)

Another wrinkle in the human versus data domain is to constrain the
print size specifications so the 1st dimension is always equal to or
smaller(/larger) than the second (unless the order of the dimensions is
relevant to orientation).

The code snippet above makes 8x10 different to 10x8 but most of us who
did prints in wet baths would consider them them equal.

Gavan Schneider
+61 405 124 883
dr(dot)gavan(dot)schneider(at)pendari(dot)net

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David G. Johnston 2021-12-01 23:55:47 Re: sort output per alpha-numeric?
Previous Message David G. Johnston 2021-12-01 23:24:09 Re: sort output per alpha-numeric?