~/ learn/ postgresql/ cards/ Bulk inserts & data-modifying CTEs
1 of 2

Copy all cancelled orders into a new table archived(id, customer_id) with INSERT … SELECT, and RETURN the copied rows.

Copy all cancelled orders into a new table archived(id, customer_id) with INSERT … SELECT, and RETURN the copied rows.

Answer

CREATE TABLE archived (id int, customer_id int); INSERT INTO archived SELECT id, customer_id FROM orders WHERE status = 'cancelled' RETURNING *;

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/dafc1f24-fb73-42c2-8061-83b84b77a661/flashcard utf-8 LF