Fwd: Castable Domains for different JSON representations - Mailing list pgsql-hackers

From Steve Chavez
Subject Fwd: Castable Domains for different JSON representations
Date
Msg-id CAGRrpzYcE4SCbxbV0HtqOHTrg7XPBhA8gkVkyP6kr6sFC6PzwA@mail.gmail.com
Whole thread Raw
In response to Castable Domains for different JSON representations  (Steve Chavez <steve@supabase.io>)
List pgsql-hackers
> The bigger picture here, though, is what are you really buying
compared to just invoking the special conversion function explicitly?
> If you have to write "sometsrangecolumn::mytsrange::json", that's
not shorter and certainly not clearer than writing a function call.

The main benefit is to be able to call `json_agg` on tables with these 
custom json representations. Then the defined json casts work 
transparently when doing:

select json_agg(x) from mytbl x;
                                                           json_agg
-------------------------------------------------------------------------------------------------------------------------------
 [{"id":1,"val":{"lower" : "2022-12-31T11:00:00", "upper" : "2023-01-01T06:00:00", "lower_inc" : false, "upper_inc" : false}}]

-- example table
create table mytbl(id int, val mytsrange);
insert into mytbl values (1, '(2022-12-31 11:00, 2023-01-01 06:00)');

This output is directly consumable on web applications and as 
you can see the expression is pretty short, with no need to use 
the explicit casts as `json_agg` already does them internally.

Best regards,
Steve

pgsql-hackers by date:

Previous
From: Noah Misch
Date:
Subject: Re: vac_truncate_clog()'s bogus check leads to bogusness
Next
From: Tomas Vondra
Date:
Subject: Re: Do we want a hashset type?