Re: Can a view use a schema search_path?

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Adam Mackler <adammackler(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Can a view use a schema search_path?
Date: 2012-09-17 14:46:37
Message-ID: CAF-3MvM54r50LpmyhGs2P_y0QpapLOqFs0Mzp8R3Rteh-zuNxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 17 September 2012 11:06, Adam Mackler <adammackler(at)gmail(dot)com> wrote:
> 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?
>
> Thanks.
> --
> Adam Mackler

Wouldn't it be easier to create a view in each schema with the
appropriate search_path?

That way, you get the view that your search_path points to, which then
in turn uses the tables from the search_path in use when the view was
created.

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Edson Richter 2012-09-17 14:48:58 Get time for each operation in "Explain..."
Previous Message Raymond O'Donnell 2012-09-17 14:30:44 Re: On Ubuntu 12.04 i do have two psql one of those isn't working