Hi,
 
Another (and less optimised :)) alternative;
 
pgsql-sql=# select m,dense_rank() over (order by (m-1)/3) from generate_series(1,10) m;
m | dense_rank
----+------------
1 | 1
2 | 1
3 | 1
4 | 2
5 | 2
6 | 2
7 | 3
8 | 3
9 | 3
10 | 4
(10 rows)
 
Best regards.
Samed YILDIRIM
 
 
 
01.08.2020, 15:35, "Torsten Grust" <torsten.grust@gmail.com>:
Hi,
 
maybe this does the job already (/ is integer division):
 
SELECT i, 1 + (i-1) / 3 
FROM   generate_series(1,10) AS i;
 
An expression like (i-1) / 3 could, of course, also be used as partitioning criterion in GROUP BY and/or window functions.
 
Cheers,
  —T
 
On Sat, Aug 1, 2020 at 2:15 PM Mike Martin <redtux1@gmail.com> wrote:
Say I have a field of ints, as for example created by with ordinality or generate_series, is it possible to group by a range? eq
 
1,2,3,4,5,6,7,8,9,10
step 3
so output is
 
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
10 4
 
thanks
 
 
--
| Torsten Grust
| Torsten.Grust@gmail.com