Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 338679FB2B5 for ; Tue, 23 Jan 2007 00:26:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 71178-06 for ; Tue, 23 Jan 2007 00:26:36 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.229]) by postgresql.org (Postfix) with ESMTP id 17BCE9FB2A9 for ; Tue, 23 Jan 2007 00:26:05 -0400 (AST) Received: by wx-out-0506.google.com with SMTP id i28so1647414wxd for ; Mon, 22 Jan 2007 20:26:05 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:organization:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=jEGwbKY4eloTiPXN3X3JzkYPtGs23CwFTHQKBTaKpUNJ/wRAX/a2p24ErzR0zGJHd//2pJAxe/hA4tP4noDRsMzipZVoOGSPiPzCRi+NZD56gvaC1j0dTmSh3wP6tv9tpTkgWULWi9HJ27hbKginJi4TgI+ZAO78EeRBuYkRSYo= Received: by 10.70.99.9 with SMTP id w9mr12191499wxb.1169526365256; Mon, 22 Jan 2007 20:26:05 -0800 (PST) Received: from ?192.168.1.9? ( [201.68.234.22]) by mx.google.com with ESMTP id i16sm7744029wxd.2007.01.22.20.26.03; Mon, 22 Jan 2007 20:26:04 -0800 (PST) Message-ID: <45B58E56.4000804@gmail.com> Date: Tue, 23 Jan 2007 02:25:58 -0200 From: Iannsp Reply-To: iannsp@gmail.com Organization: iann tech User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: "Smart Softwares - D. & S." CC: pgsql-admin@postgresql.org Subject: Re: Function with Array References: <9907c4090701221151x202a390fq4efcc36411b5ed50@mail.gmail.com> In-Reply-To: <9907c4090701221151x202a390fq4efcc36411b5ed50@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.048 tagged_above=0 required=5 tests=AWL, BAYES_40, SPF_PASS X-Spam-Level: X-Archive-Number: 200701/207 X-Sequence-Number: 24363 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