Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

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

Datum add_one (PG_FUNCTION_ARGS)
Datum add_one_float8 (PG_FUNCTION_ARGS)
Datum makepoint (PG_FUNCTION_ARGS)
Datum copytext (PG_FUNCTION_ARGS)
Datum concat_text (PG_FUNCTION_ARGS)
Datum c_overpaid (PG_FUNCTION_ARGS)
 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)

Variables

 PG_MODULE_MAGIC

Function Documentation

Datum add_one ( PG_FUNCTION_ARGS   ) 

Definition at line 37 of file funcs_new.c.

References arg, PG_GETARG_INT32, and PG_RETURN_INT32.

Datum add_one_float8 ( PG_FUNCTION_ARGS   ) 

Definition at line 49 of file funcs_new.c.

References arg, PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

{
    /* The macros for FLOAT8 hide its pass-by-reference nature */
    float8      arg = PG_GETARG_FLOAT8(0);

    PG_RETURN_FLOAT8(arg + 1.0);
}

Datum c_overpaid ( PG_FUNCTION_ARGS   ) 

Definition at line 120 of file funcs_new.c.

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

{
    HeapTupleHeader t = PG_GETARG_HEAPTUPLEHEADER(0);
    int32       limit = PG_GETARG_INT32(1);
    bool        isnull;
    int32       salary;

    salary = DatumGetInt32(GetAttributeByName(t, "salary", &isnull));
    if (isnull)
        PG_RETURN_BOOL(false);

    /*
     * Alternatively, we might prefer to do PG_RETURN_NULL() for null salary
     */

    PG_RETURN_BOOL(salary > limit);
}

Datum concat_text ( PG_FUNCTION_ARGS   ) 

Definition at line 100 of file funcs_new.c.

References palloc(), PG_GETARG_TEXT_P, PG_RETURN_TEXT_P, SET_VARSIZE, VARDATA, and VARSIZE.

{
    text       *arg1 = PG_GETARG_TEXT_P(0);
    text       *arg2 = PG_GETARG_TEXT_P(1);
    int32       arg1_size = VARSIZE(arg1) - VARHDRSZ;
    int32       arg2_size = VARSIZE(arg2) - VARHDRSZ;
    int32       new_text_size = arg1_size + arg2_size + VARHDRSZ;
    text       *new_text = (text *) palloc(new_text_size);

    SET_VARSIZE(new_text, new_text_size);
    memcpy(VARDATA(new_text), VARDATA(arg1), arg1_size);
    memcpy(VARDATA(new_text) + arg1_size, VARDATA(arg2), arg2_size);
    PG_RETURN_TEXT_P(new_text);
}

Datum copytext ( PG_FUNCTION_ARGS   ) 

Definition at line 77 of file funcs_new.c.

References palloc(), PG_GETARG_TEXT_P, PG_RETURN_TEXT_P, SET_VARSIZE, VARDATA, VARHDRSZ, and VARSIZE.

{
    text       *t = PG_GETARG_TEXT_P(0);

    /*
     * VARSIZE is the total size of the struct in bytes.
     */
    text       *new_t = (text *) palloc(VARSIZE(t));

    SET_VARSIZE(new_t, VARSIZE(t));

    /*
     * VARDATA is a pointer to the data region of the struct.
     */
    memcpy((void *) VARDATA(new_t),     /* destination */
           (void *) VARDATA(t), /* source */
           VARSIZE(t) - VARHDRSZ);      /* how many bytes */
    PG_RETURN_TEXT_P(new_t);
}

Datum makepoint ( PG_FUNCTION_ARGS   ) 

Definition at line 60 of file funcs_new.c.

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

{
    Point      *pointx = PG_GETARG_POINT_P(0);
    Point      *pointy = PG_GETARG_POINT_P(1);
    Point      *new_point = (Point *) palloc(sizeof(Point));

    new_point->x = pointx->x;
    new_point->y = pointy->y;

    PG_RETURN_POINT_P(new_point);
}

PG_FUNCTION_INFO_V1 ( add_one   ) 
PG_FUNCTION_INFO_V1 ( concat_text   ) 
PG_FUNCTION_INFO_V1 ( c_overpaid   ) 
PG_FUNCTION_INFO_V1 ( copytext   ) 
PG_FUNCTION_INFO_V1 ( add_one_float8   ) 
PG_FUNCTION_INFO_V1 ( makepoint   ) 

Variable Documentation

Definition at line 20 of file funcs_new.c.