Skip site navigation (1) Skip section navigation (2)

Re: Defining the same relation in another database

From: "Guido Barosio" <gbarosio(at)gmail(dot)com>
To: "Michael Talbot-Wilson" <mtw(at)view(dot)net(dot)au>
Cc: "Pgsql Novice Mailing List" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Defining the same relation in another database
Date: 2006-04-19 08:55:04
Message-ID: f7f6b4c70604190155p1690e229jbebb9247943edae7@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Shortly:

You just need to user pg_dump and psql. You may use them alltogether
in one piped sentence, or in two different sentences

a)

To run pg_dump, get the schema, no data,  a single table, and redirect
STDOUT to the psql command, which should take the imput and follow the
SQL instructions.

pg_dump -s -t table databaseA | psql databaseB

b)

To run pg_dump, get the schema, no data, a single table, and redirect
STDOUT to a file.
You may pickup that file later with psql -f.

1. pg_dump -s -t table databaseA > table_schema.sql
2. psql -f table_schema.sql databaseB

Good luck,
Guido

On 4/19/06, Michael Talbot-Wilson <mtw(at)view(dot)net(dot)au> wrote:
> How do you do this?  I guess it may require heroic methods such as the
> editing of dumps.  Or it is easy?
>
> I'd like to do this because the \d is complicated.  I've prototyped
> this thing in a temp database and now I'd like to do it for real.  I'd
> rather not copy it down on paper and do it all again.
>
> It is okay to move the relation and its data, but I really just want
> to recreate it in another database.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>


--
Guido Barosio
-----------------------
http://www.globant.com
guido(dot)barosio(at)globant(dot)com

In response to

Responses

pgsql-novice by date

Next:From: Robert LandsmeerDate: 2006-04-19 09:10:32
Subject: Re: Find all foreign keys and dropping them from a script.
Previous:From: Shoaib MirDate: 2006-04-19 08:17:04
Subject: Re: Defining the same relation in another database

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group