Re: Working with PostgreSQL enums in C code - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Working with PostgreSQL enums in C code
Date
Msg-id AANLkTinsBwZLMoPF3Yq_Xzrav5dfYgKamKXggyO71m6H@mail.gmail.com
Whole thread Raw
In response to Working with PostgreSQL enums in C code  (Joseph Adams <joeyadams3.14159@gmail.com>)
Responses Re: Working with PostgreSQL enums in C code
List pgsql-hackers
On Fri, May 28, 2010 at 12:07 AM, Joseph Adams
<joeyadams3.14159@gmail.com> wrote:
> I learned that to return an enum value from C, one needs to return the
> OID of the right row of the pg_enum table.  I eventually managed to
> write the code below, which is mostly based on the enum_in function in
> src/backend/utils/adt/enum.c .

PG_RETURN macros shouldn't do any nontrivial processing (see the
existing ones for references).  I assume you have the enum labels
declared in pg_enum.h, so I think you can just return the correct OID
values directly.  Declare constants for them in pg_enum.h and then
just do PG_RETURN_OID(whatever).

#define JSONTypeNullOid   ...
#define JSONTypeStringOid ...
#define JSONTypeNumberOid ...

It really shouldn't be necessary to do a catalog lookup to retrieve a constant.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Failback with log shipping
Next
From: Andrew Dunstan
Date:
Subject: Re: mingw initdb failure on HEAD