|
| 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 | +-- between regular and CLOBBER_CACHE_ALWAYS builds, so we must have two |
| 7 | +-- expected-output files to cover both cases. To minimize the maintenance |
| 8 | +-- effort resulting from that, this file should contain only tests that |
| 9 | +-- do have different results under CLOBBER_CACHE_ALWAYS. |
| 10 | +-- |
| 11 | +-- check behavior with changes of a named rowtype |
| 12 | +create table c_mutable(f1 int, f2 text); |
| 13 | +create function c_sillyaddone(int) returns int language plpgsql as |
| 14 | +$$ declare r c_mutable; begin r.f1 := $1; return r.f1 + 1; end $$; |
| 15 | +select c_sillyaddone(42); |
| 16 | + c_sillyaddone |
| 17 | +--------------- |
| 18 | + 43 |
| 19 | +(1 row) |
| 20 | + |
| 21 | +alter table c_mutable drop column f1; |
| 22 | +alter table c_mutable add column f1 float8; |
| 23 | +-- currently, this fails due to cached plan for "r.f1 + 1" expression |
| 24 | +-- (but a CLOBBER_CACHE_ALWAYS build will succeed) |
| 25 | +select c_sillyaddone(42); |
| 26 | +ERROR: type of parameter 4 (double precision) does not match that when preparing the plan (integer) |
| 27 | +CONTEXT: PL/pgSQL function c_sillyaddone(integer) line 1 at RETURN |
| 28 | +-- but it's OK if we force plan rebuilding |
| 29 | +discard plans; |
| 30 | +select c_sillyaddone(42); |
| 31 | + c_sillyaddone |
| 32 | +--------------- |
| 33 | + 43 |
| 34 | +(1 row) |
| 35 | + |
| 36 | +-- check behavior with changes in a record rowtype |
| 37 | +create function show_result_type(text) returns text language plpgsql as |
| 38 | +$$ |
| 39 | + declare |
| 40 | + r record; |
| 41 | + t text; |
| 42 | + begin |
| 43 | + execute $1 into r; |
| 44 | + select pg_typeof(r.a) into t; |
| 45 | + return format('type %s value %s', t, r.a::text); |
| 46 | + end; |
| 47 | +$$; |
| 48 | +select show_result_type('select 1 as a'); |
| 49 | + show_result_type |
| 50 | +---------------------- |
| 51 | + type integer value 1 |
| 52 | +(1 row) |
| 53 | + |
| 54 | +-- currently this fails due to cached plan for pg_typeof expression |
| 55 | +-- (but a CLOBBER_CACHE_ALWAYS build will succeed) |
| 56 | +select show_result_type('select 2.0 as a'); |
| 57 | +ERROR: type of parameter 5 (numeric) does not match that when preparing the plan (integer) |
| 58 | +CONTEXT: SQL statement "select pg_typeof(r.a)" |
| 59 | +PL/pgSQL function show_result_type(text) line 7 at SQL statement |
| 60 | +-- but it's OK if we force plan rebuilding |
| 61 | +discard plans; |
| 62 | +select show_result_type('select 2.0 as a'); |
| 63 | + show_result_type |
| 64 | +------------------------ |
| 65 | + type numeric value 2.0 |
| 66 | +(1 row) |
| 67 | + |
0 commit comments