pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Andre Holzner <Andre.Holzner@cern.ch>
To: pgsql-sql@postgresql.org
Subject: plpgsql function with more than one array argument
Date: Tue, 29 Jan 2002 00:52:21 +0100
Message-ID: <3C55E435.280AE10C@cern.ch> (raw )
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é
Message-ID: <3C55E435.280AE10C@cern.ch>
Permalink: ../3C55E435.280AE10C@cern.ch/
Also on: postgresql.org/message-id/3C55E435.280AE10C@cern.ch
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: Andre.Holzner@cern.ch, pgsql-sql@postgresql.org
Subject: Re: plpgsql function with more than one array argument
In-Reply-To: <3C55E435.280AE10C@cern.ch>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox