Skip to content

Commit d10a79d

Browse files

File tree

5 files changed

+106
-14
lines changed

5 files changed

+106
-14
lines changed

lib/parser_csv.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ CSVParserInit(CSVParser *self, Checker *checker, const char *infile, TupleDesc d
233233
{
234234
for (i = 0; i < desc->natts; i++)
235235
{
236-
#if PG_VERSION_NUM >= 110000
236+
#if PG_VERSION_NUM >= 180000
237+
if (strcmp(lfirst(name), NameStr(TupleDescAttr(desc, i)->attname)) == 0)
238+
#elif PG_VERSION_NUM >= 110000
237239
if (strcmp(lfirst(name), desc->attrs[i].attname.data) == 0)
238240
#else
239241
if (strcmp(lfirst(name), desc->attrs[i]->attname.data) == 0)
@@ -694,7 +696,9 @@ CSVParserRead(CSVParser *self, Checker *checker)
694696
else
695697
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
696698
errmsg("missing data for column \"%s\"",
697-
#if PG_VERSION_NUM >= 110000
699+
#if PG_VERSION_NUM >= 180000
700+
NameStr(TupleDescAttr(self->former.desc, self->former.attnum[self->base.parsing_field])->attname)),
701+
#elif PG_VERSION_NUM >= 110000
698702
NameStr(self->former.desc->attrs[self->former.attnum[self->base.parsing_field]].attname)),
699703
#else
700704
NameStr(self->former.desc->attrs[self->former.attnum[self->base.parsing_field]]->attname)),

lib/parser_function.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,16 @@ FunctionParserInit(FunctionParser *self, Checker *checker, const char *infile, T
333333

334334
self->desc = CreateTupleDescCopy(desc);
335335
for (i = 0; i < desc->natts; i++)
336-
#if PG_VERSION_NUM >= 110000
336+
{
337+
#if PG_VERSION_NUM >= 180000
338+
TupleDescAttr(self->desc, i)->attnotnull = TupleDescAttr(desc, i)->attnotnull;
339+
populate_compact_attribute(self->desc, i);
340+
#elif PG_VERSION_NUM >= 110000
337341
self->desc->attrs[i].attnotnull = desc->attrs[i].attnotnull;
338342
#else
339343
self->desc->attrs[i]->attnotnull = desc->attrs[i]->attnotnull;
340344
#endif
345+
}
341346

342347
self->estate = CreateExecutorState();
343348
self->econtext = GetPerTupleExprContext(self->estate);

lib/pg_btree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,9 @@ tuple_to_cstring(TupleDesc tupdesc, HeapTuple tuple)
11931193
bool nq;
11941194

11951195
/* Ignore dropped columns in datatype */
1196-
#if PG_VERSION_NUM >= 110000
1196+
#if PG_VERSION_NUM >= 180000
1197+
if (TupleDescAttr(tupdesc, i)->attisdropped)
1198+
#elif PG_VERSION_NUM >= 110000
11971199
if (tupdesc->attrs[i].attisdropped)
11981200
#else
11991201
if (tupdesc->attrs[i]->attisdropped)
@@ -1214,7 +1216,9 @@ tuple_to_cstring(TupleDesc tupdesc, HeapTuple tuple)
12141216
Oid foutoid;
12151217
bool typisvarlena;
12161218

1217-
#if PG_VERSION_NUM >= 110000
1219+
#if PG_VERSION_NUM >= 180000
1220+
getTypeOutputInfo(TupleDescAttr(tupdesc, i)->atttypid, &foutoid, &typisvarlena);
1221+
#elif PG_VERSION_NUM >= 110000
12181222
getTypeOutputInfo(tupdesc->attrs[i].atttypid, &foutoid, &typisvarlena);
12191223
#else
12201224
getTypeOutputInfo(tupdesc->attrs[i]->atttypid, &foutoid, &typisvarlena);

lib/reader.c

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,16 @@ CheckerInit(Checker *checker, Relation rel, TupleChecker *tchecker)
493493

494494
checker->desc = CreateTupleDescCopy(desc);
495495
for (n = 0; n < desc->natts; n++)
496-
#if PG_VERSION_NUM >= 110000
496+
{
497+
#if PG_VERSION_NUM >= 180000
498+
TupleDescAttr(checker->desc, n)->attnotnull = TupleDescAttr(desc, n)->attnotnull;
499+
populate_compact_attribute(checker->desc, n);
500+
#elif PG_VERSION_NUM >= 110000
497501
checker->desc->attrs[n].attnotnull = desc->attrs[n].attnotnull;
498502
#else
499503
checker->desc->attrs[n]->attnotnull = desc->attrs[n]->attnotnull;
500504
#endif
505+
}
501506
}
502507
}
503508

@@ -595,7 +600,10 @@ CheckerConstraints(Checker *checker, HeapTuple tuple, int *parsing_field)
595600

596601
for (i = 0; i < desc->natts; i++)
597602
{
598-
#if PG_VERSION_NUM >= 110000
603+
#if PG_VERSION_NUM >= 180000
604+
if (TupleDescAttr(desc, i)->attnotnull &&
605+
att_isnull(i, tuple->t_data->t_bits))
606+
#elif PG_VERSION_NUM >= 110000
599607
if (desc->attrs[i].attnotnull &&
600608
att_isnull(i, tuple->t_data->t_bits))
601609
#else
@@ -608,7 +616,9 @@ CheckerConstraints(Checker *checker, HeapTuple tuple, int *parsing_field)
608616
ereport(ERROR,
609617
(errcode(ERRCODE_NOT_NULL_VIOLATION),
610618
errmsg("null value in column \"%s\" violates not-null constraint",
611-
#if PG_VERSION_NUM >= 110000
619+
#if PG_VERSION_NUM >= 180000
620+
NameStr(TupleDescAttr(desc, i)->attname))));
621+
#elif PG_VERSION_NUM >= 110000
612622
NameStr(desc->attrs[i].attname))));
613623
#else
614624
NameStr(desc->attrs[i]->attname))));
@@ -630,11 +640,16 @@ TupleFormerInit(TupleFormer *former, Filter *filter, TupleDesc desc)
630640

631641
former->desc = CreateTupleDescCopy(desc);
632642
for (i = 0; i < desc->natts; i++)
633-
#if PG_VERSION_NUM >= 110000
643+
{
644+
#if PG_VERSION_NUM >= 180000
645+
TupleDescAttr(former->desc, i)->attnotnull = TupleDescAttr(desc, i)->attnotnull;
646+
populate_compact_attribute(former->desc, i);
647+
#elif PG_VERSION_NUM >= 110000
634648
former->desc->attrs[i].attnotnull = desc->attrs[i].attnotnull;
635649
#else
636650
former->desc->attrs[i]->attnotnull = desc->attrs[i]->attnotnull;
637651
#endif
652+
}
638653

639654
/*
640655
* allocate buffer to store columns or function arguments
@@ -689,7 +704,19 @@ TupleFormerInit(TupleFormer *former, Filter *filter, TupleDesc desc)
689704
former->maxfields = 0;
690705
for (i = 0; i < natts; i++)
691706
{
692-
#if PG_VERSION_NUM >= 110000
707+
#if PG_VERSION_NUM >= 180000
708+
/* ignore dropped columns */
709+
if (TupleDescAttr(desc, i)->attisdropped)
710+
continue;
711+
712+
/* get type information and input function */
713+
getTypeInputInfo(TupleDescAttr(desc, i)->atttypid,
714+
&in_func_oid, &former->typIOParam[i]);
715+
fmgr_info(in_func_oid, &former->typInput[i]);
716+
717+
former->typMod[i] = TupleDescAttr(desc, i)->atttypmod;
718+
former->typId[i] = TupleDescAttr(desc, i)->atttypid;
719+
#elif PG_VERSION_NUM >= 110000
693720
/* ignore dropped columns */
694721
if (attrs[i].attisdropped)
695722
continue;
@@ -807,7 +834,19 @@ tupledesc_match(TupleDesc dst_tupdesc, TupleDesc src_tupdesc)
807834

808835
for (i = 0; i < dst_tupdesc->natts; i++)
809836
{
810-
#if PG_VERSION_NUM >= 110000
837+
#if PG_VERSION_NUM >= 180000
838+
FormData_pg_attribute *dattr = TupleDescAttr(dst_tupdesc, i);
839+
FormData_pg_attribute *sattr = TupleDescAttr(src_tupdesc, i);
840+
841+
if (dattr->atttypid == sattr->atttypid)
842+
continue; /* no worries */
843+
if (!dattr->attisdropped)
844+
return false;
845+
846+
if (dattr->attlen != sattr->attlen ||
847+
dattr->attalign != sattr->attalign)
848+
return false;
849+
#elif PG_VERSION_NUM >= 110000
811850
FormData_pg_attribute dattr = dst_tupdesc->attrs[i];
812851
FormData_pg_attribute sattr = src_tupdesc->attrs[i];
813852

@@ -1262,7 +1301,19 @@ CoercionDeformTuple(TupleChecker *self, HeapTuple tuple, int *parsing_field)
12621301

12631302
for (i = 0; i < natts; i++)
12641303
{
1265-
#if PG_VERSION_NUM >= 110000
1304+
#if PG_VERSION_NUM >= 180000
1305+
if (TupleDescAttr(self->sourceDesc, i)->atttypid ==
1306+
TupleDescAttr(self->targetDesc, i)->atttypid)
1307+
continue;
1308+
1309+
getTypeOutputInfo(TupleDescAttr(self->sourceDesc, i)->atttypid,
1310+
&iofunc, &self->typIsVarlena[i]);
1311+
fmgr_info(iofunc, &self->typOutput[i]);
1312+
1313+
getTypeInputInfo(TupleDescAttr(self->targetDesc, i)->atttypid, &iofunc,
1314+
&self->typIOParam[i]);
1315+
fmgr_info(iofunc, &self->typInput[i]);
1316+
#elif PG_VERSION_NUM >= 110000
12661317
if (self->sourceDesc->attrs[i].atttypid ==
12671318
self->targetDesc->attrs[i].atttypid)
12681319
continue;
@@ -1298,7 +1349,33 @@ CoercionDeformTuple(TupleChecker *self, HeapTuple tuple, int *parsing_field)
12981349
{
12991350
*parsing_field = i + 1;
13001351

1301-
#if PG_VERSION_NUM >= 110000
1352+
#if PG_VERSION_NUM >= 180000
1353+
/* Ignore dropped columns in datatype */
1354+
if (TupleDescAttr(self->targetDesc, i)->attisdropped)
1355+
continue;
1356+
1357+
if (self->nulls[i])
1358+
{
1359+
/* emit nothing... */
1360+
continue;
1361+
}
1362+
else if (TupleDescAttr(self->sourceDesc, i)->atttypid ==
1363+
TupleDescAttr(self->targetDesc, i)->atttypid)
1364+
{
1365+
continue;
1366+
}
1367+
else
1368+
{
1369+
char *value;
1370+
1371+
value = OutputFunctionCall(&self->typOutput[i], self->values[i]);
1372+
self->values[i] = InputFunctionCall(&self->typInput[i], value,
1373+
self->typIOParam[i],
1374+
TupleDescAttr(self->targetDesc, i)->atttypmod);
1375+
pfree(value);
1376+
}
1377+
}
1378+
#elif PG_VERSION_NUM >= 110000
13021379
/* Ignore dropped columns in datatype */
13031380
if (self->targetDesc->attrs[i].attisdropped)
13041381
continue;

lib/source.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ CreateRemoteSource(const char *path, TupleDesc desc)
481481
/* count valid fields */
482482
for (nattrs = 0, i = 0; i < desc->natts; i++)
483483
{
484-
#if PG_VERSION_NUM >= 110000
484+
#if PG_VERSION_NUM >= 180000
485+
if (TupleDescAttr(desc, i)->attisdropped)
486+
#elif PG_VERSION_NUM >= 110000
485487
if (desc->attrs[i].attisdropped)
486488
#else
487489
if (desc->attrs[i]->attisdropped)

0 commit comments

Comments
 (0)