Questions tagged [c]

Questions concerning the C programming language as used in conjunction with database servers. For example writing User Defined Functions in C for Oracle (or other servers). Topics such as writing extensions for PostgreSQL in C would also be relevant. Non-database related C questions should be directed to StackOveflow.

Filter by
Sorted by
Tagged with
2 votes
1 answer
280 views

Environment variables in Postgres C extension

I cannot get environment variable in my PostgreSQL C extension code. For example, this function always returns 111: #include "postgres.h" #include "fmgr.h" #include <stdlib.h>...
  • 35
0 votes
1 answer
66 views

Postgres C API: How can we copy a Datum?

As far as I understand, SPI_getbinval returns a pointer into the passed row. That is, the following would be unsafe: dat = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &...
1 vote
1 answer
1k views

What is the difference between RETURNS `SETOF integer` and RETURNS TABLE(name int)`?

Given the two definitions below, is there any difference? CREATE FUNCTION foo(OUT foobar int4) RETURNS SETOF int4 AS 'MODULE_PATHNAME', 'foo' LANGUAGE C STRICT VOLATILE; And, CREATE FUNCTION foo() ...
  • 58.9k
0 votes
1 answer
57 views

In what circumstance is Materialize_Random set in allowedMode?

In PostgreSQL there is a field called allowedMode called SFRM_Materialize_Random The Tuplestore must be created with randomAccess = true if SFRM_Materialize_Random is set in allowedModes, but it can (...
  • 58.9k
0 votes
1 answer
50 views

Is there a way to a maintain the function signature in C and not in a SQL file?

Currently the docs says, There are two ways you can build a composite data value (henceforth a “tuple”): you can build it from an array of Datum values, or from an array of C strings that can be ...
  • 58.9k
0 votes
1 answer
17 views

Does PostgreSQL provide anything to dump fcinfo?

I'm looking to get into writing extension in C. I want to better understand what this argument is and how they get changed in different invocations. Is there anything that can dump this argument out ...
  • 58.9k
0 votes
1 answer
172 views

What arguments get passed with PG_FUNCTION_ARGS (with the V1 convention)?

PostgreSQL Documents all their C functions with a "V1" interface, but they don't actually show what they get, PG_FUNCTION_INFO_V1(add_one); Datum add_one(PG_FUNCTION_ARGS) { int32 arg ...
  • 58.9k
0 votes
1 answer
88 views

What is SFRM_Materialize_Preferred and how can it be used to write more performant functions?

Researching this question, I see there is a value for SetFunctionReturnMode called SFRM_Materialize_Preferred. What is this? Can this be used to write more performant functions? There are multiple ...
  • 58.9k
0 votes
1 answer
137 views

C Extension: Is it faster to return a set with ValuePerCall or Materialize mode?

PostgreSQL documents it's Set Returning Functions with C extensions like this, C-language functions have two options for returning sets (multiple rows). In one method, called ValuePerCall mode, a ...
  • 58.9k
1 vote
2 answers
367 views

Is there a method to print/debug from within a C function in PostgreSQL?

When you're extending PostgreSQL in C, how does one introspect/debug/dump a variable? Is there a method other than returning a custom result set to the client? Something like a printf that I can ...
  • 58.9k
0 votes
1 answer
118 views

Remote PostgreSQL DB with local buffer ... how could it look like

I have a sensor which is generating a data vector let's say every second (adjustable to up to 100 vectors per second) at a remote location. The location got 4G modem to send the data. Due to power ...
0 votes
1 answer
791 views

I am getting this error : "Error 102 : non-boolean type specified in a context where a condition is expected" for this request : [closed]

private void button2_Click(object sender, EventArgs e) { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "delete from MYDB ...
  • 1
1 vote
1 answer
62 views

MySQL Server :: My C Code can remotely create a database, but not "INSERT INTO" it

I’ve written a C program which does the following when it starts: Connects to a remote Linux MySQL server over the network Creates a new, uniquely-named database Sends a “USE _____” command to ...
  • 111
1 vote
0 answers
83 views

How to read jsonb or json in postgresql spi?

How can I read a json/jsonb field in a PostgreSQL server side function? I am trying to write a server side function using C and SPI for PostgreSQL 11. The json field in mind is simple and contain ...
  • 3,105