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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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