31 #include <utils/date.h>
32 #include <utils/datetime.h>
37 #include "catalog/pg_type.h"
45 if (!(info.
type == 1186)) {
47 "Unexpected Column '%s' type. Expected INTERVAL",
59 if (!(info.
type == BPCHAROID)) {
60 elog(ERROR,
"Unexpected Column '%s' type. Expected CHAR", info.
name);
67 if (!(info.
type == TEXTOID)) {
68 elog(ERROR,
"Unexpected Column '%s' type. Expected TEXT", info.
name);
75 if (!(info.
type == JSONBOID)) {
76 elog(ERROR,
"Unexpected Column '%s' type. Expected JSONB %ld", info.
name, info.
type);
83 if (!(info.
type == INT2OID || info.
type == INT4OID)) {
85 (errmsg_internal(
"Unexpected type in column '%s'.", info.
name),
86 errhint(
"Expected SMALLINT or INTEGER")));
93 if (!(info.
type == INT2OID
94 || info.
type == INT4OID
95 || info.
type == INT8OID)) {
97 (errmsg_internal(
"Unexpected type in column '%s'.", info.
name),
98 errhint(
"Expected ANY-INTEGER")));
105 if (!(info.
type == INT2ARRAYOID
106 || info.
type == INT4ARRAYOID)) {
108 "Unexpected Column '%s' type. Expected SMALLINT-ARRAY or INTEGER-ARRAY",
116 if (!(info.
type == INT2ARRAYOID
117 || info.
type == INT4ARRAYOID
118 || info.
type == 1016)) {
120 "Unexpected Column '%s' type. Expected ANY-INTEGER-ARRAY",
128 if (!(info.
type == INT2OID
129 || info.
type == INT4OID
130 || info.
type == INT8OID
131 || info.
type == FLOAT4OID
132 || info.
type == FLOAT8OID
133 || info.
type == NUMERICOID)) {
135 (errmsg_internal(
"Unexpected type in column '%s'.", info.
name),
136 errhint(
"Found: %lu\nExpected ANY-NUMERICAL", info.
type)));
143 if (!(info.
type == 1114)) {
145 "Unexpected Column '%s' type. Expected TIMESTAMP",
157 info->
colNumber = SPI_fnumber(SPI_tuptable->tupdesc, info->
name);
159 elog(ERROR,
"Column '%s' not Found", info->
name);
166 (info->
type) = SPI_gettypeid(SPI_tuptable->tupdesc, (info->
colNumber));
168 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
169 elog(ERROR,
"Type of column '%s' not Found", info->
name);
182 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isnull);
184 if (isnull) elog(ERROR,
"Unexpected Null value in column %s", info.
name);
188 value = (int32_t) DatumGetInt16(binval);
191 value = (int32_t) DatumGetInt32(binval);
195 (errmsg_internal(
"Unexpected type in column '%s'.", info.
name),
196 errhint(
"Found: %lu\nExpected INTEGER", info.
type)));
207 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isnull);
209 if (isnull) elog(ERROR,
"Unexpected Null value in column %s", info.
name);
213 value = (int64_t) DatumGetInt16(binval);
216 value = (int64_t) DatumGetInt32(binval);
219 value = DatumGetInt64(binval);
223 (errmsg_internal(
"Unexpected type in column '%s'.", info.
name),
224 errhint(
"Found: %lu\nExpected ANY-INTEGER", info.
type)));
235 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isnull);
237 if (isnull) elog(ERROR,
"Unexpected Null value in column %s", info.
name);
245 "[SPI_getTimeStamp] Unexpected type in column %s. found %ld expected 1114",
258 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isnull);
260 if (isnull) elog(ERROR,
"Unexpected Null value in column %s", info.
name);
264 interval = DatumGetIntervalP(binval);
268 "[spi_getInterval] Unexpected type in column %s. found %ld expected %d",
271 PGR_DBG(
"time %ld secs %ld", interval->time,
272 interval->time / 1000000
273 + interval->day * SECS_PER_DAY
274 + (int64_t)(interval->month * ((DAYS_PER_YEAR / (
double) MONTHS_PER_YEAR) * SECS_PER_DAY)));
276 return interval->time / 1000000
277 + interval->day * SECS_PER_DAY
278 + (int64_t)(interval->month * ((DAYS_PER_YEAR / (
double) MONTHS_PER_YEAR) * SECS_PER_DAY));
299 HeapTuple *tuple, TupleDesc *tupdesc,
Column_info_t info,
char default_value) {
302 char value = default_value;
304 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isNull);
305 if (!(info.
type == BPCHAROID)) {
306 elog(ERROR,
"Unexpected Column type of %s. Expected CHAR", info.
name);
309 value = ((
char*)binval)[1];
312 elog(ERROR,
"Unexpected Null value in column %s", info.
name);
314 value = default_value;
324 int32_t value =
spi_getInt(tuple, tupdesc, info);
328 (errmsg(
"Invalid max_tasks value %d", value),
330 "Maximum number of tasks must be greater than or equal to 0")));
341 bool is_null =
false;
343 Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &is_null);
348 ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
359 bool is_null =
false;
361 Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &is_null);
371 ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
383 for (
size_t i = 0; i < *the_size; i++) {
385 elog(ERROR,
"Unexpected Negative value %ld in array", array[i]);
398 bool is_null =
false;
400 Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &is_null);
406 ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
443 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
478 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
513 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
548 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
582 Id value =
get_Id(tuple, tupdesc, info, 0);
583 if (value <= 0) elog(ERROR,
"Unexpected Negative value or Zero in column %s", info.
name);
603 if (step_type < min_value || step_type > max_value) {
604 elog(ERROR,
"Step value should lie between %d and %d", min_value, max_value);
640 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
661 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
683 int32_t value =
spi_getInt(tuple, tupdesc, info);
684 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
706 int32_t value =
spi_getInt(tuple, tupdesc, info);
707 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
727 char value =
spi_getChar(tuple, tupdesc, info, opt_value);
749 int32_t value =
spi_getInt(tuple, tupdesc, info);
750 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
751 if (value > 100) elog(ERROR,
"Priority exceeds the max priority 100");
773 int32_t value =
spi_getInt(tuple, tupdesc, info);
774 if (value < 0) elog(ERROR,
"Unexpected Negative value in column %s", info.
name);
786 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isnull);
788 elog(ERROR,
"Unexpected Null value in column %s", info.
name);
792 value = (double) DatumGetInt16(binval);
795 value = (double) DatumGetInt32(binval);
798 value = (double) DatumGetInt64(binval);
801 value = (double) DatumGetFloat4(binval);
804 value = DatumGetFloat8(binval);
808 value = (double) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, binval));
812 (errmsg_internal(
"Unexpected type in column '%s'.", info.
name),
813 errhint(
"Found: %lu\nExpected ANY-NUMERICAL", info.
type)));
833 char *val = DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.
colNumber));
852 Timestamp time = timestamp;
853 TMODULO(time, date, USECS_PER_DAY);
854 if (time < INT64CONST(0)) {
855 time += USECS_PER_DAY;
858 date += POSTGRES_EPOCH_JDATE;
860 if (date < 0 || date > (Timestamp) INT_MAX) {
862 (errcode(ERRCODE_INTERNAL_ERROR),
863 errmsg(
"Julian day routine does not work for negative Julian days")));
875 j2date((
int) date, &info.tm_year, &info.tm_mon, &info.tm_mday);
876 dt2time(time, &info.tm_hour, &info.tm_min, &info.tm_sec, &fsec);
882 info.tm_year = info.tm_year - 1900;
883 info.tm_mon = info.tm_mon - 1;
888 return mktime(&info) - timezone;
901 return !(colNumber == SPI_ERROR_NOATTRIBUTE);
908 for (
int i = 0; i < info_size; ++i) {
910 switch (info[i].eType) {
942 elog(ERROR,
"Unknown type of column %s", info[i].name);