pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Iannsp <iannsp@gmail.com>
To: Smart Softwares - D. & S. <smartds@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Function with Array
Date: Tue, 23 Jan 2007 02:25:58 -0200
Message-ID: <45B58E56.4000804@gmail.com> (raw)
In-Reply-To: <9907c4090701221151x202a390fq4efcc36411b5ed50@mail.gmail.com>
References: <9907c4090701221151x202a390fq4efcc36411b5ed50@mail.gmail.com>

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




view thread (3+ messages)  latest in thread

Message-ID: <45B58E56.4000804@gmail.com>
Permalink:  ../45B58E56.4000804@gmail.com/
Also on:    postgresql.org/message-id/45B58E56.4000804@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: iannsp@gmail.com, smartds@gmail.com
  Subject: Re: Function with Array
  In-Reply-To: <45B58E56.4000804@gmail.com>
  References: <9907c4090701221151x202a390fq4efcc36411b5ed50@mail.gmail.com> <45B58E56.4000804@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox