Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 7B1819FB28B for ; Tue, 23 Jan 2007 09:19:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 25439-05 for ; Tue, 23 Jan 2007 09:19:48 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.187]) by postgresql.org (Postfix) with ESMTP id 029149FB223 for ; Tue, 23 Jan 2007 09:19:52 -0400 (AST) Received: by nf-out-0910.google.com with SMTP id x4so232271nfb for ; Tue, 23 Jan 2007 05:19:51 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=cabawKJ4OZj4VgXuVAn/sBushTXzyqQXHqhFwBfRobNATTLoClcQVyRKJuUmnQXj3nK7P4tvVeU8F0i1aSr/4bmacdQR+I57KeKANINZnDEvC5rKdWTMA7sqmLJxOEI8TOhUsoX7WlMURO6LlpaAZ33nLLdqBSvlBPuMHCp/WtI= Received: by 10.48.202.11 with SMTP id z11mr1074682nff.1169558390846; Tue, 23 Jan 2007 05:19:50 -0800 (PST) Received: by 10.48.203.4 with HTTP; Tue, 23 Jan 2007 05:19:50 -0800 (PST) Message-ID: <9907c4090701230519s5805631fg1670204426b00e56@mail.gmail.com> Date: Tue, 23 Jan 2007 11:19:50 -0200 From: "Smart Softwares - D. & S." To: pgsql-admin@postgresql.org Subject: Re: Function with Array Cc: iannsp@gmail.com In-Reply-To: <45B58E56.4000804@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11111_26638028.1169558390786" References: <9907c4090701221151x202a390fq4efcc36411b5ed50@mail.gmail.com> <45B58E56.4000804@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.375 tagged_above=0 required=5 tests=BAYES_50, HTML_30_40, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200701/212 X-Sequence-Number: 24368 ------=_Part_11111_26638028.1169558390786 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi Ivo, Tentei a sua sugest=E3o... alterei a fun=E7=E3o para retornar a primeira po= si=E7=E3o do ARRAY ($1[1]), mas agora a fun=E7=E3o retorna um erro. Para executar a fun=E7=E3o digito o seguinte comando: select "SMART"."TB_ADM_CEP_SEL1"('{4,3}') Mas d=E1 o seguinte erro: ERROR: array value must start with "{" or dimension information CONTEXT: PL/pgSQL function "TB_ADM_CEP_SEL1" while casting return value to function's return type J=E1 se eu modifico para restornar o $1[0] n=E3o d=E1 erro, mas retorna nul= o. Obrigado! I tried its suggestion... I modified the function to return the first position from the ARRAY ($1[1 ]), but now the function returns an error. To execute the function I type the following command: select "SMART"."TB_ADM_CEP_SEL1"('{4,3}') But it gives the following error: ERROR: array value must start with "{" or dimension information CONTEXT: PL/pgSQL function "TB_ADM_CEP_SEL1" while casting return value to function's return type Already if I modify to restornar $1[0 ] I do not give error, but he returns null. Thank you! 2007/1/23, Iannsp : > > Smart Softwares - D. & S. escreveu: > > > > Hello to all... I am with a problem in a function that I am creating. > > The parameters that are function go to receive are an ARRAY and the > > return also will be an ARRAY, the entrance parameters will be used in > > a clause SQL. E the exit ARRAY will be the result of the SQL. However, > > I elaborated the function and independent of the value that played in > > the ARRAY the result of the SQL was always null. To make a test I > > elaborated the function below and I perceived that my ARRAY had the > > null values. > > > > CREATE OR REPLACE FUNCTION TB_ADM_CEP_SEL (numeric []) > > RETURNS numeric [] AS > > $body$ > > DECLARE > > BEGIN > > --SELECT "TX_CEP" FROM "SMART"."TB_ADM_CEP" > > --WHERE "PK_IN_COD_CEP" =3D $1[0]; > > RETURN $1[0]; > > END; > > $body$ > > LANGUAGE 'plpgsql' VOLATILE RETURNS NULL ON NULL INPUT SECURITY INVOKER= ; > > > > Somebody knows what I am making of made a mistake in this function to > > have these results? They forgive my English good and not very obliged > > for the suggestions. > > Thank you... > Hi, > your problem happened because the array type are zero based, the array > type iniciate your index with 1. > try use RETURN $1[1] and you will see the correct answer. > > ok. > > > -- > Ivo Nascimento > Iann tech - Desenvolvendo solu=E7=F5es com performance e seguran=E7a > http://www.ianntech.com.br > > ------=_Part_11111_26638028.1169558390786 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hi Ivo,
Tentei a sua sugest=E3o... alterei a fun=E7=E3o para retornar a primei= ra posi=E7=E3o do ARRAY ($1[1]), mas agora a fun=E7=E3o retorna um erro.
Para executar a fun=E7=E3o digito o seguinte comando:

select "SMART"."TB_ADM_CEP_SEL1"('{4,3}')

Mas d=E1 o seguinte erro:
ERROR:  array value must start with &q= uot;{" or dimension information
CONTEXT:  PL/pgSQL function &q= uot;TB_ADM_CEP_SEL1" while casting return value to function's retu= rn type=20

J=E1 se eu modifico para restornar o $1[0] n=E3o d=E1 erro, mas retorna = nulo.

Obrigado!

 

I tried its suggestion... I modified the function to return the first po= sition from the ARRAY ($1[1 ]), but now the function returns an error. To e= xecute the function I type the following command:

select "SMART"."TB_ADM_CEP_SEL1"('{4,3}')

But it gives the following error:
ERROR:  array value must start= with "{" or dimension information
CONTEXT:  PL/pgSQL fun= ction "TB_ADM_CEP_SEL1" while casting return value to function= 9;s return type=20

Already if I modify to restornar $1[0 ] I do not give error, but he retu= rns null.
Thank you!



 
2007/1/23, Iannsp <iannsp@gmail.com>:=20
Smart Softwares - D. & S. es= creveu:
>
> Hello to all... I am with a problem in a function t= hat I am creating.=20
> The parameters that are function go to receive are an ARRAY and th= e
> return also will be an ARRAY, the entrance parameters will be use= d in
> a clause SQL. E the exit ARRAY will be the result of the SQL. = However,=20
> I elaborated the function and independent of the value that played= in
> the ARRAY the result of the SQL was always null. To make a test= I
> elaborated the function below and I perceived that my ARRAY had = the=20
> null values.
>
> CREATE OR REPLACE FUNCTION TB_ADM_CEP= _SEL (numeric [])
>      RETURNS numeri= c [] AS
> $body$
> DECLARE
> BEGIN
>  &nb= sp;    --SELECT "TX_CEP" FROM "SMART".&q= uot;TB_ADM_CEP"=20
>       --WHERE "PK_IN_COD_CEP&qu= ot; =3D $1[0];
>   RETURN $1[0];
> END;
> $body= $
> LANGUAGE 'plpgsql' VOLATILE RETURNS NULL ON NULL INPUT SE= CURITY INVOKER;
>
> Somebody knows what I am making of made a m= istake in this function to=20
> have these results? They forgive my English good and not very obli= ged
> for the suggestions.
> Thank you...
Hi,
your proble= m happened because the array type are zero based, the array
type iniciat= e your index with 1.=20
try use RETURN $1[1] and you will see the correct answer.

ok.

--
Ivo Nascimento
Iann tech - Desenvolvendo solu=E7=F5es com= performance e seguran=E7a
http://www.ianntech.com.br


------=_Part_11111_26638028.1169558390786--