aboutsummaryrefslogtreecommitdiff
path: root/src/test/regress/expected/plpgsql.out
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/regress/expected/plpgsql.out')
-rw-r--r--src/test/regress/expected/plpgsql.out77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out
index cd2c79f4d50..731db2c7760 100644
--- a/src/test/regress/expected/plpgsql.out
+++ b/src/test/regress/expected/plpgsql.out
@@ -1747,6 +1747,83 @@ SELECT * FROM test_ret_rec_dyn(5) AS (a int, b numeric, c text);
(1 row)
--
+-- Test some simple polymorphism cases.
+--
+create function f1(x anyelement) returns anyelement as $$
+begin
+ return x + 1;
+end$$ language plpgsql;
+select f1(42) as int, f1(4.5) as num;
+ int | num
+-----+-----
+ 43 | 5.5
+(1 row)
+
+select f1(point(3,4)); -- fail for lack of + operator
+ERROR: operator does not exist: point + integer
+LINE 1: SELECT x + 1
+ ^
+HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
+QUERY: SELECT x + 1
+CONTEXT: PL/pgSQL function f1(anyelement) line 3 at RETURN
+drop function f1(x anyelement);
+create function f1(x anyelement) returns anyarray as $$
+begin
+ return array[x + 1, x + 2];
+end$$ language plpgsql;
+select f1(42) as int, f1(4.5) as num;
+ int | num
+---------+-----------
+ {43,44} | {5.5,6.5}
+(1 row)
+
+drop function f1(x anyelement);
+create function f1(x anyarray) returns anyelement as $$
+begin
+ return x[1];
+end$$ language plpgsql;
+select f1(array[2,4]) as int, f1(array[4.5, 7.7]) as num;
+ int | num
+-----+-----
+ 2 | 4.5
+(1 row)
+
+select f1(stavalues1) from pg_statistic; -- fail, can't infer element type
+ERROR: argument declared anyarray is not an array but type anyarray
+drop function f1(x anyarray);
+create function f1(x anyarray) returns anyarray as $$
+begin
+ return x;
+end$$ language plpgsql;
+select f1(array[2,4]) as int, f1(array[4.5, 7.7]) as num;
+ int | num
+-------+-----------
+ {2,4} | {4.5,7.7}
+(1 row)
+
+select f1(stavalues1) from pg_statistic; -- fail, can't infer element type
+ERROR: PL/pgSQL functions cannot accept type anyarray
+CONTEXT: compilation of PL/pgSQL function "f1" near line 1
+drop function f1(x anyarray);
+-- fail, can't infer type:
+create function f1(x anyelement) returns anyrange as $$
+begin
+ return array[x + 1, x + 2];
+end$$ language plpgsql;
+ERROR: cannot determine result data type
+DETAIL: A function returning "anyrange" must have at least one "anyrange" argument.
+create function f1(x anyrange) returns anyarray as $$
+begin
+ return array[lower(x), upper(x)];
+end$$ language plpgsql;
+select f1(int4range(42, 49)) as int, f1(float8range(4.5, 7.8)) as num;
+ int | num
+---------+-----------
+ {42,49} | {4.5,7.8}
+(1 row)
+
+drop function f1(x anyrange);
+--
-- Test handling of OUT parameters, including polymorphic cases.
-- Note that RETURN is optional with OUT params; we try both ways.
--