I got some strange behavior of combined generate_series. In 2 different polygons that I tried to fill with a grid, one grid was much rarer:
The query was like this:
SELECT
osm_id ,
generate_series(floor(st_xmin(way))::int, ceiling(st_xmax(way))::int, 150) x,
generate_series(floor(st_ymin(way))::int, ceiling(st_ymax(way))::int, 150) y
from osm_polygon
order by osm_id, x, y;
I tried tracing the problem, and just entered min/max coordinates. Generate series from min/max values create correct number of values: 9 and 12 rows respectively.
=> select generate_series(9237195, 9238873, 150) x;
x
---------
9237195
9237345
9237495
9237645
9237795
9237945
9238095
9238245
9238395
9238545
9238695
9238845
(12 rows)
=> select generate_series(7371701, 7372922, 150) y order by y;
y
---------
7371701
7371851
7372001
7372151
7372301
7372451
7372601
7372751
7372901
(9 rows)
Combined, they should make 108 rows, right? No, only 36 rows:
=> select generate_series(9237195, 9238873, 150) x, generate_series(7371701, 7372922, 150) y order by x, y;
x | y
---------+---------
9237195 | 7371701
9237195 | 7372151
9237195 | 7372601
9237345 | 7371851
9237345 | 7372301
9237345 | 7372751
9237495 | 7372001
9237495 | 7372451
9237495 | 7372901
9237645 | 7371701
9237645 | 7372151
9237645 | 7372601
9237795 | 7371851
9237795 | 7372301
9237795 | 7372751
9237945 | 7372001
9237945 | 7372451
9237945 | 7372901
9238095 | 7371701
9238095 | 7372151
9238095 | 7372601
9238245 | 7371851
9238245 | 7372301
9238245 | 7372751
9238395 | 7372001
9238395 | 7372451
9238395 | 7372901
9238545 | 7371701
9238545 | 7372151
9238545 | 7372601
9238695 | 7371851
9238695 | 7372301
9238695 | 7372751
9238845 | 7372001
9238845 | 7372451
9238845 | 7372901
(36 rows)
Brute force actually does work here:
with a as (select generate_series(9237195, 9238873, 150) x),
b as (select generate_series(7371701, 7372922, 150) y)
select x, y from a, b;
Makes 108 rows. Fine, except queries get more complex.
Why so?
Postgres version is 9.1