Skip to main content

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.

0 votes
0 answers
32 views

Why does newly inserted data not appear immediately in GridDB Cloud queries?

I’m testing GridDB Cloud and noticed an odd behavior when querying right after an insert. Here’s a simplified example with the C API: GSContainer *cont; GSRow *row; GSQuery *qry; GSRowSet *rs; ...
Hassan Saeed's user avatar
0 votes
1 answer
124 views

Database systems - data type alignment padding and record size (C/C++ related)

In PostgreSQL there is alignment padding of various datatypes which can increase (or decrease) the size of records (as stored on disk) in varying ways (see these links, 1, 2, 3): I searched for "...
Vérace's user avatar
  • 31k
1 vote
0 answers
88 views

In Postgres C extension development, the argument of function is a tuple, how to iterate all its attributes

This is my .c file Datum show_line(PG_FUNCTION_ARGS) { /* Get Input*/ HeapTupleHeader tup_hdr; TupleDesc tup_desc; Oid tupType; int32 tupTypmod; bool isNull; // int tuplen; ...
Lingze Zeng's user avatar
1 vote
0 answers
127 views

How to write a heterogeneous variadic function

I am trying to write a postgres stored procedure that can take a variable number of arguments of potentially different types (i.e. a heterogeneous list of arguments). As I learned from here, the ...
tinlyx's user avatar
  • 3,840
1 vote
1 answer
65 views

How can I get PostgreSQL to follow up filtering jobs that my FDW ignored?

I'm making a FDW (Foreign Data Wrapper) in PostgreSQL for myself using C. It seems to be working rudimentary, but I have one problem. When I pass it a query like the following via psql: select * from ...
yasoo7964's user avatar
1 vote
1 answer
481 views

How is PostgreSQL's extension system implemented?

I am interested in how PostgreSQL's extension system is implemented. How can a postgres server call user-defined C which is built separately from the server. This question comes from Reddit u/...
Evan Carroll's user avatar
  • 65.8k
2 votes
1 answer
526 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>...
Nikola's user avatar
  • 35
0 votes
1 answer
159 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, &...
user2959071's user avatar
3 votes
1 answer
5k 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() ...
Evan Carroll's user avatar
  • 65.8k
0 votes
1 answer
272 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 (...
Evan Carroll's user avatar
  • 65.8k
0 votes
1 answer
88 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 ...
Evan Carroll's user avatar
  • 65.8k
0 votes
1 answer
46 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 ...
Evan Carroll's user avatar
  • 65.8k
0 votes
1 answer
507 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 ...
Evan Carroll's user avatar
  • 65.8k
1 vote
1 answer
209 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 ...
Evan Carroll's user avatar
  • 65.8k
0 votes
1 answer
290 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 ...
Evan Carroll's user avatar
  • 65.8k

15 30 50 per page