0
0
PostgreSQLquery~10 mins

INSERT with RETURNING clause 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 insert a new user and return the inserted 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
CRETURNING
DFETCH
Attempts:
3 left
💡 Hint
Common Mistakes
Using SELECT instead of RETURNING after INSERT.
Forgetting to specify the column after RETURNING.
2fill in blank
medium

Complete the code to insert a product and return both id and name.

PostgreSQL
INSERT INTO products (name, price) VALUES ('Book', 9.99) [1] id, name;
Drag options to blanks, or click blank then click option'
ARETURNING
BFETCH
CSELECT
DOUTPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using OUTPUT which is not valid in PostgreSQL.
Trying to use SELECT after INSERT.
3fill in blank
hard

Fix the error in the code to return the inserted row's email.

PostgreSQL
INSERT INTO customers (name, email) VALUES ('Bob', 'bob@example.com') [1] email;
Drag options to blanks, or click blank then click option'
AFETCH
BRETURNING
COUTPUT
DSELECT
Attempts:
3 left
💡 Hint
Common Mistakes
Using SELECT instead of RETURNING.
Using OUTPUT which is for other SQL dialects.
4fill in blank
hard

Fill both blanks to insert a new order and return order_id and total.

PostgreSQL
INSERT INTO orders (customer_id, total) VALUES (123, 45.67) [1] [2];
Drag options to blanks, or click blank then click option'
ARETURNING
BSELECT
Corder_id, total
DOUTPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using OUTPUT which is not valid in PostgreSQL.
Putting SELECT instead of RETURNING.
5fill in blank
hard

Fill all three blanks to insert a new employee and return id and name.

PostgreSQL
INSERT INTO employees (name, department, salary) VALUES ('Eve', 'HR', 60000) [1] [2] [3];
Drag options to blanks, or click blank then click option'
ARETURNING
Bname
Cdepartment
Did,
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting commas between column names.
Using OUTPUT instead of RETURNING.