Re: [libpq] OIDs of extension types? Of custom types?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dominique Devienne <ddevienne(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, pgsql-general(at)postgresql(dot)org
Subject: Re: [libpq] OIDs of extension types? Of custom types?
Date: 2022-10-14 14:35:09
Message-ID: 1183347.1665758109@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dominique Devienne <ddevienne(at)gmail(dot)com> writes:
> On Fri, Oct 14, 2022 at 2:31 PM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
>> You use the #defines like TEXTOID for the built-in Oids, right?

> I don't. I used
> https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat
> as a reference.
> I suspect that should be fairly stable, right? I have at least 2 or 3
> dozen OIDs pairs (scalar + array) of primitives
> and other types (Oid, Name, Text, Bytea, Uuid, etc...). Are there
> #defines for all of those? Where?

They're stable, but writing magic numbers leads to unreadable code.
Use the macros from catalog/pg_type_d.h.

>> For types from an extensions, you would run a query on "pg_type".

> OK, thanks.

In SQL queries, you can avoid hard-wiring anything by writing
things like "'hstore'::regtype". It may or may not be possible
to avoid fetching the OID altogether that way.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Verite 2022-10-14 14:39:13 Re: Number of updated rows with LibPQ
Previous Message Dominique Devienne 2022-10-14 13:42:13 Re: [libpq] OIDs of extension types? Of custom types?