Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0SNxNl93903 for ; Mon, 28 Jan 2002 18:59:23 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id g0SNqOi09925 for pgsql-sql@postgresql.org; Mon, 28 Jan 2002 18:52:24 -0500 (EST) (envelope-from news) From: Andre Holzner X-Newsgroups: comp.databases.postgresql.sql Subject: plpgsql function with more than one array argument Date: Tue, 29 Jan 2002 00:52:21 +0100 Organization: ETH Zuerich Lines: 78 Message-ID: <3C55E435.280AE10C@cern.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: news@hub.org X-Sender: "Andre Holzner" <@smtp.cern.ch> X-Mailer: Mozilla 4.77C-CERN UNIX lxplus006 45 [en] (X11; U; Linux 2.2.19 i686) X-Accept-Language: en, fr-FR To: pgsql-sql@postgresql.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by postgresql.org id g0T0E1m95109 X-Archive-Number: 200202/21 X-Sequence-Number: 6453 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é