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

From Tom Lane
Subject Re: Working with PostgreSQL enums in C code
Date
Msg-id 24404.1275054440@sss.pgh.pa.us
Whole thread Raw
In response to Re: Working with PostgreSQL enums in C code  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Working with PostgreSQL enums in C code
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> 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).

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


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Next
From: Pavel Stehule
Date:
Subject: Re: functional call named notation clashes with SQL feature