Re: sort output per alpha-numeric?
От | Gavan Schneider |
---|---|
Тема | Re: sort output per alpha-numeric? |
Дата | |
Msg-id | 3ADA4F64-1223-44EF-97E1-0BCA1D9A643F@pendari.org обсуждение исходный текст |
Ответ на | Re: sort output per alpha-numeric? ("David G. Johnston" <david.g.johnston@gmail.com>) |
Ответы |
Re: sort output per alpha-numeric?
|
Список | pgsql-admin |
On 2 Dec 2021, at 9:50, David G. Johnston wrote:
On Wed, Dec 1, 2021 at 3:38 PM Sbob <sbob@quadratum-braccas.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.gavan.schneider@pendari.net
В списке pgsql-admin по дате отправления: