1--
2-- Cache-behavior-dependent test cases
3--
4-- These tests logically belong in plpgsql_record.sql, and perhaps someday
5-- can be merged back into it.  For now, however, their results are different
6-- depending on debug_discard_caches, so we must have two expected-output
7-- files to cover both cases.  To minimize the maintenance effort resulting
8-- from that, this file should contain only tests that do have different
9-- results under debug_discard_caches.
10--
11
12-- check behavior with changes of a named rowtype
13create table c_mutable(f1 int, f2 text);
14
15create function c_sillyaddone(int) returns int language plpgsql as
16$$ declare r c_mutable; begin r.f1 := $1; return r.f1 + 1; end $$;
17select c_sillyaddone(42);
18
19alter table c_mutable drop column f1;
20alter table c_mutable add column f1 float8;
21
22-- currently, this fails due to cached plan for "r.f1 + 1" expression
23-- (but if debug_discard_caches is on, it will succeed)
24select c_sillyaddone(42);
25
26-- but it's OK if we force plan rebuilding
27discard plans;
28select c_sillyaddone(42);
29
30-- check behavior with changes in a record rowtype
31create function show_result_type(text) returns text language plpgsql as
32$$
33    declare
34        r record;
35        t text;
36    begin
37        execute $1 into r;
38        select pg_typeof(r.a) into t;
39        return format('type %s value %s', t, r.a::text);
40    end;
41$$;
42
43select show_result_type('select 1 as a');
44-- currently this fails due to cached plan for pg_typeof expression
45-- (but if debug_discard_caches is on, it will succeed)
46select show_result_type('select 2.0 as a');
47
48-- but it's OK if we force plan rebuilding
49discard plans;
50select show_result_type('select 2.0 as a');
51