Skip to content

Commit 6275cd0

Browse files
committed
Show ‘?column?’ as column name for JSONB dot notation with trailing .*
1 parent a90375b commit 6275cd0

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/backend/parser/parse_target.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,13 +1805,18 @@ FigureColnameInternal(Node *node, char **name)
18051805
char *fname = NULL;
18061806
ListCell *l;
18071807

1808-
/* find last field name, if any, ignoring "*" and subscripts */
1808+
/*
1809+
* find last field name, if any, ignoring subscripts, and use
1810+
* '?column?' when there's a trailing '*'.
1811+
*/
18091812
foreach(l, ind->indirection)
18101813
{
18111814
Node *i = lfirst(l);
18121815

18131816
if (IsA(i, String))
18141817
fname = strVal(i);
1818+
else if (IsA(i, A_Star))
1819+
fname = "?column?";
18151820
}
18161821
if (fname)
18171822
{

src/test/regress/expected/jsonb.out

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,31 +5982,31 @@ SELECT (jb).a.b.c FROM test_jsonb_dot_notation;
59825982

59835983
/* wild card member access */
59845984
SELECT (jb).a.* FROM test_jsonb_dot_notation;
5985-
a
5985+
?column?
59865986
-------------------------------------------
59875987
["c", "d", "f", {"y": "yyy", "z": "zzz"}]
59885988
(1 row)
59895989

59905990
SELECT (jb).* FROM test_jsonb_dot_notation;
5991-
jb
5991+
?column?
59925992
------------------------------------------------------------------------------------------------------------------------------
59935993
[[1, 2, {"b": "c"}, {"b": "d", "e": "f", "x": {"y": "yyy", "z": "zzz"}}], [3, 4, {"b": "g", "x": {"y": "YYY", "z": "ZZZ"}}]]
59945994
(1 row)
59955995

59965996
SELECT (jb).* FROM test_jsonb_dot_notation t;
5997-
jb
5997+
?column?
59985998
------------------------------------------------------------------------------------------------------------------------------
59995999
[[1, 2, {"b": "c"}, {"b": "d", "e": "f", "x": {"y": "yyy", "z": "zzz"}}], [3, 4, {"b": "g", "x": {"y": "YYY", "z": "ZZZ"}}]]
60006000
(1 row)
60016001

60026002
SELECT (t.jb).* FROM test_jsonb_dot_notation t;
6003-
jb
6003+
?column?
60046004
------------------------------------------------------------------------------------------------------------------------------
60056005
[[1, 2, {"b": "c"}, {"b": "d", "e": "f", "x": {"y": "yyy", "z": "zzz"}}], [3, 4, {"b": "g", "x": {"y": "YYY", "z": "ZZZ"}}]]
60066006
(1 row)
60076007

60086008
SELECT (jb).* FROM test_jsonb_dot_notation;
6009-
jb
6009+
?column?
60106010
------------------------------------------------------------------------------------------------------------------------------
60116011
[[1, 2, {"b": "c"}, {"b": "d", "e": "f", "x": {"y": "yyy", "z": "zzz"}}], [3, 4, {"b": "g", "x": {"y": "YYY", "z": "ZZZ"}}]]
60126012
(1 row)
@@ -6016,13 +6016,13 @@ ERROR: missing FROM-clause entry for table "t"
60166016
LINE 1: SELECT (t.jb).* FROM test_jsonb_dot_notation;
60176017
^
60186018
SELECT (t.jb).* FROM test_jsonb_dot_notation t;
6019-
jb
6019+
?column?
60206020
------------------------------------------------------------------------------------------------------------------------------
60216021
[[1, 2, {"b": "c"}, {"b": "d", "e": "f", "x": {"y": "yyy", "z": "zzz"}}], [3, 4, {"b": "g", "x": {"y": "YYY", "z": "ZZZ"}}]]
60226022
(1 row)
60236023

60246024
SELECT (jb).a.* FROM test_jsonb_dot_notation;
6025-
a
6025+
?column?
60266026
-------------------------------------------
60276027
["c", "d", "f", {"y": "yyy", "z": "zzz"}]
60286028
(1 row)
@@ -6046,7 +6046,7 @@ SELECT (jb).a.*.y FROM test_jsonb_dot_notation;
60466046
(1 row)
60476047

60486048
SELECT (jb).a.*.* FROM test_jsonb_dot_notation;
6049-
a
6049+
?column?
60506050
----------------
60516051
["yyy", "zzz"]
60526052
(1 row)
@@ -6088,7 +6088,7 @@ SELECT (jb).*.x FROM test_jsonb_dot_notation;
60886088
(1 row)
60896089

60906090
SELECT (jb).*.x.* FROM test_jsonb_dot_notation;
6091-
x
6091+
?column?
60926092
------------------------------
60936093
["yyy", "zzz", "YYY", "ZZZ"]
60946094
(1 row)
@@ -6112,20 +6112,20 @@ SELECT (jb).*.*.y FROM test_jsonb_dot_notation;
61126112
(1 row)
61136113

61146114
SELECT (jb).*.*.* FROM test_jsonb_dot_notation;
6115-
jb
6115+
?column?
61166116
------------------------------
61176117
["yyy", "zzz", "YYY", "ZZZ"]
61186118
(1 row)
61196119

61206120
SELECT (jb).*.*.*.* FROM test_jsonb_dot_notation;
6121-
jb
6122-
----
6121+
?column?
6122+
----------
61236123

61246124
(1 row)
61256125

61266126
SELECT (jb).a.b.c.* FROM test_jsonb_dot_notation;
6127-
c
6128-
---
6127+
?column?
6128+
----------
61296129

61306130
(1 row)
61316131

@@ -6141,7 +6141,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT (jb).* FROM test_jsonb_dot_notation;
61416141
(2 rows)
61426142

61436143
SELECT (jb).* FROM test_jsonb_dot_notation;
6144-
jb
6144+
?column?
61456145
------------------------------------------------------------------------------------------------------------------------------
61466146
[[1, 2, {"b": "c"}, {"b": "d", "e": "f", "x": {"y": "yyy", "z": "zzz"}}], [3, 4, {"b": "g", "x": {"y": "YYY", "z": "ZZZ"}}]]
61476147
(1 row)
@@ -6180,7 +6180,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT (jb).a.* FROM test_jsonb_dot_notation;
61806180
(2 rows)
61816181

61826182
SELECT (jb).a.* FROM test_jsonb_dot_notation;
6183-
a
6183+
?column?
61846184
-------------------------------------------
61856185
["c", "d", "f", {"y": "yyy", "z": "zzz"}]
61866186
(1 row)

0 commit comments

Comments
 (0)