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

From: Dean Rasheed <dean_rasheed(at)hotmail(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: So what's an "empty" array anyway?
Date: 2008-11-15 11:58:36
Message-ID: COL109-W4406AC3893699BDE949719F2110@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Peter Eisentraut wrote:
> It was pointed out to me today that a zero-dimensional
> matrix is a scalar. This makes a bit of sense, if you say
> that
>
> '{{56}}' is of type int[][], 2 dimensions
> '{56}' is of type int[], 1 dimension
> '56' is of type int, 0 dimensions
>
> Notice that the number of brace pairs in the literal
> matches the number of bracket pairs in the type
> declaration.
>
> By that logic, '{}' has one dimension. I think this also
> works best in practice, for example with array
> concatenation.

When I think about this, I think that '{x}' has dimension 1 greater
than 'x'. So '{x}' may be a 2-D array, if 'x' is a 1-D array. But
it is always the case that dim('{x}')>= 1.

It seems logical therefore to treat '{}' as an empty array of
something (possibly other arrays), but its precise meaning is
undefined until you actually coerce it into a specific type. Thus
you could have:

'{}'::int - illegal
'{}'::int[] - empty array of integers
'{}'::int[][] - empty 2-D array of integers

However, I would say that '{{}}' isn't an empty array, since the outer
array has 1 element ('{}'). So this leads to:

'{{}}'::int - illegal
'{{}}'::int[] - illegal
'{{}}'::int[][] - non-empty array containing an empty array of integers
(ie. a 1x0 matrix)
'{{},{}}'::int[][] - non-empty array containing 2 empty arrays of integers
(ie. a 2x0 matrix)

I don't know if Nx0 matrices actually have any use, but that's where
the logic takes me.

Dean

_________________________________________________________________
Win £1000 John Lewis shopping sprees with BigSnapSearch.com
http://clk.atdmt.com/UKM/go/117442309/direct/01/

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2008-11-15 12:04:08 Re: A error reported in patch "clientcert option for pg_hba"
Previous Message Dmitry Koterov 2008-11-15 10:04:28 Re: Sometimes pg_dump generates dump which is not restorable