pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14953: pg_blocking_pids / array_length inconsistency
4+ messages / 4 participants
[nested] [flat]

* BUG #14953: pg_blocking_pids / array_length inconsistency
@ 2017-12-07 14:40 steven.winfield@cantabcapital.com
  2017-12-07 15:07 ` Re: BUG #14953: pg_blocking_pids / array_length inconsistency Marko Tiikkaja <marko@joh.to>
  2017-12-07 15:27 ` Re: BUG #14953: pg_blocking_pids / array_length inconsistency Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 4+ messages in thread

From: steven.winfield@cantabcapital.com @ 2017-12-07 14:40 UTC (permalink / raw)
  To: pgsql-bugs; +Cc: steven.winfield@cantabcapital.com

The following bug has been logged on the website:

Bug reference:      14953
Logged by:          Steven Winfield
Email address:      steven.winfield@cantabcapital.com
PostgreSQL version: 10.0
Operating system:   Linux
Description:        

It seems as though pg_blocking_pids() can return a zero-length,
one-dimensional array whereas users can only create NULL-length,
zero-dimensional arrays (even though the type suggests it is one
dimensional: 'integer[]')

test=# SELECT pg_blocking_pids(pg_backend_pid()),
array_length(pg_blocking_pids(pg_backend_pid()), 1), '{}'::integer[],
array_length('{}'::integer[], 1);
 pg_blocking_pids | array_length | int4 | array_length
------------------+--------------+------+--------------
 {}               |            0 | {}   |
(1 row)

This means that, for example, the code to check for an empty array of PIDs
must be special-cased.

For what it's worth, I think having array_length('{}'::integer[], 1) = 0 is
far more sensible, and 
making differently-dimensioned empty arrays compare equal (as mentioned
previously[1]) is quite confusing.


[1]
https://www.postgresql.org/message-id/tencent_5D502954744B7F744ED6F34E%40qq.com



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14953: pg_blocking_pids / array_length inconsistency
  2017-12-07 14:40 BUG #14953: pg_blocking_pids / array_length inconsistency steven.winfield@cantabcapital.com
@ 2017-12-07 15:07 ` Marko Tiikkaja <marko@joh.to>
  2017-12-07 15:13   ` RE: BUG #14953: pg_blocking_pids / array_length inconsistency Steven Winfield <Steven.Winfield@cantabcapital.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Marko Tiikkaja @ 2017-12-07 15:07 UTC (permalink / raw)
  To: steven.winfield@cantabcapital.com; +Cc: pgsql-bugs

On Thu, Dec 7, 2017 at 3:40 PM, <steven.winfield@cantabcapital.com> wrote:

> For what it's worth, I think having array_length('{}'::integer[], 1) = 0 is
> far more sensible, and
> making differently-dimensioned empty arrays compare equal (as mentioned
> previously[1]) is quite confusing.
>

I'm not saying this isn't a bug, but you might want to start using the
cardinality() function for comparisons like this.


.m

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* RE: BUG #14953: pg_blocking_pids / array_length inconsistency
  2017-12-07 14:40 BUG #14953: pg_blocking_pids / array_length inconsistency steven.winfield@cantabcapital.com
  2017-12-07 15:07 ` Re: BUG #14953: pg_blocking_pids / array_length inconsistency Marko Tiikkaja <marko@joh.to>
@ 2017-12-07 15:13   ` Steven Winfield <Steven.Winfield@cantabcapital.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Steven Winfield @ 2017-12-07 15:13 UTC (permalink / raw)
  To: Marko Tiikkaja <marko@joh.to>; +Cc: pgsql-bugs

Thanks - I hadn’t spotted that, even though it was added in 9.4.

Steven.

From: Marko Tiikkaja [mailto:marko@joh.to]
Sent: 07 December 2017 15:07
To: Steven Winfield
Cc: Pg Bugs
Subject: Re: BUG #14953: pg_blocking_pids / array_length inconsistency

On Thu, Dec 7, 2017 at 3:40 PM, <steven.winfield@cantabcapital.com<mailto:steven.winfield@cantabcapital.com>> wrote:
For what it's worth, I think having array_length('{}'::integer[], 1) = 0 is
far more sensible, and
making differently-dimensioned empty arrays compare equal (as mentioned
previously[1]) is quite confusing.

I'm not saying this isn't a bug, but you might want to start using the cardinality() function for comparisons like this.


.m


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14953: pg_blocking_pids / array_length inconsistency
  2017-12-07 14:40 BUG #14953: pg_blocking_pids / array_length inconsistency steven.winfield@cantabcapital.com
@ 2017-12-07 15:27 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 4+ messages in thread

From: Tom Lane @ 2017-12-07 15:27 UTC (permalink / raw)
  To: steven.winfield@cantabcapital.com; +Cc: pgsql-bugs

steven.winfield@cantabcapital.com writes:
> It seems as though pg_blocking_pids() can return a zero-length,
> one-dimensional array whereas users can only create NULL-length,
> zero-dimensional arrays (even though the type suggests it is one
> dimensional: 'integer[]')

This has been fixed recently in HEAD:
https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=716ea626a

but we decided not to back-patch the change.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2017-12-07 15:27 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07 14:40 BUG #14953: pg_blocking_pids / array_length inconsistency steven.winfield@cantabcapital.com
2017-12-07 15:07 ` Marko Tiikkaja <marko@joh.to>
2017-12-07 15:13   ` Steven Winfield <Steven.Winfield@cantabcapital.com>
2017-12-07 15:27 ` Tom Lane <tgl@sss.pgh.pa.us>

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