Skip to content
Learn Netverks

Lesson

Step 34/36 94% through track

postgis-teaser

PostGIS teaser

Last reviewed Jun 1, 2026 Content v20260601
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches PostGIS teaser: the SQL patterns, schema habits, and query reasoning you need before advancing in PostgreSQL.

Teams query PostGIS teaser on every PostgreSQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply PostGIS teaser in contexts like: Geospatial apps, full-text search, and vector similarity via Postgres extensions.

Copy Postgres SQL into psql, local PostgreSQL, or DB Fiddle (PostgreSQL dialect)—use \d and EXPLAIN ANALYZE where lessons show them. The in-browser lab ships later; psql is the practice path now.

Toward the end—consolidate before PostGIS teaser, interview prep, and production checklist.

PostGIS extends PostgreSQL with geographic types and spatial functions—maps, distance queries, and geofencing for logistics and location apps.

Enable PostGIS

CREATE EXTENSION IF NOT EXISTS postgis;

CREATE TABLE stores (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  location GEOGRAPHY(POINT, 4326) NOT NULL
);

INSERT INTO stores (name, location)
VALUES ('Downtown', ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 4326)::geography);

Practice: Review prior lessons in psql, then attempt interview-style queries without peeking.

Distance query

SELECT name,
       ST_Distance(location, ST_MakePoint(-122.4, 37.77)::geography) AS meters
FROM stores
ORDER BY meters
LIMIT 5;

When to adopt

If queries are mostly points and distances, PostGIS beats storing lat/lng in plain floats. Heavy map tile serving may still pair with specialized services—but keep authoritative geometry in Postgres.

Important interview questions and answers

  1. Q: GEOGRAPHY vs GEOMETRY?
    A: GEOGRAPHY uses earth spheroid for distance; GEOMETRY is planar—pick for your accuracy needs.
  2. Q: SRID 4326?
    A: WGS 84 latitude/longitude—common GPS coordinate system.

Self-check

  1. Which extension adds geographic types?
  2. What function creates a point from lon/lat?

Tip: Use GEOGRAPHY for meter distances on Earth; verify SRID matches your data source.

Interview prep

PostGIS?

Extension adding geographic types and spatial queries.

SRID 4326?

WGS 84 lat/lon coordinate system.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • SRID meaning?
  • ST_DWithin use?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump