PostgreSQL Source Code  git master
funcs.c File Reference
#include "postgres.h"
#include "executor/executor.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 (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 24 of file funcs.c.

References add_one_float8(), arg, PG_FUNCTION_INFO_V1(), PG_GETARG_INT32, and PG_RETURN_INT32.

25 {
27 
28  PG_RETURN_INT32(arg + 1);
29 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
signed int int32
Definition: c.h:355
void * arg

◆ add_one_float8()

Datum add_one_float8 ( PG_FUNCTION_ARGS  )

Definition at line 36 of file funcs.c.

References arg, makepoint(), PG_FUNCTION_INFO_V1(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

Referenced by add_one().

37 {
38  /* The macros for FLOAT8 hide its pass-by-reference nature */
40 
41  PG_RETURN_FLOAT8(arg + 1.0);
42 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
double float8
Definition: c.h:491
void * arg

◆ c_overpaid()

Datum c_overpaid ( PG_FUNCTION_ARGS  )

Definition at line 110 of file funcs.c.

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

Referenced by concat_text().

111 {
113  int32 limit = PG_GETARG_INT32(1);
114  bool isnull;
115  int32 salary;
116 
117  salary = DatumGetInt32(GetAttributeByName(t, "salary", &isnull));
118  if (isnull)
119  PG_RETURN_BOOL(false);
120 
121  /*
122  * Alternatively, we might prefer to do PG_RETURN_NULL() for null salary
123  */
124 
125  PG_RETURN_BOOL(salary > limit);
126 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define DatumGetInt32(X)
Definition: postgres.h:472
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:1002
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:311
signed int int32
Definition: c.h:355
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ concat_text()

Datum concat_text ( PG_FUNCTION_ARGS  )

Definition at line 90 of file funcs.c.

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

Referenced by copytext().

91 {
92  text *arg1 = PG_GETARG_TEXT_PP(0);
93  text *arg2 = PG_GETARG_TEXT_PP(1);
94  int32 arg1_size = VARSIZE_ANY_EXHDR(arg1);
95  int32 arg2_size = VARSIZE_ANY_EXHDR(arg2);
96  int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
97  text *new_text = (text *) palloc(new_text_size);
98 
99  SET_VARSIZE(new_text, new_text_size);
100  memcpy(VARDATA(new_text), VARDATA_ANY(arg1), arg1_size);
101  memcpy(VARDATA(new_text) + arg1_size, VARDATA_ANY(arg2), arg2_size);
102  PG_RETURN_TEXT_P(new_text);
103 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARHDRSZ
Definition: c.h:561
signed int int32
Definition: c.h:355
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:370
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:949
Definition: c.h:555
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329

◆ copytext()

Datum copytext ( PG_FUNCTION_ARGS  )

Definition at line 64 of file funcs.c.

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

Referenced by makepoint().

65 {
66  text *t = PG_GETARG_TEXT_PP(0);
67 
68  /*
69  * VARSIZE_ANY_EXHDR is the size of the struct in bytes, minus the
70  * VARHDRSZ or VARHDRSZ_SHORT of its header. Construct the copy with a
71  * full-length header.
72  */
73  text *new_t = (text *) palloc(VARSIZE_ANY_EXHDR(t) + VARHDRSZ);
74 
76 
77  /*
78  * VARDATA is a pointer to the data region of the new struct. The source
79  * could be a short datum, so retrieve its data through VARDATA_ANY.
80  */
81  memcpy((void *) VARDATA(new_t), /* destination */
82  (void *) VARDATA_ANY(t), /* source */
83  VARSIZE_ANY_EXHDR(t)); /* how many bytes */
84  PG_RETURN_TEXT_P(new_t);
85 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARHDRSZ
Definition: c.h:561
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:370
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:949
Definition: c.h:555
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329

◆ makepoint()

Datum makepoint ( PG_FUNCTION_ARGS  )

Definition at line 47 of file funcs.c.

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

Referenced by add_one_float8().

48 {
49  Point *pointx = PG_GETARG_POINT_P(0);
50  Point *pointy = PG_GETARG_POINT_P(1);
51  Point *new_point = (Point *) palloc(sizeof(Point));
52 
53  new_point->x = pointx->x;
54  new_point->y = pointy->y;
55 
56  PG_RETURN_POINT_P(new_point);
57 }
float8 x
Definition: geo_decls.h:57
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
float8 y
Definition: geo_decls.h:57
void * palloc(Size size)
Definition: mcxt.c:949

◆ PG_FUNCTION_INFO_V1() [1/6]

PG_FUNCTION_INFO_V1 ( add_one  )

◆ PG_FUNCTION_INFO_V1() [2/6]

PG_FUNCTION_INFO_V1 ( add_one_float8  )

◆ PG_FUNCTION_INFO_V1() [3/6]

PG_FUNCTION_INFO_V1 ( makepoint  )

◆ PG_FUNCTION_INFO_V1() [4/6]

PG_FUNCTION_INFO_V1 ( copytext  )

◆ PG_FUNCTION_INFO_V1() [5/6]

PG_FUNCTION_INFO_V1 ( concat_text  )

◆ PG_FUNCTION_INFO_V1() [6/6]

PG_FUNCTION_INFO_V1 ( c_overpaid  )

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 16 of file funcs.c.