I am not sure I will understand the code inside PG_DUMP
I could call PG_DUMP and store the info on a text file and then read it into my program and then issue an SQL command
But I was hoping to get the info directly from the Postgres tables using some fancy query.
I am using some queries that give me a list of tables and a list of fields in a table but now I need the actual SQL as shown on PgAdmin
Maybe somebody knows the way PgAdmin generates it
--- On Mon, 4/11/11, Michael Glaesemann <grzm@seespotcode.net> wrote:
From: Michael Glaesemann <grzm@seespotcode.net> Subject: Re: [NOVICE] Need SQL of create TABLE including INDEX and SEQUENCE To: "Francisco Leovey" <fleovey@yahoo.com> Cc: pgsql-novice@postgresql.org Date: Monday, April 11, 2011, 1:06 PM
On Apr 11, 2011, at 7:55, Francisco Leovey wrote:
> Hello > > For a new project where I am running 2 versions of Postgres (8.4 and 9.0) simultaneously on an Ubuntu server: > I need the syntax of an SQL statement in order to create tables and all index from one database to the other via a utility program I have in Perl. > I see PgAdmin shows on the lower pane all the SQL needed to create a table and all its index, but I do not know how to obtain that info. > It would be optimal if I can get all the info in a single query (the way pgdump does). > Also I need the SQL to create all the SEQUENCES.
Can you call pg_dump?
pg_dump -s -t your_table
Otherwise, I recommend taking a look at the pg_dump source code.