Search Postgresql Archives

Returning Vector of Pairs with a PostgreSQL C Extension Function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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&lt;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&lt;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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux