RE: Extracting metadata about attributes from catalog - Mailing list pgsql-hackers

From Alex Pilosov
Subject RE: Extracting metadata about attributes from catalog
Date
Msg-id Pine.BSO.4.10.10106241102590.9446-100000@spider.pilosoft.com
Whole thread Raw
In response to RE: Extracting metadata about attributes from catalog  ("Bernardo Pons" <bernardo@atlas-iap.es>)
List pgsql-hackers
On Sun, 24 Jun 2001, Bernardo Pons wrote:

> 
> > Do 'psql -E ...', it will display actual queries used by psql.
> 
> I already do it. At the end of my first message there was an example with
> exactly the query you suggested.
> 
> > Your particular query is:
> > SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull,
> > a.atthasdef, a.attnum
> > FROM pg_class c, pg_attribute a, pg_type t
> > WHERE c.relname = '...tablename...'
> >   AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
> > ORDER BY a.attnum
Sorry about that. For parameterized types (like numeric, varchar),
atttypmod contains specific information. For varchar-like parameters, its
length of the field+4 (54 means varchar(50), for example). For numeric
paremeter (numeric(a,b)), its 327680*b+a

I'm not sure if there's a better (and more documented) way to decode those
numbers, though.....



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [PATCH] Re: Setuid functions
Next
From: Tom Lane
Date:
Subject: Re: Extracting metadata about attributes from catalog