From 5352cc4193b956be446d6f5f21dd5282c463118b Mon Sep 17 00:00:00 2001 From: Euler Taveira Date: Thu, 9 Nov 2017 02:02:32 +0000 Subject: [PATCH] TupleDescAttr() support 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. --- wal2json.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wal2json.c b/wal2json.c index cdbcde17757b..75a421f8b98b 100644 --- a/wal2json.c +++ b/wal2json.c @@ -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); @@ -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 */