From: Rob Sargent <robjsargent@gmail.com>
To: Tiffany Thang <tiffanythang@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Copy entire schema A to a different schema B
Date: Wed, 20 Feb 2019 17:02:25 -0700
Message-ID: <fd929e51-1e7e-9e6c-cc70-49bca2c778a4@gmail.com> (raw)
In-Reply-To: <CAB_W-NPfsj96jTepXUbk_7rF2K55xoEejpV+fhTNTMmsXPxZ5g@mail.gmail.com>
References: <CAB_W-NMjRS4ah_txcF=pZmYA_KfZLm+mT5eL26-az+xTHEdXcA@mail.gmail.com>
<9aa9cb06-8bca-910c-5251-d974849dda7c@gmail.com>
<CAB_W-NN-ty=XL1Mmf4BfFj8P1ruczGNxBd4vxSZgYVG7N0A+3g@mail.gmail.com>
<65a629f9-6745-6cec-30d0-87eaf1ffa7bf@aklaver.com>
<CAB_W-NORbOCrssvc+b1CcPy=Ka=k_5WU4bAtMtJiMDwjY=AzOA@mail.gmail.com>
<ed7629d0-876d-a03d-9445-a1a5d4f20acc@gmail.com>
<CAB_W-NPfsj96jTepXUbk_7rF2K55xoEejpV+fhTNTMmsXPxZ5g@mail.gmail.com>
On 2/20/19 4:21 PM, Tiffany Thang wrote:
> Hi Ron,
> How would that work if I'm only interested in importing/refreshing a
> single table in a target schema that contains several other tables?
>
> Thanks.
>
> Tiff
>
> On Wed, Feb 20, 2019 at 5:36 PM Rob Sargent <robjsargent@gmail.com
> <mailto:robjsargent@gmail.com>> wrote:
>
>
> On 2/20/19 3:22 PM, Tiffany Thang wrote:
>> Hi Adrian,
>> I managed to backup my table in parallel using -Fd but I'm back
>> to my original issue where I could not restore the table to a
>> different schema.
>>
>> For example,
>> I would like to backup testuser1.mytable and restore it to
>> testuser2.mytable.
>>
>> pg_dump -U testuser1 -Fd -f c:\temp\testuser1 -j 8 -t mytable -h
>> myserver testdb
>>
>> where mytable is in testuser1 schema
>>
>> The dump completed fine but when I attempted to restore the table
>> using pg_restore to another database, it tried to create the
>> table in testuser1 schema. The restore failed since testuser1
>> schema does not exist in the target database. When I created a
>> testuser1 schema in the target database, the restore worked fine.
>> Since the dump toc is in binary format, I could not make the
>> change to reflect the new target schema, testuser2.
>>
>> So, how should I go about restoring tables from one schema to a
>> different schema name?
>>
>> Thanks.
>>
>> Tiff
>>
>>
> Can you not simply rename the schema after importing it? Perhaps
> renaming an exiting version first, if necessary. Rename schema A
> to B; import schema A; rename A to C; rename B to A;
>
>
If nothing is in the way for the restore maybe all you need is
ALTER TABLE [ IF EXISTS ]/|name|/
SET SCHEMA/|new_schema|/
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: robjsargent@gmail.com, tiffanythang@gmail.com
Subject: Re: Copy entire schema A to a different schema B
In-Reply-To: <fd929e51-1e7e-9e6c-cc70-49bca2c778a4@gmail.com>
References: <CAB_W-NMjRS4ah_txcF=pZmYA_KfZLm+mT5eL26-az+xTHEdXcA@mail.gmail.com> <9aa9cb06-8bca-910c-5251-d974849dda7c@gmail.com> <CAB_W-NN-ty=XL1Mmf4BfFj8P1ruczGNxBd4vxSZgYVG7N0A+3g@mail.gmail.com> <65a629f9-6745-6cec-30d0-87eaf1ffa7bf@aklaver.com> <CAB_W-NORbOCrssvc+b1CcPy=Ka=k_5WU4bAtMtJiMDwjY=AzOA@mail.gmail.com> <ed7629d0-876d-a03d-9445-a1a5d4f20acc@gmail.com> <CAB_W-NPfsj96jTepXUbk_7rF2K55xoEejpV+fhTNTMmsXPxZ5g@mail.gmail.com> <fd929e51-1e7e-9e6c-cc70-49bca2c778a4@gmail.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