Re: CStringGetTextDatum and other conversions in server-side code

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: CStringGetTextDatum and other conversions in server-side code
Дата
Msg-id 56D77A12.6000603@joeconway.com
обсуждение исходный текст
Ответ на CStringGetTextDatum and other conversions in server-side code  (<david@andl.org>)
Ответы Re: CStringGetTextDatum and other conversions in server-side code  (<david@andl.org>)
Список pgsql-general
(please do not post HTML to these lists; see:
https://wiki.postgresql.org/wiki/Mailing_Lists)

On 03/02/2016 03:06 PM, david@andl.org wrote:
> Writing a language handler: pl_language_handler. Need to do a variety of
> data conversions. One of them is char* C-string to and from Text/Varchar.
>
> The include file postgres.h has the macro CStringGetDatum but this is of
> no use: it’s just a cast.
>
> There is a builtin macro CStringGetTextDatum which calls a function and
> looks like it might work. Questions:
>
> 1.       Is this the right function?
> 2.       Is it OK to use, or are there restrictions?
> 3.       Does it have friends: are there other conversion functions like
> this for other data types (decimal, time in particular)?
> 4.       Is there any particular documentation I can read?

Your best bet is to look at examples. The code in the source tree under
contrib has many examples, and more specifically src/pl/* should have
even more relevant examples. Remember, grep is your friend -- get a copy
of the source tree and try:

cd <location-of-postgres-source-code>
grep -rni CStringGetTextDatum src/pl/* --include=*.c
grep -rni CStringGetTextDatum contrib/* --include=*.c
grep -rni TextDatumGetCstring contrib/* --include=*.c

Additionally there are external projects that implement postgres
procedural language handlers, e.g.:
  https://github.com/jconway/plr
Lots of good examples there too. Google for others.

Basically any symbol exported from the postgres backend can be used by
your PL. There is not a lot of documentation other than in the source
code itself. Look at examples, see what they do, emulate it.

HTH,

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development


Вложения

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

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Issue enabling track_counts to launch autovacuum in 9.4.5
Следующее
От: cchee-ob
Дата:
Сообщение: BDR concern/issue