PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
funcs.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "utils/fmgrprotos.h"
#include "utils/geo_decls.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 25 of file funcs.c.

26{
28
30}
int32_t int32
Definition: c.h:498
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#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 37 of file funcs.c.

38{
39 /* The macros for FLOAT8 hide its pass-by-reference nature */
41
42 PG_RETURN_FLOAT8(arg + 1.0);
43}
double float8
Definition: c.h:601
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

◆ c_overpaid()

Datum c_overpaid ( PG_FUNCTION_ARGS  )

Definition at line 130 of file funcs.c.

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

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

◆ concat_text()

Datum concat_text ( PG_FUNCTION_ARGS  )

Definition at line 91 of file funcs.c.

92{
93 text *arg1 = PG_GETARG_TEXT_PP(0);
94 text *arg2 = PG_GETARG_TEXT_PP(1);
95 int32 arg1_size = VARSIZE_ANY_EXHDR(arg1);
96 int32 arg2_size = VARSIZE_ANY_EXHDR(arg2);
97 int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
98 text *new_text = (text *) palloc(new_text_size);
99
100 SET_VARSIZE(new_text, new_text_size);
101 memcpy(VARDATA(new_text), VARDATA_ANY(arg1), arg1_size);
102 memcpy(VARDATA(new_text) + arg1_size, VARDATA_ANY(arg2), arg2_size);
103 PG_RETURN_TEXT_P(new_text);
104}
#define VARHDRSZ
Definition: c.h:663
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
void * palloc(Size size)
Definition: mcxt.c:1317
Definition: c.h:658
#define VARDATA(PTR)
Definition: varatt.h:278
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

References 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 65 of file funcs.c.

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

References 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 48 of file funcs.c.

49{
50 Point *pointx = PG_GETARG_POINT_P(0);
51 Point *pointy = PG_GETARG_POINT_P(1);
52 Point *new_point = (Point *) palloc(sizeof(Point));
53
54 new_point->x = pointx->x;
55 new_point->y = pointy->y;
56
57 PG_RETURN_POINT_P(new_point);
58}
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:185
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:186
float8 y
Definition: geo_decls.h:99
float8 x
Definition: geo_decls.h:98

References palloc(), PG_GETARG_POINT_P, PG_RETURN_POINT_P, Point::x, and Point::y.

◆ 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 111 of file funcs.c.

112{
113 text *t1 = PG_GETARG_TEXT_PP(0);
114 text *t2 = PG_GETARG_TEXT_PP(1);
116 bool result;
117
119 collid,
120 PointerGetDatum(t1),
121 PointerGetDatum(t2)));
122 PG_RETURN_BOOL(result);
123}
Oid collid
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:812
#define PG_GET_COLLATION()
Definition: fmgr.h:198
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
unsigned int Oid
Definition: postgres_ext.h:30
Datum text_starts_with(PG_FUNCTION_ARGS)
Definition: varlena.c:1847

References collid, DatumGetBool(), DirectFunctionCall2Coll(), 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 17 of file funcs.c.