Another solution would be to create a view based on a function and pass the schema name to the function.
But, I think you have to rethink your server configuration and may be whole development environment. One server for live data and staging, testing , training ... I found that really dangerous
From: Alban Hertroys <haramrae@xxxxxxxxx>
To: Adam Mackler <adammackler@xxxxxxxxx>
Cc: pgsql-general@xxxxxxxxxxxxxx
Sent: Monday, September 17, 2012 4:46 PM
Subject: Re: Can a view use a schema search_path?
On 17 September 2012 11:06, Adam Mackler <adammackler@xxxxxxxxx> 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.
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
But, I think you have to rethink your server configuration and may be whole development environment. One server for live data and staging, testing , training ... I found that really dangerous
Regards
From: Alban Hertroys <haramrae@xxxxxxxxx>
To: Adam Mackler <adammackler@xxxxxxxxx>
Cc: pgsql-general@xxxxxxxxxxxxxx
Sent: Monday, September 17, 2012 4:46 PM
Subject: Re: Can a view use a schema search_path?
On 17 September 2012 11:06, Adam Mackler <adammackler@xxxxxxxxx> 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.
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general