Re: Question Again - Mailing list pgsql-general

From Andrew McMillan
Subject Re: Question Again
Date
Msg-id 39B6A407.AA2B215D@catalyst.net.nz
Whole thread Raw
In response to Question Again  ("Cristian D. GAL" <gal@mail.com>)
List pgsql-general
"Cristian D. GAL" wrote:
>
> >> is there a solution to find infos about a table?
> >> eg: I want to know what field names and their types has a certain table
> >> from a db.
>
> I read TFM and found -c option to 'psql' and came up with this trick:
>
> #!/some/where/perl
> use CGI qw(:standard);
>
> my $table = param('table');
> my $fields = `psql $DBNAME -h $DBHOST -U $DBUSER -c \"\\d $table\" -q`;
> print $fields;
> ..
>
> is there something a little more elegant than this?

strings /usr/lib/postgresql/bin/psql

Will give you a useful reference to the actual database queries behind
that \d, or you could look at the source, of course!

psql may not be in that location if you don't use Debian, of course :-)

Cheers,
                    Andrew.
--
_____________________________________________________________________
            Andrew McMillan, e-mail: Andrew@cat-it.co.nz
Catalyst IT Ltd, PO Box 10-225, Level 22, 105 The Terrace, Wellington
Me: +64 (21) 635 694, Fax: +64 (4) 499 5596, Office: +64 (4) 499 2267

pgsql-general by date:

Previous
From: "jeff seaman"
Date:
Subject: postgres and windows NT
Next
From: "Gary MacDougall"
Date:
Subject: Re: post installation error