| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | TalGloz <glozmantal(at)gmail(dot)com> | 
| Cc: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: Returning Vector of Pairs with a PostgreSQL C Extension Function | 
| Date: | 2018-08-25 15:44:24 | 
| Message-ID: | 4192.1535211864@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
TalGloz <glozmantal(at)gmail(dot)com> writes:
> I want to return an vector of pairs using a C extension.
You're going to have to work a lot harder than this:
>         // Return vector of pairs
>         std::vector<std::pair<std::string, std::string>> ret;
>         ret.emplace_back(encodedLocalT1, encodedLocalT2);
>         PG_RETURN_ARRAYTYPE_P(ret);
I do not know what the internal representation of std::vector is in
your C++ library, but it seems highly unlikely that it exactly matches
what Postgres arrays look like.  Nor has Postgres ever heard of a
std::pair.  You'd need to either create a composite type of two text
columns and then build an array of those, or else decide to return a
two-dimensional array to represent this case.  In any case, you must
use Postgres functions to construct the return value; the C++ library
is completely useless for that.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | TalGloz | 2018-08-25 15:57:07 | Re: Returning Vector of Pairs with a PostgreSQL C Extension Function | 
| Previous Message | TalGloz | 2018-08-25 12:54:38 | Returning Vector of Pairs with a PostgreSQL C Extension Function |