pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #6242: ERROR: unexpected CASE WHEN clause: 333
3+ messages / 2 participants
[nested] [flat]
* BUG #6242: ERROR: unexpected CASE WHEN clause: 333
@ 2011-10-07 07:29 Sergey <sergey-1987@yandex.ru>
0 siblings, 1 reply; 3+ messages in thread
From: Sergey @ 2011-10-07 07:29 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged online:
Bug reference: 6242
Logged by: Sergey
Email address: sergey-1987@yandex.ru
PostgreSQL version: 8.4.4
Operating system: FreeBSD 8.1-RELEASE
Description: ERROR: unexpected CASE WHEN clause: 333
Details:
create view test_view as
select
case n when null then 1 when 1 then 2 when 2 then 3 end
from (
values (null), (1), (2)
) as t(n)
pg_dump then fail with error: "ERROR: unexpected CASE WHEN clause: 333" but
select * from test_view does not.
This error occurs with the configuration "transform_null_equals".
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #6242: ERROR: unexpected CASE WHEN clause: 333
@ 2011-10-07 08:26 Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
parent: Sergey <sergey-1987@yandex.ru>
0 siblings, 1 reply; 3+ messages in thread
From: Heikki Linnakangas @ 2011-10-07 08:26 UTC (permalink / raw)
To: Sergey <sergey-1987@yandex.ru>; +Cc: pgsql-bugs
On 07.10.2011 10:29, Sergey wrote:
>
> The following bug has been logged online:
>
> Bug reference: 6242
> Logged by: Sergey
> Email address: sergey-1987@yandex.ru
> PostgreSQL version: 8.4.4
> Operating system: FreeBSD 8.1-RELEASE
> Description: ERROR: unexpected CASE WHEN clause: 333
> Details:
>
> create view test_view as
> select
> case n when null then 1 when 1 then 2 when 2 then 3 end
> from (
> values (null), (1), (2)
> ) as t(n)
>
> pg_dump then fail with error: "ERROR: unexpected CASE WHEN clause: 333" but
> select * from test_view does not.
>
> This error occurs with the configuration "transform_null_equals".
Hmm, this seems to be similar to the case of deconstructing SQL function
inlining in CASE-WHEN constructs we fixed a while ago
(http://archives.postgresql.org/pgsql-hackers/2011-05/msg01319.php, last
paragraph). On PostgreSQL 8.4.9, you don't get that error, but this:
CREATE VIEW test_view AS
SELECT CASE t.n WHEN (CASE_TEST_EXPR IS NULL) THEN 1 WHEN 1 THEN 2
WHEN 2 THEN 3 ELSE NULL::integer END AS "case" FROM (VALUES
(NULL::integer), (1), (2)) t(n);
That's not much better than the error, though, because that will fail on
restore.
I think the real bug here is that transform_null_equals affects the
evaluation of the "n WHEN null" condition at all. The documentation of
transform_null_equals says:
> Note that this option only affects the exact form = NULL, not other comparison operators or other expressions that are computationally equivalent to some expression involving the equals operator (such as IN). Thus, this option is not a general fix for bad programming.
In that CASE construct there was no "exact form = NULL", so
transform_null_equals should have had no effect on it.
I'm inclined to do a quick fix in transformAExprOp() function to not
apply the transformation if either side of the = operation is a
CaseTestExpr, per attached patch. We could potentially have the same
problem with any "a = NULL" expression created internally in the parser,
but I don't see any more instances of that, aside from this construction
of WHEN expressions.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
Attachments:
fix-case-when-transform_null_equals-1.patch (text/x-diff, 941B) download
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 9f68d26..90ff8d8 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -719,12 +719,15 @@ transformAExprOp(ParseState *pstate, A_Expr *a)
/*
* Special-case "foo = NULL" and "NULL = foo" for compatibility with
* standards-broken products (like Microsoft's). Turn these into IS NULL
- * exprs.
+ * exprs. (If either side is a CaseTestExpr, then the expression was
+ * generated internally from a CASE-WHEN expression, and
+ * transform_null_equals does not apply.)
*/
if (Transform_null_equals &&
list_length(a->name) == 1 &&
strcmp(strVal(linitial(a->name)), "=") == 0 &&
- (exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)))
+ (exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)) &&
+ (!IsA(lexpr, CaseTestExpr) && !IsA(rexpr, CaseTestExpr)))
{
NullTest *n = makeNode(NullTest);
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #6242: ERROR: unexpected CASE WHEN clause: 333
@ 2011-10-08 08:34 Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
parent: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
0 siblings, 0 replies; 3+ messages in thread
From: Heikki Linnakangas @ 2011-10-08 08:34 UTC (permalink / raw)
To: Sergey <sergey-1987@yandex.ru>; +Cc: pgsql-bugs
On 07.10.2011 11:26, Heikki Linnakangas wrote:
> I'm inclined to do a quick fix in transformAExprOp() function to not
> apply the transformation if either side of the = operation is a
> CaseTestExpr, per attached patch. We could potentially have the same
> problem with any "a = NULL" expression created internally in the parser,
> but I don't see any more instances of that, aside from this construction
> of WHEN expressions.
Committed that patch, thanks for the report!
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2011-10-08 08:34 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-10-07 07:29 BUG #6242: ERROR: unexpected CASE WHEN clause: 333 Sergey <sergey-1987@yandex.ru>
2011-10-07 08:26 ` Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
2011-10-08 08:34 ` Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox