Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]

Lists: pgsql-hackers
From: Decibel! <decibel(at)decibel(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-07 22:47:43
Message-ID: 20070807224743.GY25704@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

ISTM that having a built-in array_to_set function would be awfully
useful... Is the aggregate method below an acceptable way to do it?

----- Forwarded message from Merlin Moncure <mmoncure(at)gmail(dot)com> -----
On 8/3/07, Guy Fraser <guy(at)incentre(dot)net> wrote:
> On Wed, 2007-08-01 at 07:14 +0530, Merlin Moncure wrote:
> > On 8/1/07, Decibel! <decibel(at)decibel(dot)org> wrote:
> > > David Fetter and I just came up with these, perhaps others will find
> > > them useful:
> > >
> > > CREATE OR REPLACE FUNCTION array_to_set(anyarray, int) RETURNS SETOF anyelement LANGUAGE SQL AS $$
> > > SELECT $1[i] from generate_series(array_lower($1, $2), array_upper($1, $2)) i
> > > $$;
> > > CREATE OR REPLACE FUNCTION array_to_set(anyarray) RETURNS SETOF anyelement LANGUAGE SQL AS $$
> > > SELECT array_to_set($1, 1)
> > > $$;
> >
> > very nice, although IMO there is a strong justification for these
> > functions to be in core and written in C for efficiency (along with
> > array_accum, which I have hand burn from copying and pasting out of
> > the documentation).
> >
> > merlin
> >
> Excellent timing guys. :^)
>
> I was trying to build a function to list the items of an array, but
> ran into problems and was going to post what I had been working on.
>
> Your functions work great.
>
> In case you don't have the function to generate an array from a set
> here is one I have been using :
>
>
> CREATE AGGREGATE array_accum (
> BASETYPE = anyelement,
> SFUNC = array_append,
> STYPE = anyarray,
> INITCOND = '{}'
> );

I think that's what just about everyone uses. Unfortunately the
reverse of the function (array_to_set above) AFAIK does not map
directly to the C array API.

merlin

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

----- End forwarded message -----

--
Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Jeremy Drake <pgsql(at)jdrake(dot)com>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-08 05:18:32
Message-ID: Pine.BSO.4.64.0708072214440.27513@resin.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, 7 Aug 2007, Decibel! wrote:

> ISTM that having a built-in array_to_set function would be awfully
> useful... Is the aggregate method below an acceptable way to do it?

Umm, the array_to_set function is not an aggregate. Personally, when I
need this functionality, I use this function conveniently present in the
default install:

select * from information_schema._pg_expandarray(ARRAY['foo', 'bar', 'baz']);
x | n
-----+---
foo | 1
bar | 2
baz | 3
(3 rows)

Not exactly well documented or well known, but it works.

>
> ----- Forwarded message from Merlin Moncure <mmoncure(at)gmail(dot)com> -----
> On 8/3/07, Guy Fraser <guy(at)incentre(dot)net> wrote:
> > On Wed, 2007-08-01 at 07:14 +0530, Merlin Moncure wrote:
> > > On 8/1/07, Decibel! <decibel(at)decibel(dot)org> wrote:
> > > > David Fetter and I just came up with these, perhaps others will find
> > > > them useful:
> > > >
> > > > CREATE OR REPLACE FUNCTION array_to_set(anyarray, int) RETURNS SETOF anyelement LANGUAGE SQL AS $$
> > > > SELECT $1[i] from generate_series(array_lower($1, $2), array_upper($1, $2)) i
> > > > $$;
> > > > CREATE OR REPLACE FUNCTION array_to_set(anyarray) RETURNS SETOF anyelement LANGUAGE SQL AS $$
> > > > SELECT array_to_set($1, 1)
> > > > $$;
> > >
> > > very nice, although IMO there is a strong justification for these
> > > functions to be in core and written in C for efficiency (along with
> > > array_accum, which I have hand burn from copying and pasting out of
> > > the documentation).
> > >
> > > merlin
> > >
> > Excellent timing guys. :^)
> >
> > I was trying to build a function to list the items of an array, but
> > ran into problems and was going to post what I had been working on.
> >
> > Your functions work great.
> >
> > In case you don't have the function to generate an array from a set
> > here is one I have been using :
> >
> >
> > CREATE AGGREGATE array_accum (
> > BASETYPE = anyelement,
> > SFUNC = array_append,
> > STYPE = anyarray,
> > INITCOND = '{}'
> > );
>
> I think that's what just about everyone uses. Unfortunately the
> reverse of the function (array_to_set above) AFAIK does not map
> directly to the C array API.
>
> merlin
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>
>
> ----- End forwarded message -----
>
>

--
Mollison's Bureaucracy Hypothesis:
If an idea can survive a bureaucratic review and be implemented
it wasn't worth doing.


From: Decibel! <decibel(at)decibel(dot)org>
To: Jeremy Drake <pgsql(at)jdrake(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-08 16:41:04
Message-ID: 20070808164104.GF20424@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Aug 07, 2007 at 10:18:32PM -0700, Jeremy Drake wrote:
> On Tue, 7 Aug 2007, Decibel! wrote:
>
> > ISTM that having a built-in array_to_set function would be awfully
> > useful... Is the aggregate method below an acceptable way to do it?
>
> Umm, the array_to_set function is not an aggregate. Personally, when I

Sorry, should have been more clear... array_to_set as shown below isn't,
but array_accum is, and does the opposite (set_to_array).

> need this functionality, I use this function conveniently present in the
> default install:
>
> select * from information_schema._pg_expandarray(ARRAY['foo', 'bar', 'baz']);
> x | n
> -----+---
> foo | 1
> bar | 2
> baz | 3
> (3 rows)
>
> Not exactly well documented or well known, but it works.

Worse than that, that's something that's entirely internal and could
change at any release. The fact that it exists for info_schema indicates
further need for these functions to exist in the backend.

> >
> > ----- Forwarded message from Merlin Moncure <mmoncure(at)gmail(dot)com> -----
> > On 8/3/07, Guy Fraser <guy(at)incentre(dot)net> wrote:
> > > On Wed, 2007-08-01 at 07:14 +0530, Merlin Moncure wrote:
> > > > On 8/1/07, Decibel! <decibel(at)decibel(dot)org> wrote:
> > > > > David Fetter and I just came up with these, perhaps others will find
> > > > > them useful:
> > > > >
> > > > > CREATE OR REPLACE FUNCTION array_to_set(anyarray, int) RETURNS SETOF anyelement LANGUAGE SQL AS $$
> > > > > SELECT $1[i] from generate_series(array_lower($1, $2), array_upper($1, $2)) i
> > > > > $$;
> > > > > CREATE OR REPLACE FUNCTION array_to_set(anyarray) RETURNS SETOF anyelement LANGUAGE SQL AS $$
> > > > > SELECT array_to_set($1, 1)
> > > > > $$;
> > > >
> > > > very nice, although IMO there is a strong justification for these
> > > > functions to be in core and written in C for efficiency (along with
> > > > array_accum, which I have hand burn from copying and pasting out of
> > > > the documentation).
> > > >
> > > > merlin
> > > >
> > > Excellent timing guys. :^)
> > >
> > > I was trying to build a function to list the items of an array, but
> > > ran into problems and was going to post what I had been working on.
> > >
> > > Your functions work great.
> > >
> > > In case you don't have the function to generate an array from a set
> > > here is one I have been using :
> > >
> > >
> > > CREATE AGGREGATE array_accum (
> > > BASETYPE = anyelement,
> > > SFUNC = array_append,
> > > STYPE = anyarray,
> > > INITCOND = '{}'
> > > );
> >
> > I think that's what just about everyone uses. Unfortunately the
> > reverse of the function (array_to_set above) AFAIK does not map
> > directly to the C array API.
> >
> > merlin
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 9: In versions below 8.0, the planner will ignore your desire to
> > choose an index scan if your joining column's datatypes do not
> > match
> >
> >
> > ----- End forwarded message -----
> >
> >
>
> --
> Mollison's Bureaucracy Hypothesis:
> If an idea can survive a bureaucratic review and be implemented
> it wasn't worth doing.
>

--
Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-08 17:03:34
Message-ID: 29453D07-814B-4375-B4F2-43E2C1E867DB@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Aug 8, 2007, at 11:41 , Decibel! wrote:

> On Tue, Aug 07, 2007 at 10:18:32PM -0700, Jeremy Drake wrote:

>> select * from information_schema._pg_expandarray(ARRAY['foo',
>> 'bar', 'baz']);
>> x | n
>> -----+---
>> foo | 1
>> bar | 2
>> baz | 3
>> (3 rows)
>>
>> Not exactly well documented or well known, but it works.
>
> Worse than that, that's something that's entirely internal and could
> change at any release. The fact that it exists for info_schema
> indicates
> further need for these functions to exist in the backend.

Personally, I think expandarray is more appropriate and its
functionality probably more generally useful, as it identifies the
array indices as well. Note you can also rename the columns.

select * from information_schema._pg_expandarray(ARRAY['foo', 'bar',
'baz']) as b(a,i);
a | i
-----+---
foo | 1
bar | 2
baz | 3
(3 rows)

array_to_set really isn't, as AFAICS it didn't guarantee element
uniqueness (but that's just a naming issue).

Michael Glaesemann
grzm seespotcode net


From: Decibel! <decibel(at)decibel(dot)org>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-08 17:18:44
Message-ID: 20070808171844.GI20424@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 08, 2007 at 12:03:34PM -0500, Michael Glaesemann wrote:
> Personally, I think expandarray is more appropriate and its
> functionality probably more generally useful, as it identifies the
> array indices as well. Note you can also rename the columns.

Sure. My point is that we should have a way to convert arrays to sets
and back in the backend.
--
Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-08 17:29:43
Message-ID: 8FE363D9-E3A5-41BB-AD85-9D7CBD817EB1@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Aug 8, 2007, at 12:18 , Decibel! wrote:

> On Wed, Aug 08, 2007 at 12:03:34PM -0500, Michael Glaesemann wrote:
>> Personally, I think expandarray is more appropriate and its
>> functionality probably more generally useful, as it identifies the
>> array indices as well. Note you can also rename the columns.
>
> Sure. My point is that we should have a way to convert arrays to sets
> and back in the backend.

Can't really argue with you there, as I find array_accum myself.
(Though I'd still nit-pick that this isn't an array to set
conversion, but rather array to--possibly single-column--table.)

Michael Glaesemann
grzm seespotcode net


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: "Decibel!" <decibel(at)decibel(dot)org>, Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-14 15:05:31
Message-ID: 200708141505.l7EF5VV27340@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


TODO item?

---------------------------------------------------------------------------

Michael Glaesemann wrote:
-- Start of PGP signed section.
>
> On Aug 8, 2007, at 12:18 , Decibel! wrote:
>
> > On Wed, Aug 08, 2007 at 12:03:34PM -0500, Michael Glaesemann wrote:
> >> Personally, I think expandarray is more appropriate and its
> >> functionality probably more generally useful, as it identifies the
> >> array indices as well. Note you can also rename the columns.
> >
> > Sure. My point is that we should have a way to convert arrays to sets
> > and back in the backend.
>
> Can't really argue with you there, as I find array_accum myself.
> (Though I'd still nit-pick that this isn't an array to set
> conversion, but rather array to--possibly single-column--table.)
>
> Michael Glaesemann
> grzm seespotcode net
>
>
-- End of PGP section, PGP failed!

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Michael Glaesemann" <grzm(at)seespotcode(dot)net>, Decibel! <decibel(at)decibel(dot)org>, "Jeremy Drake" <pgsql(at)jdrake(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-14 15:38:33
Message-ID: 162867790708140838n4c0e2625u42168f491513e037@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2007/8/14, Bruce Momjian <bruce(at)momjian(dot)us>:
>
> TODO item?
>
> + If your life is a hard drive, Christ can be your backup. +
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

I am against. It's too simple do it in SQL language.

Regards
Pavel Stehule


From: Joe Conway <mail(at)joeconway(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Michael Glaesemann <grzm(at)seespotcode(dot)net>, "Decibel!" <decibel(at)decibel(dot)org>, Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-14 17:01:55
Message-ID: 46C1E003.2070406@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> TODO item?
>

Probably. See SQL2003 UNNEST:

<collection derived table> ::=
UNNEST <left paren> <collection value expression> <right paren>
[ WITH ORDINALITY ]

<collection value expression> ::=
<array value expression>
| <multiset value expression>

Joe


From: Decibel! <decibel(at)decibel(dot)org>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Michael Glaesemann <grzm(at)seespotcode(dot)net>, Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-14 21:08:27
Message-ID: 20070814210827.GQ54135@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Aug 14, 2007 at 05:38:33PM +0200, Pavel Stehule wrote:
> 2007/8/14, Bruce Momjian <bruce(at)momjian(dot)us>:
> >
> > TODO item?
> >
> > + If your life is a hard drive, Christ can be your backup. +
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: explain analyze is your friend
>
> I am against. It's too simple do it in SQL language.

Why make everyone who works with arrays create a function just to do
this? Something that's of use to common users should be included, simple
or not.
--
Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Michael Glaesemann" <grzm(at)seespotcode(dot)net>, Decibel! <decibel(at)decibel(dot)org>, "Jeremy Drake" <pgsql(at)jdrake(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-15 01:48:34
Message-ID: b42b73150708141848w34db5b0bo807e2b18e5610d65@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 8/14/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>
> TODO item?

I would say yes...array_accum is virtually an essential function when
working with arrays and the suggested array_to_set (and it's built in
cousin, _pg_expand_array) really should not be built around
generate_series when a C function is faster and will scale much
better.

array_to_set, as suggested in SQL, is something only a relative expert
with PostgreSQL could be expected to write.

Thus could generate_series be relieved from providing the only core
function for set returning functions in the documentation. IMO, this
part of the documentation could use some expansion anyways :)

merlin


From: David Fetter <david(at)fetter(dot)org>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Michael Glaesemann <grzm(at)seespotcode(dot)net>, Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-15 04:15:26
Message-ID: 20070815041526.GB12471@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Aug 14, 2007 at 04:08:27PM -0500, Decibel! wrote:
> On Tue, Aug 14, 2007 at 05:38:33PM +0200, Pavel Stehule wrote:
> > 2007/8/14, Bruce Momjian <bruce(at)momjian(dot)us>:
> > >
> > > TODO item?
> > >
> > > + If your life is a hard drive, Christ can be your backup. +
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 6: explain analyze is your friend
> >
> > I am against. It's too simple do it in SQL language.
>
> Why make everyone who works with arrays create a function just to do
> this? Something that's of use to common users should be included, simple
> or not.

As I recall, this wasn't included because it didn't do all of what the
SQL:2003 standard UNNEST does, although looking it over, the only
thing it "doesn't do" is to allow the results to come back in any
order other than the array index's. Sadly, UNNEST would be a new
feature, and we're *way* past that for 8.3 :/

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!
Consider donating to PostgreSQL: http://www.postgresql.org/about/donate


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Michael Glaesemann" <grzm(at)seespotcode(dot)net>, "Jeremy Drake" <pgsql(at)jdrake(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-15 04:47:05
Message-ID: 162867790708142147u3596fd5es802d1b32a9fb1a40@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2007/8/14, Decibel! <decibel(at)decibel(dot)org>:
> On Tue, Aug 14, 2007 at 05:38:33PM +0200, Pavel Stehule wrote:
> > 2007/8/14, Bruce Momjian <bruce(at)momjian(dot)us>:
> > >
> > > TODO item?
> > >
> > > + If your life is a hard drive, Christ can be your backup. +
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 6: explain analyze is your friend
> >
> > I am against. It's too simple do it in SQL language.
>
> Why make everyone who works with arrays create a function just to do
> this? Something that's of use to common users should be included, simple
> or not.
> --

Unpacking array is more SQL construct for me, than SRF function. With
function you cannot conntrol behave of unpacking. With SQL construct I
can

SELECT DISTINCT a(i) FROM generate_series ... remove duplicities
SELECT a(i) FROM generate_series ORDER BY .. sorted output
etc

But I can

SELECT * FROM generate_series(ARRAY[1,3,4,5,7,10]);

else
FUNCTION generate_series(anyarray) returns setof any

Regards
Pavel Stehule


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Michael Glaesemann" <grzm(at)seespotcode(dot)net>, Decibel! <decibel(at)decibel(dot)org>, "Jeremy Drake" <pgsql(at)jdrake(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-15 04:50:44
Message-ID: 162867790708142150m6353f598md7aa0f9988554bee@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2007/8/15, Merlin Moncure <mmoncure(at)gmail(dot)com>:
> On 8/14/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >
> > TODO item?
>
> I would say yes...array_accum is virtually an essential function when
> working with arrays and the suggested array_to_set (and it's built in
> cousin, _pg_expand_array) really should not be built around
> generate_series when a C function is faster and will scale much
> better.
>

Hello Merlin

array_accum is good sample of PostgreSQL possibilities. But it is slow.

SELECT ARRAY(SELECT ... FROM ...)) is much faster. :(

so I unlike not necessary aggregate functions

I agree. These constructs can be showed in doc

Regards
Pavel Stehule


From: Decibel! <decibel(at)decibel(dot)org>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Michael Glaesemann <grzm(at)seespotcode(dot)net>, Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-15 15:06:13
Message-ID: 20070815150613.GA54135@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 15, 2007 at 06:47:05AM +0200, Pavel Stehule wrote:
> 2007/8/14, Decibel! <decibel(at)decibel(dot)org>:
> > On Tue, Aug 14, 2007 at 05:38:33PM +0200, Pavel Stehule wrote:
> > > 2007/8/14, Bruce Momjian <bruce(at)momjian(dot)us>:
> > > >
> > > > TODO item?
> > > >
> > > > + If your life is a hard drive, Christ can be your backup. +
> > > >
> > > > ---------------------------(end of broadcast)---------------------------
> > > > TIP 6: explain analyze is your friend
> > >
> > > I am against. It's too simple do it in SQL language.
> >
> > Why make everyone who works with arrays create a function just to do
> > this? Something that's of use to common users should be included, simple
> > or not.
> > --
>
> Unpacking array is more SQL construct for me, than SRF function. With
> function you cannot conntrol behave of unpacking. With SQL construct I
> can

Huh? You can do a DISTINCT or an ORDER BY on the output of a SRF.

> SELECT DISTINCT a(i) FROM generate_series ... remove duplicities
> SELECT a(i) FROM generate_series ORDER BY .. sorted output
> etc
>
> But I can
>
> SELECT * FROM generate_series(ARRAY[1,3,4,5,7,10]);
>
> else
> FUNCTION generate_series(anyarray) returns setof any
--
Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Michael Glaesemann" <grzm(at)seespotcode(dot)net>, "Jeremy Drake" <pgsql(at)jdrake(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-08-15 16:08:32
Message-ID: 162867790708150908s65a7a404r5544e176ca437ec9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2007/8/15, Decibel! <decibel(at)decibel(dot)org>:
> On Wed, Aug 15, 2007 at 06:47:05AM +0200, Pavel Stehule wrote:
> > 2007/8/14, Decibel! <decibel(at)decibel(dot)org>:
> > > On Tue, Aug 14, 2007 at 05:38:33PM +0200, Pavel Stehule wrote:
> > > > 2007/8/14, Bruce Momjian <bruce(at)momjian(dot)us>:
> > > > >
> > > > > TODO item?
> > > > >
> > > > > + If your life is a hard drive, Christ can be your backup. +
> > > > >
> > > > > ---------------------------(end of broadcast)---------------------------
> > > > > TIP 6: explain analyze is your friend
> > > >
> > > > I am against. It's too simple do it in SQL language.
> > >
> > > Why make everyone who works with arrays create a function just to do
> > > this? Something that's of use to common users should be included, simple
> > > or not.
> > > --
> >
> > Unpacking array is more SQL construct for me, than SRF function. With
> > function you cannot conntrol behave of unpacking. With SQL construct I
> > can
>
> Huh? You can do a DISTINCT or an ORDER BY on the output of a SRF.

Yes, but then you get little bit different my form :)

>
> > SELECT DISTINCT a(i) FROM generate_series ... remove duplicities
> > SELECT a(i) FROM generate_series ORDER BY .. sorted output
> > etc
> >
> > But I can
> >
> > SELECT * FROM generate_series(ARRAY[1,3,4,5,7,10]);
> >
> > else
> > FUNCTION generate_series(anyarray) returns setof any
> --
> Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
> EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)
>
>


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Michael Glaesemann <grzm(at)seespotcode(dot)net>, "Decibel!" <decibel(at)decibel(dot)org>, Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2007-09-14 03:44:11
Message-ID: 200709140344.l8E3iBb16482@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


This has been saved for the 8.4 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Pavel Stehule wrote:
> 2007/8/15, Merlin Moncure <mmoncure(at)gmail(dot)com>:
> > On 8/14/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > >
> > > TODO item?
> >
> > I would say yes...array_accum is virtually an essential function when
> > working with arrays and the suggested array_to_set (and it's built in
> > cousin, _pg_expand_array) really should not be built around
> > generate_series when a C function is faster and will scale much
> > better.
> >
>
> Hello Merlin
>
> array_accum is good sample of PostgreSQL possibilities. But it is slow.
>
> SELECT ARRAY(SELECT ... FROM ...)) is much faster. :(
>
> so I unlike not necessary aggregate functions
>
> I agree. These constructs can be showed in doc
>
> Regards
> Pavel Stehule

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Michael Glaesemann <grzm(at)seespotcode(dot)net>, "Decibel!" <decibel(at)decibel(dot)org>, Jeremy Drake <pgsql(at)jdrake(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [mmoncure@gmail.com: Re: [GENERAL] array_to_set functions]
Date: 2008-03-12 15:14:39
Message-ID: 200803121514.m2CFEd812654@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Added to TODO:

* Add array_accum() and array_to_set() functions for arrays

http://archives.postgresql.org/pgsql-hackers/2007-08/msg00464.php

---------------------------------------------------------------------------

Merlin Moncure wrote:
> On 8/14/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >
> > TODO item?
>
> I would say yes...array_accum is virtually an essential function when
> working with arrays and the suggested array_to_set (and it's built in
> cousin, _pg_expand_array) really should not be built around
> generate_series when a C function is faster and will scale much
> better.
>
> array_to_set, as suggested in SQL, is something only a relative expert
> with PostgreSQL could be expected to write.
>
> Thus could generate_series be relieved from providing the only core
> function for set returning functions in the documentation. IMO, this
> part of the documentation could use some expansion anyways :)
>
> merlin
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +