mirror of
https://github.com/postgres/postgres.git
synced 2025-05-18 17:41:14 +03:00
Fix broken logic for pretty-printing parenthesis-suppression in UNION
et al.
This commit is contained in:
parent
e5a806bb29
commit
abef61155d
@ -3,7 +3,7 @@
|
|||||||
* back to source text
|
* back to source text
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.157.2.1 2004/05/07 03:20:01 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.157.2.2 2004/07/06 04:50:54 tgl Exp $
|
||||||
*
|
*
|
||||||
* This software is copyrighted by Jan Wieck - Hamburg.
|
* This software is copyrighted by Jan Wieck - Hamburg.
|
||||||
*
|
*
|
||||||
@ -1990,6 +1990,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
|
|||||||
TupleDesc resultDesc)
|
TupleDesc resultDesc)
|
||||||
{
|
{
|
||||||
StringInfo buf = context->buf;
|
StringInfo buf = context->buf;
|
||||||
|
bool need_paren;
|
||||||
|
|
||||||
if (IsA(setOp, RangeTblRef))
|
if (IsA(setOp, RangeTblRef))
|
||||||
{
|
{
|
||||||
@ -1998,24 +1999,37 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
|
|||||||
Query *subquery = rte->subquery;
|
Query *subquery = rte->subquery;
|
||||||
|
|
||||||
Assert(subquery != NULL);
|
Assert(subquery != NULL);
|
||||||
|
Assert(subquery->setOperations == NULL);
|
||||||
|
/* Need parens if ORDER BY, FOR UPDATE, or LIMIT; see gram.y */
|
||||||
|
need_paren = (subquery->sortClause ||
|
||||||
|
subquery->rowMarks ||
|
||||||
|
subquery->limitOffset ||
|
||||||
|
subquery->limitCount);
|
||||||
|
if (need_paren)
|
||||||
|
appendStringInfoChar(buf, '(');
|
||||||
get_query_def(subquery, buf, context->namespaces, resultDesc,
|
get_query_def(subquery, buf, context->namespaces, resultDesc,
|
||||||
context->prettyFlags, context->indentLevel);
|
context->prettyFlags, context->indentLevel);
|
||||||
|
if (need_paren)
|
||||||
|
appendStringInfoChar(buf, ')');
|
||||||
}
|
}
|
||||||
else if (IsA(setOp, SetOperationStmt))
|
else if (IsA(setOp, SetOperationStmt))
|
||||||
{
|
{
|
||||||
SetOperationStmt *op = (SetOperationStmt *) setOp;
|
SetOperationStmt *op = (SetOperationStmt *) setOp;
|
||||||
bool need_paren;
|
|
||||||
|
|
||||||
need_paren = (PRETTY_PAREN(context) ?
|
/*
|
||||||
!IsA(op->rarg, RangeTblRef) : true);
|
* We force parens whenever nesting two SetOperationStmts.
|
||||||
|
* There are some cases in which parens are needed around a leaf
|
||||||
if (!PRETTY_PAREN(context))
|
* query too, but those are more easily handled at the next level
|
||||||
appendStringInfoString(buf, "((");
|
* down (see code above).
|
||||||
|
*/
|
||||||
|
need_paren = !IsA(op->larg, RangeTblRef);
|
||||||
|
|
||||||
|
if (need_paren)
|
||||||
|
appendStringInfoChar(buf, '(');
|
||||||
get_setop_query(op->larg, query, context, resultDesc);
|
get_setop_query(op->larg, query, context, resultDesc);
|
||||||
|
if (need_paren)
|
||||||
if (!PRETTY_PAREN(context))
|
|
||||||
appendStringInfoChar(buf, ')');
|
appendStringInfoChar(buf, ')');
|
||||||
|
|
||||||
if (!PRETTY_INDENT(context))
|
if (!PRETTY_INDENT(context))
|
||||||
appendStringInfoChar(buf, ' ');
|
appendStringInfoChar(buf, ' ');
|
||||||
switch (op->op)
|
switch (op->op)
|
||||||
@ -2042,27 +2056,13 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
|
|||||||
if (PRETTY_INDENT(context))
|
if (PRETTY_INDENT(context))
|
||||||
appendStringInfoChar(buf, '\n');
|
appendStringInfoChar(buf, '\n');
|
||||||
|
|
||||||
if (PRETTY_PAREN(context))
|
need_paren = !IsA(op->rarg, RangeTblRef);
|
||||||
{
|
|
||||||
if (need_paren)
|
if (need_paren)
|
||||||
{
|
|
||||||
appendStringInfoChar(buf, '(');
|
|
||||||
if (PRETTY_INDENT(context))
|
|
||||||
appendStringInfoChar(buf, '\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
appendStringInfoChar(buf, '(');
|
appendStringInfoChar(buf, '(');
|
||||||
|
|
||||||
get_setop_query(op->rarg, query, context, resultDesc);
|
get_setop_query(op->rarg, query, context, resultDesc);
|
||||||
|
if (need_paren)
|
||||||
if (PRETTY_PAREN(context))
|
appendStringInfoChar(buf, ')');
|
||||||
{
|
|
||||||
if (need_paren)
|
|
||||||
appendStringInfoChar(buf, ')');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
appendStringInfoString(buf, "))");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user