Re: proposal: enhancing plpgsql debug API - returns text value of variable content - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: enhancing plpgsql debug API - returns text value of variable content
Date
Msg-id CAFj8pRDGfAP__a5_WWPgbmHQLrQ0mTG9eSRFOnq_DHfQAu0iaA@mail.gmail.com
Whole thread Raw
In response to proposal: enhancing plpgsql debug API - returns text value of variable content  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: proposal: enhancing plpgsql debug API - returns text value of variable content
List pgsql-hackers


po 17. 8. 2020 v 8:40 odesílatel Pavel Stehule <pavel.stehule@gmail.com> napsal:
Hi

I am working on tracing support to plpgsql_check


I would like to print content of variables - and now, I have to go some deeper than I would like. I need to separate between scalar, row, and record variables. PLpgSQL has code for it - but it is private.

Now plpgsql debug API has an API for expression evaluation - and it is working fine, but there is a need to know the necessary namespace. Unfortunately, the plpgsql variables have not assigned any info about related namespaces. It increases the necessary work for implementing conditional breakpoints or just printing all variables (and maintaining a lot of plpgsql code outside plpgsql core).

So my proposals:

1. enhancing debug api about method

char *get_cstring_valule(PLpgSQL_variable *var, bool *isnull)

2. enhancing PLpgSQL_var structure about related namespace "struct PLpgSQL_nsitem *ns",
PLpgSQL_stmt *scope statement (statement that limits scope of variable's visibility). For usage in debuggers, tracers can be nice to have a info about kind of variable (function argument, local variable, automatic custom variable (FORC), automatic internal variable (SQLERRM, FOUND, TG_OP, ...).

Comments, notes?

There are two patches

The first patch enhances dbg api by two functions - eval_datum and cast_value - it is an interface for functions exec_eval_datum and do_cast_value. With this API it is easy to take a value of any PLpgSQL variable (without the necessity to duplicate a lot of plpgsql's code), and it easy to transform this value to any expected type - usually it should provide the cast to the text type.

Second patch injects pointer to related namespace to any plpgsql statement. Reference to namespace is required for building custom expressions that can be evaluated by assign_expr function. I would like to use it for conditional breakpoints or conditional tracing. Without this patch it is difficult to detect the correct namespace and ensure the correct variable's visibility.

Regards

Pavel


Regards

Pavel


Attachment

pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: doc review for v13
Next
From: Tom Lane
Date:
Subject: Re: BUG #16583: merge join on tables with different DB collation behind postgres_fdw fails