X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 12ECC52ECB for ; Wed, 27 Jul 2005 04:08:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59303-08 for ; Wed, 27 Jul 2005 07:08:49 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.207]) by svr1.postgresql.org (Postfix) with ESMTP id 3851352E65 for ; Wed, 27 Jul 2005 04:08:48 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id z6so68002nzd for ; Wed, 27 Jul 2005 00:08:49 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references; b=fAubCYQ25X2AsB0ZTwJHgTho3CSluI16YRz3L1GmDFZUCXG7c+fn8kG9X4HPRy77Q+P3bd8vbKvKlxm4vVtJrKG3perfKF/GUN2PibyreKttULqREcCdCbrRbo19Rg0EuK57MP21SXBpMkNQ7SVm2xH0MkKC6Elh8ZLEiEwPQsk= Received: by 10.36.224.6 with SMTP id w6mr564364nzg; Wed, 27 Jul 2005 00:08:49 -0700 (PDT) Received: by 10.36.119.19 with HTTP; Wed, 27 Jul 2005 00:08:49 -0700 (PDT) Message-ID: Date: Wed, 27 Jul 2005 12:38:49 +0530 From: Gnanavel S Reply-To: Gnanavel S To: Lathika Wijerathne Subject: Re: User Define Functions Cc: pgsql-admin@postgresql.org In-Reply-To: <20050726224915.55373F6D@dm16.mta.everyone.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_28076_19580660.1122448129361" References: <20050726224915.55373F6D@dm16.mta.everyone.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.471 tagged_above=0 required=5 tests=AWL, HTML_MESSAGE, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200507/213 X-Sequence-Number: 18269 ------=_Part_28076_19580660.1122448129361 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline use=20 set search_path =3D yourschemaname to set the schema before calling the function On 7/27/05, Lathika Wijerathne wrote: >=20 > Hi, >=20 > I have created the database with 3 schemas.=20 >=20 > Example : Schema names : Newyorlk, Atlanta,California >=20 > Each schema has a similar tables. But there can be schema specific table= s=20 > too. >=20 > I want to create a user define functions to retrieve information. >=20 > ---------------------------------------------------------------------- >=20 > CREATE OR REPLACE FUNCTION Newyorlk.get_customer_name (custid integer,=20 > invoice integer) >=20 > RETURNS varchar AS >=20 > $$ >=20 > DECLARE >=20 > m_display varchar (100); >=20 > m_status varchar(10); >=20 > BEGIN >=20 > SELECT cname INTO m_display from Newyorlk.*CUSTOMER* >=20 > WHERE id =3D custid; >=20 > SELECT status INTO m_status from Newyorlk.*CUSTOMER_INVOICE* >=20 > WHERE id =3D invoice; >=20 > m_display :=3D m_display||'-'|| m_status ; >=20 > RETURN m_display; >=20 > END; >=20 > $$ >=20 > LANGUAGE 'plpgsql' VOLATILE; >=20 > -------------------------------------------------------------------- >=20 > In the above function if I change Newyorlk.*CUSTOMER to CUSTOMER . *It= =20 > gives a runtime error saying table not available. >=20 > I think when I remove the schema name, posgresSql checks the table in the= =20 > public schema. >=20 > But in Oracle, when we give the schema name with the function name, it= =20 > assumes all the objects within the functions are referring to that schema= . >=20 > Do you know any other way to do a user define function, without hard=20 > cording schema name each time when referring to a table. >=20 > Thanks in Advance >=20 > Lathika >=20 > =20 --=20 with regards, S.Gnanavel Satyam Computer Services Ltd. ------=_Part_28076_19580660.1122448129361 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline use
set search_path =3D yourschemaname
to set the schema before calling the function

= On 7/27/05, Lathika Wijerathne < lathika@rezgateway.com> wrote:

Hi,

 

I have created the database with 3 schemas.

Example : Schema names : Newyorlk, Atlanta,California

 

Each  schema has a similar  tables. But there can be schema specific tables too.

 

I want to create a user define functions to retrieve informati= on.

 

--------------------------------------------------------------= --------

CREATE OR REPLACE FUNCTION Newyorlk.get_customer_name (custid integer, invoice integer)

  RETURNS varchar AS

$$

 

DECLARE

 m_display      varchar (100);

 m_status        varchar(10);

  BEGIN

 

   SELECT cname   INTO m_display from Newy= orlk.CUSTOMER

  WHERE   id =3D custid;

 

  SELECT  status   INTO m_status = ;  from Newyorlk.CUSTOMER_INVOICE=

  WHERE   id =3D invoice;

 

 m_display :=3D m_display||'-'|| m_status  ;

 

   RETURN m_display;

  END;

$$

  LANGUAGE 'plpgsql' VOLATILE;

--------------------------------------------------------------= ------

 

In the above function if I change Newyorlk.CUSTOMER  to CUSTOMER . It gives a runtime error saying table not available.

I think when I remove the schema name, posgresSql checks the table in the public schema.

 

But in Oracle, when we give the schema name with the function name, it assumes all the objects within the functions are referring to that schema.

Do you know any other way to do a user define function, without hard cording schema name each time when referring to a table.

 

Thanks in Advance

Lathika

 

 




--
with regards,
S.Gnan= avel
Satyam Computer Services Ltd. ------=_Part_28076_19580660.1122448129361--