Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHrXz-0001Sr-RD for pgsql-sql@arkaria.postgresql.org; Mon, 24 Feb 2014 09:10:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WHrXz-0002ah-AW for pgsql-sql@arkaria.postgresql.org; Mon, 24 Feb 2014 09:09:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHrXy-0002aY-9r for pgsql-sql@postgresql.org; Mon, 24 Feb 2014 09:09:58 +0000 Received: from gw03.mail.saunalahti.fi ([195.197.172.111]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHrXw-0003Wq-Hf for pgsql-sql@postgresql.org; Mon, 24 Feb 2014 09:09:58 +0000 Received: from cfwo-20.mail.saunalahti.fi (cfwo-20.mail.saunalahti.fi [62.142.5.102]) by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 663242804D for ; Mon, 24 Feb 2014 11:09:56 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by cfwo-20.mail.saunalahti.fi (Postfix) with ESMTP id 2945A2007E for ; Mon, 24 Feb 2014 11:09:56 +0200 (EET) X-Spam-Checker-Version: SpamAssassin 3.3.2-saunamods_5.22 (2011-06-06) on cfwo-20.mail.saunalahti.fi X-Spam-Level: X-Spam-Status: No, score=0.0 required=7.0 tests=none shortcircuit=no autolearn=no version=3.3.2-saunamods_5.22 Received: from tarazed.webmail.wippies.com (tarazed.webmail.wippies.com [195.197.55.111]) by cfwo-20.mail.saunalahti.fi (Postfix) with ESMTP id 71D7520077 for ; Mon, 24 Feb 2014 11:09:55 +0200 (EET) Date: Mon, 24 Feb 2014 11:09:54 +0200 (EET) From: Pena Kupen To: postgres list Message-ID: <1033700286.3098071393232995132.JavaMail.kupen@wippies.fi> Subject: Re: array in function MIME-Version: 1.0 Content-Type: text/plain; Charset=iso-8859-1; Format=Flowed Content-Transfer-Encoding: quoted-printable X-Mailer: Saunalahti webmail - http://saunalahti.fi X-Originating-IP: 87.100.207.98 X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hi, I try to change it: ERROR: syntax error at or near "ANY" at character 35 QUERY: SELECT 1 FROM types WHERE type_id ANY($1)=20 CONTEXT: PL/pgSQL function "hastype" line 4 at EXECUTE statement > p.s. newer try to merge variables to SQL string without sanitization - yo= ur > code is SQL injection vulnerable - and doesn't work >=20 You are right! This must be always taking case of. I have made this sample = so simple as possible.=20 -kupen Pavel Stehule [pavel.stehule@gmail.com] kirjoitti:=20 > Hello >=20 > pls, try >=20 > EXECUTE 'SELECT 1 FROM types WHERE type_id ANY($1) ' INTO hasValue USING > _list; >=20 >=20 > Regards >=20 > Pavel >=20 > p.s. newer try to merge variables to SQL string without sanitization - yo= ur > code is SQL injection vulnerable - and doesn't work >=20 >=20 > 2014-02-24 9:42 GMT+01:00 Pena Kupen : >=20 > > Hi, > > > > I have a problem with function, where I want to use execute and create = sql > > for it. > > > > My table is: > > create table types ( > > id integer, > > type_id character varying, > > explain character varying > > ); > > > > And function: > > CREATE or REPLACE FUNCTION hasType(_list character varying[]) RETURNS > > integer > > LANGUAGE plpgsql > > AS $$ > > > > DECLARE hasValue integer; > > BEGIN > > EXECUTE 'SELECT 1 FROM types WHERE type_id ANY('|| _list ||') ' > > INTO hasValue; > > IF hasValue IS NULL THEN > > RETURN 0; > > ELSE > > RETURN 1; > > END IF; > > END; > > $$; > > > > Executing function with array parameter: > > select hasType(ARRAY['E','F','','']); > > > > I got error: > > SQL error: > > ERROR: operator is not unique: unknown || character varying[] at > > character 49 > > HINT: Could not choose a best candidate operator. You might need to add > > explicit type casts. > > QUERY: SELECT 'SELECT 1 FROM types WHERE type_id ANY('|| $1 ||') ' > > CONTEXT: PL/pgSQL function "hastype" line 4 at EXECUTE statement > > In statement: > > select hasType(ARRAY['E','F','','']); > > > > How to add array in parameter list to sql-sentence? > > > > -kupen > > > > > > -- > > Wippies-vallankumous on t=E4=E4ll=E4! Varmista paikkasi vallankumouksen > > eturintamassa ja liity Wippiesiin heti! > > http://www.wippies.com/ > > > > > > > > > > -- > > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > > To make changes to your subscription: > > http://www.postgresql.org/mailpref/pgsql-sql > > >=20 --=20 Wippies-vallankumous on t=E4=E4ll=E4! Varmista paikkasi vallankumouksen etu= rintamassa ja liity Wippiesiin heti! http://www.wippies.com/ --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql