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: PostgreSQL C Language Extension with C++ Code
Date: Sun, 12 Aug 2018 11:09:02 -0700 (MST)
Message-ID: <1534097342417-0.post@n3.nabble.com> (raw)
In-Reply-To: <CA+FnnTzH1gZ8o4a_WTD79kk7CNUzFu0NHUmbs03Gax0Su4Lgzw@mail.gmail.com>
References: <1534093538827-0.post@n3.nabble.com>
	<CA+FnnTzH1gZ8o4a_WTD79kk7CNUzFu0NHUmbs03Gax0Su4Lgzw@mail.gmail.com>

OK now I have this code:

1:   extern "C" {  // The C header should go here
2:   #include <postgres.h>
3:   #include <utils/rel.h>
4:   #include <fmgr.h>
5:   #include <utils/array.h>
6:   #include <utils/builtins.h>
7:   #include <catalog/pg_type.h>
8:   #include <stdlib.h>
9:   #include <stdint.h>
10:  
11: PG_MODULE_MAGIC;
12: }
13:
14: // CPP header without extern "C"
15: #include <string>
16: #include <vector>
17: #include <iostream>
18: #include <fstream>
19: #include <seal/seal.h> // external compiled c++ library linked on
running 'make'
20:
21: Datum sum_of_numbers(PG_FUNCTION_ARGS);
22: PG_FUNCTION_INFO_V1(sum_of_numbers);
33: 
34: extern "C" { // CPP function
35:         int64_t sum_of_numbers(){
36:                 std::vector<int64_t> numbers {23, 445, 64};
37:                 auto sum = 0;
38:                 for (auto &item : numbers){
39:                         sum += item;
40:                 }
41:                 return sum;
42:         }
43: }

The error this time for PostgreSQL is:
*ERROR:  could not find function information for function "sum_of_numbers"
HINT:  SQL-callable functions need an accompanying
PG_FUNCTION_INFO_V1(funcname).
SQL state: 42883*

Thanks,
Tal




--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html




view thread (10+ messages)  latest in thread

Message-ID: <1534097342417-0.post@n3.nabble.com>
Permalink:  ../1534097342417-0.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1534097342417-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: PostgreSQL C Language Extension with C++ Code
  In-Reply-To: <1534097342417-0.post@n3.nabble.com>
  References: <1534093538827-0.post@n3.nabble.com> <CA+FnnTzH1gZ8o4a_WTD79kk7CNUzFu0NHUmbs03Gax0Su4Lgzw@mail.gmail.com> <1534097342417-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