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

Started by Pavel Stehulealmost 22 years ago2 messagesbugs
Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#1)
Re: is array bug? (array[][])[] = NULL

Pavel Stehule <stehule@kix.fsv.cvut.cz> writes:

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