You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yesterday I fixed this issue in pglast, and trying now I see that the same problem afflicts also the deparse() machinery.
Basically,
SELECT (false AND true) IS FALSE
and
SELECT a = (true IS FALSE)
come out without the needed parens.
I was able to mimick the fix for the first case, but I'm not sure how to address the second case: in pglast I consulted the BooleanTest's parent node, and when its a A_Expr I encoded it within parens.
Here is a diff, with test cases and the mentioned fix:
diff --git a/src/postgres_deparse.c b/src/postgres_deparse.c
index e4cac50..a9c5bd0 100644
--- a/src/postgres_deparse.c+++ b/src/postgres_deparse.c@@ -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:
diff --git a/test/deparse_tests.c b/test/deparse_tests.c
index 2860797..8ac26bf 100644
--- a/test/deparse_tests.c+++ b/test/deparse_tests.c@@ -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;
Maybe if you can gimme some hint I may find some time to implement a complete PR fixing the issue.
Thanks&bye!
The text was updated successfully, but these errors were encountered:
lelit
added a commit
to lelit/libpg_query
that referenced
this issue
Aug 26, 2023
Yesterday I fixed this issue in
pglast
, and trying now I see that the same problem afflicts also thedeparse()
machinery.Basically,
and
come out without the needed parens.
I was able to mimick the fix for the first case, but I'm not sure how to address the second case: in
pglast
I consulted the BooleanTest's parent node, and when its aA_Expr
I encoded it within parens.Here is a diff, with test cases and the mentioned fix:
Maybe if you can gimme some hint I may find some time to implement a complete PR fixing the issue.
Thanks&bye!
The text was updated successfully, but these errors were encountered: