Re: Restoring a table with a different name

From: "Jim Wilson" <jimw(at)kelcomaine(dot)com>
To: "Mike Nolan" <nolan(at)gw(dot)tssi(dot)com>, "pgsql general list" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Restoring a table with a different name
Date: 2004-02-28 02:21:06
Message-ID: twig.1077934866.21883@kelcomaine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Nolan said:

> > > If I edit the dump file with 'sed' to change the table name, I get
> > > 'invalid command \N' errors trying to reload it.
> >
> > What sed syntax are you using?
>
> Here's the command line I used:
>
> sed -e 's/memmast/wk_memmast/' memmast.dmp > wk_memmast.dmp
>
> I see two potential problems here, and it took both of them to bite me.
>
> One is that I'm not changing all occurrences of 'memmast' to 'wk_memmast'.
> The other is that the string 'memmast' can and does occur within the
> name of another column, so the name of that column was edited by sed
> in the CREATE TABLE statement but not in the LOAD command.
>
> Changing the command line to:
>
> sed -e 's/ memmast / wk_memmast /' memmast.dmp > wk_memmast.dmp
>
> works, and without changing that column name.
>
> I think, however, that I may need to go with the other method (copying
> the table and dumping/restoring the copy), because the restore runs into
> name conflicts with several indexes and there is a trigger procedure
> on that table.

Also you could try (assuming you have perl, which you should):

perl -pi -e 's/ memmast / wk_memmast /' memmast.dmp

to replace all occurances in the file w/o making a copy.

And:

perl -pi -e 's/CREATE UNIQUE INDEX /CREATE UNIQUE INDEX wk_/' memmast.dmp
perl -pi -e 's/CREATE INDEX /CREATE INDEX wk_/' memmast.dmp

It looks like you've got the idea anyway. There are ways to get even fancier
with the perl tool, but for now keep it simple and have fun with it.

Best,

Jim Wilson

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moran 2004-02-28 02:45:01 setting datestyle for different databases within a cluster
Previous Message Bill Moran 2004-02-28 02:09:38 Re: efficient storing of urls