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

Поиск
Список
Период
Сортировка
Искать

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

От:
Pavel Stehule <stehule@kix.fsv.cvut.cz>
Дата:
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

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

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Pavel Stehule  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
FAQ