Extensions (PostGIS etc.)Advanced
1Question 1 of 1
sqlWhat are PostgreSQL Extensions and how do you install and use PostGIS?
Explanation & Concept
Extensions package extra SQL functions, data types, and index operators that seamlessly integrate into the PostgreSQL engine core.
PostGIS is the industry-standard spatial extension, providing GIS geometry types (Points, Polygons), spatial indexes (R-Tree / GiST), and geographic calculation functions (distance, intersection, containment).
Code Example
sql
-- Enable the spatial extension
CREATE EXTENSION IF NOT EXISTS postgis;
-- Create table with geographic coordinates
CREATE TABLE stores (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
location GEOGRAPHY(Point, 4326)
);
-- Find stores within 5 kilometers of coordinates
SELECT name
FROM stores
WHERE ST_DWithin(location, ST_MakePoint(-73.985, 40.748)::geography, 5000);How It Works & Key Takeaways
`ST_DWithin` calculates real-world geodesic distances in meters on the Earth's spheroid using spatial indexes, without requiring flat-plane cartesian approximations.
Mock Test · 1 Questions · Optional
Ready for Connection Pooling?
Take a quick test to evaluate yourself, or move straight to the next module.
Advanced1 questions