Spatial SQL extends standard SQL with functions and data types for storing, querying, and analyzing geographic data. It allows analysts and developers to perform geospatial operations — such as calculating distances, finding intersections, or running spatial joins — using the same SQL syntax they already know, directly inside databases and cloud data warehouses.
What is Spatial SQL?
Standard SQL operates on numbers, strings, and dates. Spatial SQL adds GEOGRAPHY and GEOMETRY data types that represent points, lines, polygons, and other shapes on the Earth’s surface. It also provides functions to manipulate these types, following the OGC Simple Features standard (ISO 19125).
Common spatial SQL functions include:
- ST_Distance — Calculate the distance between two geometries
- ST_Intersects — Check if two geometries overlap
- ST_Contains — Check if one geometry contains another
- ST_Buffer — Create a zone around a geometry at a given distance
- ST_Area — Calculate the area of a polygon
- ST_Union — Merge multiple geometries into one
How Spatial SQL Works
Spatial SQL works by storing geographic features as column values in database tables. A table of stores might have columns for name, revenue, and a GEOGRAPHY column containing each store’s location as a point. You can then write queries that combine business logic with spatial operations:
SELECT store_name, revenue
FROM stores
WHERE ST_Distance(location, ST_GeogPoint(-73.99, 40.75)) < 5000
ORDER BY revenue DESC
This query finds all stores within 5 kilometers of a point in Manhattan, sorted by revenue — a task that would require specialized GIS software without Spatial SQL.
Spatial SQL in Cloud Data Warehouses
Major cloud data warehouses now support spatial SQL natively:
- BigQuery — GEOGRAPHY type with a comprehensive set of ST_ functions
- Snowflake — GEOGRAPHY and GEOMETRY types with spatial functions
- Databricks — Spatial support through H3 and Sedona/GeoSpark
- Redshift — GEOMETRY type with spatial functions
CARTO’s Analytics Toolbox extends these data warehouses with hundreds of additional spatial functions — including spatial indexing (H3, Quadbin), spatial statistics, and advanced analytics — that run natively inside the warehouse without moving data.
Advantages Over Traditional GIS
Spatial SQL in cloud data warehouses offers several advantages over traditional desktop GIS:
- Scale — Process billions of spatial records using distributed cloud compute
- Integration — Spatial analysis lives alongside business data, BI tools, and ML pipelines
- Accessibility — Any analyst who knows SQL can perform spatial analysis without learning GIS software
- Governance — Data stays in the warehouse, maintaining security policies and access controls
- Automation — Spatial queries can be scheduled, versioned, and integrated into data pipelines
Frequently Asked Questions
Do I need to learn a new language for Spatial SQL?
No. Spatial SQL uses standard SQL syntax with additional functions (prefixed with ST_). If you know SQL, you can start writing spatial queries immediately.
What is the OGC Simple Features standard?
The OGC Simple Features standard (ISO 19125) defines a common set of spatial data types and functions that ensure interoperability across databases and GIS tools. Functions like ST_Intersects and ST_Buffer follow this standard.



