dbTalk Databases Forums  

[BUGS] is array bug? (array[][])[] = NULL

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


Discuss [BUGS] is array bug? (array[][])[] = NULL in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pavel Stehule
 
Posts: n/a

Default [BUGS] is array bug? (array[][])[] = NULL - 06-04-2004 , 08:00 AM






Hello

I am not sure so decrease of array dimensions is regular operations.
But following code dont make syntax error.

create or replace function xxx() returns bool as $$
declare v1 varchar[]; v2 varchar[][];
begin
v2 := array[array[1,2], array[3,4]];
raise notice 'v2 %', v2;
v1 := v2[1];
raise notice 'v1 %', v1;
return 't';
end; $$ language plpgsql;

I expect v1 = [1,2], but v1 is null.
What is wrong?

Regards
Pavel Stehule


---------------------------(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
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] is array bug? (array[][])[] = NULL - 06-04-2004 , 09:55 AM






Pavel Stehule <stehule (AT) kix (DOT) fsv.cvut.cz> writes:
Quote:
I expect v1 = [1,2], but v1 is null.
What is wrong?
Postgres arrays don't work that way; you're assuming the semantics are
like C which they aren't.

You could get an approximation to what you want with array slicing, viz
v2[1:1][1:2]
but note that this doesn't decrease the dimensionality of the result.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


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.