okbob / plpgsql_check

plpgsql_check is a linter tool (does source code static analyze) for the PostgreSQL language plpgsql (the native language for PostgreSQL store procedures).
https://groups.google.com/forum/#!forum/postgresql-extensions-hacking
Other
641 stars 53 forks source link

dynamyc code fails when profiler is on #149

Closed pestryakovda closed 1 year ago

pestryakovda commented 1 year ago

Hi Here is a test:

show shared_preload_libraries;
plpgsql,pg_stat_statements,plpgsql_check

SELECT VERSION();
PostgreSQL 15.4 (Debian 15.4-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

create or replace procedure demo_procedure() as
$body$
declare
    l_cur refcursor;
    l_str varchar;
begin
    open l_cur for execute 'select $1 as p_x' using 'some text';
    FETCH l_cur INTO l_str;
    raise notice '%', l_str;
end;
$body$ language plpgsql;

set plpgsql_check.profiler = on;

call demo_procedure();

fails with error:
[42P02] ERROR: there is no parameter $1
PL/pgSQL function demo_procedure() line 13 at OPEN

when profiler is off, same code works well

okbob commented 1 year ago

I am able to reproduce it. It is related to queryid calculation.

okbob commented 1 year ago

should be fixed by 0b417f8996ef257fac90c0c682e4b96aac23c551

pestryakovda commented 1 year ago

It works Thank you!