Skip to content

Commit 3e7fccd

Browse files
authored
Add plpgsql-check test (#1168)
* add plpgsql-check test * drop schema after test
1 parent 5db3d68 commit 3e7fccd

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

nix/tests/expected/plpgsql-check.out

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
create schema v;
2+
create table v.t1(
3+
a int,
4+
b int
5+
);
6+
create or replace function v.f1()
7+
returns void
8+
language plpgsql
9+
as $$
10+
declare r record;
11+
begin
12+
for r in select * from v.t1
13+
loop
14+
raise notice '%', r.c; -- there is bug - table t1 missing "c" column
15+
end loop;
16+
end;
17+
$$;
18+
select * from v.f1();
19+
f1
20+
----
21+
22+
(1 row)
23+
24+
-- use plpgsql_check_function to check the function for errors
25+
select * from plpgsql_check_function('v.f1()');
26+
plpgsql_check_function
27+
-------------------------------------------------
28+
error:42703:6:RAISE:record "r" has no field "c"
29+
Context: SQL expression "r.c"
30+
(2 rows)
31+
32+
drop schema v cascade;
33+
NOTICE: drop cascades to 2 other objects
34+
DETAIL: drop cascades to table v.t1
35+
drop cascades to function v.f1()

nix/tests/sql/plpgsql-check.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
create schema v;
2+
3+
create table v.t1(
4+
a int,
5+
b int
6+
);
7+
8+
create or replace function v.f1()
9+
returns void
10+
language plpgsql
11+
as $$
12+
declare r record;
13+
begin
14+
for r in select * from v.t1
15+
loop
16+
raise notice '%', r.c; -- there is bug - table t1 missing "c" column
17+
end loop;
18+
end;
19+
$$;
20+
21+
select * from v.f1();
22+
23+
-- use plpgsql_check_function to check the function for errors
24+
select * from plpgsql_check_function('v.f1()');
25+
26+
drop schema v cascade;

0 commit comments

Comments
 (0)