Re: Call function with dynamic schema name

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: IlGenna <alessio(dot)gennari78(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Call function with dynamic schema name
Date: 2012-01-15 18:27:05
Message-ID: CAFj8pRDkMZ3vyFz9-dGJdp2YA5ckiJ0a4Fa1TLw9TOkDu2jZLQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

2012/1/15 IlGenna <alessio(dot)gennari78(at)gmail(dot)com>:
> Can you provide me e little example plz?

CREATE SCHEMA s1;
CREATE SCHEMA s2;

CREATE TABLE s1.a1(a int);
CREATE TABLE s2.a1(a int);

CREATE OR REPLACE FUNCTION s1.fx1()
RETURNS int AS $$
BEGIN RETURN (SELECT MAX(a) FROM s1.a1); END
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION s2.fx1()
RETURNS int AS $$
BEGIN RETURN (SELECT MAX(a) FROM s2.a1); END
$$ LANGUAGE plpgsql;

SET search_path TO s1;
SELECT fx1(); -- returns max from s1.a1;

SET search_path TO s2;
SELECT fx1(); -- returns max from s2.s1;

Regards

Pavel Stehule

>
> Thanks in advance.
>
> Alessio
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/Call-function-with-dynamic-schema-name-tp5146721p5146739.html
> Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros 2012-01-15 21:13:18 Re: sql query problem
Previous Message IlGenna 2012-01-15 17:37:25 Re: Call function with dynamic schema name