Re: [BUGS] casting strings to multidimensional arrays yields strange

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Kris Jurka <books(at)ejurka(dot)com>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [BUGS] casting strings to multidimensional arrays yields strange
Date: 2004-08-04 17:33:24
Message-ID: 41111DE4.4000901@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Tom Lane wrote:
> [ cc'ing pghackers in case anyone wants to object ]
> Joe Conway <mail(at)joeconway(dot)com> writes:
>>I think that even once we support NULL array elements, they should be
>>explicitly requested -- i.e. throwing an error on non-rectangular input
>>is still the right thing to do. I haven't suggested that in the past
>>because of the backward-compatibility issue, but maybe now is the time
>>to bite the bullet.
>
> Okay with me. Anyone on pghackers not happy?
>
>>If you think this qualifies as a bug fix for 7.5, I can take a look at
>>it next week.
>
> Yeah, we can call it a bug fix.

The attached addresses the above issue as well as the ones mentioned in
my RFC post from yesterday found here:
http://archives.postgresql.org/pgsql-hackers/2004-08/msg00126.php

So whereas you used to get this:
test=# select '{{{1,2},{4,5,6}},{7,8}}'::int[];
int4
------
{}
(1 row)

you now get this:
test=# select '{{{1,2},{4,5,6}},{7,8}}'::int[];
ERROR: multidimensional arrays must have array expressions with
matching dimensions

Negative lower bound indicies now work also, and array_out will always
output explicit dimensions for an array with any dimension having a
lower bound of other than one. This allows the dimensions to be
preserved across pg_dump/reload cycles:

CREATE TABLE foo (
f1 integer[]
);
COPY foo (f1) FROM stdin;
[1:1][3:4][-2:0]={{{1,2,3},{4,5,6}}}
[-42:-41][12:14]={{1,2,3},{4,5,6}}
\.

test=# select f1, array_lower(f1, 1) as lb1, array_lower(f1, 2) as lb2,
array_lower(f1, 3) as lb3 from foo;
f1 | lb1 | lb2 | lb3
--------------------------------------+-----+-----+-----
[1:1][3:4][-2:0]={{{1,2,3},{4,5,6}}} | 1 | 3 | -2
[-42:-41][12:14]={{1,2,3},{4,5,6}} | -42 | 12 |
(2 rows)

If there are no objections, I'll adjust the appropriate regression
script/expected files and commit tonight. And of course I'll follow up
with documentation updates too.

Any thoughts on whether or not to apply this to 7.4?

Thanks,

Joe

Attachment Content-Type Size
array-fixes.1.patch text/x-patch 7.0 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-08-04 17:44:14 Re: [BUGS] casting strings to multidimensional arrays yields strange results
Previous Message Gaetano Mendola 2004-08-04 15:05:37 Re: BUG #1204: user-defined function in transaction

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-08-04 17:44:14 Re: [BUGS] casting strings to multidimensional arrays yields strange results
Previous Message Gaetano Mendola 2004-08-04 17:10:42 Re: PITR - recovery to a particular transaction

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2004-08-04 17:44:14 Re: [BUGS] casting strings to multidimensional arrays yields strange results
Previous Message Tom Lane 2004-08-04 17:14:13 Re: More fixes for pg_dump