PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
funcs_new.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "utils/geo_decls.h"
Include dependency graph for funcs_new.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

Datum add_one ( PG_FUNCTION_ARGS  )

Definition at line 27 of file funcs_new.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT32.

28 {
30 
31  PG_RETURN_INT32(arg + 1);
32 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
void * arg
Datum add_one_float8 ( PG_FUNCTION_ARGS  )

Definition at line 39 of file funcs_new.c.

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

40 {
41  /* The macros for FLOAT8 hide its pass-by-reference nature */
43 
44  PG_RETURN_FLOAT8(arg + 1.0);
45 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
double float8
Definition: c.h:381
void * arg
Datum c_overpaid ( PG_FUNCTION_ARGS  )

Definition at line 113 of file funcs_new.c.

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

114 {
116  int32 limit = PG_GETARG_INT32(1);
117  bool isnull;
118  int32 salary;
119 
120  salary = DatumGetInt32(GetAttributeByName(t, "salary", &isnull));
121  if (isnull)
122  PG_RETURN_BOOL(false);
123 
124  /*
125  * Alternatively, we might prefer to do PG_RETURN_NULL() for null salary
126  */
127 
128  PG_RETURN_BOOL(salary > limit);
129 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define DatumGetInt32(X)
Definition: postgres.h:478
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:850
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:276
signed int int32
Definition: c.h:256
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum concat_text ( PG_FUNCTION_ARGS  )

Definition at line 93 of file funcs_new.c.

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

94 {
95  text *arg1 = PG_GETARG_TEXT_PP(0);
96  text *arg2 = PG_GETARG_TEXT_PP(1);
97  int32 arg1_size = VARSIZE_ANY_EXHDR(arg1);
98  int32 arg2_size = VARSIZE_ANY_EXHDR(arg2);
99  int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
100  text *new_text = (text *) palloc(new_text_size);
101 
102  SET_VARSIZE(new_text, new_text_size);
103  memcpy(VARDATA(new_text), VARDATA_ANY(arg1), arg1_size);
104  memcpy(VARDATA(new_text) + arg1_size, VARDATA_ANY(arg2), arg2_size);
105  PG_RETURN_TEXT_P(new_text);
106 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define VARDATA(PTR)
Definition: postgres.h:303
#define VARHDRSZ
Definition: c.h:445
signed int int32
Definition: c.h:256
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
void * palloc(Size size)
Definition: mcxt.c:849
Definition: c.h:439
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
Datum copytext ( PG_FUNCTION_ARGS  )

Definition at line 67 of file funcs_new.c.

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

68 {
69  text *t = PG_GETARG_TEXT_PP(0);
70 
71  /*
72  * VARSIZE_ANY_EXHDR is the size of the struct in bytes, minus the
73  * VARHDRSZ or VARHDRSZ_SHORT of its header. Construct the copy with a
74  * full-length header.
75  */
76  text *new_t = (text *) palloc(VARSIZE_ANY_EXHDR(t) + VARHDRSZ);
77 
79 
80  /*
81  * VARDATA is a pointer to the data region of the new struct. The source
82  * could be a short datum, so retrieve its data through VARDATA_ANY.
83  */
84  memcpy((void *) VARDATA(new_t), /* destination */
85  (void *) VARDATA_ANY(t), /* source */
86  VARSIZE_ANY_EXHDR(t)); /* how many bytes */
87  PG_RETURN_TEXT_P(new_t);
88 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define VARDATA(PTR)
Definition: postgres.h:303
#define VARHDRSZ
Definition: c.h:445
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
void * palloc(Size size)
Definition: mcxt.c:849
Definition: c.h:439
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
Datum makepoint ( PG_FUNCTION_ARGS  )

Definition at line 50 of file funcs_new.c.

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

51 {
52  Point *pointx = PG_GETARG_POINT_P(0);
53  Point *pointy = PG_GETARG_POINT_P(1);
54  Point *new_point = (Point *) palloc(sizeof(Point));
55 
56  new_point->x = pointx->x;
57  new_point->y = pointy->y;
58 
59  PG_RETURN_POINT_P(new_point);
60 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
void * palloc(Size size)
Definition: mcxt.c:849
PG_FUNCTION_INFO_V1 ( add_one  )
PG_FUNCTION_INFO_V1 ( add_one_float8  )
PG_FUNCTION_INFO_V1 ( makepoint  )
PG_FUNCTION_INFO_V1 ( copytext  )
PG_FUNCTION_INFO_V1 ( concat_text  )
PG_FUNCTION_INFO_V1 ( c_overpaid  )

Variable Documentation

PG_MODULE_MAGIC

Definition at line 19 of file funcs_new.c.