Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

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

pgsql-bugs by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group