1 -- test warnings and errors from plperl
2 create or replace function perl_elog(text) returns void language plperl as $$
8 select perl_elog('explicit elog');
15 create or replace function perl_warn(text) returns void language plperl as $$
21 select perl_warn('implicit elog via warn');
22 WARNING: implicit elog via warn at line 4.
28 -- test strict mode on/off
29 SET plperl.use_strict = true;
30 create or replace function uses_global() returns text language plperl as $$
34 return 'uses_global worked';
37 ERROR: Global symbol "$global" requires explicit package name (did you forget to declare "my $global"?) at line 3.
38 Global symbol "$other_global" requires explicit package name (did you forget to declare "my $other_global"?) at line 4.
39 CONTEXT: compilation of PL/Perl function "uses_global"
41 ERROR: function uses_global() does not exist
42 LINE 1: select uses_global();
44 HINT: No function matches the given name and argument types. You might need to add explicit type casts.
45 SET plperl.use_strict = false;
46 create or replace function uses_global() returns text language plperl as $$
50 return 'uses_global worked';
59 -- make sure we don't choke on readonly values
60 do language plperl $$ elog(NOTICE, ${^TAINT}); $$;
62 -- test recovery after "die"
63 create or replace function just_die() returns void language plperl AS $$
67 ERROR: just die at line 2.
68 CONTEXT: PL/Perl function "just_die"
69 create or replace function die_caller() returns int language plpgsql as $$
73 EXCEPTION WHEN OTHERS THEN
74 RAISE NOTICE 'caught die';
86 create or replace function indirect_die_caller() returns int language plperl as $$
87 my $prepared = spi_prepare('SELECT die_caller() AS fx');
88 my $a = spi_exec_prepared($prepared)->{rows}->[0]->{fx};
89 my $b = spi_exec_prepared($prepared)->{rows}->[0]->{fx};
92 select indirect_die_caller();
100 -- Test non-ASCII error messages
102 -- Note: this test case is known to fail if the database encoding is
103 -- EUC_CN, EUC_JP, EUC_KR, or EUC_TW, for lack of any equivalent to
104 -- U+00A0 (no-break space) in those encodings. However, testing with
105 -- plain ASCII data would be rather useless, so we must live with that.
106 SET client_encoding TO UTF8;
107 create or replace function error_with_nbsp() returns void language plperl as $$
108 elog(ERROR, "this message contains a no-break space");
110 select error_with_nbsp();
111 ERROR: this message contains a no-break space at line 2.
112 CONTEXT: PL/Perl function "error_with_nbsp"