Re: Function with Array

From: Iannsp <iannsp(at)gmail(dot)com>
To: "Smart Softwares - D(dot) & S(dot)" <smartds(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Function with Array
Date: 2007-01-23 04:25:58
Message-ID: 45B58E56.4000804@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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" = $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ções com performance e segurança
http://www.ianntech.com.br

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Kranti 2007-01-23 08:00:30 RESTORE SCHEMA
Previous Message Alvaro Herrera 2007-01-22 22:35:57 Re: Upgrading to 8.2, changes in user/group management scripts