Re: Working with PostgreSQL enums in C code

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Joseph Adams <joeyadams3(dot)14159(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Working with PostgreSQL enums in C code
Date: 2010-05-28 13:47:20
Message-ID: 24404.1275054440@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> 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).

Yeah, that was my first reaction too. If we don't already have one,
it would be appropriate to provide a "lookup enum value" function
(functionally about the same as enum_in, but designed to be called
conveniently from C). Then, if you needed to work from a textual
enum label, you'd call that function and then PG_RETURN_OID.

However, for a built-in enum type, I agree with Robert's solution of
just #define-ing fixed OIDs for the values of the type.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2010-05-28 14:08:47 Re: functional call named notation clashes with SQL feature
Previous Message Bruce Momjian 2010-05-28 13:41:24 Re: [9.1] pg_stat_get_backend_server_addr