Skip to content

Commit

Permalink
regress tests and minor cleaning and enhancing
Browse files Browse the repository at this point in the history
  • Loading branch information
okbob committed Feb 6, 2025
1 parent d6f521e commit 3b4d492
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 2 deletions.
25 changes: 25 additions & 0 deletions expected/plpgsql_check_active.out
Original file line number Diff line number Diff line change
Expand Up @@ -9422,3 +9422,28 @@ $$ language plpgsql;
-- should not to crash
select trace_test(3);
ERROR: too late initialization of fmgr_plpgsql_cache
create table testtable_pure_expr(a int);
-- detection of not pure expressions
create or replace function pure_expr()
returns void as $$
declare v int;
begin
v := 1
delete from testtable_pure_expr where a = 10;
raise notice '%', v;
end;
$$ language plpgsql;
-- raise warning
select * from plpgsql_check_function('pure_expr()');
plpgsql_check_function
--------------------------------------------------------------------
warning extra:42601:4:assignment:expression is not pure expression
Query: v := 1
-- ^
delete from testtable_pure_expr where a = 10
Detail: there is a possibility of unwanted behave
Hint: Maybe you forgot to use a semicolon.
Context: at assignment to variable "v" declared on line 2
(7 rows)

drop table testtable_pure_expr;
16 changes: 16 additions & 0 deletions expected/plpgsql_check_active_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -9424,3 +9424,19 @@ $$ language plpgsql;
-- should not to crash
select trace_test(3);
ERROR: too late initialization of fmgr_plpgsql_cache
create table testtable_pure_expr(a int);
-- detection of not pure expressions
create or replace function pure_expr()
returns void as $$
declare v int;
begin
v := 1
delete from testtable_pure_expr where a = 10;
raise notice '%', v;
end;
$$ language plpgsql;
ERROR: syntax error at or near "delete" at character 91
-- raise warning
select * from plpgsql_check_function('pure_expr()');
ERROR: function "pure_expr()" does not exist
drop table testtable_pure_expr;
25 changes: 25 additions & 0 deletions expected/plpgsql_check_active_2.out
Original file line number Diff line number Diff line change
Expand Up @@ -9421,3 +9421,28 @@ $$ language plpgsql;
-- should not to crash
select trace_test(3);
ERROR: too late initialization of fmgr_plpgsql_cache
create table testtable_pure_expr(a int);
-- detection of not pure expressions
create or replace function pure_expr()
returns void as $$
declare v int;
begin
v := 1
delete from testtable_pure_expr where a = 10;
raise notice '%', v;
end;
$$ language plpgsql;
-- raise warning
select * from plpgsql_check_function('pure_expr()');
plpgsql_check_function
--------------------------------------------------------------------
warning extra:42601:4:assignment:expression is not pure expression
Query: v := 1
-- ^
delete from testtable_pure_expr where a = 10
Detail: there is a possibility of unwanted behave
Hint: Maybe you forgot to use a semicolon.
Context: at assignment to variable "v" declared on line 2
(7 rows)

drop table testtable_pure_expr;
25 changes: 25 additions & 0 deletions expected/plpgsql_check_active_3.out
Original file line number Diff line number Diff line change
Expand Up @@ -9422,3 +9422,28 @@ $$ language plpgsql;
-- should not to crash
select trace_test(3);
ERROR: too late initialization of fmgr_plpgsql_cache
create table testtable_pure_expr(a int);
-- detection of not pure expressions
create or replace function pure_expr()
returns void as $$
declare v int;
begin
v := 1
delete from testtable_pure_expr where a = 10;
raise notice '%', v;
end;
$$ language plpgsql;
-- raise warning
select * from plpgsql_check_function('pure_expr()');
plpgsql_check_function
--------------------------------------------------------------------
warning extra:42601:4:assignment:expression is not pure expression
Query: v := 1
-- ^
delete from testtable_pure_expr where a = 10
Detail: there is a possibility of unwanted behave
Hint: Maybe you forgot to use a semicolon.
Context: at assignment to variable "v" declared on line 2
(7 rows)

drop table testtable_pure_expr;
18 changes: 18 additions & 0 deletions sql/plpgsql_check_active.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5619,3 +5619,21 @@ $$ language plpgsql;
\c
-- should not to crash
select trace_test(3);

create table testtable_pure_expr(a int);

-- detection of not pure expressions
create or replace function pure_expr()
returns void as $$
declare v int;
begin
v := 1
delete from testtable_pure_expr where a = 10;
raise notice '%', v;
end;
$$ language plpgsql;

-- raise warning
select * from plpgsql_check_function('pure_expr()');

drop table testtable_pure_expr;
5 changes: 3 additions & 2 deletions src/check_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "executor/spi_priv.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/optimizer.h"
#include "parser/parse_node.h"
Expand Down Expand Up @@ -440,9 +441,9 @@ check_pure_expr(PLpgSQL_checkstate *cstate, Query *query, char *query_str)
ERRCODE_SYNTAX_ERROR, 0,
"expression is not pure expression",
"there is a possibility of unwanted behave",
NULL,
"Maybe you forgot to use a semicolon.",
PLPGSQL_CHECK_WARNING_EXTRA,
0, query_str, NULL);
exprLocation(query->targetList), query_str, NULL);
}
}

Expand Down

0 comments on commit 3b4d492

Please sign in to comment.