Show json field name instead of ?column?

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Show json field name instead of ?column?
Date: 2025-09-23 08:31:43
Message-ID: CAEoWx2mtGd12bLpPXPGOWX3p8iUiRefbMdbN-q72NU7jPsSCtA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

While reviewing Json Simplified Accessor Support [1], 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]
https://www.postgresql.org/message-id/CAK98qZ1JNNAx4QneJG%2BeX7iLesOhd6A68FNQVvvHP6Up_THf3A%40mail.gmail.com

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

Attachment Content-Type Size
v1-0001-PoC-Show-JSON-field-name-as-it-is-instead-of-colu.patch application/octet-stream 2.8 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Peter Eisentraut 2025-09-23 08:01:03 Re: allow benign typedef redefinitions (C11)