From: Tom Lane <tgl@sss.pgh.pa.us>
To: TalGloz <glozmantal@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Returning Vector of Pairs with a PostgreSQL C Extension Function
Date: Sat, 25 Aug 2018 11:44:24 -0400
Message-ID: <4192.1535211864@sss.pgh.pa.us> (raw)
In-Reply-To: <1535201678396-0.post@n3.nabble.com>
References: <1535201678396-0.post@n3.nabble.com>
TalGloz <glozmantal@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, glozmantal@gmail.com
Subject: Re: Returning Vector of Pairs with a PostgreSQL C Extension Function
In-Reply-To: <4192.1535211864@sss.pgh.pa.us>
References: <1535201678396-0.post@n3.nabble.com> <4192.1535211864@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox