pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: David Gauthier <davegauthierpg@gmail.com>
To: Postgres General <pgsql-general@postgresql.org>
Subject: Re: How can I recreate a view in a new schema such that the view def references tables in the new schema ?
Date: Thu, 26 Mar 2020 10:34:48 -0700
Message-ID: <6abf5665-d761-c380-07ef-dce28c8fce08@aklaver.com> (raw)
In-Reply-To: <CAMBRECB_0+Rch1CsQ=NyBzbgm7_6cOrmULQSk-80=5hRM+BeCQ@mail.gmail.com>
References: <CAMBRECB_0+Rch1CsQ=NyBzbgm7_6cOrmULQSk-80=5hRM+BeCQ@mail.gmail.com>

On 3/26/20 10:16 AM, David Gauthier wrote:
> 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.


Well first, the current minor version of 9.6 is .17 so you are 10 
releases behind. In fact the 9.6.8 release includes changes that impact 
the below:
https://www.postgresql.org/docs/9.6/release-9-6-8.html

> 
> 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 ?

By manually changing the definition? It is not an error for a VIEW in 
one schema to refer to tables in other schemas. AFAIK the code has no 
way of knowing you want to move the underlying tables just by specifying 
a search_path.

> 
> Thanks in Advance.


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (7+ messages)  latest in thread

Message-ID: <6abf5665-d761-c380-07ef-dce28c8fce08@aklaver.com>
Permalink:  ../6abf5665-d761-c380-07ef-dce28c8fce08@aklaver.com/
Also on:    postgresql.org/message-id/6abf5665-d761-c380-07ef-dce28c8fce08@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, davegauthierpg@gmail.com
  Subject: Re: How can I recreate a view in a new schema such that the view def references tables in the new schema ?
  In-Reply-To: <6abf5665-d761-c380-07ef-dce28c8fce08@aklaver.com>
  References: <CAMBRECB_0+Rch1CsQ=NyBzbgm7_6cOrmULQSk-80=5hRM+BeCQ@mail.gmail.com> <6abf5665-d761-c380-07ef-dce28c8fce08@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox