Dumping table definitions

Поиск
Список
Период
Сортировка
Искать

Dumping table definitions

От:
"Mark Fenbers" <Mark.Fenbers@noaa.gov>
Дата:
Вложения:
I am looking for a way to reformat the information that is generated from
    \d mytable
into SQL syntax, such that the table can be recreated with 'psql -f 
mytable.sql' complete with index and constraint definitions.  I can do 
awk and sed commands to do this if I need to, but first wanted to check 
if Pg already had tools to export the table structure (without the 
data).  Does it?

Also, Is there a way to export the structure of all tables at once 
instead of one table at a time?

Mark

Re: Dumping table definitions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Mark Fenbers"  writes:
> I am looking for a way to reformat the information that is generated from
>     \d mytable
> into SQL syntax, such that the table can be recreated with 'psql -f 
> mytable.sql' complete with index and constraint definitions.  I can do 
> awk and sed commands to do this if I need to, but first wanted to check 
> if Pg already had tools to export the table structure (without the 
> data).  Does it?

pg_dump with the -s switch is a much better way ...
		regards, tom lane

Re: Dumping table definitions

От:
"Jim Buttafuoco" <jim@contactbda.com>
Дата:

use pg_dump with the --schema-only and --table= params


---------- Original Message -----------
From: "Mark Fenbers" 
To: Pg SQL Discussion Group 
Sent: Mon, 18 Jul 2005 12:50:54 -0400
Subject: [SQL] Dumping table definitions

> I am looking for a way to reformat the information that is generated from
>     \d mytable
> into SQL syntax, such that the table can be recreated with 'psql -f 
> mytable.sql' complete with index and constraint definitions.  I can do 
> awk and sed commands to do this if I need to, but first wanted to check 
> if Pg already had tools to export the table structure (without the 
> data).  Does it?
> 
> Also, Is there a way to export the structure of all tables at once 
> instead of one table at a time?
> 
> Mark
------- End of Original Message -------


Re: Dumping table definitions

От:
Dawid Kuroczko <qnex42@gmail.com>
Дата:
On 7/18/05, Mark Fenbers  wrote:
> I am looking for a way to reformat the information that is generated from
>     \d mytable
> into SQL syntax, such that the table can be recreated with 'psql -f
> mytable.sql' complete with index and constraint definitions.  I can do
> awk and sed commands to do this if I need to, but first wanted to check
> if Pg already had tools to export the table structure (without the
> data).  Does it?

pg_dump is your friend!  Use option -s (--schema-only).
It will dump the information you want. :-)
 Regards,   Dawid

FAQ