Re: BUG #2212: Extracting array from 2 dim array may be incorrect

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Walter Roeland" <wroeland(at)marcatel(dot)net>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2212: Extracting array from 2 dim array may be incorrect
Date: 2006-01-26 17:28:09
Message-ID: 19963.1138296489@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Walter Roeland" <wroeland(at)marcatel(dot)net> writes:
> Select (Array[5,8,1])[2] as E;
> returns 8 (ok, dimension is lowerd from 1 to 0).

> Select (Array[Array[3,2,2],Array[7,4,4],Array[5,8,1]])[3:3] as V;
> returns {{5,8,1}} (I suppose this is ok, same dimension).

> But:
> Select (Array[Array[3,2,2],Array[7,4,4],Array[5,8,1]])[3] as V;
> Returns Null, as far I understand it should return {5,8,1}, i.e. lowering
> dimension from 2 to 1.

The current rule is that if you write an array slice subscript (ie,
use ":" in at least one of the subscripts), you get an array out.
If you don't write ":", you get a single element out. We cannot
really change this on-the-fly, because the result type of the
expression has to be determinable at parse time. (If the exact number
of dimensions of an array were part of its type signature, we could
do what you're imagining, but it's not: all arrays over the same base
type have the same type, and dimensionality is strictly a run-time
thing.)

I can see the argument for raising an error, instead of returning NULL,
when the number of subscripts isn't compatible with the number of
dimensions. But I'm not sure it's worth taking any
backward-compatibility risks for...

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2006-01-26 17:45:00 Re: BUG #2195: log_min_messages crash server when in DEBUG3 to
Previous Message Tom Lane 2006-01-26 17:09:15 Re: BUG #2215: Cannot restore backup cause of view's representaion