Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jHWPJ-0003yl-C9 for pgsql-general@arkaria.postgresql.org; Thu, 26 Mar 2020 17:35:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHWPH-0007sH-Pg for pgsql-general@arkaria.postgresql.org; Thu, 26 Mar 2020 17:35:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jHWPG-0007qE-2j for pgsql-general@lists.postgresql.org; Thu, 26 Mar 2020 17:35:03 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jHWP6-0000x5-OH for pgsql-general@postgresql.org; Thu, 26 Mar 2020 17:35:00 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 1A4AC5C021F; Thu, 26 Mar 2020 13:34:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 26 Mar 2020 13:34:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=E xt0tDfhl58ag91d1eHuoV/HvG/og2lQSHK3SU3Bwnw=; b=HsF9KrGzEawpunXTC CgNXzGua7certSQtUztCZAsvLjn0YHH8mXpIFe7jWCOC8tlVt0W6ooQtIzjlkJYD UO13lzVyCvWJZVhOjHKnM1D/I2wKgn9F97RiZdKyvEdmhe+T99Xe+GiptGVtLhex u3DxtLUBtEvB4N0diWppNnPPYui4o/IhmAQhQWOYpvvgwgOwTVPArBOrROvVi4+P H/wTncH2n+5dqlCEtsUrHiwqEItsEjz/QFnIcI0RZ8xRt3vxzxCO5Nkj6pRbqzuw CQcOMYzUk+XsCcqDrnAACFT+wPlSJEUHHWeuGjxYy4O0xeVfUqlp4gF6bep2WkoV GEvbA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=Ext0tDfhl58ag91d1eHuoV/HvG/og2lQSHK3SU3Bw nw=; b=JD2ppiIqvwEp04b1kuAYeUZjdJz1QX5ywTCMgVRKB8sKyH95D5tBny8Bt tgvWi+ESqerPtW/JvzsYOQ9M7fdwLSfhOmfpNK3L7V8f9wLnbnwRYpMAzm5u4GOU Cgl10sP5hNGpcDW6K5eIfAmk1WDh2e1g4uex6s7bM+vJ7eRIPrjI9I4v+QgB6woC K/b0duRfh5q58lhSH0BjCWx75h1N2+8xZ7VEXAI2rqRLX87ZvLMWTIxmM5hgXqcW MOqqRk5YC9SthCGvrZkfYgPJ+dgv+1FNprwSX7Aj6qC4FDQjAxpDrLt+/XK6gm5O OcHoHkPsvF0HhaH8WDfFeAWkCQYfQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehjedgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejhedrudej vddrledtrdelvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.10] (75-172-90-92.tukw.qwest.net [75.172.90.92]) by mail.messagingengine.com (Postfix) with ESMTPA id 51AC1306A0C6; Thu, 26 Mar 2020 13:34:49 -0400 (EDT) Subject: Re: How can I recreate a view in a new schema such that the view def references tables in the new schema ? To: David Gauthier , Postgres General References: From: Adrian Klaver Message-ID: <6abf5665-d761-c380-07ef-dce28c8fce08@aklaver.com> Date: Thu, 26 Mar 2020 10:34:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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