Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjo9m-0002lF-Rs for pgsql-general@arkaria.postgresql.org; Wed, 16 Jan 2019 16:35:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gjo9l-0004LP-H7 for pgsql-general@arkaria.postgresql.org; Wed, 16 Jan 2019 16:35:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjo9j-000411-UI for pgsql-general@lists.postgresql.org; Wed, 16 Jan 2019 16:35:09 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjo9g-0007or-Hh for pgsql-general@postgresql.org; Wed, 16 Jan 2019 16:35:06 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 008A828361; Wed, 16 Jan 2019 11:35:04 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 16 Jan 2019 11:35:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imap.cc; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=fm2; bh=RqUwhMyD0XiPipNSnxM13Ot6ibH ih4+99HCIAoRq6+E=; b=jwadYtwDmEWh4uGFzn9FHiS6SfBhNnQfQjlHuoT4Eau Nqsq+rD3F6iClVp97mvQuKJbemwOiqXwY0paKI8rPXBm11cRQCPOi3Y/Sf9TBqdz 643OF+cBEdxoDAJy4ShxbQEu+1UTYZPEEmbjd3ZpBUd85WrfNmmVvq11qzMjpk7N XRj7969BSqMhOEQqJRNFM+aB1n837EUVEXZP7wzKm9NFs4fblgpAmWB0kV1x8fkG llSLNTMZR1JC/TdKwPEUtDuE3AktAdjhVvMOfxiSO0YjWT+sn/HSkCxAxexPhX6L fJnD3gcRMia+Tse0Wd1AF7g9wI3miIaBZX0OSDhkBvw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=RqUwhM yD0XiPipNSnxM13Ot6ibHih4+99HCIAoRq6+E=; b=XPRZomeSGUDIiCUU669VRH JLB8nZrtXxjf9cQdpuZdE8YhvmAtsGXJ+tbV7fHqiSNFulFGchwAzCJXTZPJoBVm gueQ3gLPU/UYqhfh+jmKngVWi2tV5dN78agOakCGU0ISVmVV4Cqpseo61BSXtPNi mdznlyZjnBPefdTNoFkJ3ZG1aXOn0Wc+31xZh6w9JRrmkGZRRbefSfJeERG/uLRG KG/t0ymjAac4PltazcwBe+NANrfAJA9IpLDhkjEiB2UTTvNS8b8mNDHkE8POzM11 BevTXSUfJWIyB2hyL9ax4483t3d033yCmHtxG9WSJ2zBljtznj41T1bGO9qmii1Q == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrgeehgdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefuvfhfhffkffgfgggjtgesrgdtre ertdefjeenucfhrhhomheptehlvgigvgihuceurghshhhtrghnohhvuceosggrshhhthgr nhhovhesihhmrghprdgttgeqnecukfhppedukeehrddvhedrfeefrdejtdenucfrrghrrg hmpehmrghilhhfrhhomhepsggrshhhthgrnhhovhesihhmrghprdgttgenucevlhhushht vghrufhiiigvpedt X-ME-Proxy: Received: from [10.2.33.124] (unknown [185.25.33.70]) by mail.messagingengine.com (Postfix) with ESMTPA id E1C1AE469F; Wed, 16 Jan 2019 11:35:02 -0500 (EST) Subject: Re: Array_agg and dimensions in Array To: Mike Martin , pgsql-general@postgresql.org References: From: Alexey Bashtanov Message-ID: Date: Wed, 16 Jan 2019 16:34:59 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------4D95343D27F4377594BAC1A8" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------4D95343D27F4377594BAC1A8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Mike, > I have come across a problem which I cant seem to solve in a nice way > Basically I have a (small) table of tags > What I need to is combine two concatenated fields with a literal value > as an array element. You can create a custom aggregate function like this: alexey@[local]/alexey=# create aggregate array_cat_agg(anyarray) (SFUNC = array_cat, STYPE = anyarray, COMBINEFUNC = array_cat, PARALLEL = SAFE); CREATE AGGREGATE And use it like this: alexey@[local]/alexey=# select grp, array_cat_agg(array['--foo', bar || '=' || baz]) from (values ('g1', 'a', 'b'), ('g1', 'c', 'd'), ('g2', 'e', 'f')) _ (grp, bar, baz) group by grp; ┌─────┬───────────────────────┐ │ grp │     array_cat_agg     │ ├─────┼───────────────────────┤ │ g2  │ {--foo,e=f}           │ │ g1  │ {--foo,a=b,--foo,c=d} │ └─────┴───────────────────────┘ (2 rows) Is that what you need? Best, Alex --------------4D95343D27F4377594BAC1A8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Hi Mike,
I have come across a problem which I cant seem to solve in a nice way
Basically I have a (small) table of tags
What I need to is combine two concatenated fields with a literal value as an array element.
You can create a custom aggregate function like this:

alexey@[local]/alexey=# create aggregate array_cat_agg(anyarray) (SFUNC = array_cat, STYPE = anyarray, COMBINEFUNC = array_cat, PARALLEL = SAFE);
CREATE AGGREGATE

And use it like this:

alexey@[local]/alexey=# select grp, array_cat_agg(array['--foo', bar || '=' || baz]) from (values ('g1', 'a', 'b'), ('g1', 'c', 'd'), ('g2', 'e', 'f')) _ (grp, bar, baz) group by grp;
┌─────┬───────────────────────┐
│ grp │     array_cat_agg     │
├─────┼───────────────────────┤
│ g2  │ {--foo,e=f}           │
│ g1  │ {--foo,a=b,--foo,c=d} │
└─────┴───────────────────────┘
(2 rows)

Is that what you need?

Best, Alex
--------------4D95343D27F4377594BAC1A8--