Re: patch: General purpose utility functions used by the JSON data type

Поиск
Список
Период
Сортировка
От Joseph Adams
Тема Re: patch: General purpose utility functions used by the JSON data type
Дата
Msg-id AANLkTiksJpop_mmhgb7a2Cgz5tANO8pvpyURRY3QqqjL@mail.gmail.com
обсуждение исходный текст
Ответ на Re: patch: General purpose utility functions used by the JSON data type  (David Fetter <david@fetter.org>)
Ответы Re: patch: General purpose utility functions used by the JSON data type  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers
On Fri, Aug 13, 2010 at 2:02 PM, David Fetter <david@fetter.org> wrote:
> On Fri, Aug 13, 2010 at 01:33:06PM -0400, Robert Haas wrote:
>> Maybe so, but it's not clear the interface that Joseph implemented is
>> the one everyone wants...
>
> Fair enough.  What's the interface now in a nutshell?  Lack of
> nutshells might well mean the interface needs more work...

Suppose we have:

-- SQL --
CREATE TYPE colors AS ENUM ('red', 'green', 'blue');

-- C --
enum Colors {RED, GREEN, BLUE, COLOR_COUNT};

In a nutshell:

* Define an enum mapping like so:

static EnumLabel enum_labels[COLOR_COUNT] =
{{COLOR_RED, "red"},{COLOR_GREEN, "green"},{COLOR_BLUE, "blue"}
};

* Get the OIDs of the enum labels:

Oid oids[COLOR_COUNT];
getEnumLabelOids("colors", enum_labels, oids, COLOR_COUNT);

* Convert C enum values to OIDs using the table:

PG_RETURN_OID(oids[COLOR_BLUE]);

A caller would typically cache the Oid table with fn_extra.

Currently, getEnumLabelOids puts InvalidOid for labels that could not
successfully be looked up.  This will probably be changed to
ereport(ERROR) instead.

Also, I'm thinking that getEnumLabelOids should be renamed to
something that's easier to remember.  Maybe enum_oids or
get_enum_oids.


Joey Adams


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: WIP partial replication patch
Следующее
От: Tom Lane
Дата:
Сообщение: Re: review: psql: edit function, show function commands patch