Forum OpenACS Q&A: Re: getting Meta Data information

Collapse
Posted by David Siktberg on
In PostgreSQL you can query the tables pg_class, pg_attribute, and pg_type.  Here is a tcl code fragment I've used to get information on a single table.  You should check the PostgreSQL documentation for more information about these tables and how they are used, or inspect the table contents directly.  Maybe there is an easier way ...

set ZZtable_oid [database_to_tcl_string $db "select relfilenode from pg_class where relname='$ZZtable'"]

set ZZdd_set [ns_db select $db "select attname, atttypid, atttypmod, typname
from pg_attribute, pg_type where attnum > 0 and pg_type.oid = atttypid and attrelid = $ZZtable_oid"]

while { [ns_db getrow $db $ZZdd_set] } {
    set ZZcolname [ns_set get $ZZdd_set attname]
    set ZZdd_type($ZZcolname) [ns_set get $ZZdd_set typname]
}