0
0
PostgreSQLquery~10 mins

RETURNING clause mental model in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return the inserted row's id.

PostgreSQL
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com') [1] id;
Drag options to blanks, or click blank then click option'
AOUTPUT
BSELECT
CWHERE
DRETURNING
Attempts:
3 left
💡 Hint
Common Mistakes
Using SELECT instead of RETURNING causes syntax errors.
Using WHERE after VALUES is invalid here.
2fill in blank
medium

Complete the code to return all columns after updating a user's email.

PostgreSQL
UPDATE users SET email = 'new@example.com' WHERE id = 5 [1] *;
Drag options to blanks, or click blank then click option'
ARETURNING
BSELECT
COUTPUT
DFETCH
Attempts:
3 left
💡 Hint
Common Mistakes
Using OUTPUT instead of RETURNING is invalid in PostgreSQL.
Using SELECT after UPDATE causes syntax errors.
3fill in blank
hard

Fix the error in the DELETE statement to return the deleted user's name.

PostgreSQL
DELETE FROM users WHERE id = 10 [1] name;
Drag options to blanks, or click blank then click option'
ARETURNING
BSELECT
COUTPUT
DFETCH
Attempts:
3 left
💡 Hint
Common Mistakes
Using SELECT after DELETE causes syntax errors.
Using OUTPUT is not supported in PostgreSQL.
4fill in blank
hard

Fill both blanks to return the id and email of the newly inserted user.

PostgreSQL
INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com') [1] [2];
Drag options to blanks, or click blank then click option'
ARETURNING
Bid, email
C*
DWHERE
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE instead of column names causes errors.
Using * returns all columns, not just id and email.
5fill in blank
hard

Fill all three blanks to update a user's name and return the id, name, and email.

PostgreSQL
UPDATE users SET name = 'Charlie' WHERE id = 7 [1] [2] [3];
Drag options to blanks, or click blank then click option'
ARETURNING
Bid,
Cname, email
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using * returns all columns, not just the specified ones.
Missing commas between column names causes syntax errors.