Medium sql

PostgreSQL SERIAL and REFERENCES #8

Problem

PostgreSQL: PostgreSQL SERIAL and REFERENCES #8

Hints
  • Use WITH for CTEs, OVER() for windows

Your practice code

Ready — edit the code above and click Run.

Solution

CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  customer_id INT NOT NULL REFERENCES customers(id),
  amount NUMERIC(12,2) NOT NULL CHECK (amount >= 0),
  created_at TIMESTAMPTZ DEFAULT NOW()
);

Try solving on your own first, then reveal the official answer.

Explanation

PostgreSQL: CTEs, window functions, ILIKE, JSONB @>, EXPLAIN ANALYZE.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details