Re: casting strings to multidimensional arrays yields strange results

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: casting strings to multidimensional arrays yields strange results
Date: 2004-07-27 14:08:12
Message-ID: 28217.1090937292@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers pgsql-patches

Kris Jurka <books(at)ejurka(dot)com> writes:
> Casting strings to multidimensional arrays yields strange results.

array_in has fairly bizarre behavior when presented with non-rectangular
input data, such as your examples:

> jurka=# SELECT '{{1,2},{2,3},{4}}'::int[][];

> jurka=# SELECT '{{1},{2,3},{4,5}}'::int[][];

I don't recall the details right now of how it chooses the actual array
dimensions, but it's weird. I've been tempted to rewrite it but have
refrained for fear of breaking existing applications. Also, it's not
entirely clear what the behavior *should* be.

Right now I think the sanest behavior would be to throw an error on
non-rectangular input. Once we have support for null elements in
arrays, however, it would arguably be reasonable to pad with NULLs
where needed, so that the above would be read as

{{1,2},{2,3},{4,NULL}}

{{1,NULL},{2,3},{4,5}}

respectively. If that's the direction we want to head in, it would
probably be best to leave array_in alone until we can do that; users
tend to get unhappy when we change behavior repeatedly.

What's your thoughts?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kris Jurka 2004-07-27 16:07:22 Re: casting strings to multidimensional arrays yields strange
Previous Message Kris Jurka 2004-07-27 06:49:38 Re: BUG #1201: void functions called through jdbc driver

Browse pgsql-hackers by date

  From Date Subject
Next Message Chris Browne 2004-07-27 14:37:13 Re: why is postgres-R not in standard dev Path.
Previous Message Bruce Momjian 2004-07-27 13:11:55 Savepoints inside functions

Browse pgsql-patches by date

  From Date Subject
Next Message Kris Jurka 2004-07-27 16:07:22 Re: casting strings to multidimensional arrays yields strange
Previous Message Andreas Pflug 2004-07-27 13:25:17 Admin functions contrib