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 1ftajz-0007ZJ-8g for pgsql-general@arkaria.postgresql.org; Sat, 25 Aug 2018 15:44:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftajt-0002Fy-CV for pgsql-general@arkaria.postgresql.org; Sat, 25 Aug 2018 15:44:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftajt-0002Fr-4R for pgsql-general@lists.postgresql.org; Sat, 25 Aug 2018 15:44:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftajl-0008IO-5p for pgsql-general@postgresql.org; Sat, 25 Aug 2018 15:44:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w7PFiO3Z004193; Sat, 25 Aug 2018 11:44:24 -0400 From: Tom Lane To: TalGloz cc: pgsql-general@postgresql.org Subject: Re: Returning Vector of Pairs with a PostgreSQL C Extension Function In-reply-to: <1535201678396-0.post@n3.nabble.com> References: <1535201678396-0.post@n3.nabble.com> Comments: In-reply-to TalGloz message dated "Sat, 25 Aug 2018 05:54:38 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4191.1535211864.1@sss.pgh.pa.us> Date: Sat, 25 Aug 2018 11:44:24 -0400 Message-ID: <4192.1535211864@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk TalGloz 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> 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