agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedWeird issue with truncation of values in array with some tables
4+ messages / 4 participants
[nested] [flat]
* Weird issue with truncation of values in array with some tables
@ 2020-08-16 13:48 Mike Martin <redtux1@gmail.com>
2020-08-16 15:13 ` Re: Weird issue with truncation of values in array with some tables David G. Johnston <david.g.johnston@gmail.com>
2020-08-16 17:12 ` Re: Weird issue with truncation of values in array with some tables Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 4+ messages in thread
From: Mike Martin @ 2020-08-16 13:48 UTC (permalink / raw)
To: pgsql-sql <pgsql-sql@lists.postgresql.org>
Hi
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?
thanks
Mike
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Weird issue with truncation of values in array with some tables
2020-08-16 13:48 Weird issue with truncation of values in array with some tables Mike Martin <redtux1@gmail.com>
@ 2020-08-16 15:13 ` David G. Johnston <david.g.johnston@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: David G. Johnston @ 2020-08-16 15:13 UTC (permalink / raw)
To: Mike Martin <redtux1@gmail.com>; +Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
On Sun, Aug 16, 2020, 06:49 Mike Martin <redtux1@gmail.com> wrote:
> Hi
> 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?
>
It's likely related to the following:
https://www.postgresql.org/docs/12/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
The system uses no more than NAMEDATALEN-1 bytes of an identifier; longer
names can be written in commands, but they will be truncated. By default,
NAMEDATALEN is 64 so the maximum identifier length is 63 bytes.
David J.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Weird issue with truncation of values in array with some tables
2020-08-16 13:48 Weird issue with truncation of values in array with some tables Mike Martin <redtux1@gmail.com>
@ 2020-08-16 17:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-08-16 21:19 ` Re: Weird issue with truncation of values in array with some tables Mike Martin <mike@redtux.plus.com>
1 sibling, 1 reply; 4+ messages in thread
From: Tom Lane @ 2020-08-16 17:12 UTC (permalink / raw)
To: Mike Martin <redtux1@gmail.com>; +Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Weird issue with truncation of values in array with some tables
2020-08-16 13:48 Weird issue with truncation of values in array with some tables Mike Martin <redtux1@gmail.com>
2020-08-16 17:12 ` Re: Weird issue with truncation of values in array with some tables Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-08-16 21:19 ` Mike Martin <mike@redtux.plus.com>
0 siblings, 0 replies; 4+ messages in thread
From: Mike Martin @ 2020-08-16 21:19 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Thanks!
Possibly the use of name type in pg_tables could be emphasized and maybe a
note about name type in docs somewhere
On Sun, 16 Aug 2020, 18:12 Tom Lane, <tgl@sss.pgh.pa.us> wrote:
> 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
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2020-08-16 21:19 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-08-16 13:48 Weird issue with truncation of values in array with some tables Mike Martin <redtux1@gmail.com>
2020-08-16 15:13 ` David G. Johnston <david.g.johnston@gmail.com>
2020-08-16 17:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-08-16 21:19 ` Mike Martin <mike@redtux.plus.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox