Complete the code to insert a new user into the users table using a writable CTE.
WITH new_user AS (INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com') RETURNING [1]) SELECT * FROM new_user;
The RETURNING * clause returns all columns of the inserted row, which is useful to see the full inserted record.
Complete the code to update the email of a user with id 5 using a writable CTE.
WITH updated_user AS (UPDATE users SET email = 'newemail@example.com' WHERE id = 5 RETURNING [1]) SELECT * FROM updated_user;
Using RETURNING * returns all columns of the updated row, showing the full updated record.
Fix the error in the DELETE statement to return the deleted rows using a writable CTE.
WITH deleted_users AS (DELETE FROM users WHERE last_login < '2023-01-01' RETURNING [1]) SELECT * FROM deleted_users;
Using RETURNING * returns all columns of the deleted rows, which is useful to see what was removed.
Fill both blanks to insert multiple products and return their ids and names.
WITH inserted_products AS (INSERT INTO products (name, price) VALUES ('Pen', 1.5), ('Notebook', 3.0) RETURNING [1], [2]) SELECT * FROM inserted_products;
Returning id and name shows the unique identifier and the product name of inserted rows.
Fill all three blanks to update user status, return id, status, and email of updated users.
WITH updated_status AS (UPDATE users SET status = 'active' WHERE last_login > '2024-01-01' RETURNING [1], [2], [3]) SELECT * FROM updated_status;
Returning id, status, and email shows key details of the updated users.