Re: So what's an "empty" array anyway?

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: So what's an "empty" array anyway?
Date: 2008-10-21 18:20:15
Message-ID: 162867790810211120k30dc9d5bm6daa91b9fa918102@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2008/10/21 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Currently, the constructs
> '{}'::arraytype
> ARRAY[]::arraytype
> return zero-dimensional arrays, as does the underlying function
> construct_empty_array(). I can't immediately find any way at SQL
> level to produce an empty array with one or more dimensions.
> However, construct_array and construct_md_array will happily build
> zero-length arrays of dimension 1 or higher, leading to weirdnesses
> such as illustrated here:
> http://archives.postgresql.org/pgsql-general/2008-10/msg00915.php
>

> Seems like we ought to clean this up. I'm not sure which way to jump
> though: should we decree that arrays of no elements must always have
> zero dimensions, or should we get rid of that and standardize on, say,
> 1-D array with lower bound 1 and upper bound 0?
>

I believe so zero dimensions for empty array should be more clean and
more simple. This solve question about array_dims too. But this empty
dimensionless array should be simple cast to dimensional empty array.

array_ndims(array[]) --> 0
array[1,2] || array[] = array[1,2]
array[[1,2],[1,3]] || array[] = array[[1,2],[1,3]]

or
array[1,2] = array[] -> false
array[[1,2],[1,3]] = array[] -> false

Regards
Pavel Stehule

> A somewhat related issue that I noticed while poking at this is that
> array_dims() returns NULL for a zero-dimension array. That seems a bit
> bogus too; wouldn't an empty string be saner? Of course the issue
> goes away if we get rid of zero-dimension arrays.
>
> Thoughts?
>
> regards, tom lane
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-10-21 18:23:21 Re: So what's an "empty" array anyway?
Previous Message Merlin Moncure 2008-10-21 18:13:05 Re: So what's an "empty" array anyway?