Skip to content

Commit 3b4d492

Browse files
committed
regress tests and minor cleaning and enhancing
1 parent d6f521e commit 3b4d492

6 files changed

+112
-2
lines changed

expected/plpgsql_check_active.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9422,3 +9422,28 @@ $$ language plpgsql;
94229422
-- should not to crash
94239423
select trace_test(3);
94249424
ERROR: too late initialization of fmgr_plpgsql_cache
9425+
create table testtable_pure_expr(a int);
9426+
-- detection of not pure expressions
9427+
create or replace function pure_expr()
9428+
returns void as $$
9429+
declare v int;
9430+
begin
9431+
v := 1
9432+
delete from testtable_pure_expr where a = 10;
9433+
raise notice '%', v;
9434+
end;
9435+
$$ language plpgsql;
9436+
-- raise warning
9437+
select * from plpgsql_check_function('pure_expr()');
9438+
plpgsql_check_function
9439+
--------------------------------------------------------------------
9440+
warning extra:42601:4:assignment:expression is not pure expression
9441+
Query: v := 1
9442+
-- ^
9443+
delete from testtable_pure_expr where a = 10
9444+
Detail: there is a possibility of unwanted behave
9445+
Hint: Maybe you forgot to use a semicolon.
9446+
Context: at assignment to variable "v" declared on line 2
9447+
(7 rows)
9448+
9449+
drop table testtable_pure_expr;

expected/plpgsql_check_active_1.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9424,3 +9424,19 @@ $$ language plpgsql;
94249424
-- should not to crash
94259425
select trace_test(3);
94269426
ERROR: too late initialization of fmgr_plpgsql_cache
9427+
create table testtable_pure_expr(a int);
9428+
-- detection of not pure expressions
9429+
create or replace function pure_expr()
9430+
returns void as $$
9431+
declare v int;
9432+
begin
9433+
v := 1
9434+
delete from testtable_pure_expr where a = 10;
9435+
raise notice '%', v;
9436+
end;
9437+
$$ language plpgsql;
9438+
ERROR: syntax error at or near "delete" at character 91
9439+
-- raise warning
9440+
select * from plpgsql_check_function('pure_expr()');
9441+
ERROR: function "pure_expr()" does not exist
9442+
drop table testtable_pure_expr;

expected/plpgsql_check_active_2.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9421,3 +9421,28 @@ $$ language plpgsql;
94219421
-- should not to crash
94229422
select trace_test(3);
94239423
ERROR: too late initialization of fmgr_plpgsql_cache
9424+
create table testtable_pure_expr(a int);
9425+
-- detection of not pure expressions
9426+
create or replace function pure_expr()
9427+
returns void as $$
9428+
declare v int;
9429+
begin
9430+
v := 1
9431+
delete from testtable_pure_expr where a = 10;
9432+
raise notice '%', v;
9433+
end;
9434+
$$ language plpgsql;
9435+
-- raise warning
9436+
select * from plpgsql_check_function('pure_expr()');
9437+
plpgsql_check_function
9438+
--------------------------------------------------------------------
9439+
warning extra:42601:4:assignment:expression is not pure expression
9440+
Query: v := 1
9441+
-- ^
9442+
delete from testtable_pure_expr where a = 10
9443+
Detail: there is a possibility of unwanted behave
9444+
Hint: Maybe you forgot to use a semicolon.
9445+
Context: at assignment to variable "v" declared on line 2
9446+
(7 rows)
9447+
9448+
drop table testtable_pure_expr;

expected/plpgsql_check_active_3.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9422,3 +9422,28 @@ $$ language plpgsql;
94229422
-- should not to crash
94239423
select trace_test(3);
94249424
ERROR: too late initialization of fmgr_plpgsql_cache
9425+
create table testtable_pure_expr(a int);
9426+
-- detection of not pure expressions
9427+
create or replace function pure_expr()
9428+
returns void as $$
9429+
declare v int;
9430+
begin
9431+
v := 1
9432+
delete from testtable_pure_expr where a = 10;
9433+
raise notice '%', v;
9434+
end;
9435+
$$ language plpgsql;
9436+
-- raise warning
9437+
select * from plpgsql_check_function('pure_expr()');
9438+
plpgsql_check_function
9439+
--------------------------------------------------------------------
9440+
warning extra:42601:4:assignment:expression is not pure expression
9441+
Query: v := 1
9442+
-- ^
9443+
delete from testtable_pure_expr where a = 10
9444+
Detail: there is a possibility of unwanted behave
9445+
Hint: Maybe you forgot to use a semicolon.
9446+
Context: at assignment to variable "v" declared on line 2
9447+
(7 rows)
9448+
9449+
drop table testtable_pure_expr;

sql/plpgsql_check_active.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5619,3 +5619,21 @@ $$ language plpgsql;
56195619
\c
56205620
-- should not to crash
56215621
select trace_test(3);
5622+
5623+
create table testtable_pure_expr(a int);
5624+
5625+
-- detection of not pure expressions
5626+
create or replace function pure_expr()
5627+
returns void as $$
5628+
declare v int;
5629+
begin
5630+
v := 1
5631+
delete from testtable_pure_expr where a = 10;
5632+
raise notice '%', v;
5633+
end;
5634+
$$ language plpgsql;
5635+
5636+
-- raise warning
5637+
select * from plpgsql_check_function('pure_expr()');
5638+
5639+
drop table testtable_pure_expr;

src/check_expr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "catalog/pg_proc.h"
1818
#include "catalog/pg_type.h"
1919
#include "executor/spi_priv.h"
20+
#include "nodes/nodeFuncs.h"
2021
#include "optimizer/clauses.h"
2122
#include "optimizer/optimizer.h"
2223
#include "parser/parse_node.h"
@@ -440,9 +441,9 @@ check_pure_expr(PLpgSQL_checkstate *cstate, Query *query, char *query_str)
440441
ERRCODE_SYNTAX_ERROR, 0,
441442
"expression is not pure expression",
442443
"there is a possibility of unwanted behave",
443-
NULL,
444+
"Maybe you forgot to use a semicolon.",
444445
PLPGSQL_CHECK_WARNING_EXTRA,
445-
0, query_str, NULL);
446+
exprLocation(query->targetList), query_str, NULL);
446447
}
447448
}
448449

0 commit comments

Comments
 (0)