I need to put below 'table' into a json, where values would be as easily accessible as from table. Here's the small sample and simple example query of usage.
with prizes as (
select t.stake, tickets_no, t.prize
from (values
(400, 5, 10)
, (1000, 10, 25)
, (2000, 50, 70)
) t
(stake, tickets_no, prize)
order by 1,2
)
select max(prize) from prizes
where 1200 >= stake
and 27 >= tickets_no
I want to put it in some kind of this structure:
https://www.db-fiddle.com/f/pS5vR4CM8Y6sjsVXkw7XUY/1
create table promotions
(id integer,
details jsonb);
insert into promotions
values
(1, '{"name": "promo1", "rules":[/* it should be an array here or somehow different? */]}');