From 8f433168a441fb21ad29a45dead842504eb257ad Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 27 Oct 2018 11:25:20 +0100 Subject: [PATCH v2 1/2] Remove obsolete pg_attrdef.adsrc column This has been deprecated and effectively unused for a long time. --- doc/src/sgml/catalogs.sgml | 20 +++----------------- src/backend/catalog/heap.c | 12 ------------ src/include/catalog/pg_attrdef.h | 1 - 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 9edba96fab..08cc0ea062 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -947,27 +947,13 @@ <structname>pg_attrdef</structname> Columns adbin pg_node_tree - The internal representation of the column default value - - - - adsrc - text - - A human-readable representation of the default value + The column default value, in nodeToString() + representation. Use pg_get_expr(adbin, adrelid) to + convert it to an SQL expression. - - - The adsrc field is historical, and is best - not used, because it does not track outside changes that might affect - the representation of the default value. Reverse-compiling the - adbin field (with pg_get_expr for - example) is a better way to display the default value. - - diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 3c9c03c997..640e283688 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -2152,7 +2152,6 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr, bool is_internal, bool add_column_mode) { char *adbin; - char *adsrc; Relation adrel; HeapTuple tuple; Datum values[4]; @@ -2169,21 +2168,12 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, */ adbin = nodeToString(expr); - /* - * Also deparse it to form the mostly-obsolete adsrc field. - */ - adsrc = deparse_expression(expr, - deparse_context_for(RelationGetRelationName(rel), - RelationGetRelid(rel)), - false, false); - /* * Make the pg_attrdef entry. */ values[Anum_pg_attrdef_adrelid - 1] = RelationGetRelid(rel); values[Anum_pg_attrdef_adnum - 1] = attnum; values[Anum_pg_attrdef_adbin - 1] = CStringGetTextDatum(adbin); - values[Anum_pg_attrdef_adsrc - 1] = CStringGetTextDatum(adsrc); adrel = heap_open(AttrDefaultRelationId, RowExclusiveLock); @@ -2198,10 +2188,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, /* now can free some of the stuff allocated above */ pfree(DatumGetPointer(values[Anum_pg_attrdef_adbin - 1])); - pfree(DatumGetPointer(values[Anum_pg_attrdef_adsrc - 1])); heap_freetuple(tuple); pfree(adbin); - pfree(adsrc); /* * Update the pg_attribute entry for the column to show that a default diff --git a/src/include/catalog/pg_attrdef.h b/src/include/catalog/pg_attrdef.h index e4a37ec326..a9a2351efd 100644 --- a/src/include/catalog/pg_attrdef.h +++ b/src/include/catalog/pg_attrdef.h @@ -33,7 +33,6 @@ CATALOG(pg_attrdef,2604,AttrDefaultRelationId) #ifdef CATALOG_VARLEN /* variable-length fields start here */ pg_node_tree adbin BKI_FORCE_NOT_NULL; /* nodeToString representation of default */ - text adsrc BKI_FORCE_NOT_NULL; /* human-readable representation of default */ #endif } FormData_pg_attrdef; base-commit: 5953c99697621174f50aa219a3cd457212968268 -- 2.19.1