Thread: Question

Question

From
"Cristian D. GAL"
Date:
Hi,

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.

--
Cristian D. GAL
gal@mail.com


Re: Question

From
"Adam Lang"
Date:
at the psql prompt type: \d <tablename>

Adam Lang
Systems Engineer
Rutgers Casualty Insurance Company
----- Original Message -----
From: "Cristian D. GAL" <gal@mail.com>
To: <pgsql-general@postgresql.org>
Sent: Wednesday, September 06, 2000 10:54 AM
Subject: [GENERAL] Question


>
> Hi,
>
> 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.
>
> --
> Cristian D. GAL
> gal@mail.com


Re: Question

From
Frank Bax
Date:
At 05:54 PM 9/06/00 +0300, you 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.

in psql use:    \d tablename

Inside your own program you will need a query.  You can display the query
behind any psql command if you start psql with the -E option.

Frank


Question Again

From
"Cristian D. GAL"
Date:
>> 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?

Cristian GAL
gal@mail.com



Re: Question Again

From
Andrew McMillan
Date:
"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