summaryrefslogtreecommitdiff
path: root/contrib/spi/moddatetime.c
diff options
context:
space:
mode:
authorPavan Deolasee2017-06-14 05:42:18 +0000
committerPavan Deolasee2017-06-14 05:42:18 +0000
commit15dd5274c323fb93e4e3ea9ad2185aaaec10f79c (patch)
tree9dafb4c7f735d9429ea461dc792933af87493c33 /contrib/spi/moddatetime.c
parentdfbb88e3bbb526dcb204b456b9e5cfd9d10d0d0a (diff)
parentd5cb3bab564e0927ffac7c8729eacf181a12dd40 (diff)
Merge from PG master upto d5cb3bab564e0927ffac7c8729eacf181a12dd40
This is the result of the "git merge remotes/PGSQL/master" upto the said commit point. We have done some basic analysis, fixed compilation problems etc, but bulk of the logical problems in conflict resolution etc will be handled by subsequent commits.
Diffstat (limited to 'contrib/spi/moddatetime.c')
-rw-r--r--contrib/spi/moddatetime.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/contrib/spi/moddatetime.c b/contrib/spi/moddatetime.c
index c6d33b7355..70476f77c2 100644
--- a/contrib/spi/moddatetime.c
+++ b/contrib/spi/moddatetime.c
@@ -15,11 +15,12 @@ OH, me, I'm Terry Mackintosh <terry@terrym.com>
*/
#include "postgres.h"
+#include "access/htup_details.h"
#include "catalog/pg_type.h"
#include "executor/spi.h"
#include "commands/trigger.h"
+#include "utils/builtins.h"
#include "utils/rel.h"
-#include "utils/timestamp.h"
PG_MODULE_MAGIC;
@@ -34,6 +35,7 @@ moddatetime(PG_FUNCTION_ARGS)
int attnum; /* positional number of field to change */
Oid atttypid; /* type OID of field to change */
Datum newdt; /* The current datetime. */
+ bool newdtnull; /* null flag for it */
char **args; /* arguments */
char *relname; /* triggered relation name */
Relation rel; /* triggered relation */
@@ -84,9 +86,9 @@ moddatetime(PG_FUNCTION_ARGS)
/*
* This is where we check to see if the field we are supposed to update
- * even exists. The above function must return -1 if name not found?
+ * even exists.
*/
- if (attnum < 0)
+ if (attnum <= 0)
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("\"%s\" has no attribute \"%s\"",
@@ -115,22 +117,13 @@ moddatetime(PG_FUNCTION_ARGS)
args[0], relname)));
newdt = (Datum) 0; /* keep compiler quiet */
}
+ newdtnull = false;
-/* 1 is the number of items in the arrays attnum and newdt.
- attnum is the positional number of the field to be updated.
- newdt is the new datetime stamp.
- NOTE that attnum and newdt are not arrays, but then a 1 element array
- is not an array any more then they are. Thus, they can be considered a
- one element array.
-*/
- rettuple = SPI_modifytuple(rel, rettuple, 1, &attnum, &newdt, NULL);
-
- if (rettuple == NULL)
- /* internal error */
- elog(ERROR, "moddatetime (%s): %d returned by SPI_modifytuple",
- relname, SPI_result);
+ /* Replace the attnum'th column with newdt */
+ rettuple = heap_modify_tuple_by_cols(rettuple, tupdesc,
+ 1, &attnum, &newdt, &newdtnull);
-/* Clean up */
+ /* Clean up */
pfree(relname);
return PointerGetDatum(rettuple);