Re: Can a view use a schema search_path?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Can a view use a schema search_path?
Date: 2012-09-17 12:59:09
Message-ID: k376qj$7po$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adam Mackler, 17.09.2012 11:06:
> I have the feeling the answer is no, but I would like an
> authoritative answer before I give up.
>
> My plan was to have two schemas: one for the live data, and one for
> staging, training, and testing. Both schemas would have
> identically-named tables. I wanted to create a single view in the
> public schema, and have that one view refer to the tables in one or
> the other schema depending on my search_path setting at the time I
> query the view.
>
> But it seems that at the time the view is created it decides which
> schema's table it's referring to, even if I don't explicitly qualify
> the table names with the schema name.
>
> Am I correct in concluding that there's no way to have a single view
> in the public schema that selects data from tables in different other
> schemas depending on my search_path at the time I execute a query
> involving that view?
>

You could achieve this using a set returning function.
Inside the function you'd check the search_path and then dynamically build the approriate SELECT statement

Regards
Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Angelico 2012-09-17 13:11:31 Re: Can a view use a schema search_path?
Previous Message Rafal Pietrak 2012-09-17 12:24:03 Re: foreign key from array element