Simplified
Simplified

Change one video, not all

YOU
Lab 6

Change one video, not all

Write each query here, and run it on a real Postgres database in your browser.

Change and remove exactly the rows you mean, and read what Postgres reports back.

Scenario

Simplified's team records its videos again, renames them and cuts them. You write each change its server sends, so it hits only the rows you mean.

Time
About 12 min
Steps
6
Where
Your browser

What this lab tests

  • 4.2 Changing and Removing Rows: Changing a value in a row, Taking a row out for good, What a missing WHERE does, How many rows did that change?

Simplified's videos table holds eight videos.

videosidtitlechapterseconds1Servers11402Memory and disk1953Queries and results11204The primary key21105Generated ids2956The schema2807Text in quotes31508The empty result3100

Can you change one row, and leave the other seven alone?

These queries change the table. After each run, you'll see videos as your query left it.

PostgreSQLStarting in your browser…
1

Step 1: A longer recording

The team records The empty result again, and it comes out 15 seconds longer. Its id is 8.

Add 15 to that row's seconds, and to no other row's.

TestsChanging a value in a row4.2 Changing and Removing Rows
SQLYour query
Connecting…
1
2
3
⌘ / Ctrl Enter to run
2

Step 2: Fix the assistant's UPDATE

Queries and results, whose id is 3, gets one more example, so it runs 20 seconds longer.

An assistant wrote this UPDATE for it.

Predict its command tag, run it, then fix it.

TestsWhat a missing WHERE does4.2 Changing and Removing RowsHow many rows did that change?4.2 Changing and Removing Rows
Pass step 1 to open this one.
3

Step 3: Check before you delete

The team cuts Generated ids, whose id is 5.

Before the DELETE, check its WHERE with a SELECT.

Send back every column of the rows that DELETE will remove.

TestsWhat a missing WHERE does4.2 Changing and Removing Rows
Pass step 2 to open this one.
4

Step 4: Cut Generated ids

Your SELECT sent back one row: Generated ids.

Now remove that row, with the same WHERE.

TestsTaking a row out for good4.2 Changing and Removing Rows
Pass step 3 to open this one.
5

Step 5: A new title, and a new chapter

The team renames The primary key, whose id is 4, to Primary keys.

It also moves that row to chapter 1.

Change both cells with one UPDATE.

TestsChanging a value in a row4.2 Changing and Removing Rows
Pass step 4 to open this one.
6

Step 6: The old title

Say Simplified's server still finds that row by its old title, The primary key.

It adds 10 seconds to the row with that title.

Predict the command tag, then write that UPDATE and run it.

TestsHow many rows did that change?4.2 Changing and Removing Rows
Pass step 5 to open this one.

Not yet, and every row changed

The query has no WHERE, so every row passed.

End it with a WHERE that only one row passes, like WHERE id = 8.

syntax error at or near "WHERE"

Look just before WHERE.

A comma after the last value in SET is one too many.

column "Primary keys" does not exist

Text goes in single quotes, never double quotes: 'Primary keys'.

Finish the lab

Each step passes once its query sends back the right rows, or makes the right change. Then mark the lab complete to unlock the next lesson.

0 of 6 steps done
Assistant

Highlight lesson text and click Ask AI, or type a question below.