From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | david(at)andl(dot)org |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: CStringGetTextDatum and other conversions in server-side code |
Date: | 2016-03-02 23:41:06 |
Message-ID: | 56D77A12.6000603@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)andl(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | cchee-ob | 2016-03-02 23:54:03 | BDR concern/issue |
Previous Message | David G. Johnston | 2016-03-02 23:38:37 | Re: Issue enabling track_counts to launch autovacuum in 9.4.5 |