Skip to content

Commit

Permalink
fix constant traicing inside format function when positional placehol…
Browse files Browse the repository at this point in the history
…der was used
  • Loading branch information
okbob committed Feb 26, 2024
1 parent 5ffbe47 commit 8fb6693
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
29 changes: 29 additions & 0 deletions expected/plpgsql_check_active.out
Original file line number Diff line number Diff line change
Expand Up @@ -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();
29 changes: 29 additions & 0 deletions expected/plpgsql_check_active_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -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();
27 changes: 27 additions & 0 deletions sql/plpgsql_check_active.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion src/expr_walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8fb6693

Please sign in to comment.