Skip site navigation (1) Skip section navigation (2)

Re: Working with PostgreSQL enums in C code

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Joseph Adams <joeyadams3(dot)14159(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Working with PostgreSQL enums in C code
Date: 2010-05-28 11:17:23
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Fri, May 28, 2010 at 12:07 AM, Joseph Adams
<joeyadams3(dot)14159(at)gmail(dot)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
The Enterprise Postgres Company

In response to


pgsql-hackers by date

Next:From: Andrew DunstanDate: 2010-05-28 11:51:04
Subject: Re: mingw initdb failure on HEAD
Previous:From: Heikki LinnakangasDate: 2010-05-28 10:58:43
Subject: Failback with log shipping

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group