pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedArray dimension as integer
2+ messages / 2 participants
[nested] [flat]
* Array dimension as integer
@ 2003-05-08 09:57 Victor Yegorov <viy@nordlb.lv>
2003-05-08 15:44 ` Re: Array dimension as integer Achilleus Mantzios <achill@matrix.gatewaynet.com>
0 siblings, 1 reply; 2+ messages in thread
From: Victor Yegorov @ 2003-05-08 09:57 UTC (permalink / raw)
To: pgsql-sql
Hello.
I'm using:
PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC 2.95.3
and I'd like to have a function, which would receive array of varchars and then
create and EXECUTE insert statement for each of array elements (array has 1
dimension):
FOR i IN 1..array_length_function($1) LOOP
EXECUTE ...;
END LOOP;
I've tried to use array_dims, but it gives data in string format:
select test_array('{\'a\'}');
WARNING: Error occurred while executing PL/pgSQL function test_array
WARNING: line 8 at select into variables
ERROR: pg_atoi: error in "[1:1]": can't parse "[1:1]"
I've attached test_array source.
--
Victor Yegorov
Attachments:
f.sql (text/plain, 288B) download
--
-- Function to update data
--
CREATE OR REPLACE FUNCTION test_array(varchar[]) RETURNS int4 IMMUTABLE AS '
DECLARE
t_data ALIAS FOR $1;
_size INT4;
BEGIN
SELECT INTO _size array_dims(t_data);
RAISE NOTICE ''Input array size is %'',_size;
RETURN _size;
END;
' LANGUAGE plpgsql;
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Array dimension as integer
2003-05-08 09:57 Array dimension as integer Victor Yegorov <viy@nordlb.lv>
@ 2003-05-08 15:44 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
0 siblings, 0 replies; 2+ messages in thread
From: Achilleus Mantzios @ 2003-05-08 15:44 UTC (permalink / raw)
To: Victor Yegorov <viy@nordlb.lv>; +Cc: pgsql-sql
On Thu, 8 May 2003, Victor Yegorov wrote:
> Hello.
>
> I'm using:
>
> PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC 2.95.3
>
> and I'd like to have a function, which would receive array of varchars and then
> create and EXECUTE insert statement for each of array elements (array has 1
> dimension):
>
> FOR i IN 1..array_length_function($1) LOOP
> EXECUTE ...;
> END LOOP;
>
> I've tried to use array_dims, but it gives data in string format:
>
> select test_array('{\'a\'}');
> WARNING: Error occurred while executing PL/pgSQL function test_array
> WARNING: line 8 at select into variables
> ERROR: pg_atoi: error in "[1:1]": can't parse "[1:1]"
use something like
substr(array_dims(yourTable.yourArrayColumn),4,1)::int
to get the dim in [1xN] arrays
>
> I've attached test_array source.
>
>
--
==================================================================
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
Nikis 4, Glyfada
Athens 16610
Greece
tel: +30-210-8981112
fax: +30-210-8981877
email: achill@matrix.gatewaynet.com
mantzios@softlab.ece.ntua.gr
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-05-08 15:44 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-05-08 09:57 Array dimension as integer Victor Yegorov <viy@nordlb.lv>
2003-05-08 15:44 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
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