Show json field name instead of ?column?

Started by Chao Liabout 1 year ago1 messageshackers

Thread notes

1 note#feature#minor#enhancement
hackorum-bot#feature#minor#enhancement
hackorum-bot
1 day ago

@global #feature #minor #enhancement

#feature#minor#enhancement
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

Hi Hackers,

While reviewing Json Simplified Accessor Support [1]/messages/by-id/CAK98qZ1JNNAx4QneJG+eX7iLesOhd6A68FNQVvvHP6Up_THf3A@mail.gmail.com, I noticed that with
the new accessor, it will show the actual json field name, for example:
```
evantest=# select (j).b.c from ttt;
c
----

20
(2 rows)
```

"c" is the last segment of the accessor, so the column name shows as "c".

While now "->" and "->" operators will show "?column?" as column names when
accessing Json fields. It had been my concern for many years when I was a
PG user. Now as I started to work on PG itself, I want to change that.

With this PoC patch, it will also use the last segment of an accessor path
as field name:
```
evantest=# select j->'b'->'c' from ttt;
c
----

20
(2 rows)

evantest=# select j#>array['b','c'] from ttt;
c
----

20
(2 rows)
```

But this patch has not handled case of:
```
evantest=# select j#>'{b,c}' from ttt;
?column?
----------

20
(2 rows)
```

Because I don't find an existing function to parse '{b,c}' to an array as
it is the parse phase, array_int() is not usable.

This patch is not ready for review, code is not polished, tests are not
updated. I just want to throw out the idea first to see any interest and
objection.

[1]: /messages/by-id/CAK98qZ1JNNAx4QneJG+eX7iLesOhd6A68FNQVvvHP6Up_THf3A@mail.gmail.com
/messages/by-id/CAK98qZ1JNNAx4QneJG+eX7iLesOhd6A68FNQVvvHP6Up_THf3A@mail.gmail.com

Best regards,
Chao Li (Evan)
---------------------
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

t52333_1
v1-0001-PoC-Show-JSON-field-name-as-it-is-instead-of-colu.patchapplication/octet-stream; name=v1-0001-PoC-Show-JSON-field-name-as-it-is-instead-of-colu.patchDownload+57-2