1_wrr.patch
text/x-diff
Filename: 1_wrr.patch
Type: text/x-diff
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/utils/adt/ruleutils.c | 40 | 0 |
| src/test/regress/expected/triggers.out | 3 | 3 |
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 3beed37..272d1a5 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -4007,7 +4007,47 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
}
if (attnum == InvalidAttrNumber)
+ {
attname = NULL;
+ /*
+ * The notation "relation.*" represents a whole-row reference.
+ * While parsing a whole-row reference is transformed into
+ * a Var with varno set to the correct range table entry,
+ * and varattno == 0 to signal that it references the whole tuple.
+ * For reference see comments of function makeWholeRowVar
+ * While deparsing we need to take care of this case
+ * This block of code is deparsing a whole-row reference.
+ * A whole row reference will be deparsed either into alias.*::relation
+ * or relation.*::relation depending on alias
+ * Explicit typecasting to relation is needed because
+ * input of anonymous composite types is not implemented
+ */
+
+ if (rte->relid != InvalidOid && refname && var->varattno == 0 &&
+ var->varno >= 1 && var->varno <= list_length(dpns->rtable))
+ {
+ char *rel_name;
+ List *schemalist;
+
+ schemalist = NULL;
+ if (schemaname)
+ list_make1(schemaname);
+
+ /* This relation name is required for explicit type casting later */
+ rel_name = generate_relation_name(rte->relid, schemalist);
+
+ /* Add name space qualification if required */
+ if (schemaname)
+ appendStringInfo(buf, "%s.", quote_identifier(schemaname));
+ appendStringInfoString(buf, quote_identifier(refname));
+ appendStringInfoString(buf, ".*::");
+ appendStringInfoString(buf, quote_identifier(rel_name));
+
+ pfree(rel_name);
+
+ return attname;
+ }
+ }
else
attname = get_rte_attribute_name(rte, attnum);
diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out
index 0e7177e..cb39881 100644
--- a/src/test/regress/expected/triggers.out
+++ b/src/test/regress/expected/triggers.out
@@ -387,9 +387,9 @@ SELECT pg_get_triggerdef(oid, false) FROM pg_trigger WHERE tgrelid = 'main_table
(1 row)
SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_any';
- pg_get_triggerdef
---------------------------------------------------------------------------------------------------------------------------------------------------------------
- CREATE TRIGGER modified_any BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN (old.* IS DISTINCT FROM new.*) EXECUTE PROCEDURE trigger_func('modified_any')
+ pg_get_triggerdef
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ CREATE TRIGGER modified_any BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN (old.*::main_table IS DISTINCT FROM new.*::main_table) EXECUTE PROCEDURE trigger_func('modified_any')
(1 row)
DROP TRIGGER modified_a ON main_table;