Thread: PQftype() and Oid

PQftype() and Oid

From
Andro
Date:
Hi,<br /><br />Oids are in pg_type catalog (server side) and src/include/catalog/pg_type.h (hard-wired).<br /><br />But
whatshould we compare the Oid returned by PQftype() with?<br />Let's say I want to check if column 1 is a VARCHAR, do I
haveto <br /><br />if (PQftype(res,1) == 1043)<br /> ...;<br /><br />?<br />Isn't there a kind of enum which we could
relyon to find out types? What if Oids change in pg_type.h?<br /><br />Thanks<br /><br />Charles<br /><br /> 

Re: PQftype() and Oid

From
Volkan YAZICI
Date:
On Aug 04 04:38, Andro wrote:
> Oids are in pg_type catalog (server side) and src/include/catalog/pg_type.h
> (hard-wired).
> 
> But what should we compare the Oid returned by PQftype() with?
> Let's say I want to check if column 1 is a VARCHAR, do I have to
> 
> if (PQftype(res,1) == 1043)
> ...;
> 
> ?
> Isn't there a kind of enum which we could rely on to find out types? What if
> Oids change in pg_type.h?

You can make another query on pg_type to learn OID of a specific type.
And then compare it with the returned one from PQftype(main_query_res).

Furthermore, I think this is the only reliable way of accomplising this
task. (IIRC, PHP PostgreSQL API does same too.) Otherwise, when you use
hard-wired headers (e.g. by including pg_type.h) what will you do when
related server has a custom type that isn't get shippied with the
PostgreSQL headers you included.


Regards.


Re: PQftype() and Oid

From
Andro
Date:
While I agree this is a reliable way of matching, this has a
significant impact on performance to make an extra query on each field
that I want the type of ! And this makes this approach definitly not
the one to implement IMO.

Best,

Charles

On 8/5/06, Volkan YAZICI <yazicivo@ttnet.net.tr> wrote:
> On Aug 04 04:38, Andro wrote:
> > Oids are in pg_type catalog (server side) and src/include/catalog/pg_type.h
> > (hard-wired).
> >
> > But what should we compare the Oid returned by PQftype() with?
> > Let's say I want to check if column 1 is a VARCHAR, do I have to
> >
> > if (PQftype(res,1) == 1043)
> > ...;
> >
> > ?
> > Isn't there a kind of enum which we could rely on to find out types? What if
> > Oids change in pg_type.h?
>
> You can make another query on pg_type to learn OID of a specific type.
> And then compare it with the returned one from PQftype(main_query_res).
>
> Furthermore, I think this is the only reliable way of accomplising this
> task. (IIRC, PHP PostgreSQL API does same too.) Otherwise, when you use
> hard-wired headers (e.g. by including pg_type.h) what will you do when
> related server has a custom type that isn't get shippied with the
> PostgreSQL headers you included.
>
>
> Regards.
>