PostgreSQL Source Code git master
Loading...
Searching...
No Matches
funcs.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "utils/fmgrprotos.h"
#include "utils/geo_decls.h"
#include "varatt.h"
Include dependency graph for funcs.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (add_one)
 
Datum add_one (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (add_one_float8)
 
Datum add_one_float8 (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (makepoint)
 
Datum makepoint (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (copytext)
 
Datum copytext (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (concat_text)
 
Datum concat_text (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (t_starts_with)
 
Datum t_starts_with (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (c_overpaid)
 
Datum c_overpaid (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ add_one()

Datum add_one ( PG_FUNCTION_ARGS  )

Definition at line 26 of file funcs.c.

27{
29
31}
int32_t int32
Definition c.h:542
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
void * arg

References arg, PG_GETARG_INT32, and PG_RETURN_INT32.

◆ add_one_float8()

Datum add_one_float8 ( PG_FUNCTION_ARGS  )

Definition at line 38 of file funcs.c.

39{
40 /* The macros for FLOAT8 hide its pass-by-reference nature */
42
43 PG_RETURN_FLOAT8(arg + 1.0);
44}
double float8
Definition c.h:644
#define PG_GETARG_FLOAT8(n)
Definition fmgr.h:283
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

◆ c_overpaid()

Datum c_overpaid ( PG_FUNCTION_ARGS  )

Definition at line 131 of file funcs.c.

132{
134 int32 limit = PG_GETARG_INT32(1);
135 bool isnull;
137
138 salary = DatumGetInt32(GetAttributeByName(t, "salary", &isnull));
139 if (isnull)
140 PG_RETURN_BOOL(false);
141
142 /*
143 * Alternatively, we might prefer to do PG_RETURN_NULL() for null salary
144 */
145
146 PG_RETURN_BOOL(salary > limit);
147}
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition execUtils.c:1061
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition fmgr.h:313
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
static int32 DatumGetInt32(Datum X)
Definition postgres.h:212
static int fb(int x)

References DatumGetInt32(), fb(), GetAttributeByName(), PG_GETARG_HEAPTUPLEHEADER, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ concat_text()

Datum concat_text ( PG_FUNCTION_ARGS  )

Definition at line 92 of file funcs.c.

93{
100
105}
#define VARHDRSZ
Definition c.h:711
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
void * palloc(Size size)
Definition mcxt.c:1387
Definition c.h:706
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition varatt.h:472
static char * VARDATA(const void *PTR)
Definition varatt.h:305
static char * VARDATA_ANY(const void *PTR)
Definition varatt.h:486
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

References fb(), palloc(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, SET_VARSIZE(), VARDATA(), VARDATA_ANY(), VARHDRSZ, and VARSIZE_ANY_EXHDR().

◆ copytext()

Datum copytext ( PG_FUNCTION_ARGS  )

Definition at line 66 of file funcs.c.

67{
68 text *t = PG_GETARG_TEXT_PP(0);
69
70 /*
71 * VARSIZE_ANY_EXHDR is the size of the struct in bytes, minus the
72 * VARHDRSZ or VARHDRSZ_SHORT of its header. Construct the copy with a
73 * full-length header.
74 */
76
78
79 /*
80 * VARDATA is a pointer to the data region of the new struct. The source
81 * could be a short datum, so retrieve its data through VARDATA_ANY.
82 */
83 memcpy(VARDATA(new_t), /* destination */
84 VARDATA_ANY(t), /* source */
85 VARSIZE_ANY_EXHDR(t)); /* how many bytes */
87}

References fb(), palloc(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, SET_VARSIZE(), VARDATA(), VARDATA_ANY(), VARHDRSZ, and VARSIZE_ANY_EXHDR().

◆ makepoint()

Datum makepoint ( PG_FUNCTION_ARGS  )

Definition at line 49 of file funcs.c.

50{
54
55 new_point->x = pointx->x;
56 new_point->y = pointy->y;
57
59}
#define palloc_object(type)
Definition fe_memutils.h:74
#define PG_GETARG_POINT_P(n)
Definition geo_decls.h:184
#define PG_RETURN_POINT_P(x)
Definition geo_decls.h:185

References fb(), palloc_object, PG_GETARG_POINT_P, and PG_RETURN_POINT_P.

◆ PG_FUNCTION_INFO_V1() [1/7]

PG_FUNCTION_INFO_V1 ( add_one  )

◆ PG_FUNCTION_INFO_V1() [2/7]

PG_FUNCTION_INFO_V1 ( add_one_float8  )

◆ PG_FUNCTION_INFO_V1() [3/7]

PG_FUNCTION_INFO_V1 ( c_overpaid  )

◆ PG_FUNCTION_INFO_V1() [4/7]

PG_FUNCTION_INFO_V1 ( concat_text  )

◆ PG_FUNCTION_INFO_V1() [5/7]

PG_FUNCTION_INFO_V1 ( copytext  )

◆ PG_FUNCTION_INFO_V1() [6/7]

PG_FUNCTION_INFO_V1 ( makepoint  )

◆ PG_FUNCTION_INFO_V1() [7/7]

PG_FUNCTION_INFO_V1 ( t_starts_with  )

◆ t_starts_with()

Datum t_starts_with ( PG_FUNCTION_ARGS  )

Definition at line 112 of file funcs.c.

113{
117 bool result;
118
120 collid,
123 PG_RETURN_BOOL(result);
124}
Oid collid
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition fmgr.c:813
#define PG_GET_COLLATION()
Definition fmgr.h:198
static bool DatumGetBool(Datum X)
Definition postgres.h:100
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
unsigned int Oid
Datum text_starts_with(PG_FUNCTION_ARGS)
Definition varlena.c:1545

References collid, DatumGetBool(), DirectFunctionCall2Coll(), fb(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PointerGetDatum(), and text_starts_with().

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 18 of file funcs.c.