30 #include "catalog/pg_type.h"
40 return !(colNumber == SPI_ERROR_NOATTRIBUTE);
54 info->
colNumber = SPI_fnumber(SPI_tuptable->tupdesc, info->
name);
56 elog(ERROR,
"Column '%s' not Found", info->
name);
63 (info->
type) = SPI_gettypeid(SPI_tuptable->tupdesc, (info->
colNumber));
64 if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
65 elog(ERROR,
"Type of column '%s' not Found", info->
name);
82 for (i = 0; i < info_size; ++i) {
84 switch (info[i].eType) {
101 elog(ERROR,
"Unknown type of column %s", info[i].name);
114 if (!(info.
type == BPCHAROID)) {
115 elog(ERROR,
"Unexpected Column '%s' type. Expected CHAR", info.
name);
121 if (!(info.
type == TEXTOID)) {
122 elog(ERROR,
"Unexpected Column '%s' type. Expected TEXT", info.
name);
128 if (!(info.
type == INT2OID
129 || info.
type == INT4OID
130 || info.
type == INT8OID)) {
132 "Unexpected Column '%s' type. Expected ANY-INTEGER",
139 if (!(info.
type == INT2ARRAYOID
140 || info.
type == INT4ARRAYOID
141 || info.
type == 1016)) {
143 "Unexpected Column '%s' type. Expected ANY-INTEGER-ARRAY",
149 if (!(info.
type == INT2OID
150 || info.
type == INT4OID
151 || info.
type == INT8OID
152 || info.
type == FLOAT4OID
153 || info.
type == FLOAT8OID
154 || info.
type == NUMERICOID)) {
156 "Unexpected Column '%s' type. Expected ANY-NUMERICAL",
172 bool strict,
char default_value) {
175 char value = default_value;
177 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isNull);
178 if (!(info.
type == BPCHAROID)) {
179 elog(ERROR,
"Unexpected Column type of %s. Expected CHAR", info.
name);
182 value = ((
char*)binval)[1];
185 elog(ERROR,
"Unexpected Null value in column %s", info.
name);
187 value = default_value;
200 uint64_t *the_size) {
201 bool is_null =
false;
203 Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &is_null);
208 ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
220 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isnull);
222 elog(ERROR,
"Unexpected Null value in column %s", info.
name);
225 value = (int64_t) DatumGetInt16(binval);
228 value = (int64_t) DatumGetInt32(binval);
231 value = DatumGetInt64(binval);
235 "Unexpected Column type of %s. Expected ANY-INTEGER",
240 PGR_DBG(
"Variable: %s Value: %ld", info.
name, value);
250 binval = SPI_getbinval(*tuple, *tupdesc, info.
colNumber, &isnull);
252 elog(ERROR,
"Unexpected Null value in column %s", info.
name);
256 value = (double) DatumGetInt16(binval);
259 value = (double) DatumGetInt32(binval);
262 value = (double) DatumGetInt64(binval);
265 value = (double) DatumGetFloat4(binval);
268 value = DatumGetFloat8(binval);
272 value = (double) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, binval));
276 "Unexpected Column type of %s. Expected ANY-NUMERICAL",
281 PGR_DBG(
"Variable: %s Value: %.20f", info.
name, value);
294 return DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.
colNumber));