dbTalk Databases Forums  

[BUGS] casting strings to multidimensional arrays yields strange results

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] casting strings to multidimensional arrays yields strange results in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kris Jurka
 
Posts: n/a

Default [BUGS] casting strings to multidimensional arrays yields strange results - 07-27-2004 , 01:30 AM







Casting strings to multidimensional arrays yields strange results. In one
case there are discard values and the other a value magically appears.
Trying both of these with the array[] constructor syntax yields the
expected:
ERROR: multidimensional arrays must have array expressions with matching
dimensions

Tested on both 7.4.3 and 7.5dev.

Kris Jurka

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

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


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] casting strings to multidimensional arrays yields strange results - 07-27-2004 , 10:44 PM






Kris Jurka <books (AT) ejurka (DOT) com> writes:
Quote:
Are you considering NULL padding arrays constructed with the
ARRAY[] syntax?
Don't think anyone's really thought about it.

Quote:
we should consistently pad with 0 instead of sometimes padding and sometimes
truncating.
"Pad with 0" is a meaningless concept as soon as you think about
nonnumeric data types. I'm not very sure what's even happening
inside the code --- it's a bit surprising it doesn't crash outright
on pass-by-reference data types ...

I'd agree that the truncation behavior is wrong, but I don't want to
get rid of it by causing the padding behavior to happen more often.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] casting strings to multidimensional arrays yields strange results - 07-27-2004 , 10:49 PM



Kris Jurka <books (AT) ejurka (DOT) com> writes:
Quote:
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:

Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #4  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] casting strings to multidimensional arrays yields strange results - 07-28-2004 , 09:03 AM



[ cc'ing pghackers in case anyone wants to object ]

Joe Conway <mail (AT) joeconway (DOT) com> writes:
Quote:
Tom Lane wrote:
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.

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?

Quote:
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.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.