Question

Started by Cristian D. GALover 25 years ago5 messagesgeneral
Jump to latest
#1Cristian D. GAL
gal@mail.com

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

#2Adam Lang
aalang@rutgersinsurance.com
In reply to: Cristian D. GAL (#1)
Re: Question

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

Show quoted text

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

#3Frank Bax
fbax@execulink.com
In reply to: Cristian D. GAL (#1)
Re: Question

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

#4Cristian D. GAL
gal@mail.com
In reply to: Adam Lang (#2)
Question Again

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

#5Andrew McMillan
andrew@catalyst.net.nz
In reply to: Cristian D. GAL (#4)
Re: Question Again

"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