Fwd: Castable Domains for different JSON representations

Поиск
Список
Период
Сортировка
От Steve Chavez
Тема Fwd: Castable Domains for different JSON representations
Дата
Msg-id CAGRrpzYcE4SCbxbV0HtqOHTrg7XPBhA8gkVkyP6kr6sFC6PzwA@mail.gmail.com
обсуждение исходный текст
Ответ на Castable Domains for different JSON representations  (Steve Chavez <steve@supabase.io>)
Список 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 по дате отправления:

Предыдущее
От: Noah Misch
Дата:
Сообщение: Re: vac_truncate_clog()'s bogus check leads to bogusness
Следующее
От: Tomas Vondra
Дата:
Сообщение: Re: Do we want a hashset type?