Skip site navigation (1) Skip section navigation (2)

Re: dumping fields from Perl

From: Zak McGregor <zak(at)mighty(dot)co(dot)za>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: dumping fields from Perl
Date: 2004-02-29 23:17:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
On Sun, 29 Feb 2004 13:11:48 -0600
Tony Rice <email(at)email(dot)com> wrote:

> How can I dump the field names and their type and attributes from Perl?

use Pg;
use strict;
use warnings;

my $select=<<"SQL";

SELECT c.relname, a.attname, t.typname, a.attrelid 
FROM pg_class c, pg_attribute a, pg_type t
WHERE c.relkind = 'r' 
AND a.attnum > 0
AND a.attrelid = c.oid and a.atttypid = t.oid
ORDER BY relname, attname


# Do connection here...
my $PG=new Pg::connectdb(".....");
my $res=$PG->exec($select);


Hope that helps. I may have typoed above, and it is untested, but it's something
to work with.



========================================================================        Searchable database of 10 000+ car specs

In response to

pgsql-general by date

Next:From: Zak McGregorDate: 2004-03-01 00:14:56
Subject: count(1) return 0?
Previous:From: eleinDate: 2004-02-29 22:44:59
Subject: Re: SERIAL type - auto-increment grouped by other field

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group