summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2014-01-09 01:18:06 +0000
committerTom Lane2014-01-09 01:18:58 +0000
commit080b7db72ebbec22580237631d6b07d0e1147b01 (patch)
tree756ffb242ae077c408e04889810d1b0b0adbcdfe /src/test
parentdaa7527afc2274432094ebe7ceb03aa41f916607 (diff)
Fix "cannot accept a set" error when only some arms of a CASE return a set.
In commit c1352052ef1d4eeb2eb1d822a207ddc2d106cb13, I implemented an optimization that assumed that a function's argument expressions would either always return a set (ie multiple rows), or always not. This is wrong however: we allow CASE expressions in which some arms return a set of some type and others just return a scalar of that type. There may be other examples as well. To fix, replace the run-time test of whether an argument returned a set with a static precheck (expression_returns_set). This adds a little bit of query startup overhead, but it seems barely measurable. Per bug #8228 from David Johnston. This has been broken since 8.0, so patch all supported branches.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/rangefuncs.out14
-rw-r--r--src/test/regress/sql/rangefuncs.sql9
2 files changed, 23 insertions, 0 deletions
diff --git a/src/test/regress/expected/rangefuncs.out b/src/test/regress/expected/rangefuncs.out
index a988dd01a12..9d40510ecdb 100644
--- a/src/test/regress/expected/rangefuncs.out
+++ b/src/test/regress/expected/rangefuncs.out
@@ -1992,3 +1992,17 @@ select * from foobar(); -- fail
ERROR: function return row and query-specified return row do not match
DETAIL: Returned row contains 3 attributes, but query expects 2.
drop function foobar();
+-- check behavior when a function's input sometimes returns a set (bug #8228)
+SELECT *,
+ lower(CASE WHEN id = 2 THEN (regexp_matches(str, '^0*([1-9]\d+)$'))[1]
+ ELSE str
+ END)
+FROM
+ (VALUES (1,''), (2,'0000000049404'), (3,'FROM 10000000876')) v(id, str);
+ id | str | lower
+----+------------------+------------------
+ 1 | |
+ 2 | 0000000049404 | 49404
+ 3 | FROM 10000000876 | from 10000000876
+(3 rows)
+
diff --git a/src/test/regress/sql/rangefuncs.sql b/src/test/regress/sql/rangefuncs.sql
index ac2769fdba9..07d2e1a490e 100644
--- a/src/test/regress/sql/rangefuncs.sql
+++ b/src/test/regress/sql/rangefuncs.sql
@@ -599,3 +599,12 @@ $$ select (1, 2.1, 3) $$ language sql;
select * from foobar(); -- fail
drop function foobar();
+
+-- check behavior when a function's input sometimes returns a set (bug #8228)
+
+SELECT *,
+ lower(CASE WHEN id = 2 THEN (regexp_matches(str, '^0*([1-9]\d+)$'))[1]
+ ELSE str
+ END)
+FROM
+ (VALUES (1,''), (2,'0000000049404'), (3,'FROM 10000000876')) v(id, str);