Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7MDI-0001So-PM for pgsql-sql@arkaria.postgresql.org; Sun, 16 Aug 2020 17:12:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k7MDH-00027J-Mq for pgsql-sql@arkaria.postgresql.org; Sun, 16 Aug 2020 17:12:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7MDH-00027C-G8 for pgsql-sql@lists.postgresql.org; Sun, 16 Aug 2020 17:12:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7MDF-0004pR-BF for pgsql-sql@lists.postgresql.org; Sun, 16 Aug 2020 17:12:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 07GHCo1w989597; Sun, 16 Aug 2020 13:12:50 -0400 From: Tom Lane To: Mike Martin cc: pgsql-sql Subject: Re: Weird issue with truncation of values in array with some tables In-reply-to: References: Comments: In-reply-to Mike Martin message dated "Sun, 16 Aug 2020 14:48:16 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <989595.1597597970.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 16 Aug 2020 13:12:50 -0400 Message-ID: <989596.1597597970@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mike Martin writes: > I have come across a weird issue with truncation of text in an array (in > this case using pg_indexes view) > This query truncates the second array element at 63 characters > SELECT ARRAY[indexname,indexdef] FROM pg_indexes > However reversing the order doesn't truncate > SELECT ARRAY[indexdef,indexname] FROM pg_indexes > Anyone know why this behaviour occurs? indexname is of type name, indexdef is of type text, and the rules for inferring the type of an array[] construct are such that the first element's type wins in these cases. regression=3D# SELECT pg_typeof(ARRAY[indexname,indexdef]) FROM pg_indexes= limit 1; pg_typeof = ----------- name[] (1 row) regression=3D# SELECT pg_typeof(ARRAY[indexdef,indexname]) FROM pg_indexes= limit 1; pg_typeof = ----------- text[] (1 row) You could insert an explicit cast to text to avoid the truncation of indexdef to name: regression=3D# SELECT pg_typeof(ARRAY[indexname::text,indexdef]) FROM pg_i= ndexes limit 1; pg_typeof = ----------- text[] (1 row) The documentation about that is here: https://www.postgresql.org/docs/current/typeconv-union-case.html although looking at this example it seems like that description isn't telling the full truth. regards, tom lane