1997-01-05 22:20:34 +01:00
|
|
|
/******************************************************************************
|
|
|
|
These are user-defined functions that can be bound to a Postgres backend
|
|
|
|
and called by Postgres to execute SQL functions of the same name.
|
|
|
|
|
|
|
|
The calling format for these functions is defined by the CREATE FUNCTION
|
|
|
|
SQL statement that binds them to the backend.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
1999-03-14 16:22:15 +01:00
|
|
|
#include "postgres.h" /* for variable length type */
|
1997-09-07 07:04:48 +02:00
|
|
|
#include "utils/palloc.h" /* for palloc */
|
|
|
|
#include "executor/executor.h" /* for GetAttributeByName() */
|
1999-03-14 16:22:15 +01:00
|
|
|
#include "utils/geo_decls.h" /* for point type */
|
1997-01-05 22:20:34 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* The following prototypes declare what we assume the user declares to
|
1997-01-05 22:20:34 +01:00
|
|
|
Postgres in his CREATE FUNCTION statement.
|
|
|
|
*/
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
int add_one(int arg);
|
1999-03-14 16:22:15 +01:00
|
|
|
Point *makepoint(Point *pointx, Point *pointy );
|
1997-09-08 23:56:23 +02:00
|
|
|
text *copytext(text *t);
|
1997-09-08 04:41:22 +02:00
|
|
|
|
1999-03-14 16:22:15 +01:00
|
|
|
bool c_overpaid(TupleTableSlot *t, /* the current instance of EMP */
|
|
|
|
int4 limit);
|
1997-01-05 22:20:34 +01:00
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
add_one(int arg)
|
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg + 1;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1999-03-14 16:22:15 +01:00
|
|
|
Point *
|
|
|
|
makepoint(Point *pointx, Point *pointy )
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-03-14 16:22:15 +01:00
|
|
|
Point *new_point = (Point *) palloc(sizeof(Point));
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-03-14 16:22:15 +01:00
|
|
|
new_point->x = pointx->x;
|
|
|
|
new_point->y = pointy->y;
|
|
|
|
|
|
|
|
return new_point;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
text *
|
1997-09-08 23:56:23 +02:00
|
|
|
copytext(text *t)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* VARSIZE is the total size of the struct in bytes.
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
text *new_t = (text *) palloc(VARSIZE(t));
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-18 22:22:58 +02:00
|
|
|
MemSet(new_t, 0, VARSIZE(t));
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return new_t;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
1999-03-14 16:22:15 +01:00
|
|
|
c_overpaid(TupleTableSlot *t, /* the current instance of EMP */
|
1997-09-07 07:04:48 +02:00
|
|
|
int4 limit)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
bool isnull = false;
|
|
|
|
int4 salary;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
salary = (int4) GetAttributeByName(t, "salary", &isnull);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (isnull)
|
1998-09-01 05:29:17 +02:00
|
|
|
return false;
|
|
|
|
return salary > limit;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|