Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VuuEn-0000Ix-3m for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Dec 2013 01:23:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VuuEm-000653-JE for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Dec 2013 01:23:16 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VuuEl-00063d-AM for pgsql-bugs@postgresql.org; Mon, 23 Dec 2013 01:23:15 +0000 Received: from mimolette.dalibo.net ([212.85.154.222]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VuuEi-0000zM-C3 for pgsql-bugs@postgresql.org; Mon, 23 Dec 2013 01:23:14 +0000 Received: from [192.168.0.38] (ip-68.net-81-220-133.standre.rev.numericable.fr [81.220.133.68]) by mimolette.dalibo.net (Postfix) with ESMTPSA id 83A766820018; Mon, 23 Dec 2013 02:23:10 +0100 (CET) Message-ID: <52B7902C.5050405@dalibo.com> Date: Mon, 23 Dec 2013 02:21:48 +0100 From: Vik Fearing User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: jp.deplaix@gmail.com, pgsql-bugs@postgresql.org Subject: Re: BUG #8696: Type-checking seems to fail on UNIONs with arrays References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 12/23/2013 01:47 AM, jp.deplaix@gmail.com wrote: > (SELECT NULL AS test) > UNION > (SELECT NULL AS test) > UNION > (SELECT array_agg(t.name) AS test FROM foo AS t) > ; > > > fails with: > ERROR: UNION types text and text[] cannot be matched > > > Is it (as I suppose) a bug or a well known limitation ? It's a well known limitation (I knew what was coming before I read it), but I can't seem to find the right keywords to dig up a reference about it at the moment. It has nothing to do with arrays, but the fact that you have *two* unknown types before a known one. To wit: vik=# select null union select null union select 1; ERROR: UNION types text and integer cannot be matched LINE 1: select null union select null union select 1; The workaround is to provide the type in either the first or second union-ed query: vik=# select null::integer union select null union select 1; int4 ---- 1 (2 rows) vik=# select null union select null::integer union select 1; ?column? -------- 1 (2 rows) PS: Interesting that the column name changed with those two queries... -- Vik -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs