From: | TalGloz <glozmantal(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Returning Vector of Pairs with a PostgreSQL C Extension Function |
Date: | 2018-08-25 12:54:38 |
Message-ID: | 1535201678396-0.post@n3.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
I want to return an vector of pairs using a C extension. This is a simple
code I have:
extern "C" {
Datum pair(PG_FUNCTION_ARGS){
// For text aka. character varying parameter
text *t1 = PG_GETARG_TEXT_PP(0);
text *t2 = PG_GETARG_TEXT_PP(1);
std::string localT1 = text_to_cstring(t1);
std::string localT2 = text_to_cstring(t2);
/* Construct the return value of the C extention to PostgreSQl */
// Returns Text ponter of casted cstrings to text
//PG_RETURN_TEXT_P(cstring_to_text_with_len(localT1.c_str(),
localT1.size()));
//PG_RETURN_TEXT_P(cstring_to_text_with_len(encodedLocalT1.c_str(),
encodedLocalT1.size()));
//PG_RETURN_TEXT_P(cstring_to_text_with_len(outputParam.c_str(),
outputParam.size()));
// Return vector of pairs
std::vector<std::pair<std::string, std::string>> ret;
ret.emplace_back(encodedLocalT1, encodedLocalT2);
PG_RETURN_ARRAYTYPE_P(ret);
};
PG_FUNCTION_INFO_V1(pair);
}
But it doesn't work like it. Even using this doesn't work:
ArrayType *array;
std::vector<std::pair<std::string, std::string>> ret;
ret.emplace_back(encodedLocalT1, encodedLocalT2);
array = ret;
PG_RETURN_POINTER(array);
Is it possible to return a vector of pairs? If not then how can I return 2
strings in an Array?
Best regards,
Tal
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2018-08-25 15:44:24 | Re: Returning Vector of Pairs with a PostgreSQL C Extension Function |
Previous Message | Naveen Dabas | 2018-08-25 05:44:48 | Re: pg_sample |