diff --git a/expected/plpgsql_check_active.out b/expected/plpgsql_check_active.out index bf05336..7d4c724 100644 --- a/expected/plpgsql_check_active.out +++ b/expected/plpgsql_check_active.out @@ -9257,3 +9257,32 @@ NOTICE: 7 NOTICE: 8 NOTICE: 9 NOTICE: 10 +-- should not raise warning +create or replace function fx(p text) +returns void as $$ +begin + execute format($_$select '%1$I'$_$, p); +end; +$$ language plpgsql; +-- should be ok +select * from plpgsql_check_function('fx(text)'); + plpgsql_check_function +------------------------ +(0 rows) + +drop function fx(text); +create or replace function fx() +returns void as $$ +declare p varchar; +begin + p := 'ahoj'; + execute format($_$select '%1$I'$_$, p); +end; +$$ language plpgsql; +-- should be ok +select * from plpgsql_check_function('fx()'); + plpgsql_check_function +------------------------ +(0 rows) + +drop function fx(); diff --git a/expected/plpgsql_check_active_1.out b/expected/plpgsql_check_active_1.out index bade33e..de678a1 100644 --- a/expected/plpgsql_check_active_1.out +++ b/expected/plpgsql_check_active_1.out @@ -9260,3 +9260,32 @@ NOTICE: 7 NOTICE: 8 NOTICE: 9 NOTICE: 10 +-- should not raise warning +create or replace function fx(p text) +returns void as $$ +begin + execute format($_$select '%1$I'$_$, p); +end; +$$ language plpgsql; +-- should be ok +select * from plpgsql_check_function('fx(text)'); + plpgsql_check_function +------------------------ +(0 rows) + +drop function fx(text); +create or replace function fx() +returns void as $$ +declare p varchar; +begin + p := 'ahoj'; + execute format($_$select '%1$I'$_$, p); +end; +$$ language plpgsql; +-- should be ok +select * from plpgsql_check_function('fx()'); + plpgsql_check_function +------------------------ +(0 rows) + +drop function fx(); diff --git a/sql/plpgsql_check_active.sql b/sql/plpgsql_check_active.sql index d03ad1f..563e9ef 100644 --- a/sql/plpgsql_check_active.sql +++ b/sql/plpgsql_check_active.sql @@ -5488,3 +5488,30 @@ begin end loop; end; $$; + +-- should not raise warning +create or replace function fx(p text) +returns void as $$ +begin + execute format($_$select '%1$I'$_$, p); +end; +$$ language plpgsql; + +-- should be ok +select * from plpgsql_check_function('fx(text)'); + +drop function fx(text); + +create or replace function fx() +returns void as $$ +declare p varchar; +begin + p := 'ahoj'; + execute format($_$select '%1$I'$_$, p); +end; +$$ language plpgsql; + +-- should be ok +select * from plpgsql_check_function('fx()'); + +drop function fx(); diff --git a/src/expr_walk.c b/src/expr_walk.c index 2950198..6a9aadb 100644 --- a/src/expr_walk.c +++ b/src/expr_walk.c @@ -597,7 +597,7 @@ plpgsql_check_get_formatted_string(PLpgSQL_checkstate *cstate, } } - _arg = argpos >= 1 ? argpos : arg + 1; + _arg = argpos >= 1 ? argpos + 1: arg + 1; if (_arg <= nargs) { char *str;