Thread: Defining the same relation in another database

Defining the same relation in another database

From
Michael Talbot-Wilson
Date:
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.


Re: Defining the same relation in another database

From
"Shoaib Mir"
Date:
Take the database dump using

pg_dump dbname > outfile

Now you can easily take out the DDL for relations and use them in another database.

/Shoaib

On 4/19/06, Michael Talbot-Wilson <mtw@view.net.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

Re: Defining the same relation in another database

From
"Guido Barosio"
Date:
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@view.net.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.barosio@globant.com

Re: Defining the same relation in another database

From
Michael Talbot-Wilson
Date:
On Wed, 19 Apr 2006, Guido Barosio wrote:

> pg_dump -s -t table databaseA | psql databaseB

Thanks.