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 1foxOm-0004CV-W9 for pgsql-general@arkaria.postgresql.org; Sun, 12 Aug 2018 20:55:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1foxOk-00039J-2d for pgsql-general@arkaria.postgresql.org; Sun, 12 Aug 2018 20:55:38 +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 1foxOj-00039C-N0 for pgsql-general@lists.postgresql.org; Sun, 12 Aug 2018 20:55:37 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1foxOc-00020x-Rx for pgsql-general@postgresql.org; Sun, 12 Aug 2018 20:55:36 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 0449BE853757 for ; Sun, 12 Aug 2018 13:55:30 -0700 (MST) Date: Sun, 12 Aug 2018 13:55:30 -0700 (MST) From: TalGloz To: pgsql-general@postgresql.org Message-ID: <1534107330015-0.post@n3.nabble.com> In-Reply-To: <1607.1534101134@sss.pgh.pa.us> References: <1534093538827-0.post@n3.nabble.com> <1534097342417-0.post@n3.nabble.com> <31921.1534098408@sss.pgh.pa.us> <1534099202325-0.post@n3.nabble.com> <1607.1534101134@sss.pgh.pa.us> Subject: Re: PostgreSQL C Language Extension with C++ Code 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 OK It worked. This is how I did it, hopefully it is right extern "C" { #include #include #include #include #include #include #include #include PG_MODULE_MAGIC; } #include #include #include #include #include // external compiled c++ library linked on running 'make' extern "C" { Datum sum_of_numbers(PG_FUNCTION_ARGS){ std::vector numbers {23, 445, 64}; int sum = 0; for (auto &item : numbers){ sum += item; } return sum; }; PG_FUNCTION_INFO_V1(sum_of_numbers); } I've managed to create and execute the function in my PostgreSQL database. So basically I can execute any CPP code as long as I declare my functions like this: extern "C" { Datum function_name(PG_FUNCTION_ARGS){ // CPP code here }; PG_FUNCTION_INFO_V1(function_name); } In addition tho thath, all the C headers should be * inside a extern "C" { }* block and all the CPP headers *outside the extern "C" { }* block, did I get it right? Thanks, Tal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html