Skip to content

Commit

Permalink
Set the aliases in postgres tile store for earlier versions of postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Jan 8, 2025
1 parent 7acde84 commit 2742f27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,17 @@ protected static Query prepareQuery(Tileset tileset, int zoom) {
var querySqlWithParams = String.format(
"""
SELECT
id AS id,
tags - 'id' AS tags,
ST_AsMVTGeom(geom, ST_TileEnvelope(?, ?, ?)) AS geom
tile.id AS id,
tile.tags - 'id' AS tags,
ST_AsMVTGeom(tile.geom, ST_TileEnvelope(?, ?, ?)) AS geom
FROM (
SELECT id, tags, geom
FROM (%s)
WHERE geom IS NOT NULL
AND geom && ST_TileEnvelope(?, ?, ?, margin => (64.0/4096)))
SELECT
data.id AS id,
data.tags AS tags,
data.geom AS geom
FROM (%s) AS data
WHERE data.geom IS NOT NULL
AND data.geom && ST_TileEnvelope(?, ?, ?, margin => (64.0/4096))) AS tile
""",
querySql);
layerSql.append(querySqlWithParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void prepareQuery() {
List.of(new TilesetQuery(0, 20, "SELECT id, tags, geom FROM table")))));
var query = PostgresTileStore.prepareQuery(tileset, 10);
assertEquals(
"SELECT (SELECT ST_AsMVT(mvtGeom.*, 'a') FROM (SELECT id AS id, tags - 'id' AS tags, ST_AsMVTGeom(geom, ST_TileEnvelope(?, ?, ?)) AS geom FROM ( SELECT id, tags, geom FROM (SELECT id, tags, geom FROM table) WHERE geom IS NOT NULL AND geom && ST_TileEnvelope(?, ?, ?, margin => (64.0/4096))) ) AS mvtGeom) || (SELECT ST_AsMVT(mvtGeom.*, 'b') FROM (SELECT id AS id, tags - 'id' AS tags, ST_AsMVTGeom(geom, ST_TileEnvelope(?, ?, ?)) AS geom FROM ( SELECT id, tags, geom FROM (SELECT id, tags, geom FROM table) WHERE geom IS NOT NULL AND geom && ST_TileEnvelope(?, ?, ?, margin => (64.0/4096))) ) AS mvtGeom) AS mvtTile",
"SELECT (SELECT ST_AsMVT(mvtGeom.*, 'a') FROM (SELECT tile.id AS id, tile.tags - 'id' AS tags, ST_AsMVTGeom(tile.geom, ST_TileEnvelope(?, ?, ?)) AS geom FROM ( SELECT data.id AS id, data.tags AS tags, data.geom AS geom FROM (SELECT id, tags, geom FROM table) AS data WHERE data.geom IS NOT NULL AND data.geom && ST_TileEnvelope(?, ?, ?, margin => (64.0/4096))) AS tile ) AS mvtGeom) || (SELECT ST_AsMVT(mvtGeom.*, 'b') FROM (SELECT tile.id AS id, tile.tags - 'id' AS tags, ST_AsMVTGeom(tile.geom, ST_TileEnvelope(?, ?, ?)) AS geom FROM ( SELECT data.id AS id, data.tags AS tags, data.geom AS geom FROM (SELECT id, tags, geom FROM table) AS data WHERE data.geom IS NOT NULL AND data.geom && ST_TileEnvelope(?, ?, ?, margin => (64.0/4096))) AS tile ) AS mvtGeom) AS mvtTile",
query.sql());
}
}

0 comments on commit 2742f27

Please sign in to comment.