Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

GIS & Geospatial Data (QGIS, GeoPandas, PostGIS) Module 8

Spatial SQL with PostGIS interview questions

Interview questions on spatial SQL with PostGIS: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

19 questions: 5 warm-ups and 14 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What is an SRID in PostGIS, and what happens when one query compares geometries with different SRIDs?

    Answered in the lesson PostGIS setup: geometry, geography and SRIDs

  2. Fresher

    ST_Contains or ST_Covers for points in polygons: what is the difference, and when does it matter?

    Answered in the lesson Spatial relationships and joins in SQL

  3. Mid

    In a PostGIS plan, what is the difference between an Index Cond and a Filter?

    Answered in the lesson PostGIS indexes, KNN and query plans

  4. Fresher

    Why is ST_Buffer(geom, 0) a risky way to repair an invalid polygon?

    Answered in the lesson Geometry processing in PostGIS

  5. Fresher

    Why must GeoJSON for a web map be in longitude and latitude?

    Answered in the lesson Serving GeoJSON, vector tiles and OGC APIs

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A nightly job loads a partner's CSV of clinics into a geometry(Point, 32643) column. Since the partner changed its export, 40 of 9,000 clinics appear on the equator near 70.5° E, and the job logged no error. What happened, how do you find every bad row, and how do you stop it in the database?

    What it tests
    Knowing that a typed column gives a value without an SRID its own, telling degrees from metres by their range, and enforcing a rule with a constraint.
    First step
    Read the stored numbers of one bad row. Values like 75.06 and 18.13 are degrees, not metres of UTM zone 43N, where eastings near the town are about 500,000. Then ask how they got in without an error: a plain POINT(lon lat) with no SRID written takes the column's SRID, so the degrees were stored as metres.
    Follow-ups

    From the lesson PostGIS setup: geometry, geography and SRIDs

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    You must store 2 million bus stops for a country six UTM zones wide. The main queries are "stops within 500 m of me" and a nightly length of every route. Do you choose geometry or geography, in which SRID, and what changes if the team later needs buffers and unions every day?

    What it tests
    Choosing a type from the extent and the operations, knowing what each type measures and which functions it has, and keeping one stored truth with casts where needed.
    First step
    Start from the extent: six zones means no single UTM plane is accurate everywhere; in the lesson's run one zone's plane was 3,240 m too long over 952 km, 9 degrees east of its centre. Then list the operations: radius searches and lengths are among geography's 31 functions, and both are true in metres on the ellipsoid.
    Follow-ups

    From the lesson PostGIS setup: geometry, geography and SRIDs

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Fresher to mid

    A dashboard sums clinics per ward from a join with ST_Intersects and shows 9 clinics for a town that has 8. Explain the cause, write a query that counts every clinic exactly once, and say how you would make sure the totals still add up after every data load.

    What it tests
    Seeing what intersects does with points on borders, turning a business decision into SQL, and guarding it with a query that fails loudly.
    First step
    Find the clinic that is counted twice: join clinics to wards, group by clinic and keep those with more than one ward. Then look at its coordinates against the wards' borders, and ask which predicates count a point that lies exactly on a boundary.
    Follow-ups

    From the lesson Spatial relationships and joins in SQL

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Mid to senior

    A grant rule says two wards are neighbours only if they share a stretch of border, not just a corner. An analyst used ST_Touches and got more neighbour pairs than the planners expect for a grid of 12 square wards. Which query gives the right pairs, and how do you explain the difference to the analyst?

    What it tests
    Knowing what a named predicate is true for, reading the DE-9IM matrix behind it, and writing a pattern when no named predicate fits the rule.
    First step
    Ask what ST_Touches is true for: any pair whose boundaries meet while their interiors do not. Then sketch where two squares of a grid can meet, along a side or at a single corner, and look for the test that tells a shared line from a shared point.
    Follow-ups

    From the lesson Spatial relationships and joins in SQL

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Mid to senior

    A report lists each household's nearest clinic within 1.5 km with a CROSS JOIN LATERAL query. It has fewer rows than there are households, and the team published it as complete. What happened, how do you fix the query, and what should the report say?

    What it tests
    Knowing what a lateral subquery with no result does to its outer row in each kind of join, and reporting the rows without an answer instead of losing them.
    First step
    Count the households, then the report's rows, and look at one missing household: measure its distance to every clinic. Then ask what CROSS JOIN LATERAL does with an outer row when the subquery, limited to 1.5 km, returns nothing.
    Follow-ups

    From the lesson Spatial relationships and joins in SQL

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid to senior

    A "five nearest stores" query takes 300 ms on 2 million stores, although stores.geom has a GiST index. The SQL joins the customer's row to the stores and orders by distance. What do you look for in the plan, and how do you rewrite the query?

    What it tests
    Knowing when the distance operator is index-assisted, telling a Sort from an index scan in distance order, and writing nearest-first search per row with LATERAL.
    First step
    Run EXPLAIN ANALYZE and look for a Sort above a Seq Scan of stores: that means every store was measured and the two million distances sorted. Then ask what the index needs before it can return stores in distance order, and whether this query's ORDER BY gives it that.
    Follow-ups

    From the lesson PostGIS indexes, KNN and query plans

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  7. Senior to staff

    A fleet table takes 50 million GPS pings a day, appended in time order and never updated. Dashboards ask for the pings in one district during the last hour. Which indexes do you build, and why not a single GiST index on the geometry?

    What it tests
    Matching index methods to how rows are stored and queried, and combining a time filter with a spatial one at this scale.
    First step
    List the two filters of every dashboard query, time and place, and how the rows lie on disk: in time order, not in spatial order. Then ask which filter a BRIN index could use, and what one GiST index over the whole table would cost on 50 million inserts a day.
    Follow-ups

    From the lesson PostGIS indexes, KNN and query plans

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  8. Mid to senior

    A radius endpoint answered in 3 ms for months. After a full nightly reload of its table it takes 40 ms, although the index exists and EXPLAIN still shows a Bitmap Index Scan. What do you check, and what fixes it for good?

    What it tests
    Reading the pages and rows a plan reports, knowing how row order and statistics affect an indexed query, and making the fix part of the load.
    First step
    Compare the plan of the slow query with one from before the reload, line by line: the same index, the same candidates, but perhaps many more Heap Blocks, because the reload wrote the rows in a different order. Check too when the table was last analysed.
    Follow-ups

    From the lesson PostGIS indexes, KNN and query plans

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  9. Mid to senior

    A state's 30 district boundaries are simplified nightly with ST_SimplifyPreserveTopology for a dashboard. Every district is valid, yet analysts find slivers between neighbours and households counted in two districts. Explain why, and how you would produce simplified districts that still add up.

    What it tests
    Understanding coverages and shared edges, knowing what each simplification function promises, and separating display geometry from the geometry that is counted.
    First step
    Ask where each shared border is stored: once in each of the two districts. Then ask what a function that sees one district at a time can know about its neighbour's copy of the same border, and look for slivers along exactly those borders.
    Follow-ups

    From the lesson Geometry processing in PostGIS

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  10. Mid to senior

    A city wants "hot spots" of dengue cases from 40,000 geocoded cases. DBSCAN with eps 50 m gives 2,000 tiny clusters; with eps 500 m, one cluster covers half the city. How do you choose eps and minpoints, and what do you report so that the result can be trusted?

    What it tests
    Knowing what eps and minpoints mean, tying parameters to the public-health question, and reporting clustering results with their sensitivity.
    First step
    Start from the question, not the algorithm: what distance makes two cases related, for example how far the mosquito flies or a household's neighbourhood, and how many cases make a focus worth a visit. Then run DBSCAN at a few values around those and look at how the clusters and the noise change.
    Follow-ups

    From the lesson Geometry processing in PostGIS

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  11. Senior to staff

    A team generalises the national boundary layer inside PostGIS every night for web maps, and analysts now complain that areas and counts changed. Which processing belongs in the database, and how do you keep analytical and display geometry apart without two teams editing two copies?

    What it tests
    Deciding where processing belongs, designing derived geometry that is rebuilt from one source, and protecting measurements from display shortcuts.
    First step
    Check which geometry the analysts' queries read: if the nightly job overwrote the source column with simplified shapes, every area and count since then used display geometry. The first fix is to keep the source untouched and put the simplified shapes somewhere else.
    Follow-ups

    From the lesson Geometry processing in PostGIS

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  12. Mid to senior

    A city map serves 5 million address points as vector tiles straight from PostGIS. Tiles at low zoom weigh over a megabyte and the map stutters while panning. What do you measure first, and what do you change in the tile SQL?

    What it tests
    Measuring tile sizes per zoom, knowing why dense points make heavy tiles, and choosing between dropping, thinning and aggregating features by zoom.
    First step
    Measure before changing anything: for a few of the busiest tiles at each zoom, count the features and the bytes, with the same SQL the server runs. Then compare the zooms with each other, and the features per tile with what a screen can show.
    Follow-ups

    From the lesson Serving GeoJSON, vector tiles and OGC APIs

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  13. Mid to senior

    You must put a "clinics near me" endpoint backed by PostGIS on the public internet. What sits between the internet and the database, and which settings of the database and its roles do you change before launch?

    What it tests
    Designing least-privilege access to a spatial database, limiting what one request can cost, and keeping the database itself off the public network.
    First step
    Draw the path of one request: browser, web server or API, database. Then give each hop the least it needs: the public reaches only the API, the API connects with a role that can read the clinics and nothing else, and every value from the request reaches the SQL as a parameter.
    Follow-ups

    From the lesson Serving GeoJSON, vector tiles and OGC APIs

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  14. Fresher to mid

    A dashboard downloads 200,000 land parcels as one GeoJSON file of 90 MB before it draws anything. Users also want to click a parcel to see its details and to download a district's parcels. GeoJSON, vector tiles or OGC API - Features: which do you use for what?

    What it tests
    Matching formats and services to how clients use the data, and estimating the cost of each choice from sizes.
    First step
    Separate the three uses: looking at the map, clicking one parcel, downloading a district. Then ask what each needs to receive: only the parcels on screen, one parcel's attributes, or a complete set of features in a known format.
    Follow-ups

    From the lesson Serving GeoJSON, vector tiles and OGC APIs

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes

All GIS & Geospatial Data (QGIS, GeoPandas, PostGIS) interview questions · The GIS & Geospatial Data (QGIS, GeoPandas, PostGIS) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.