agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mike Martin <redtux1@gmail.com>
Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Subject: Re: Weird issue with truncation of values in array with some tables
Date: Sun, 16 Aug 2020 13:12:50 -0400
Message-ID: <989596.1597597970@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOwYNKYfKPfAL4rgP0AO_w0Mn7h8yiXd_Qi9swPdAc4CAUXeAQ@mail.gmail.com>
References: <CAOwYNKYfKPfAL4rgP0AO_w0Mn7h8yiXd_Qi9swPdAc4CAUXeAQ@mail.gmail.com>

Mike Martin <redtux1@gmail.com> 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=# SELECT pg_typeof(ARRAY[indexname,indexdef]) FROM pg_indexes limit 1;
 pg_typeof 
-----------
 name[]
(1 row)

regression=# 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=# SELECT pg_typeof(ARRAY[indexname::text,indexdef]) FROM pg_indexes 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





view thread (4+ messages)  latest in thread

Message-ID: <989596.1597597970@sss.pgh.pa.us>
Permalink:  ../989596.1597597970@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/989596.1597597970@sss.pgh.pa.us

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, redtux1@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: Re: Weird issue with truncation of values in array with some tables
  In-Reply-To: <989596.1597597970@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox