From 70c915a0f27ade36e0239e621d5569d5e2021cae Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Sat, 9 Apr 2022 11:01:10 -0700 Subject: [PATCH] PG15: Handle data type changes in pg_collation. Account for PG commit 54637508f8. --- src/backend/distributed/commands/collation.c | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/commands/collation.c b/src/backend/distributed/commands/collation.c index c284404ce..930d7c770 100644 --- a/src/backend/distributed/commands/collation.c +++ b/src/backend/distributed/commands/collation.c @@ -60,12 +60,30 @@ CreateCollationDDLInternal(Oid collationId, Oid *collowner, char **quotedCollati Form_pg_collation collationForm = (Form_pg_collation) GETSTRUCT(heapTuple); char collprovider = collationForm->collprovider; - const char *collcollate = NameStr(collationForm->collcollate); - const char *collctype = NameStr(collationForm->collctype); Oid collnamespace = collationForm->collnamespace; const char *collname = NameStr(collationForm->collname); bool collisdeterministic = collationForm->collisdeterministic; +#if PG_VERSION_NUM >= PG_VERSION_15 + bool isnull; + Datum datum = SysCacheGetAttr(COLLOID, heapTuple, Anum_pg_collation_collcollate, + &isnull); + Assert(!isnull); + char *collcollate = TextDatumGetCString(datum); + datum = SysCacheGetAttr(COLLOID, heapTuple, Anum_pg_collation_collctype, &isnull); + Assert(!isnull); + char *collctype = TextDatumGetCString(datum); +#else + + /* + * In versions before 15, collcollate and collctype were type "name". Use + * pstrdup() to match the interface of 15 so that we consistently free the + * result later. + */ + char *collcollate = pstrdup(NameStr(collationForm->collcollate)); + char *collctype = pstrdup(NameStr(collationForm->collctype)); +#endif + if (collowner != NULL) { *collowner = collationForm->collowner; @@ -103,6 +121,9 @@ CreateCollationDDLInternal(Oid collationId, Oid *collowner, char **quotedCollati quote_literal_cstr(collctype)); } + pfree(collcollate); + pfree(collctype); + if (!collisdeterministic) { appendStringInfoString(&collationNameDef, ", deterministic = false");