pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedUser Define Functions
2+ messages / 2 participants
[nested] [flat]
* User Define Functions
@ 2005-07-27 05:51 Lathika Wijerathne <lathika@rezgateway.com>
0 siblings, 1 reply; 2+ messages in thread
From: Lathika Wijerathne @ 2005-07-27 05:51 UTC (permalink / raw)
To: pgsql-admin
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 information.
----------------------------------------------------------------------
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 Newyorlk.CUSTOMER
WHERE id = custid;
SELECT status INTO m_status from Newyorlk.CUSTOMER_INVOICE
WHERE id = invoice;
m_display := 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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: User Define Functions
@ 2005-07-27 07:08 Gnanavel S <s.gnanavel@gmail.com>
parent: Lathika Wijerathne <lathika@rezgateway.com>
0 siblings, 0 replies; 2+ messages in thread
From: Gnanavel S @ 2005-07-27 07:08 UTC (permalink / raw)
To: Lathika Wijerathne <lathika@rezgateway.com>; +Cc: pgsql-admin
use
set search_path = 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 information.
>
> ----------------------------------------------------------------------
>
> 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 Newyorlk.*CUSTOMER*
>
> WHERE id = custid;
>
> SELECT status INTO m_status from Newyorlk.*CUSTOMER_INVOICE*
>
> WHERE id = invoice;
>
> m_display := 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.Gnanavel
Satyam Computer Services Ltd.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-07-27 07:08 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-27 05:51 User Define Functions Lathika Wijerathne <lathika@rezgateway.com>
2005-07-27 07:08 ` Gnanavel S <s.gnanavel@gmail.com>
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