Postgres in depth · Chapter 4 of 65

Publishing the first courses

By the end of this chapter you can add rows to a table, many at once, name the columns you fill, leave the rest to their defaults, write text that contains a quote, and get back the rows you just added. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Day one: an empty server
  • 4 tasks
  • PostgreSQL
  • In the all labs plan

The first 2 chapters of Postgres in depth are free. This one comes with the all labs plan.

Why you need this

The courses and students tables exist, and they are empty. Kabir has the first courses ready: titles, teachers, prices, launch days. Some are finished, some are drafts with no launch day yet, and one has no price yet. The first students are signing up, and one of them is Riya D'Souza, whose name has an apostrophe in it.

CREATE TABLE made the shape; nothing you know so far puts a row in it. And when the website saves a row, it wants to see what was saved, without a second query.

What you build: 4 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    first-course.sql: the first course

    Add LCO's first course to the empty courses table: id 1, title HTML and CSS from Zero, instructor Kabir Mehta, level beginner, price 0, published (true), launched on 2026-01-04.

    Afterwards courses has exactly this one row, with every column as given.

  2. Task 2

    catalogue.sql: four courses in one statement

    Add four published beginner and intermediate courses in one INSERT statement:

    id 2, Complete JavaScript, Kabir Mehta, beginner, price 1999, published, launched 2026-01-06;

    id 3, React from Zero, Neha Kapoor, intermediate, price 2499, published, launched 2026-01-14;

    id 4, Node.js APIs, Rahul Iyer, intermediate, price 2499, published, launched 2026-01-24;

    id 5, SQL Fundamentals, Rahul Iyer, beginner, price 999, published, launched 2026-01-15.

    Afterwards courses has exactly these four rows (the table starts empty), and the file has one INSERT.

  3. Task 3

    drafts.sql: two drafts with gaps

    Add two draft courses (not published) in one INSERT:

    id 11, 100% Practical TypeScript, Neha Kapoor, intermediate, price 1999;

    id 14, DevOps with AWS, Siddharth Jain, advanced, and no price yet.

    Neither has a launch day. Leave every unknown value empty: the column gets its default, which is NULL in this table.

    Afterwards courses has exactly these two rows, with launched_on empty for both and price empty for DevOps with AWS.

    Careful: an empty value is not 0 and not an empty string. A price of 0 would make the course free.

  4. Task 4 · interview question

    Interview: new-students.sql, an apostrophe and RETURNING

    Sign up three students in one INSERT and return what was stored:

    id 6, Riya D'Souza, riya.dsouza@example.com, phone +91 9850066554, city Kochi, signed up 2026-01-15;

    id 7, Kabir Das, kabir.das@example.com, no phone (leave it empty), city Kolkata, signed up 2026-01-20;

    id 8, Meera Reddy, meera.reddy@example.com, phone +91 9860033221, city Hyderabad, signed up 2026-02-02.

    The statement returns two columns, id and name, one row per new student. Any order.

    Afterwards students has exactly these three rows.

    Careful: Riya's name contains a single quote, the same character that ends a text value.

What you will learn

  • INSERT ... VALUES: one row, then many rows in one statement.
  • Column lists: naming the columns you fill, in your order.
  • DEFAULT: what a column gets when you leave it out.
  • Quoting text: a single quote inside a text value.
  • RETURNING: the inserted rows, sent straight back.

More in Day one: an empty server

Build "Publishing the first courses" yourself

LCO, an edtech company, moves its platform onto a single Postgres server you run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Postgres in depth are free. This one comes with the all labs plan.