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;
select id,
category_id,
title,
row_number() over(partition by category_id) as rownum
from articles
order by rownum
limit 10;