1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
\set VERBOSITY terse
-- test bad arg
create function test_err1(dat text)
returns text as $$
cluster 'testcluster';
run on hashtext(username);
$$ language plproxy;
select * from test_err1('dat');
ERROR: column "username" does not exist at character 24
create function test_err2(dat text)
returns text as $$
cLuStEr 'testcluster';
rUn oN hAshtext($2);
$$ language plproxy;
ERROR: PL/Proxy function public.test_err2(1): Compile error at line 3: invalid argument reference: $2
select * from test_err2('dat');
ERROR: function test_err2(unknown) does not exist at character 15
create function test_err3(dat text)
returns text as $$
cluster 'nonexists';
run on hashtext($1);
$$ language plproxy;
select * from test_err3('dat');
ERROR: no such cluster: nonexists
-- should work
create function test_err_none(dat text)
returns text as $$
cluster 'testcluster';
run on hashtext($1);
select 'ok';
$$ language plproxy;
select * from test_err_none('dat');
test_err_none
---------------
ok
(1 row)
--- result map errors
create function test_map_err1(dat text)
returns text as $$ cluster 'testcluster'; run on 0;
select dat as "foo", 'asd' as "bar";
$$ language plproxy;
select * from test_map_err1('dat');
ERROR: PL/Proxy function public.test_map_err1(1): single field function but got record
create function test_map_err2(dat text, out res1 text, out res2 text)
returns record as $$ cluster 'testcluster'; run on 0;
select dat as res1;
$$ language plproxy;
select * from test_map_err2('dat');
ERROR: PL/Proxy function public.test_map_err2(1): Got too few fields from remote end
create function test_map_err3(dat text, out res1 text, out res2 text)
returns record as $$ cluster 'testcluster'; run on 0;
select dat as res1, 'foo' as res_none;
$$ language plproxy;
select * from test_map_err3('dat');
ERROR: PL/Proxy function public.test_map_err3(1): Field res2 does not exists in result
create function test_map_err4(dat text, out res1 text, out res2 text)
returns record as $$
--cluster 'testcluster';
run on hashtext(dat);
select dat as res2, 'foo' as res1;
$$ language plproxy;
ERROR: PL/Proxy function public.test_map_err4(1): Compile error at line 5: CLUSTER statement missing
select * from test_map_err4('dat');
ERROR: function test_map_err4(unknown) does not exist at character 15
create function test_variadic_err(first text, rest variadic text[])
returns text as $$
cluster 'testcluster';
$$ language plproxy;
ERROR: PL/Proxy does not support variadic args
select * from test_variadic_err('dat', 'dat', 'dat');
ERROR: function test_variadic_err(unknown, unknown, unknown) does not exist at character 15
create function test_volatile_err(dat text)
returns text
stable
as $$
cluster 'testcluster';
$$ language plproxy;
ERROR: PL/Proxy functions must be volatile
select * from test_volatile_err('dat');
ERROR: function test_volatile_err(unknown) does not exist at character 15
create function test_pseudo_arg_err(dat cstring)
returns text
as $$
cluster 'testcluster';
$$ language plproxy;
ERROR: PL/Proxy function public.test_pseudo_arg_err(0): unsupported pseudo type: cstring (2275)
select * from test_pseudo_arg_err(textout('dat'));
ERROR: function test_pseudo_arg_err(cstring) does not exist at character 15
create function test_pseudo_ret_err(dat text)
returns cstring
as $$
cluster 'testcluster';
$$ language plproxy;
-- not detected in validator
select * from test_pseudo_ret_err('dat');
ERROR: PL/Proxy function public.test_pseudo_ret_err(0): unsupported pseudo type: cstring (2275)
create function test_runonall_err(dat text)
returns text
as $$
cluster 'testcluster';
run on all;
$$ language plproxy;
ERROR: PL/Proxy function public.test_runonall_err(1): RUN ON ALL requires set-returning function
select * from test_runonall_err('dat');
ERROR: function test_runonall_err(unknown) does not exist at character 15
-- make sure that errors from non-setof functions returning <> 1 row have
-- a proper sqlstate
create function test_no_results_plproxy()
returns int
as $$
cluster 'testcluster';
run on any;
select 1 from pg_database where datname = '';
$$ language plproxy;
create function test_no_results()
returns void
as $$
begin
begin
perform test_no_results_plproxy();
exception when no_data_found then
null;
end;
end;
$$ language plpgsql;
select * from test_no_results();
test_no_results
-----------------
(1 row)
create function test_multi_results_plproxy()
returns int
as $$
cluster 'testcluster';
run on any;
select 1 from pg_database;
$$ language plproxy;
create function test_multi_results()
returns void
as $$
begin
begin
perform test_multi_results_plproxy();
exception when too_many_rows then
null;
end;
end;
$$ language plpgsql;
select * from test_multi_results();
test_multi_results
--------------------
(1 row)
|