From 834000bdea3e0339a83d28e217f5532516eeed56 Mon Sep 17 00:00:00 2001 From: Lukas Fittl Date: Wed, 25 Oct 2023 00:24:06 -0700 Subject: [PATCH] Deparser: Treat type casts inside "func_expr_windowless" as functions This is mainly in use for RangeFunction, but the logic in the grammar here is more broad, allowing type casts to show up in places where a function call would be expected. Fix by always using the "cast(..)" syntax in such cases. --- src/postgres_deparse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/postgres_deparse.c b/src/postgres_deparse.c index 0ea0ab41..9e231185 100644 --- a/src/postgres_deparse.c +++ b/src/postgres_deparse.c @@ -29,6 +29,7 @@ typedef enum DeparseNodeContext { DEPARSE_NODE_CONTEXT_CREATE_TYPE, DEPARSE_NODE_CONTEXT_ALTER_TYPE, DEPARSE_NODE_CONTEXT_SET_STATEMENT, + DEPARSE_NODE_CONTEXT_FUNC_EXPR, // Identifier vs constant context DEPARSE_NODE_CONTEXT_IDENTIFIER, DEPARSE_NODE_CONTEXT_CONSTANT @@ -1782,7 +1783,7 @@ static void deparseFuncExprWindowless(StringInfo str, Node* node) deparseSQLValueFunction(str, castNode(SQLValueFunction, node)); break; case T_TypeCast: - deparseTypeCast(str, castNode(TypeCast, node), DEPARSE_NODE_CONTEXT_NONE); + deparseTypeCast(str, castNode(TypeCast, node), DEPARSE_NODE_CONTEXT_FUNC_EXPR); break; case T_CoalesceExpr: deparseCoalesceExpr(str, castNode(CoalesceExpr, node)); @@ -3546,7 +3547,7 @@ static void deparseTypeCast(StringInfo str, TypeCast *type_cast, DeparseNodeCont Assert(type_cast->typeName != NULL); - if (IsA(type_cast->arg, A_Expr)) + if (IsA(type_cast->arg, A_Expr) || context == DEPARSE_NODE_CONTEXT_FUNC_EXPR) { appendStringInfoString(str, "CAST("); deparseExpr(str, type_cast->arg);