On 8/12/24 04:32, Aleksander Alekseev wrote:
[...] This function takes a Datum and the appropriate out function, and returns
a char *. So you
can do this:
(gdb) call format_datum(range_out, $1)
$2 = 0x59162692d938 "[1,4)"
I assume a patch like this doesn't need documentation. Does it need a test?
Anything else?
I think you forgot to attach the patch. Or is it just a proposal?
Sorry, patch attached here.
Yours,
--
Paul ~{:-)
p...@illuminatedcomputing.com
From 38a5e20e1481aa42d746b088cc6802f99d6d4276 Mon Sep 17 00:00:00 2001
From: "Paul A. Jungwirth" <p...@illuminatedcomputing.com>
Date: Fri, 9 Aug 2024 15:46:58 -0700
Subject: [PATCH v1] Add format_datum debugging function
This function lets you say `call format_datum(foo_out, foo)` in your
debugger to get a Datum as a readable string. It returns a char *
instead of printing itself, since that seems more flexible.
---
src/backend/nodes/print.c | 19 +++++++++++++++++++
src/include/nodes/print.h | 1 +
2 files changed, 20 insertions(+)
diff --git a/src/backend/nodes/print.c b/src/backend/nodes/print.c
index 02798f4482d..d810e31d1b1 100644
--- a/src/backend/nodes/print.c
+++ b/src/backend/nodes/print.c
@@ -25,6 +25,7 @@
#include "nodes/pathnodes.h"
#include "nodes/print.h"
#include "parser/parsetree.h"
+#include "pgstat.h"
#include "utils/lsyscache.h"
@@ -246,6 +247,24 @@ pretty_format_node_dump(const char *dump)
#undef LINELEN
}
+char *
+format_datum(PGFunction outfunc, Datum val)
+{
+ FmgrInfo flinfo;
+
+ flinfo.fn_addr = outfunc;
+ flinfo.fn_oid = InvalidOid;
+ flinfo.fn_nargs = 1;
+ flinfo.fn_strict = true;
+ flinfo.fn_retset = false;
+ flinfo.fn_stats = TRACK_FUNC_ALL;
+ flinfo.fn_extra = NULL;
+ flinfo.fn_mcxt = CurrentMemoryContext;
+ flinfo.fn_expr = NULL;
+
+ return OutputFunctionCall(&flinfo, val);
+}
+
/*
* print_rt
* print contents of range table
diff --git a/src/include/nodes/print.h b/src/include/nodes/print.h
index 333103a4051..27d165edafc 100644
--- a/src/include/nodes/print.h
+++ b/src/include/nodes/print.h
@@ -23,6 +23,7 @@ extern void print(const void *obj);
extern void pprint(const void *obj);
extern void elog_node_display(int lev, const char *title,
const void *obj, bool pretty);
+extern char *format_datum(PGFunction outfunc, Datum val);
extern char *format_node_dump(const char *dump);
extern char *pretty_format_node_dump(const char *dump);
extern void print_rt(const List *rtable);
--
2.42.0