Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Table definition

1 view
Skip to first unread message

Bruno Prévost

unread,
Nov 16, 2004, 9:04:26 AM11/16/04
to
 
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
 

Goutam Paruchuri

unread,
Nov 16, 2004, 10:07:21 AM11/16/04
to
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-s...@postgresql.org [mailto:pgsql-s...@postgresql.org] On Behalf Of Bruno Prévost
Sent: Tuesday, November 16, 2004 9:04 AM
To: pgsq...@postgresql.org
Subject: [SQL] Table definition



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.

Peter Eisentraut

unread,
Nov 16, 2004, 10:16:48 AM11/16/04
to
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/

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Sam Mason

unread,
Nov 16, 2004, 10:29:23 AM11/16/04
to
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

Bruno Prévost

unread,
Nov 16, 2004, 10:40:03 AM11/16/04
to
I need to use it in sql.
Thk
Bruno

----- Original Message -----
From: "Peter Eisentraut" <pet...@gmx.net>
To: "Bruno Prévost" <b...@interaction.ws>
Cc: <pgsq...@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/
>


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majo...@postgresql.org)

Peter Eisentraut

unread,
Nov 16, 2004, 11:13:34 AM11/16/04
to
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;

:)

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Bruno Prévost

unread,
Nov 16, 2004, 11:49:11 AM11/16/04
to
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" <pet...@gmx.net>
To: "Bruno Prévost" <b...@interaction.ws>
Cc: <pgsq...@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/
>


---------------------------(end of broadcast)---------------------------

0 new messages