0
0
PostgreSQLquery~5 mins

Returning modified rows with RETURNING in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the RETURNING clause do in a PostgreSQL UPDATE statement?
It returns the rows that were modified by the UPDATE, showing their new values immediately after the change.
Click to reveal answer
beginner
How can RETURNING help when you want to see the new values of rows after an INSERT?
RETURNING lets you get the inserted rows' data right away without running a separate SELECT query.
Click to reveal answer
intermediate
Can RETURNING be used with DELETE statements in PostgreSQL? What does it return?
Yes, RETURNING can be used with DELETE to return the rows that were deleted, showing their values before removal.
Click to reveal answer
beginner
Write a simple UPDATE query that changes a user's email and returns the updated row using RETURNING.
UPDATE users SET email = 'new@example.com' WHERE id = 1 RETURNING *;
Click to reveal answer
intermediate
Why is RETURNING useful in applications that modify data?
It saves time and resources by combining data modification and retrieval in one step, avoiding extra queries.
Click to reveal answer
What does the RETURNING clause do in a PostgreSQL UPDATE statement?
APrevents the update from happening
BReturns the modified rows after the update
CDeletes the rows after updating
DCreates a backup of the table
Which SQL statements can use RETURNING in PostgreSQL?
AINSERT, UPDATE, DELETE
BSELECT only
CCREATE and DROP
DALTER only
What will this query return? UPDATE products SET price = price * 1.1 RETURNING id, price;
AOnly the old prices before update
BNothing, it only updates
CThe id and new price of all updated products
DAn error because RETURNING is invalid here
Why might RETURNING improve application performance?
AIt combines update and retrieval in one query
BIt caches data automatically
CIt compresses the database
DIt disables logging
What happens if you use RETURNING * in a DELETE statement?
AIt causes a syntax error
BIt returns nothing
CIt returns the rows after deletion
DIt returns all columns of the deleted rows
Explain how the RETURNING clause works in PostgreSQL and give an example of its use in an UPDATE statement.
Think about how to get updated rows back immediately.
You got /3 concepts.
    Describe the benefits of using RETURNING in data modification queries in PostgreSQL.
    Consider what happens without RETURNING and why it matters.
    You got /3 concepts.