A repeatable practice loop—connect, set context, explore safely with LIMIT, preview destructive changes—keeps you productive in psql and GUI clients.
psql essentials
-- Connect: psql -h localhost -U myuser -d practice
\conninfo
\dt public.*
\d customers
\timing on
SELECT id, email FROM customers LIMIT 20;Practice: Copy SQL into psql, a local PostgreSQL server, or DB Fiddle (PostgreSQL dialect). Compare output with the lesson.
Safe exploration habits
- Use
LIMITon wide tables during exploration - Run
SELECTwith the sameWHEREbeforeUPDATE/DELETE - Wrap risky changes in
BEGIN;…ROLLBACK;until confident - Keep sample DDL in a git-tracked
schema.sqlfor reproducible sandboxes
Create a practice database
CREATE DATABASE practice;
\c practice
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE
);Reuse this database through the basics and schema modules.
Important interview questions and answers
- Q: Why \d table?
A: Describes columns, types, defaults, and indexes—faster than guessing from SELECT *. - Q: LIMIT during exploration?
A: Prevents accidental multi-million-row result sets in terminals and GUIs.
Self-check
- Which psql meta-command lists tables?
- What should you run before UPDATE in production?
Challenge
Practice psql exploration
- Create database
practiceif missing. - Run
\dtand\d customersafter seeding a sample table. - Enable
\timing onand run a LIMIT query.
Done when: you see table metadata and query timing in psql.
Interview prep
- Why LIMIT in exploration?
Prevents huge result sets in terminals and GUIs.
- Preview before UPDATE?
Run SELECT with the same WHERE to verify row count.