Skip to content

Commit

Permalink
TupleDescAttr() support
Browse files Browse the repository at this point in the history
Commit d34a74dd064af959acd9040446925d9d53dff15b introduced
TupleDescAttr(tupdesc, i) in back branches (9.4.14, 9.5.9, 9.6.5, 10). If the
version supports it, use this macro. This change will unbreak (future) version
11.
  • Loading branch information
Euler Taveira committed Nov 9, 2017
1 parent cbbdda9 commit 5352cc4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion wal2json.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,16 @@ tuple_to_stringinfo(LogicalDecodingContext *ctx, TupleDesc tupdesc, HeapTuple tu
char *outputstr = NULL;
bool isnull; /* column is null? */

/*
* Commit d34a74dd064af959acd9040446925d9d53dff15b introduced
* TupleDescAttr() in back branches. If the version supports
* this macro, use it. Version 10 and later already support it.
*/
#if (PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 90605) || (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90509) || (PG_VERSION_NUM >= 90400 && PG_VERSION_NUM < 90414)
attr = tupdesc->attrs[natt];
#else
attr = TupleDescAttr(tupdesc, natt);
#endif

elog(DEBUG1, "attribute \"%s\" (%d/%d)", NameStr(attr->attname), natt, tupdesc->natts);

Expand All @@ -477,8 +486,18 @@ tuple_to_stringinfo(LogicalDecodingContext *ctx, TupleDesc tupdesc, HeapTuple tu

for (j = 0; j < indexdesc->natts; j++)
{
if (strcmp(NameStr(attr->attname), NameStr(indexdesc->attrs[j]->attname)) == 0)
Form_pg_attribute iattr;

/* See explanation a few lines above. */
#if (PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 90605) || (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90509) || (PG_VERSION_NUM >= 90400 && PG_VERSION_NUM < 90414)
iattr = indexdesc->attrs[j];
#else
iattr = TupleDescAttr(indexdesc, j);
#endif

if (strcmp(NameStr(attr->attname), NameStr(iattr->attname)) == 0)
found_col = true;

}

/* Print only indexed columns */
Expand Down

0 comments on commit 5352cc4

Please sign in to comment.