|
26 | 26 | #include "tcop/utility.h"
|
27 | 27 |
|
28 | 28 | #include "utils/array.h"
|
29 |
| -#include "utils/tqual.h" |
30 | 29 | #include "utils/datum.h"
|
31 | 30 | #if PG_VERSION_NUM>=120000
|
| 31 | +#include "access/heapam.h" |
32 | 32 | #include "utils/float.h"
|
| 33 | +#else |
| 34 | +#include "utils/tqual.h" |
33 | 35 | #endif
|
34 | 36 | #include "utils/builtins.h"
|
35 | 37 | #include "utils/datetime.h"
|
@@ -1137,9 +1139,10 @@ UserTableUpdateOpenIndexes()
|
1137 | 1139 | if (estate->es_result_relation_info->ri_NumIndices > 0)
|
1138 | 1140 | {
|
1139 | 1141 | recheckIndexes = ExecInsertIndexTuples(slot,
|
| 1142 | +#if PG_VERSION_NUM<120000 |
1140 | 1143 | &tuple->t_self,
|
| 1144 | +#endif |
1141 | 1145 | estate, false, NULL, NIL);
|
1142 |
| - |
1143 | 1146 | if (recheckIndexes != NIL)
|
1144 | 1147 | ereport(ERROR,
|
1145 | 1148 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
@@ -1182,7 +1185,7 @@ static void insert_tuple(Datum* values, bool* nulls)
|
1182 | 1185 | HeapTuple tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
|
1183 | 1186 | #if PG_VERSION_NUM>=120000
|
1184 | 1187 | ExecStoreHeapTuple(tup, slot, true);
|
1185 |
| - simple_heap_insert(rel, ExecFetchSlotHeapTuple(slot, true, NULL)); |
| 1188 | + simple_table_insert(rel, slot); |
1186 | 1189 | #else
|
1187 | 1190 | ExecStoreTuple(tup, slot, InvalidBuffer, true);
|
1188 | 1191 | simple_heap_insert(rel, slot->tts_tuple);
|
@@ -2224,6 +2227,7 @@ Datum vops_populate(PG_FUNCTION_ARGS)
|
2224 | 2227 | int rc;
|
2225 | 2228 | bool is_null;
|
2226 | 2229 | int64 loaded;
|
| 2230 | + bool type_checked = false; |
2227 | 2231 | static Oid self_oid = InvalidOid;
|
2228 | 2232 | char stmt[MAX_SQL_STMT_LEN];
|
2229 | 2233 |
|
@@ -2257,6 +2261,7 @@ Datum vops_populate(PG_FUNCTION_ARGS)
|
2257 | 2261 | HeapTuple spi_tuple = SPI_tuptable->vals[i];
|
2258 | 2262 | char const* name = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
|
2259 | 2263 | Oid type_id = DatumGetObjectId(SPI_getbinval(spi_tuple, spi_tupdesc, 2, &is_null));
|
| 2264 | + types[i].dst_type = type_id; |
2260 | 2265 | types[i].tid = vops_get_type(type_id);
|
2261 | 2266 | get_typlenbyvalalign(type_id, &types[i].len, &types[i].byval, &types[i].align);
|
2262 | 2267 | if (types[i].tid != VOPS_LAST && types[i].len < 0) { /* varying length type: extract size from atttypmod */
|
@@ -2294,6 +2299,26 @@ Datum vops_populate(PG_FUNCTION_ARGS)
|
2294 | 2299 | if (SPI_processed) {
|
2295 | 2300 | HeapTuple spi_tuple = SPI_tuptable->vals[0];
|
2296 | 2301 | spi_tupdesc = SPI_tuptable->tupdesc;
|
| 2302 | + if (!type_checked) |
| 2303 | + { |
| 2304 | + for (i = 0; i < n_attrs; i++) |
| 2305 | + { |
| 2306 | + Oid dst_type = types[i].dst_type; |
| 2307 | + Oid src_type = SPI_gettypeid(spi_tupdesc, i+1); |
| 2308 | + types[i].src_type = src_type; |
| 2309 | + if (types[i].tid != VOPS_LAST) |
| 2310 | + dst_type = vops_map_tid[types[i].tid]; |
| 2311 | + if (!(dst_type == src_type || |
| 2312 | + (dst_type == CHAROID && src_type == TEXTOID) || |
| 2313 | + (dst_type == TEXTOID && src_type == VARCHAROID) || |
| 2314 | + (dst_type == TEXTOID && src_type == BPCHAROID))) |
| 2315 | + { |
| 2316 | + elog(ERROR, "Incompatible type of attribute %d: %s vs. %s", |
| 2317 | + i+1, format_type_be(dst_type), format_type_be(src_type)); |
| 2318 | + } |
| 2319 | + } |
| 2320 | + type_checked = true; |
| 2321 | + } |
2297 | 2322 | if (j == TILE_SIZE) {
|
2298 | 2323 | for (i = 0; i < n_attrs; i++) {
|
2299 | 2324 | if (types[i].tid != VOPS_LAST) {
|
@@ -2343,7 +2368,7 @@ Datum vops_populate(PG_FUNCTION_ARGS)
|
2343 | 2368 | ((vops_bool*)tile)->payload |= (uint64)DatumGetBool(val) << j;
|
2344 | 2369 | break;
|
2345 | 2370 | case VOPS_CHAR:
|
2346 |
| - ((vops_char*)tile)->payload[j] = SPI_gettypeid(spi_tupdesc, i+1) == CHAROID |
| 2371 | + ((vops_char*)tile)->payload[j] = types[i].src_type == CHAROID |
2347 | 2372 | ? DatumGetChar(val)
|
2348 | 2373 | : *VARDATA(DatumGetTextP(val));
|
2349 | 2374 | break;
|
|
0 commit comments