Improving default column names/aliases of subscript text expressions

From: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Improving default column names/aliases of subscript text expressions
Date: 2024-12-16 13:37:48
Message-ID: CAGECzQRYAFHLnjjymsSPhL-9OExVyNfMQkZMc1hcoUQ6dDHo=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I'm working on implementing subscripts for a custom type, but one
usability issue I'm running into is that the default column names for
subscript expressions are rather bad.

The easiest way to show this is with json. Running the following in psql:

CREATE TABLE tj(data jsonb);
INSERT INTO tj values ('{"a": 123, "b": "abc", "c": [123, 456]}');
SELECT data['a'], data['b'], data['c'] FROM tj;

Gives the following output:

data │ data │ data
──────┼───────┼────────────
123 │ "abc" │ [123, 456]

I'd much rather have it output:

a │ b │ c
──────┼───────┼────────────
123 │ "abc" │ [123, 456]

I'm willing to work on improving this, but can see roughly three
different ways of doing so:

1. Change the default alias/eref to be more useful for subscripts
(probably with a GUC to enable/disable this for people depending on
the old names)
2. Add a way for the implementation of a subscript to also provide a
default alias
3. Add a hook for extensions to provide default aliases for arbitrary
expressions

A combination of these is also possible of course. Attached is a
simple POC of option 1.

Attachment Content-Type Size
v1-0001-Use-last-string-literal-subscript-as-default-colu.patch text/x-patch 1.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jakub Wartak 2024-12-16 13:45:37 Re: FileFallocate misbehaving on XFS
Previous Message Thomas Munro 2024-12-16 13:29:59 Re: Windows UTF8 system locale