Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c191ba0

Browse files
l-wangCommitfest Bot
authored and
Commitfest Bot
committed
Add "**" as a new token in scanners
DOUBLE_ASTERISK is now recognized but not yet implemented. This change improves error message readability, as "**" is supported in jsonpath_scan.l as ANY_P. However, the SQL standard for simplified JSON accessors does not specify "**", so it is not supported in that context.
1 parent 220afcb commit c191ba0

File tree

9 files changed

+47
-5
lines changed

9 files changed

+47
-5
lines changed

src/backend/parser/gram.y

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
687687
*/
688688
%token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
689689
%token <ival> ICONST PARAM
690-
%token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
690+
%token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER DOUBLE_ASTERISK
691691
%token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
692692

693693
/*
@@ -16971,6 +16971,13 @@ indirection_el:
1697116971
{
1697216972
$$ = (Node *) makeNode(A_Star);
1697316973
}
16974+
| '.' DOUBLE_ASTERISK
16975+
{
16976+
ereport(ERROR,
16977+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
16978+
errmsg("arbitrary depth wild card in simple json accessor not supported"),
16979+
parser_errposition(@2)));
16980+
}
1697416981
| '[' a_expr ']'
1697516982
{
1697616983
A_Indices *ai = makeNode(A_Indices);

src/backend/parser/scan.l

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ identifier {ident_start}{ident_cont}*
338338
typecast "::"
339339
dot_dot \.\.
340340
colon_equals ":="
341+
double_asterisk "**"
341342

342343
/*
343344
* These operator-like tokens (unlike the above ones) also match the {operator}
@@ -851,6 +852,11 @@ other .
851852
return COLON_EQUALS;
852853
}
853854

855+
{double_asterisk} {
856+
SET_YYLLOC();
857+
return DOUBLE_ASTERISK;
858+
}
859+
854860
{equals_greater} {
855861
SET_YYLLOC();
856862
return EQUALS_GREATER;

src/include/parser/scanner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef union core_YYSTYPE
5050
* the ASCII characters plus these:
5151
* %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
5252
* %token <ival> ICONST PARAM
53-
* %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
53+
* %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER DOUBLE_ASTERISK
5454
* %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
5555
* The above token definitions *must* be the first ones declared in any
5656
* bison parser built atop this scanner, so that they will have consistent

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ array ({ident_cont}|{whitespace}|[\[\]\+\-\*\%\/\(\)\>\.])*
321321
typecast "::"
322322
dot_dot \.\.
323323
colon_equals ":="
324+
double_asterisk "**"
324325

325326
/*
326327
* These operator-like tokens (unlike the above ones) also match the {operator}
@@ -832,6 +833,10 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
832833
return COLON_EQUALS;
833834
}
834835

836+
{double_asterisk} {
837+
return DOUBLE_ASTERISK;
838+
}
839+
835840
{equals_greater} {
836841
return EQUALS_GREATER;
837842
}

src/interfaces/ecpg/test/expected/sql-sqljson.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,22 @@ if (sqlca.sqlcode < 0) sqlprint();}
527527

528528
printf("Found json=%s\n", json);
529529

530-
{ ECPGdisconnect(__LINE__, "CURRENT");
530+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json ( ( '{\"a\": {\"b\": 1, \"c\": 2}, \"b\": [{\"x\": 1}, {\"x\": [12, {\"y\":1}]}]}' :: jsonb ) . ** . b )", ECPGt_EOIT,
531+
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
532+
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
531533
#line 151 "sqljson.pgc"
532534

533535
if (sqlca.sqlcode < 0) sqlprint();}
534536
#line 151 "sqljson.pgc"
535537

538+
// error
539+
540+
{ ECPGdisconnect(__LINE__, "CURRENT");
541+
#line 154 "sqljson.pgc"
542+
543+
if (sqlca.sqlcode < 0) sqlprint();}
544+
#line 154 "sqljson.pgc"
545+
536546

537547
return 0;
538548
}

src/interfaces/ecpg/test/expected/sql-sqljson.stderr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,5 +359,16 @@ SQL error: schema "jsonb" does not exist on line 121
359359
[NO_PID]: sqlca: code: 0, state: 00000
360360
[NO_PID]: ecpg_get_data on line 148: RESULT: [1, [12, {"y": 1}]] offset: -1; array: no
361361
[NO_PID]: sqlca: code: 0, state: 00000
362+
[NO_PID]: ecpg_execute on line 151: query: select json ( ( '{"a": {"b": 1, "c": 2}, "b": [{"x": 1}, {"x": [12, {"y":1}]}]}' :: jsonb ) . ** . b ); with 0 parameter(s) on connection ecpg1_regression
363+
[NO_PID]: sqlca: code: 0, state: 00000
364+
[NO_PID]: ecpg_execute on line 151: using PQexec
365+
[NO_PID]: sqlca: code: 0, state: 00000
366+
[NO_PID]: ecpg_check_PQresult on line 151: bad response - ERROR: arbitrary depth wild card in simple json accessor not supported
367+
LINE 1: ...b": [{"x": 1}, {"x": [12, {"y":1}]}]}' :: jsonb ) . ** . b )
368+
^
369+
[NO_PID]: sqlca: code: 0, state: 00000
370+
[NO_PID]: raising sqlstate 0A000 (sqlcode -400): arbitrary depth wild card in simple json accessor not supported on line 151
371+
[NO_PID]: sqlca: code: -400, state: 0A000
372+
SQL error: arbitrary depth wild card in simple json accessor not supported on line 151
362373
[NO_PID]: ecpg_finish: connection ecpg1_regression closed
363374
[NO_PID]: sqlca: code: 0, state: 00000

src/interfaces/ecpg/test/sql/sqljson.pgc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ EXEC SQL END DECLARE SECTION;
148148
EXEC SQL SELECT JSON(('{"a": {"b": 1, "c": 2}, "b": [{"x": 1}, {"x": [12, {"y":1}]}]}'::jsonb).*.x) INTO :json;
149149
printf("Found json=%s\n", json);
150150

151+
EXEC SQL SELECT JSON(('{"a": {"b": 1, "c": 2}, "b": [{"x": 1}, {"x": [12, {"y":1}]}]}'::jsonb).**.b) INTO :json;
152+
// error
153+
151154
EXEC SQL DISCONNECT;
152155

153156
return 0;

src/pl/plpgsql/src/pl_gram.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static void check_raise_parameters(PLpgSQL_stmt_raise *stmt);
245245
*/
246246
%token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
247247
%token <ival> ICONST PARAM
248-
%token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
248+
%token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER DOUBLE_ASTERISK
249249
%token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
250250

251251
/*

src/test/regress/expected/jsonb.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6181,7 +6181,7 @@ SELECT (jb).a.b.c.* FROM test_jsonb_dot_notation;
61816181
(1 row)
61826182

61836183
SELECT (jb).a.**.x FROM test_jsonb_dot_notation; -- not supported
6184-
ERROR: syntax error at or near "**"
6184+
ERROR: arbitrary depth wild card in simple json accessor not supported
61856185
LINE 1: SELECT (jb).a.**.x FROM test_jsonb_dot_notation;
61866186
^
61876187
-- explains should work

0 commit comments

Comments
 (0)