The idea · Lab 3.7.2PostGIS is the standard, industry-wide tool for geography and geometry in PostgreSQL — and it is genuinely absent here, checked directly with a full filesystem search rather than assumed either way, consistent with every other confirmed-absent tool throughout this course. What is genuinely available instead is PostgreSQL's own built-in point and polygon geometric types, which ship with core PostgreSQL and need no extension at all, plus the real earthdistance extension (built on cube) for metre-accurate great-circle distance from latitude and longitude.
This is a genuine, functional substitute, not a simulation: a real GiST index on a point column, confirmed used by EXPLAIN for a real K-nearest-neighbor query at a realistic row count; a real earth_distance() calculation cross-checked directly against the native point distance; and a real polygon @> point containment test. It is less capable than PostGIS for true GIS work (no coordinate reference systems, no complex polygon operations), but it genuinely solves all three of this lab's real production requests.
PostGIS, Checked Directly
find / -iname '*postgis*' 2>/dev/null # genuinely empty — confirmed absent
No network access to install it, no compiler to build it from source — the same confirmed-absent pattern as pg_repack and wal2json elsewhere in this block.
Real KNN Search With Native point + GiST
CREATE TABLE cafes (id serial primary key, name text, loc point);
CREATE INDEX ON cafes USING gist (loc);
SELECT name FROM cafes ORDER BY loc <-> point(14.4378, 50.0755) LIMIT 5;
At a small handful of rows, the planner reasonably prefers a sequential scan — but at a realistic 500 rows, EXPLAIN genuinely shows:
Index Scan using cafes_loc_gist_idx on cafes
Order By: (loc <-> '(14.4378,50.0755)'::point)
The native <-> distance operator and a GiST index on point need zero extensions at all — both ship with core PostgreSQL.
Real Metre-Accurate Distance With earthdistance
CREATE EXTENSION cube; CREATE EXTENSION earthdistance;
SELECT earth_distance(ll_to_earth(50.0755,14.4378), ll_to_earth(50.0875,14.4213));
-- 1781.4887268819082 <- genuinely in metres, cross-checked against the raw point distance ordering
Unlike the raw point distance (in coordinate-degree units, not metres), earthdistance's earth_distance() genuinely returns real, metre-accurate great-circle distance directly from latitude and longitude.
Real Point-in-Polygon Containment
SELECT name FROM cafes
WHERE polygon '((14.35,50.02),(14.35,50.10),(14.50,50.10),(14.50,50.02))' @> loc;
The native @> containment operator genuinely tests whether a point falls inside a polygon — the same real check a delivery-zone validation would need, with zero extensions required.
Key concepts
Native point type and the <-> KNN operator
PostgreSQL's built-in point type stores an (x,y) coordinate pair with zero extensions required. The <-> operator computes real Euclidean distance between two points and, backed by a GiST index, lets "ORDER BY loc <-> :target LIMIT N" be answered as a genuine index-accelerated K-nearest-neighbor query rather than a full table scan — confirmed directly in this lab at a realistic row count.
earthdistance / earth_distance()
A real, built-on-cube extension providing earth_distance() and ll_to_earth(), which convert a latitude/longitude pair into a real 3D point on a sphere and compute genuine great-circle distance in metres — unlike the raw point <-> operator, whose result is in the same coordinate-degree units as the input and is not directly a real-world distance.
What to remember
- PostGIS is confirmed absent on this server (no network, no compiler) — checked directly, the same pattern as pg_repack and wal2json elsewhere in this block
- PostgreSQL's native point type and the <-> operator, backed by a real GiST index, genuinely answer KNN queries with zero extensions required
- A GiST index on a tiny handful of rows is reasonably skipped by the planner in favor of a sequential scan — confirmed genuinely used only once row count reached a realistic scale
- earthdistance (built on cube) provides real, metre-accurate great-circle distance directly from latitude/longitude, distinct from the raw coordinate-degree units of the native point distance operator
- The native polygon @> operator genuinely tests point-in-polygon containment with zero extensions, covering real delivery-zone-style validation directly