Re: Returning Vector of Pairs with a PostgreSQL C Extension Function

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: TalGloz <glozmantal(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Returning Vector of Pairs with a PostgreSQL C Extension Function
Date: 2018-08-27 12:44:41
Message-ID: CAFj8pRDLd+8Uc26vXCV_gU-8GvdwtP-S2Do-YcpwBoiwZt2fwA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2018-08-27 14:40 GMT+02:00 TalGloz <glozmantal(at)gmail(dot)com>:

> It looks like changing the
>
> elements[0] = CStringGetDatum(localT1.c_str());
> elements[1] = CStringGetDatum(localT2.c_str());
>
> to:
>
> elements[0] = PointerGetDatum(cstring_to_text(localT1.c_str()));
> elements[1] = PointerGetDatum(cstring_to_text(localT2.c_str()));
>
> Solved the problem. If anyone thinks that there is a better way please tell
> me.
>

There is not better or worst way - you have to use just correct way, that
is one

There are already prepared macros

#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s))
#define TextDatumGetCString(d) text_to_cstring((text *) DatumGetPointer(d))

you can use it.

Regards

Pavel

> Best regards,
> Tal
>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-
> f1843780.html
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message TalGloz 2018-08-27 13:04:14 Re: Returning Vector of Pairs with a PostgreSQL C Extension Function
Previous Message TalGloz 2018-08-27 12:40:37 Re: Returning Vector of Pairs with a PostgreSQL C Extension Function