Re: Supporting NULL elements in arrays

From: mark(at)mark(dot)mielke(dot)cc
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Supporting NULL elements in arrays
Date: 2005-11-09 00:36:59
Message-ID: 20051109003659.GA12018@mark.mielke.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 08, 2005 at 07:21:34PM -0500, Tom Lane wrote:
> I wrote:
> > ... the most straightforward thing to do is define an empty element
> > as meaning a NULL. But this might be objected to on a couple of grounds:
> I just thought of another, potentially fatal objection: it's ambiguous
> whether '{}'::text[] should be taken to mean an empty (zero-length)
> array or an array containing a single NULL element.

To take another perspective on this, though - it isn't possible to have
NULL array elements right now, therefore, there is no precident, and who
is to say that {NULL} <> {}?

For example:

vhosts=> select ('{1, 3}'::text[])[4];
text
------

(1 row)

vhosts=> select ('{}'::text[])[4];
text
------

(1 row)

Perhaps NULL at end of array never needs to be stored, and arrays can
be considered to have an infinite number of NULL values at the end?

For array operations that require a length, such as cross-product, or
whatever, the 'length' of the array, would be the number of elements
before the infinite number of NULL values at the end.

Cheers,
mark

--
mark(at)mielke(dot)cc / markm(at)ncf(dot)ca / markm(at)nortel(dot)com __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada

One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...

http://mark.mielke.cc/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim C. Nasby 2005-11-09 00:55:17 Re: DTrace?
Previous Message Tom Lane 2005-11-09 00:21:34 Re: Supporting NULL elements in arrays