Re: [PATCH] regexp_positions ( string text, pattern text, flags text ) → setof int4range[]

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Joel Jacobson <joel(at)compiler(dot)org>
Cc: Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, David Fetter <david(at)fetter(dot)org>, Gilles Darold <gilles(at)darold(dot)net>
Subject: Re: [PATCH] regexp_positions ( string text, pattern text, flags text ) → setof int4range[]
Date: 2021-03-05 15:19:44
Message-ID: f50a9299-460c-297a-dbe9-1f96c86326f7@proxel.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 3/4/21 4:40 PM, Tom Lane wrote:
> I wonder if a 2-D integer array wouldn't be a better idea,
> ie {{startpos1,length1},{startpos2,length2},...}. My experience
> with working with parallel arrays in SQL has been unpleasant.

Hm, I can see your point but on the other hand I can't say my
experiences working with 2-D arrays have been that pleasant either. The
main issue being how there is no simple way to unnest just one dimension
of the array. Maybe it would be worth considering implementing a
function for that.

As far as I know to unnest just one dimension you would need to use
generate_series() or something like the query below. Please correct me
if I am wrong and there is some more ergonomic way to do it.

WITH d (a) AS (SELECT '{{2,3},{4,5}}'::int[])
SELECT array_agg(unnest) FROM d, unnest(a) WITH ORDINALITY GROUP BY
(ordinality - 1) / array_length(a, 2);

Andreas

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2021-03-05 15:32:07 Re: shared-memory based stats collector
Previous Message Tom Lane 2021-03-05 14:48:43 Re: Which PG version does CVE-2021-20229 affected?