Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftaw6-0008Bo-Pb for pgsql-general@arkaria.postgresql.org; Sat, 25 Aug 2018 15:57:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftaw5-0008O8-4a for pgsql-general@arkaria.postgresql.org; Sat, 25 Aug 2018 15:57:13 +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 1ftaw4-0008O0-TA for pgsql-general@lists.postgresql.org; Sat, 25 Aug 2018 15:57:12 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftaw1-0000Bd-VE for pgsql-general@postgresql.org; Sat, 25 Aug 2018 15:57:12 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id C080EEBE15D8 for ; Sat, 25 Aug 2018 08:57:07 -0700 (MST) Date: Sat, 25 Aug 2018 08:57:07 -0700 (MST) From: TalGloz To: pgsql-general@postgresql.org Message-ID: <1535212627744-0.post@n3.nabble.com> In-Reply-To: <4192.1535211864@sss.pgh.pa.us> References: <1535201678396-0.post@n3.nabble.com> <4192.1535211864@sss.pgh.pa.us> Subject: Re: Returning Vector of Pairs with a PostgreSQL C Extension Function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk OK so I think I'm on the right way with this code and now my goal is to return a text array (text[ ]) with 2 fields extern "C" {=20 Datum text_array(PG_FUNCTION_ARGS){=20 // For text aka. character varying parameter=20 text *t1 =3D PG_GETARG_TEXT_PP(0);=20 text *t2 =3D PG_GETARG_TEXT_PP(1);=20 std::string localT1 =3D text_to_cstring(t1);=20 std::string localT2 =3D text_to_cstring(t2);=20 ArrayType *array; Datum* elements[2]; int16 typlen; bool typbyval; char typalign; elements[0] =3D CStringGetDatum(localT1.c_str()); elements[1] =3D CStringGetDatum(localT2.c_str()); =20 get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign); array =3D construct_array(elements, 2, TEXTOID, typlen, typbyval, typalign); =20 PG_RETURN_ARRAYTYPE_P(array);=20 };=20 PG_FUNCTION_INFO_V1(text_array);=20 } But I'm getting this: g++ -std=3Dc++17 -fPIC -Wall -Werror -g -O0 -pthread -I/usr/pgsql-10/include/server -I/usr/local/include -I/usr/local/include/cppcodec -o seal_diff_cpp.o -c seal_diff_cpp.cpp In file included from seal_diff_cpp.cpp:2: seal_diff_cpp.cpp: In function =E2=80=98Datum seal_diff_cpp(FunctionCallInf= o)=E2=80=99: /usr/pgsql-10/include/server/postgres.h:562:29: error: invalid conversion from =E2=80=98Datum=E2=80=99 {aka =E2=80=98long unsigned int=E2=80=99} to = =E2=80=98Datum*=E2=80=99 {aka =E2=80=98long unsigned int*=E2=80=99} [-fpermissive] #define PointerGetDatum(X) ((Datum) (X)) ~^~~~~~~~~~~~ /usr/pgsql-10/include/server/postgres.h:584:28: note: in expansion of macro =E2=80=98PointerGetDatum=E2=80=99 #define CStringGetDatum(X) PointerGetDatum(X) ^~~~~~~~~~~~~~~ seal_diff_cpp.cpp:168:23: note: in expansion of macro =E2=80=98CStringGetDa= tum=E2=80=99 elements[0] =3D CStringGetDatum(localT1.c_str()); ^~~~~~~~~~~~~~~ /usr/pgsql-10/include/server/postgres.h:562:29: error: invalid conversion from =E2=80=98Datum=E2=80=99 {aka =E2=80=98long unsigned int=E2=80=99} to = =E2=80=98Datum*=E2=80=99 {aka =E2=80=98long unsigned int*=E2=80=99} [-fpermissive] #define PointerGetDatum(X) ((Datum) (X)) ~^~~~~~~~~~~~ /usr/pgsql-10/include/server/postgres.h:584:28: note: in expansion of macro =E2=80=98PointerGetDatum=E2=80=99 #define CStringGetDatum(X) PointerGetDatum(X) ^~~~~~~~~~~~~~~ seal_diff_cpp.cpp:169:16: note: in expansion of macro =E2=80=98CStringGetDa= tum=E2=80=99 elements[1] =3D CStringGetDatum(localT2.c_str()); ^~~~~~~~~~~~~~~ seal_diff_cpp.cpp:171:26: error: cannot convert =E2=80=98Datum**=E2=80=99 {= aka =E2=80=98long unsigned int**=E2=80=99} to =E2=80=98Datum*=E2=80=99 {aka =E2=80=98long uns= igned int*=E2=80=99} array =3D construct_array(elements, 2, TEXTOID, typlen, typbyval, typalig= n); ^~~~~~~~ In file included from /usr/pgsql-10/include/server/utils/acl.h:38, from /usr/pgsql-10/include/server/catalog/objectaddress.h:18, from /usr/pgsql-10/include/server/catalog/pg_publication.h:21, from /usr/pgsql-10/include/server/utils/rel.h:21, from seal_diff_cpp.cpp:6: /usr/pgsql-10/include/server/utils/array.h:370:42: note: initializing argument 1 of =E2=80=98ArrayType* construct_array(Datum*, int, Oid, int, bo= ol, char)=E2=80=99 extern ArrayType *construct_array(Datum *elems, int nelems, ~~~~~~~^~~~~ make: *** [Makefile:19: seal_diff_cpp.o] Error 1 Best regards, Tal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.ht= ml