create index my_table_index_index on my_schema.my_table using gin (cast(string_to_array(index, ', ') as int[]));
select *
from my_schema.my_table
where string_to_array(index, ', ')::int[] @> ARRAY [1, 2, 3]::int[];
select *
from my_schema.my_table
where cast(string_to_array(index, ', ') as int[]) @> cast(string_to_array(:param, ', ') as int[]);
Такие конструкторы обычно адаптированы под людей, которые не знают и знать не хотят свою базу.
SELECT a.stamper,
a.city,
AVG(a.speed) AS AVG_SPEED,
MAX(a.speed) AS MAX_SPEED,
(select b.station
from data as b
where b.city=a.city and
b.speed=max(a.speed)
limit 1) as max_speed_station
FROM data a
GROUP BY a.stamper,
a.city;
select a.*,
b.station as max_speed_station
from (SELECT stamper,
city,
AVG(speed) AS AVG_SPEED,
MAX(speed) AS MAX_SPEED
FROM data
GROUP BY stamper,
city) as a
left join data as b
on a.city=b.city and
a.MAX_SPEED=b.speed;
with
all_ranges as (
SELECT tsrange(generate_series,
generate_series + interval '30' minute,
'()') as range
FROM generate_series(current_date::timestamp + interval '9' hour,
current_date::timestamp + interval '18' hour,
'30 minutes'))
select rooms.id as room_id,
concat(to_char(lower(ar.range), 'HH24:MI'),
' - ',
to_char(upper(ar.range), 'HH24:MI')) as timerange
from all_ranges as ar
cross join rooms
where not exists (select 1
from reservations as rt
where rooms.id=rt.room_id and
ar.range && rt.occurrence)
order by 1;