Interview Q&A / PostgreSQL

INTERVIEW Q&A · 69 QUESTIONS

PostgreSQL interview questions

Indexes, EXPLAIN, transactions and isolation, JSONB and the Postgres specifics backend interviews probe.

  1. How is a window function different from GROUP BY?

    GROUP BY collapses rows into one row per group. A window function computes over a related set of rows but keeps every original row, so you can show a row's value beside its group's total or its rank.

    BeginnerQuick answer1 min read
  2. What do LAG and LEAD do, and how would you use them to find day-over-day change?

    LAG reads a column from a previous row in the window order and LEAD from a following row. Subtracting LAG from the current value gives the change from the previous row, without a self-join.

    BeginnerQuick answer1 min read
  3. What is the difference between ROW_NUMBER, RANK and DENSE_RANK?

    All number rows in a window order. ROW_NUMBER gives unique numbers with no ties, RANK gives ties the same number and then skips ahead, and DENSE_RANK gives ties the same number without skipping.

    BeginnerQuick answer1 min read