Re: MAP syntax for arrays

2018-07-19 Thread Heikki Linnakangas
On 08/05/18 18:11, Ildar Musin wrote: On 08.05.2018 17:15, Peter Eisentraut wrote: On 5/8/18 09:19, Chapman Flack wrote: On 05/08/2018 08:57 AM, Ildar Musin wrote: select map (pow(2, x) - 1 for x in array[1,2,3,4,5]); I wonder how efficient an implementation would be possible strictly as a

Re: MAP syntax for arrays

2018-05-08 Thread Alvaro Herrera
Andrew Gierth wrote: > > "Andreas" == Andreas Karlsson writes: > > Andreas> It would be a pain if the SQL committee started using MAP for > Andreas> something. > > They already did - MAP is a non-reserved keyword in sql2016, used at > least with . Can't see any obvious > conflict with use

Re: MAP syntax for arrays

2018-05-08 Thread Ildar Musin
On 08.05.2018 17:15, Peter Eisentraut wrote: On 5/8/18 09:19, Chapman Flack wrote: On 05/08/2018 08:57 AM, Ildar Musin wrote: select map (pow(2, x) - 1 for x in array[1,2,3,4,5]); I wonder how efficient an implementation would be possible strictly as a function, without grammar changes?

Re: MAP syntax for arrays

2018-05-08 Thread Tom Lane
Peter Eisentraut 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'

Re: MAP syntax for arrays

2018-05-08 Thread Peter Eisentraut
On 5/8/18 10:18, Alvaro Herrera wrote: > Peter Eisentraut wrote: >> On 5/8/18 09:19, Chapman Flack wrote: >>> On 05/08/2018 08:57 AM, Ildar Musin wrote: select map (pow(2, x) - 1 for x in array[1,2,3,4,5]); >>> >>> I wonder how efficient an implementation would be possible strictly >>> as

Re: MAP syntax for arrays

2018-05-08 Thread Andrew Gierth
> "Andreas" == Andreas Karlsson writes: Andreas> It would be a pain if the SQL committee started using MAP for Andreas> something. They already did - MAP is a non-reserved keyword in sql2016, used at least with . Can't see any obvious conflict with use in expressions, but I haven't checked

Re: MAP syntax for arrays

2018-05-08 Thread Andreas Karlsson
On 05/08/2018 02:49 PM, Ildar Musin wrote: The main point of this patch was about convenience; the performance thing came out later just as a side effect :) Many users are familiar with "map/reduce/filter" concept that many languages (not only functional ones) utilized. And my though was that it

Re: MAP syntax for arrays

2018-05-08 Thread Alvaro Herrera
Peter Eisentraut wrote: > On 5/8/18 09:19, Chapman Flack wrote: > > On 05/08/2018 08:57 AM, Ildar Musin wrote: > >> > >> select map (pow(2, x) - 1 for x in array[1,2,3,4,5]); > > > > I wonder how efficient an implementation would be possible strictly > > as a function, without grammar changes? >

Re: MAP syntax for arrays

2018-05-08 Thread Peter Eisentraut
On 5/8/18 09:19, Chapman Flack wrote: > On 05/08/2018 08:57 AM, Ildar Musin wrote: >> >> select map (pow(2, x) - 1 for x in array[1,2,3,4,5]); > > I wonder how efficient an implementation would be possible strictly > as a function, without grammar changes? Yeah, you can pass a function to another

Re: MAP syntax for arrays

2018-05-08 Thread Chapman Flack
On 05/08/2018 09:19 AM, Chapman Flack wrote: > > While PostgreSQL certainly has extensions to and divergences from > standard SQL syntax, some historical and some recent, it seems like > there ought to be a highish bar for adding new ones; or, looking at it > another way, has this feature been pro

Re: MAP syntax for arrays

2018-05-08 Thread Chapman Flack
On 05/08/2018 08:57 AM, Ildar Musin wrote: > > select map (pow(2, x) - 1 for x in array[1,2,3,4,5]); I wonder how efficient an implementation would be possible strictly as a function, without grammar changes? While PostgreSQL certainly has extensions to and divergences from standard SQL syntax,

Re: MAP syntax for arrays

2018-05-08 Thread Ildar Musin
On 08.05.2018 15:49, Ildar Musin wrote: select map (pow(x, 2) - 1 for x in array[1,2,3]); Sorry, the example should be: select map (pow(2, x) - 1 for x in array[1,2,3,4,5]); ?column? --- {1,3,7,15,31} (1 row) -- Ildar Musin i.mu...@postgrespro.ru

Re: MAP syntax for arrays

2018-05-08 Thread Ildar Musin
Hello Tom, Ashutosh, On 07.05.2018 18:16, Tom Lane wrote: Ashutosh Bapat writes: Is there a way we can improve unnest() and array_agg() to match the performance you have specified by let's say optimizing the cases specially when those two are used together. Identifying that may be some work, b

Re: MAP syntax for arrays

2018-05-07 Thread Tom Lane
Ashutosh Bapat writes: > Is there a way we can improve unnest() and array_agg() to match the > performance you have specified by let's say optimizing the cases > specially when those two are used together. Identifying that may be > some work, but will not require introducing new syntax. +1. The

Re: MAP syntax for arrays

2018-05-07 Thread Ashutosh Bapat
On Fri, May 4, 2018 at 6:38 PM, Ildar Musin wrote: > Hello hackers, > > Recently I was working with sql arrays in postgres and it turned out > that postgres doesn't have such very convinient functional constructions > as map, reduce and filter. Currently to map function over array user has > to ma

MAP syntax for arrays

2018-05-04 Thread Ildar Musin
Hello hackers, Recently I was working with sql arrays in postgres and it turned out that postgres doesn't have such very convinient functional constructions as map, reduce and filter. Currently to map function over array user has to make a subquery like: select u.* from my_table,