pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: pg_restore (fromuser -> touser)
Date: Wed, 4 Aug 2021 00:46:15 +0200
Message-ID: <20210803224615.GB3138@hjp.at> (raw)
In-Reply-To: <CA+weYr0n53CxMVC9wdLSnwMf68Om7g5wQd1AQEbLB6mREUhtcA@mail.gmail.com>
References: <CAOeXn7o5qOF4kJMthdh4AWE6UxqQw=-_xvT7kF2vmASorUWWJg@mail.gmail.com>
	<CA+weYr0n53CxMVC9wdLSnwMf68Om7g5wQd1AQEbLB6mREUhtcA@mail.gmail.com>

On 2021-07-27 09:43:45 +0800, Ben Madin wrote:
> Hi - we have had to do such operations quite commonly, if you want to automate
> / stream such a change I would suggest that you look into sed. Off the top of
> my head, consider something like this:
> 
> pg_dump --format=p --schema=schema_a original_database | sed 's/ schema_a./
> schema_b./g' | psql new_database
> 
> this is presuming a space before the schemaname, and a fullstop between schema
> and other elements.

Actually the "." in a regular expression matches any character, so this
will also replace e.g. " schema_a5" with " schema_b.". This is easily
fixed (just add a backslash), but more importantly, it will replace that
string everywhere, regardless of context. This might lead to syntax
errors or data corruption.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (10+ messages)

Message-ID: <20210803224615.GB3138@hjp.at>
Permalink:  ../20210803224615.GB3138@hjp.at/
Also on:    postgresql.org/message-id/20210803224615.GB3138@hjp.at

 · 

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: hjp-pgsql@hjp.at
  Subject: Re: pg_restore (fromuser -> touser)
  In-Reply-To: <20210803224615.GB3138@hjp.at>
  References: <CAOeXn7o5qOF4kJMthdh4AWE6UxqQw=-_xvT7kF2vmASorUWWJg@mail.gmail.com> <CA+weYr0n53CxMVC9wdLSnwMf68Om7g5wQd1AQEbLB6mREUhtcA@mail.gmail.com> <20210803224615.GB3138@hjp.at>

* 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