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.
19
questions
0
votes
1
answer
60
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 "...
1
vote
0
answers
59
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;
...
1
vote
0
answers
71
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 ...
1
vote
1
answer
32
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 ...
0
votes
1
answer
213
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/...
2
votes
1
answer
487
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>...
0
votes
1
answer
125
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, &...
3
votes
1
answer
4k
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()
...
0
votes
1
answer
250
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 (...
0
votes
1
answer
57
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 ...
0
votes
1
answer
27
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 ...
0
votes
1
answer
415
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 ...
1
vote
1
answer
167
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 ...
0
votes
1
answer
236
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 ...
1
vote
2
answers
886
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 ...