plpgsql function with more than one array argument
От | Andre Holzner |
---|---|
Тема | plpgsql function with more than one array argument |
Дата | |
Msg-id | 3C55E435.280AE10C@cern.ch обсуждение исходный текст |
Ответы |
Array slice subscripts (was Re: plpgsql function with more than one array argument)
|
Список | pgsql-sql |
Hi, thanks for reading this message. I have a table (in a postgres database) looking like this: Table "zdec_bhab"Attribute | Type | Modifier -----------+-----------+----------run | bigint |evt | bigint |...pcha | real[] |... where pcha is a 2D array, i.e. the first index can go from 1 to some number and the second is 1..3. Now, I'd like to create a plpgsql function taking as an argument two vectors (arrays) from pcha: CREATE FUNCTION mytest(real[],real[]) RETURNS real AS ' DECLARE p1 ALIAS FOR $1; p2 ALIAS FOR $2; begin -- RAISE NOTICE ''xxx %'',p2; return p2[1][1]; end;' LANGUAGE 'plpgsql'; I do the following query: select pcha[1:1][1:3],pcha[2:2][1:3],mytest(pcha[1:1][1:3],pcha[2:2][1:3]) from zdec_bhab where nch>=2; which yields: pcha | pcha | mytest ---------------------------------------------+---------------------------------------------+--------{{"-21.0788","35.0317","19.2111"}} | {{"21.0605","-34.995","-19.2111"}} | i.e. mytest seems to return something empty... however, If I uncomment the RAISE NOTICE line, I see the correct values (as in the output of the select statement). If I do select pcha[1:1][1:3],pcha[2:2][1:3],mytest(pcha[2:2][1:3],pcha[1:1][1:3]) from zdec_bhab where nch>=2; (i.e. the arguments of mytest exchanged), I get the correct values. Am I doing something wrong or is this a 'feature' ? (I'm using PostgreSQL 7.1.3 on i686-pc-linux-gnu, compiled by GCC 2.95.3). Is it possible in plpgsql to have functions with more than one array argument ? What about plperl ? Or do I have to convert the 2D array into three 1D arrays pcha_x, pcha_y and pcha_z ? best regards & thanks for the help, André
В списке pgsql-sql по дате отправления: