Skip to content

Commit 3b8679e

Browse files
author
Commitfest Bot
committed
[CF 5957] v4 - implement CAST(expr AS type FORMAT 'template')
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5957 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CACJufxH+soqLj_AuMQj-_jxunVQKX-HBQA_3_3vmV1jTRyZ1hA@mail.gmail.com Author(s): Jian He
2 parents 5487058 + a7b6d69 commit 3b8679e

File tree

14 files changed

+881
-10
lines changed

14 files changed

+881
-10
lines changed

src/backend/nodes/nodeFuncs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4464,6 +4464,8 @@ raw_expression_tree_walker_impl(Node *node,
44644464

44654465
if (WALK(tc->arg))
44664466
return true;
4467+
if (WALK(tc->format))
4468+
return true;
44674469
if (WALK(tc->typeName))
44684470
return true;
44694471
}

src/backend/parser/gram.y

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
156156
static void updateRawStmtEnd(RawStmt *rs, int end_location);
157157
static Node *makeColumnRef(char *colname, List *indirection,
158158
int location, core_yyscan_t yyscanner);
159+
static Node *makeFormattedTypeCast(Node *arg, Node *format,
160+
TypeName *typename, int location);
159161
static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
160162
static Node *makeStringConstCast(char *str, int location, TypeName *typename);
161163
static Node *makeIntConst(int val, int location);
@@ -15933,6 +15935,8 @@ func_expr_common_subexpr:
1593315935
}
1593415936
| CAST '(' a_expr AS Typename ')'
1593515937
{ $$ = makeTypeCast($3, $5, @1); }
15938+
| CAST '(' a_expr AS Typename FORMAT a_expr ')'
15939+
{ $$ = makeFormattedTypeCast($3, $7, $5, @1); }
1593615940
| EXTRACT '(' extract_list ')'
1593715941
{
1593815942
$$ = (Node *) makeFuncCall(SystemFuncName("extract"),
@@ -18820,12 +18824,25 @@ makeColumnRef(char *colname, List *indirection,
1882018824
return (Node *) c;
1882118825
}
1882218826

18827+
static Node *
18828+
makeFormattedTypeCast(Node *arg, Node *format, TypeName *typename, int location)
18829+
{
18830+
TypeCast *n = makeNode(TypeCast);
18831+
18832+
n->arg = arg;
18833+
n->format = format;
18834+
n->typeName = typename;
18835+
n->location = location;
18836+
return (Node *) n;
18837+
}
18838+
1882318839
static Node *
1882418840
makeTypeCast(Node *arg, TypeName *typename, int location)
1882518841
{
1882618842
TypeCast *n = makeNode(TypeCast);
1882718843

1882818844
n->arg = arg;
18845+
n->format = NULL;
1882918846
n->typeName = typename;
1883018847
n->location = location;
1883118848
return (Node *) n;

0 commit comments

Comments
 (0)