pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: TalGloz <glozmantal@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Returning Vector of Pairs with a PostgreSQL C Extension Function
Date: Sat, 25 Aug 2018 08:57:07 -0700 (MST)
Message-ID: <1535212627744-0.post@n3.nabble.com> (raw)
In-Reply-To: <4192.1535211864@sss.pgh.pa.us>
References: <1535201678396-0.post@n3.nabble.com>
	<4192.1535211864@sss.pgh.pa.us>

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" { 
Datum text_array(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); 

        ArrayType  *array;
        Datum*       elements[2];
        int16           typlen;
        bool            typbyval;
        char            typalign;

        elements[0] = CStringGetDatum(localT1.c_str());
        elements[1] = CStringGetDatum(localT2.c_str());
        
        get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign);
        array = construct_array(elements, 2, TEXTOID, typlen, typbyval,
typalign);
        
        PG_RETURN_ARRAYTYPE_P(array); 

}; 
PG_FUNCTION_INFO_V1(text_array); 
}

But I'm getting this:

g++ -std=c++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 ‘Datum seal_diff_cpp(FunctionCallInfo)’:
/usr/pgsql-10/include/server/postgres.h:562:29: error: invalid conversion
from ‘Datum’ {aka ‘long unsigned int’} to ‘Datum*’ {aka ‘long unsigned
int*’} [-fpermissive]
 #define PointerGetDatum(X) ((Datum) (X))
                            ~^~~~~~~~~~~~
/usr/pgsql-10/include/server/postgres.h:584:28: note: in expansion of macro
‘PointerGetDatum’
 #define CStringGetDatum(X) PointerGetDatum(X)
                            ^~~~~~~~~~~~~~~
seal_diff_cpp.cpp:168:23: note: in expansion of macro ‘CStringGetDatum’
         elements[0] = CStringGetDatum(localT1.c_str());
                       ^~~~~~~~~~~~~~~
/usr/pgsql-10/include/server/postgres.h:562:29: error: invalid conversion
from ‘Datum’ {aka ‘long unsigned int’} to ‘Datum*’ {aka ‘long unsigned
int*’} [-fpermissive]
 #define PointerGetDatum(X) ((Datum) (X))
                            ~^~~~~~~~~~~~
/usr/pgsql-10/include/server/postgres.h:584:28: note: in expansion of macro
‘PointerGetDatum’
 #define CStringGetDatum(X) PointerGetDatum(X)
                            ^~~~~~~~~~~~~~~
seal_diff_cpp.cpp:169:16: note: in expansion of macro ‘CStringGetDatum’
  elements[1] = CStringGetDatum(localT2.c_str());
                ^~~~~~~~~~~~~~~
seal_diff_cpp.cpp:171:26: error: cannot convert ‘Datum**’ {aka ‘long
unsigned int**’} to ‘Datum*’ {aka ‘long unsigned int*’}
  array = construct_array(elements, 2, TEXTOID, typlen, typbyval, typalign);
                          ^~~~~~~~
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 ‘ArrayType* construct_array(Datum*, int, Oid, int, bool,
char)’
 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.html




view thread (9+ messages)  latest in thread

Message-ID: <1535212627744-0.post@n3.nabble.com>
Permalink:  ../1535212627744-0.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1535212627744-0.post@n3.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: glozmantal@gmail.com
  Subject: Re: Returning Vector of Pairs with a PostgreSQL C Extension Function
  In-Reply-To: <1535212627744-0.post@n3.nabble.com>
  References: <1535201678396-0.post@n3.nabble.com> <4192.1535211864@sss.pgh.pa.us> <1535212627744-0.post@n3.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox