X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7C84347639D for ; Thu, 8 May 2003 05:55:38 -0400 (EDT) Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) by postgresql.org (Postfix) with ESMTP id 3DA0B475A80 for ; Thu, 8 May 2003 05:55:37 -0400 (EDT) Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h489tcbg025269 for ; Thu, 8 May 2003 12:55:38 +0300 Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; Thu, 08 May 2003 12:55:38 +0300 (EET DST) Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) by nordlb.lv (8.11.6/8.11.6) with SMTP id h489tbw16179 for ; Thu, 8 May 2003 12:55:37 +0300 Received: (qmail 22348 invoked by uid 100); 8 May 2003 09:57:45 -0000 Date: Thu, 8 May 2003 12:57:45 +0300 From: "Victor Yegorov" To: "Postgres SQL" Subject: Array dimension as integer Message-ID: <20030508095745.GA22337@nordlb.lv> Mail-Followup-To: "Postgres SQL" Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="dc+cDN39EJAMEtIO" Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Spam-Status: No, hits=-18.4 required=5.0 tests=BAYES_10,PGP_SIGNATURE_2,USER_AGENT_MUTT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/161 X-Sequence-Number: 13326 --dc+cDN39EJAMEtIO Content-Type: multipart/mixed; boundary="n8g4imXOkfNTN/H1" Content-Disposition: inline --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello. I'm using: PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC 2.95.3 =20 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. --=20 Victor Yegorov --n8g4imXOkfNTN/H1 Content-Type: text/plain; charset=koi8-r Content-Description: test_array() source Content-Disposition: attachment; filename="f.sql" Content-Transfer-Encoding: quoted-printable -- -- Function to update data -- CREATE OR REPLACE FUNCTION test_array(varchar[]) RETURNS int4 IMMUTABLE AS ' DECLARE t_data ALIAS FOR $1; _size INT4; =09 BEGIN SELECT INTO _size array_dims(t_data); RAISE NOTICE ''Input array size is %'',_size; RETURN _size; END; ' LANGUAGE plpgsql; --n8g4imXOkfNTN/H1-- --dc+cDN39EJAMEtIO Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE+uioZ2RKGLEykUDYRAs0wAJ9rkSjJ5grME6ZFeXWZNZqJSKiRUQCeKPOS vUIygRjSmNke6vFc7GSAmd4= =Dv+4 -----END PGP SIGNATURE----- --dc+cDN39EJAMEtIO--