Re: MAP syntax for arrays

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Chapman Flack <chap(at)anastigmatix(dot)net>, Ildar Musin <i(dot)musin(at)postgrespro(dot)ru>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: MAP syntax for arrays
Date: 2018-05-08 15:06:13
Message-ID: 1534.1525791973@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
> On 5/8/18 10:18, Alvaro Herrera wrote:
>> How would you invoke it? It seems you'd be forced to use EXECUTE in a
>> plpgsql function, or a C function.

> Yes, I was thinking about a C function.

The thing actually implementing MAP would presumably be in C,
so this doesn't seem like a problem technically. But having to
create a function seems like a big usability stumbling block,
probably a big enough one to make the "select array_agg(expression)
from unnest(something)" approach more attractive.

I do see the usability benefit of a dedicated MAP syntax --- I'm
just afraid of getting out in front of the SQL committee on such
things. I doubt that it's enough nicer than the sub-select way
to justify risking future standards-compliance issues.

Realistically, we're talking about this:

select a, b, (select array_agg(x*2) from unnest(arraycol) x)
from ...

versus something on the order of this:

select a, b, map(x*2 over x from arraycol)
from ...

Yeah, it's a bit shorter, but not that much ... and there's a lot
more you can do with the sub-select syntax, eg add a WHERE filter.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul Howells 2018-05-08 15:10:59 SQL:2011 Valid-Time Support
Previous Message Alvaro Herrera 2018-05-08 14:55:11 Re: cannot drop replication slot if server is running in single-user mode