Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftY5V-0008RE-T3 for pgsql-general@arkaria.postgresql.org; Sat, 25 Aug 2018 12:54:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftY5T-0004My-HX for pgsql-general@arkaria.postgresql.org; Sat, 25 Aug 2018 12:54:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftY5T-0004Mr-0S for pgsql-general@lists.postgresql.org; Sat, 25 Aug 2018 12:54:43 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftY5Q-0003iw-07 for pgsql-general@postgresql.org; Sat, 25 Aug 2018 12:54:41 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 61411EBD8246 for ; Sat, 25 Aug 2018 05:54:38 -0700 (MST) Date: Sat, 25 Aug 2018 05:54:38 -0700 (MST) From: TalGloz To: pgsql-general@postgresql.org Message-ID: <1535201678396-0.post@n3.nabble.com> Subject: Returning Vector of Pairs with a PostgreSQL C Extension Function MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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> 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> 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