Re: [HACKERS] pg_type questions

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] pg_type questions
Date: 1999-10-17 16:50:10
Message-ID: 199910171650.MAA11065@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > What would be the best way to digest the output of libpq's PQftype()?
> > (Perhaps a char * PQftypetext() would be of general use?)
>
> > (The issue here is that I do _not_ want to have to query pg_type for that
> > information, since psql has no business contacting the database server
> > when not asked to do so.)
>
> You can't have it both ways: either you look up the OID in pg_type,
> or the info you provide is incomplete/unreliable.
>
> For the standard system types like int4, text, etc, it's probably OK
> for client code to assume that particular numeric OIDs correspond to
> those types --- use the #defines that are in catalog/pg_type.h, such as
> BOOLOID, to refer to those types. (I think there are one or two places
> in libpq and/or psql that do this already, eg, to decide whether a
> column is "numeric".) The backend does this all over the place, but
> it's a little shakier for frontend code to do it, because a frontend
> might possibly be used with other database versions than the one it was
> compiled for. Still, I think you could get away with it for standard
> types --- AFAIK no one has any intention of renumbering those.
>
> (Thomas has been muttering dire things about the date/time types, so
> you might be well advised not to assume anything about those ;-).)
>
> It would not be an unreasonable idea for libpq to provide a general
> purpose type-OID-to-type-name mapper, with the understanding that this
> mapper *would* query the backend at need. (Of course it should know
> automatically about the most common standard types, and it should cache
> the results of previous lookups so any one OID is queried at most once
> per connection.) We have heard from a number of people who have built
> exactly that facility for their applications, so it's obviously useful.

Yes, Tom is exactly right on all these points. My suggestion to look in
include/catalog was just my quick answer.

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-10-17 17:25:00 Re: [HACKERS] is it possible to use LIMIT and INTERSECT ?
Previous Message Oleg Bartunov 1999-10-17 16:40:32 is it possible to use LIMIT and INTERSECT ?