*** pgsql/src/backend/utils/adt/ruleutils.c 2008/06/06 17:59:53 1.207.2.9 --- pgsql/src/backend/utils/adt/ruleutils.c 2009/02/25 18:00:22 1.207.2.10 *************** *** 3,9 **** * back to source text * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.207.2.8 2008/01/06 01:03:31 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * --- 3,9 ---- * back to source text * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.207.2.9 2008/06/06 17:59:53 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * *************** get_rule_expr(Node *node, deparse_contex *** 3556,3588 **** if (caseexpr->arg) { /* ! * The parser should have produced WHEN clauses of ! * the form "CaseTestExpr = RHS"; we want to show ! * just the RHS. If the user wrote something silly ! * like "CASE boolexpr WHEN TRUE THEN ...", then ! * the optimizer's simplify_boolean_equality() may ! * have reduced this to just "CaseTestExpr" or ! * "NOT CaseTestExpr", for which we have to show ! * "TRUE" or "FALSE". Also, depending on context ! * the original CaseTestExpr might have been reduced ! * to a Const (but we won't see "WHEN Const"). */ if (IsA(w, OpExpr)) { Node *rhs; ! Assert(IsA(linitial(((OpExpr *) w)->args), ! CaseTestExpr) || ! IsA(linitial(((OpExpr *) w)->args), ! Const)); ! rhs = (Node *) lsecond(((OpExpr *) w)->args); get_rule_expr(rhs, context, false); } ! else if (IsA(w, CaseTestExpr)) appendStringInfo(buf, "TRUE"); else if (not_clause(w)) { ! Assert(IsA(get_notclausearg((Expr *) w), CaseTestExpr)); appendStringInfo(buf, "FALSE"); } --- 3556,3593 ---- if (caseexpr->arg) { /* ! * The parser should have produced WHEN clauses of the ! * form "CaseTestExpr = RHS"; we want to show just the ! * RHS. If the user wrote something silly like "CASE ! * boolexpr WHEN TRUE THEN ...", then the optimizer's ! * simplify_boolean_equality() may have reduced this ! * to just "CaseTestExpr" or "NOT CaseTestExpr", for ! * which we have to show "TRUE" or "FALSE". Also, ! * depending on context the original CaseTestExpr ! * might have been reduced to a Const (but we won't ! * see "WHEN Const"). We have also to consider the ! * possibility that an implicit coercion was inserted ! * between the CaseTestExpr and the operator. */ if (IsA(w, OpExpr)) { + List *args = ((OpExpr *) w)->args; + Node *lhs; Node *rhs; ! Assert(list_length(args) == 2); ! lhs = strip_implicit_coercions(linitial(args)); ! Assert(IsA(lhs, CaseTestExpr) || ! IsA(lhs, Const)); ! rhs = (Node *) lsecond(args); get_rule_expr(rhs, context, false); } ! else if (IsA(strip_implicit_coercions(w), ! CaseTestExpr)) appendStringInfo(buf, "TRUE"); else if (not_clause(w)) { ! Assert(IsA(strip_implicit_coercions((Node *) get_notclausearg((Expr *) w)), CaseTestExpr)); appendStringInfo(buf, "FALSE"); }