mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Fix "cannot accept a set" error when only some arms of a CASE return a set.
In commit c1352052ef
, 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.
This commit is contained in:
@@ -930,3 +930,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)
|
||||
|
||||
|
@@ -455,3 +455,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);
|
||||
|
Reference in New Issue
Block a user