Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd3fe6e9

Browse files
committed
Simplify productions for FORMAT JSON [ ENCODING name ]
This removes the production json_encoding_clause_opt, instead mergingit into json_format_clause. Also remove the auxiliarymakeJsonEncoding() function.Reviewed-by: Amit Langote <amitlangote09@gmail.com>Discussion:https://postgr.es/m/202312071841.u2gueb5dsrbk%40alvherre.pgsql
1 parentc7a3e6b commitd3fe6e9

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

‎src/backend/nodes/makefuncs.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -857,27 +857,6 @@ makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr,
857857
returnjve;
858858
}
859859

860-
/*
861-
* makeJsonEncoding -
862-
* converts JSON encoding name to enum JsonEncoding
863-
*/
864-
JsonEncoding
865-
makeJsonEncoding(char*name)
866-
{
867-
if (!pg_strcasecmp(name,"utf8"))
868-
returnJS_ENC_UTF8;
869-
if (!pg_strcasecmp(name,"utf16"))
870-
returnJS_ENC_UTF16;
871-
if (!pg_strcasecmp(name,"utf32"))
872-
returnJS_ENC_UTF32;
873-
874-
ereport(ERROR,
875-
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
876-
errmsg("unrecognized JSON encoding: %s",name));
877-
878-
returnJS_ENC_DEFAULT;
879-
}
880-
881860
/*
882861
* makeJsonKeyValue -
883862
* creates a JsonKeyValue node

‎src/backend/parser/gram.y

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -645,16 +645,16 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
645645
%type<list>hash_partbound
646646
%type<defelt>hash_partbound_elem
647647

648-
%type<node>json_format_clause_opt
648+
%type<node>json_format_clause
649+
json_format_clause_opt
649650
json_value_expr
650651
json_returning_clause_opt
651652
json_name_and_value
652653
json_aggregate_func
653654
%type<list>json_name_and_value_list
654655
json_value_expr_list
655656
json_array_aggregate_order_by_clause_opt
656-
%type<ival>json_encoding_clause_opt
657-
json_predicate_type_constraint
657+
%type<ival>json_predicate_type_constraint
658658
%type<boolean>json_key_uniqueness_constraint_opt
659659
json_object_constructor_null_clause_opt
660660
json_array_constructor_null_clause_opt
@@ -14962,12 +14962,11 @@ a_expr:c_expr{ $$ = $1; }
1496214962
/*
1496314963
* Required by SQL/JSON, but there are conflicts
1496414964
| a_expr
14965-
FORMAT_LA JSON json_encoding_clause_opt
14965+
json_format_clause
1496614966
IS json_predicate_type_constraint
1496714967
json_key_uniqueness_constraint_opt%prec IS
1496814968
{
14969-
$3.location = @2;
14970-
$$ = makeJsonIsPredicate($1, $3, $5, $6, @1);
14969+
$$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
1497114970
}
1497214971
*/
1497314972
|a_exprISNOT
@@ -14981,13 +14980,12 @@ a_expr:c_expr{ $$ = $1; }
1498114980
/*
1498214981
* Required by SQL/JSON, but there are conflicts
1498314982
| a_expr
14984-
FORMAT_LA JSON json_encoding_clause_opt
14983+
json_format_clause
1498514984
IS NOT
1498614985
json_predicate_type_constraint
1498714986
json_key_uniqueness_constraint_opt%prec IS
1498814987
{
14989-
$3.location = @2;
14990-
$$ = makeNotExpr(makeJsonIsPredicate($1, $3, $6, $7, @1), @1);
14988+
$$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
1499114989
}
1499214990
*/
1499314991
|DEFAULT
@@ -16503,22 +16501,41 @@ json_value_expr:
1650316501
}
1650416502
;
1650516503

16504+
json_format_clause:
16505+
FORMAT_LA JSON ENCODING name
16506+
{
16507+
intencoding;
16508+
16509+
if (!pg_strcasecmp($4,"utf8"))
16510+
encoding = JS_ENC_UTF8;
16511+
elseif (!pg_strcasecmp($4,"utf16"))
16512+
encoding = JS_ENC_UTF16;
16513+
elseif (!pg_strcasecmp($4,"utf32"))
16514+
encoding = JS_ENC_UTF32;
16515+
else
16516+
ereport(ERROR,
16517+
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
16518+
errmsg("unrecognized JSON encoding: %s", $4));
16519+
16520+
$$ = (Node *)makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
16521+
}
16522+
| FORMAT_LA JSON
16523+
{
16524+
$$ = (Node *)makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
16525+
}
16526+
;
16527+
1650616528
json_format_clause_opt:
16507-
FORMAT_LA JSON json_encoding_clause_opt
16529+
json_format_clause
1650816530
{
16509-
$$ =(Node *)makeJsonFormat(JS_FORMAT_JSON, $3, @1);
16531+
$$ =$1;
1651016532
}
1651116533
|/* EMPTY*/
1651216534
{
1651316535
$$ = (Node *)makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
1651416536
}
1651516537
;
1651616538

16517-
json_encoding_clause_opt:
16518-
ENCODING name{ $$ =makeJsonEncoding($2); }
16519-
|/* EMPTY*/{ $$ = JS_ENC_DEFAULT; }
16520-
;
16521-
1652216539
json_returning_clause_opt:
1652316540
RETURNING Typename json_format_clause_opt
1652416541
{

‎src/include/nodes/makefuncs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,5 @@ extern Node *makeJsonKeyValue(Node *key, Node *value);
116116
externNode*makeJsonIsPredicate(Node*expr,JsonFormat*format,
117117
JsonValueTypeitem_type,boolunique_keys,
118118
intlocation);
119-
externJsonEncodingmakeJsonEncoding(char*name);
120119

121120
#endif/* MAKEFUNC_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp