Skip to content

Commit

Permalink
Deparser: Treat type casts inside "func_expr_windowless" as functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lfittl committed Oct 25, 2023
1 parent 3168dae commit 834000b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/postgres_deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 834000b

Please sign in to comment.