Обсуждение: Table definition

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

Table definition

От
Bruno Prévost
Дата:

 
Hi,
Anybody know how to obtain the table definition in text.
Something like "select definition from pg_catalog.pg_views where viewname = 'xxx'" but for a table.
Thanks
Bruno
 

Re: Table definition

От
"Goutam Paruchuri"
Дата:
Probably there is no direct way get the definition (i could not find one atleast).
You can probably write a custom function which gives all columns, indexes and formulate a create table statement (text definition).
 
Let us know if you find a way out.
 
- Goutam

 

From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Bruno Prévost
Sent: Tuesday, November 16, 2004 9:04 AM
To: pgsql-sql@postgresql.org
Subject: [SQL] Table definition

 
Hi,
Anybody know how to obtain the table definition in text.
Something like "select definition from pg_catalog.pg_views where viewname = 'xxx'" but for a table.
Thanks
Bruno
 


Confidentiality Notice
The information contained in this e-mail is confidential and intended for use only by the person(s) or organization listed in the address. If you have received this communication in error, please contact the sender at O'Neil & Associates, Inc., immediately. Any copying, dissemination, or distribution of this communication, other than by the intended recipient, is strictly prohibited.

Re: Table definition

От
Peter Eisentraut
Дата:
Am Dienstag, 16. November 2004 15:04 schrieb Bruno Prévost:
> Anybody know how to obtain the table definition in text.

Use pg_dump.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: Table definition

От
Sam Mason
Дата:
Bruno Prévost wrote:
>Anybody know how to obtain the table definition in text.

Not quite sure if this is quite what you're after, but would:
 $ pg_dump -st foo

help at all?  It gives out the SQL that you would need to enter to
re-create the table.

 Sam


Re: Table definition

От
Bruno Prévost
Дата:
I need to use it in sql.
Thk
Bruno
----- Original Message ----- 
From: "Peter Eisentraut" <peter_e@gmx.net>
To: "Bruno Prévost" <bp@interaction.ws>
Cc: <pgsql-sql@postgresql.org>
Sent: Tuesday, November 16, 2004 10:16 AM
Subject: Re: [SQL] Table definition


> Am Dienstag, 16. November 2004 15:04 schrieb Bruno Prévost:
>> Anybody know how to obtain the table definition in text.
>
> Use pg_dump.
>
> -- 
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
> 



Re: Table definition

От
Peter Eisentraut
Дата:
Am Dienstag, 16. November 2004 16:40 schrieb Bruno Prévost:
> I need to use it in sql.

There is no direct way to do this in SQL, but I can offer you the following 
alternative:

CREATE FUNCTION get_table_definition(text) RETURNS text AS '
#!/bin/sh
pg_dump -t $1
' LANGUAGE plsh;

:)

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: Table definition

От
Bruno Prévost
Дата:
It could help me, but pg_dump give all foreigns key and index creation.
I'm not sure if it's not better to write a custom function in plpgsql.
Bruno

----- Original Message ----- 
From: "Peter Eisentraut" <peter_e@gmx.net>
To: "Bruno Prévost" <bp@interaction.ws>
Cc: <pgsql-sql@postgresql.org>
Sent: Tuesday, November 16, 2004 11:13 AM
Subject: Re: [SQL] Table definition


> Am Dienstag, 16. November 2004 16:40 schrieb Bruno Prévost:
>> I need to use it in sql.
>
> There is no direct way to do this in SQL, but I can offer you the 
> following
> alternative:
>
> CREATE FUNCTION get_table_definition(text) RETURNS text AS '
> #!/bin/sh
> pg_dump -t $1
> ' LANGUAGE plsh;
>
> :)
>
> -- 
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>