0Pricing
SQL Academy · Lesson

Spatial Data Types

Points, lines and polygons in SQL.

What Is Spatial Data?

Spatial data describes real-world locations, shapes, and areas. Unlike a plain number or string, a spatial value carries geometric meaning — a point on a map, a road segment, or the boundary of a country.

PostGIS is a PostgreSQL extension that adds powerful spatial data types and functions, turning your database into a full geographic information system (GIS).

-- Enable the PostGIS extension
CREATE EXTENSION IF NOT EXISTS postgis;

The GEOMETRY Type

The core spatial type in PostGIS is geometry. It stores shapes in a flat (Euclidean) coordinate space. You can specify a subtype such as POINT, LINESTRING, or POLYGON as a constraint when creating a column.

Specifying the SRID (Spatial Reference ID) alongside the subtype tells PostGIS which coordinate system your data uses.

CREATE TABLE locations (
  id      SERIAL PRIMARY KEY,
  name    TEXT,
  geom    geometry(POINT, 4326)
);

All lessons in this course

  1. Spatial Data Types
  2. Distance and Nearest Neighbors
  3. Spatial Joins and Containment
  4. Spatial Indexes (GiST)
← Back to SQL Academy