How can I recreate a view in a new schema such that the view def references tables in the new schema ?

From: David Gauthier <davegauthierpg(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: How can I recreate a view in a new schema such that the view def references tables in the new schema ?
Date: 2020-03-26 17:16:09
Message-ID: CAMBRECB_0+Rch1CsQ=NyBzbgm7_6cOrmULQSk-80=5hRM+BeCQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Here's an interesting one for you...
psql (9.6.7, server 11.3) on linux

I have 2 DBs, differnet servers/instances. I want to take all the metadata
and data for a set of tables/views in the public schema of one DB and move
it all over to be inside a schema of a second DB/instance.

I'm using pg_dump to create the script and I believe I can insert a "set
search_path=myschem" in the output of pg_dump such that when it runs, the
"CREATE TABLE", "CREATE VIEW", "GRANT...", etc.... commands, will all go
into the new schema (which I have prepared). Problem is the view defs.
The view defs do not prefix the referenced tables with "myschem.", so the
CREATE VIEW xyx commands fail.

Is there a way to do this ?

Thanks in Advance.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2020-03-26 17:34:48 Re: How can I recreate a view in a new schema such that the view def references tables in the new schema ?
Previous Message Adrian Klaver 2020-03-26 16:26:39 Re: Duplicate key violation on upsert