Re: proposal: jsonb_populate_array - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: jsonb_populate_array
Date
Msg-id CAFj8pRCC6wCYfTO4bCm7n8Q9iaax+Eeg9wvW5x4bg0MyGyhCzw@mail.gmail.com
Whole thread Raw
In response to Re: proposal: jsonb_populate_array  (Chapman Flack <chap@anastigmatix.net>)
Responses Re: proposal: jsonb_populate_array
List pgsql-hackers


po 14. 8. 2023 v 15:47 odesílatel Chapman Flack <chap@anastigmatix.net> napsal:
On 2023-08-14 09:11, Erik Rijkers wrote:
>   , '$' returning date[]

I certainly like that syntax better.

It's not that the "here's a null to tell you the type I want"
is terribly unclear, but it seems not to be an idiom I have
seen a lot of in PostgreSQL before now. Are there other places
it's currently used that I've overlooked?

It is used only for hstore, json, jsonb function if I remember correctly.

I dislike this idiom too, but SQL cannot use type as parameter. I proposed anytype polymorphic pseudotype so instead

fx(null::int, ...) you can write (theoretically) fx('int', ...), but it doesn't look too much better. For composite functions we can dynamically to specify structure as SELECT FROM fx(...) AS (a int, b int), but it cannot be used for scalar functions and cannot be used for static composite types.

I can imagine some special syntax of CAST, that can push type to inside function, and allows to us to write functions like fx(non polymorphic types) RETURNS any

for proposed functionality it can look like SELECT CAST(json_populate_array('[]'::jsonb) AS date[])




Regards,
-Chap

pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: walsender "wakeup storm" on PG16, likely because of bc971f4025c (Optimize walsender wake up logic using condition variables)
Next
From: Yugo NAGATA
Date:
Subject: Re: pgbench: allow to exit immediately when any client is aborted