Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deparse of particular BooleanTest expressions #207

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/postgres_deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2879,8 +2879,8 @@ static void deparseAExpr(StringInfo str, A_Expr* a_expr, DeparseNodeContext cont
ListCell *lc;
char *name;

bool need_lexpr_parens = a_expr->lexpr != NULL && (IsA(a_expr->lexpr, BoolExpr) || IsA(a_expr->lexpr, NullTest) || IsA(a_expr->lexpr, A_Expr));
bool need_rexpr_parens = a_expr->rexpr != NULL && (IsA(a_expr->rexpr, BoolExpr) || IsA(a_expr->rexpr, NullTest) || IsA(a_expr->rexpr, A_Expr));
bool need_lexpr_parens = a_expr->lexpr != NULL && (IsA(a_expr->lexpr, BoolExpr) || IsA(a_expr->lexpr, BooleanTest) || IsA(a_expr->lexpr, NullTest) || IsA(a_expr->lexpr, A_Expr));
bool need_rexpr_parens = a_expr->rexpr != NULL && (IsA(a_expr->rexpr, BoolExpr) || IsA(a_expr->rexpr, BooleanTest) || IsA(a_expr->rexpr, NullTest) || IsA(a_expr->rexpr, A_Expr));

switch (a_expr->kind) {
case AEXPR_OP: /* normal operator */
Expand Down Expand Up @@ -3950,7 +3950,16 @@ static void deparseMinMaxExpr(StringInfo str, MinMaxExpr *min_max_expr)

static void deparseBooleanTest(StringInfo str, BooleanTest *boolean_test)
{
bool need_parens = IsA(boolean_test->arg, BoolExpr);

if (need_parens)
appendStringInfoChar(str, '(');

deparseExpr(str, (Node *) boolean_test->arg);

if (need_parens)
appendStringInfoChar(str, ')');

switch (boolean_test->booltesttype)
{
case IS_TRUE:
Expand Down
2 changes: 2 additions & 0 deletions test/deparse_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ const char* tests[] = {
"CREATE PROCEDURE returns_one() LANGUAGE sql BEGIN ATOMIC RETURN 1; END",
"CREATE PROCEDURE updates_and_returns_one() LANGUAGE sql BEGIN ATOMIC UPDATE tbl SET a = 1; RETURN 1; END",
"SELECT 1 FROM tbl LIMIT COALESCE($1, $2)",
"SELECT (false AND true) IS FALSE",
"SELECT a = (true IS FALSE)",
};

size_t testsLength = __LINE__ - 4;
Loading