works for me ;-)use DBI; use CGI; my $dbname = "dbname"; my $user = "user"; my $password = "password"; my @tables = qw/table1 table2/; my $q = new CGI; my $dbh = DBI->connect("DBI:Pg:dbname=$dbname","$user","$password", { PrintError => 0, RaiseError => 0, AutoCommit => 1 }) || die "Could not connect to database:\n"; foreach my $tab ( @tables ) { my $attrs = $dbh->func($tab, 'table_attributes'); print $q->p, $q->strong($_), $q->start_table({BORDER=>1}), $q->TR( $q->th([qw/NAME TYPE SIZE NULLABLE DEFAULT CONSTRAINT PRIMARY_ +KEY/]) ); foreach my $item ( @{$attrs} ) { my $type_name = %{$dbh->type_info(%{$item}->{TYPE})}->{TYPE_NA +ME} ; print "\n",$q->TR( $q->td( [ %{$item}->{NAME}, #%{$item}->{TYPE}, $type_name, %{$item}->{SIZE}, %{$item}->{NULLABLE}, %{$item}->{DEFAULT}, %{$item}->{CONSTRAINT}, %{$item}->{PRIMARY_KEY}, ] ) ); } print $q->end_table; }
NAME TYPE SIZE NULLABLE DEFAU +LT CONSTRAINT PRIMARY_KEY bonsai_id int4 4 0 + nextval('public.bonsais_bonsai_id_seq'::text) 1 name text 40 1 + 0 type_id int4 4 1 + 0 purchase_date bytea 4 1 + 0 birthdate bytea 4 1 + 0 shop text 80 1 + 0 comment text 1 + 0
In reply to Re: how to get complete information about tables
by insaniac
in thread how to get complete information about tables
by Miguel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |