format_datum debugging function

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: format_datum debugging function
Date: 2024-08-09 23:04:45
Message-ID: 286814e4-46d4-44d6-be45-c2ee979021e1@illuminatedcomputing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

Often in a debugger I've wanted to way to print Datums, in particular non-trivial ones like range
types. This came up a lot when I was working on multiranges, and I've wished for it lately while
working on UPDATE/DELETE FOR PORTION OF. But all the obvious approaches are inlined functions or
preprocessor macros, so they aren't available. Usually I wind up giving up on gdb and adding elog
statements. Once or twice I've copy/pasted from the three or four levels of nested macros to make
gdb do what I wanted, but it's a pain.

I assumed printing a Datum was easy, and I was the only one who didn't know how to do it. But
perhaps not. The conversation about print.c [1] made me think I should propose a way to make it
easier. 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?

[1] https://www.postgresql.org/message-id/flat/7d023c20-6679-44bd-b5f7-44106659bd5a%40eisentraut.org

Yours,

--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2024-08-09 23:08:40 Re: libpq: Fix lots of discrepancies in PQtrace
Previous Message Tom Lane 2024-08-09 22:50:14 Re: is_superuser versus set_config_option's parallelism check