On 2 Dec 2021, at 9:50, David G. Johnston wrote:
On Wed, Dec 1, 2021 at 3:38 PM Sbob <sbob@xxxxxxxxxxxxxxxxxxxxx> 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.gavan.schneider@xxxxxxxxxxx