Re: proposal: enhancing plpgsql debug API - returns text value of variable content

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: enhancing plpgsql debug API - returns text value of variable content
Date: 2020-08-18 18:04:24
Message-ID: CAFj8pRDGfAP__a5_WWPgbmHQLrQ0mTG9eSRFOnq_DHfQAu0iaA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

po 17. 8. 2020 v 8:40 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> I am working on tracing support to plpgsql_check
>
> https://github.com/okbob/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 Content-Type Size
plpgsql-enhancing-dbg-api.patch text/x-patch 2.2 KB
plpgsql-assign-current-namespace-to-stmt.patch text/x-patch 12.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-08-18 20:09:44 Re: BUG #16583: merge join on tables with different DB collation behind postgres_fdw fails
Previous Message Justin Pryzby 2020-08-18 17:17:03 Re: doc review for v13