Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
d600c1db
Commit
d600c1db
authored
Jan 19, 2005
by
Neil Conway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some basic regression tests for refcursors in PL/PgSQL.
parent
3fc86c0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
0 deletions
+126
-0
src/test/regress/expected/plpgsql.out
src/test/regress/expected/plpgsql.out
+70
-0
src/test/regress/sql/plpgsql.sql
src/test/regress/sql/plpgsql.sql
+56
-0
No files found.
src/test/regress/expected/plpgsql.out
View file @
d600c1db
...
...
@@ -2103,3 +2103,73 @@ select sp_add_user('user3');
drop function sp_add_user(text);
drop function sp_id_user(text);
--
-- tests for refcursors
--
create table rc_test (a int, b int);
copy rc_test from stdin;
create function return_refcursor(rc refcursor) returns refcursor as $$
begin
open rc for select a from rc_test;
return rc;
end
$$ language 'plpgsql';
create function refcursor_test1(refcursor) returns refcursor as $$
begin
perform return_refcursor($1);
return $1;
end
$$ language 'plpgsql';
begin;
select refcursor_test1('test1');
refcursor_test1
-----------------
test1
(1 row)
fetch next from test1;
a
---
5
(1 row)
select refcursor_test1('test2');
refcursor_test1
-----------------
test2
(1 row)
fetch all from test2;
a
-----
5
50
500
(3 rows)
commit;
-- should fail
fetch next from test1;
ERROR: cursor "test1" does not exist
create function refcursor_test2(int) returns boolean as $$
declare
c1 cursor (param integer) for select * from rc_test where a > param;
nonsense record;
begin
open c1($1);
fetch c1 into nonsense;
close c1;
if found then
return true;
else
return false;
end if;
end
$$ language 'plpgsql';
select refcursor_test2(20000) as "Should be false",
refcursor_test2(20) as "Should be true";
Should be false | Should be true
-----------------+----------------
f | t
(1 row)
src/test/regress/sql/plpgsql.sql
View file @
d600c1db
...
...
@@ -1807,3 +1807,59 @@ select sp_add_user('user3');
drop
function
sp_add_user
(
text
);
drop
function
sp_id_user
(
text
);
--
-- tests for refcursors
--
create
table
rc_test
(
a
int
,
b
int
);
copy
rc_test
from
stdin
;
5
10
50
100
500
1000
\
.
create
function
return_refcursor
(
rc
refcursor
)
returns
refcursor
as
$$
begin
open
rc
for
select
a
from
rc_test
;
return
rc
;
end
$$
language
'plpgsql'
;
create
function
refcursor_test1
(
refcursor
)
returns
refcursor
as
$$
begin
perform
return_refcursor
(
$
1
);
return
$
1
;
end
$$
language
'plpgsql'
;
begin
;
select
refcursor_test1
(
'test1'
);
fetch
next
from
test1
;
select
refcursor_test1
(
'test2'
);
fetch
all
from
test2
;
commit
;
-- should fail
fetch
next
from
test1
;
create
function
refcursor_test2
(
int
)
returns
boolean
as
$$
declare
c1
cursor
(
param
integer
)
for
select
*
from
rc_test
where
a
>
param
;
nonsense
record
;
begin
open
c1
(
$
1
);
fetch
c1
into
nonsense
;
close
c1
;
if
found
then
return
true
;
else
return
false
;
end
if
;
end
$$
language
'plpgsql'
;
select
refcursor_test2
(
20000
)
as
"Should be false"
,
refcursor_test2
(
20
)
as
"Should be true"
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment