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

Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Roman Nowak <roman_nowak(at)poczta(dot)onet(dot)pl>, PostgreSQL-documentation <pgsql-docs(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value
Date: 2007-01-31 04:07:11
Message-ID: 200701310407.l0V47B317659@momjian.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-docspgsql-patches
Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> This is not a bug, this is a definitional disagreement, and your TODO
> >> entry presupposes an answer that I don't particularly agree with.
> 
> > Well, our documentation suggests thaat [1] is the same as [1:1]:
> > 	http://www.postgresql.org/docs/8.2/static/arrays.html#AEN5791
> 
> It says absolutely no such thing.  A subscript expression involving m:n
> produces a "slice", hence an array of different dimensionality from the
> original, whereas a subscript expression not involving any colon
> produces a single element --- that is, not an array at all.
> 
> You could make a fair case that the (ARRAY[[1,2],[3,4]])[1] example
> should throw an error instead of returning null.  But to claim it is
> the same as a slice expression is a typing violation.

[ moved to docs list ]

Well, I don't understand our array documentation, so odds are others
don't either.  What are we saying here:

	An array slice is denoted by writing lower-bound:upper-bound for one or
	more array dimensions. For example, this query retrieves the first item
	on Bill's schedule for the first two days of the week:
	
	SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';
	
	        schedule
	------------------------
	 {{meeting},{training}}
	(1 row)
	
	We could also have written
	
	SELECT schedule[1:2][1] FROM sal_emp WHERE name = 'Bill';
	
	with the same result. An array subscripting operation is always taken to
	represent an array slice if any of the subscripts are written in the
	form lower:upper. A lower bound of 1 is assumed for any subscript where
	only one value is specified, as in this example:

What is the difference between 'lower-bound:upper-bound' and
'lower:upper'?  Here are the items that confuse me:

	test=> SELECT (ARRAY[[1,2],[3,4]])[1][1];
	 array
	-------
	     1
	(1 row)
	
	test=> SELECT (ARRAY[[1,2],[3,4]])[1:1];
	  array
	---------
	 {{1,2}}
	(1 row)

	test=> SELECT (ARRAY[[1,2],[3,4]])[1];
	 array
	-------
	
	(1 row)
	
The first two make sense to me, but the last one does not.  If someone
explains it, I can update our documentation.

-- 
  Bruce Momjian   bruce(at)momjian(dot)us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

In response to

pgsql-docs by date

Next:From: Bruce MomjianDate: 2007-02-01 03:18:15
Subject: Re: v8.2 US documentation
Previous:From: Tom LaneDate: 2007-01-31 03:44:17
Subject: Re: BUG #2913: Subscript on multidimensional array yields no value

pgsql-bugs by date

Next:From: Magnus HaganderDate: 2007-01-31 09:58:59
Subject: Re: [BUGS] Missing error message on missing ssl-key-files
Previous:From: Tom LaneDate: 2007-01-31 03:44:17
Subject: Re: BUG #2913: Subscript on multidimensional array yields no value

pgsql-patches by date

Next:From: Bruce MomjianDate: 2007-01-31 04:16:28
Subject: Re: [PATCHES] pg_standby
Previous:From: Tom LaneDate: 2007-01-31 03:44:17
Subject: Re: BUG #2913: Subscript on multidimensional array yields no value

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