Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHsQ2-0003eA-Jx for pgsql-sql@arkaria.postgresql.org; Mon, 24 Feb 2014 10:05:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WHsQ2-0000pk-4D for pgsql-sql@arkaria.postgresql.org; Mon, 24 Feb 2014 10:05:50 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHsQ0-0000pd-VC for pgsql-sql@postgresql.org; Mon, 24 Feb 2014 10:05:49 +0000 Received: from gw01.mail.saunalahti.fi ([195.197.172.115]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WHsPw-0008Mk-PV for pgsql-sql@postgresql.org; Mon, 24 Feb 2014 10:05:48 +0000 Received: from cfwo-22.mail.saunalahti.fi (cfwo-22.mail.saunalahti.fi [62.142.5.121]) by gw01.mail.saunalahti.fi (Postfix) with ESMTP id DACB912B03B for ; Mon, 24 Feb 2014 12:05:42 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by cfwo-22.mail.saunalahti.fi (Postfix) with ESMTP id A4C7F20076 for ; Mon, 24 Feb 2014 12:05:42 +0200 (EET) X-Spam-Checker-Version: SpamAssassin 3.3.2-saunamods_5.22 (2011-06-06) on cfwo-22.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-22.mail.saunalahti.fi (Postfix) with ESMTP id 3561F20072 for ; Mon, 24 Feb 2014 12:05:42 +0200 (EET) Date: Mon, 24 Feb 2014 12:05:41 +0200 (EET) From: Pena Kupen To: postgres list Message-ID: <1770161454.3100811393236342120.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: -2.6 (--) 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 Hello Pavel, I have taking little too much away from original sql :-) Now it works excellently! Thank's for your help! -kupen Pavel Stehule [pavel.stehule@gmail.com] kirjoitti:=20 > Hello >=20 >=20 > 2014-02-24 10:09 GMT+01:00 Pena Kupen : >=20 > > 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) CONTEXT: PL/pgSQL > > function "hastype" line 4 at EXECUTE statement >=20 >=20 > predicate should be >=20 > type_id =3D ANY($1) >=20 > Regards >=20 > Pavel >=20 >=20 > > > > > > p.s. newer try to merge variables to SQL string without sanitization - > >> your > >> code is SQL injection vulnerable - and doesn't work > >> > >> You are right! This must be always taking case of. I have made this > > sample so simple as possible. > > -kupen > > > > Pavel Stehule [pavel.stehule@gmail.com] kirjoitti: > > > >> Hello > >> > >> pls, try > >> > >> EXECUTE 'SELECT 1 FROM types WHERE type_id ANY($1) ' INTO hasValue USI= NG > >> _list; > >> > >> > >> Regards > >> > >> Pavel > >> > >> p.s. newer try to merge variables to SQL string without sanitization - > >> your > >> code is SQL injection vulnerable - and doesn't work > >> > >> > >> 2014-02-24 9:42 GMT+01:00 Pena Kupen : > >> > >> > Hi, > >> > > >> > I have a problem with function, where I want to use execute and crea= te > >> 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 vallankumouk= sen > >> > 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 > >> > > >> > >> > > > > -- > > 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