Skip site navigation (1) Skip section navigation (2)

array_agg and array_accum (patch)

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: array_agg and array_accum (patch)
Date: 2008-10-26 18:32:17
Message-ID: 1225045937.4434.21.camel@localhost.localdomain (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Here is a patch to support two aggregate functions:

1) ARRAY_AGG() -- SQL 2008 standard behavior, returns NULL on no input, 
and skips NULL inputs. 

2) ARRAY_ACCUM() -- Returns empty array on no input, and includes NULL 

These accumulate the result in a memory context that lives across calls
to the state function, so it's reasonably efficient. On my old laptop it
takes about 5s to generate an array of 1M elements -- not great, but at
least it's linear.

Although array_agg is the standard behavior, array_accum is important
because otherwise you always lose the NULLs, and that's difficult to
work around even with COALESCE. 

I added them as new native functions because ARRAY_AGG is in the
standard, but if others think they should live elsewhere that's fine. I
think that they are generally pretty useful functions for people using

This patch is contributed by Truviso.

	Jeff Davis

Attachment: array_agg.diff.gz
Description: application/x-gzip (1.8 KB)


pgsql-hackers by date

Next:From: Tom LaneDate: 2008-10-26 19:24:57
Subject: Re: BufferAccessStrategy for bulk insert
Previous:From: Tom LaneDate: 2008-10-26 16:44:06
Subject: Re: new correlation metric

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group