Insert or update: ON CONFLICT and RETURNING · exercise 1 of 1 · free preview
INSERT ... ON CONFLICT (key) DO UPDATE SET column = EXCLUDED.column inserts a new row, or updates the existing row with the same key. EXCLUDED holds the values you tried to insert. (PostgreSQL syntax; other databases use MERGE or INSERT ... ON DUPLICATE KEY.)
Product 3 (Croissant) now costs 2.40, and a new drink exists: product 10, Tea, category drinks, price 1.90. Do both in one INSERT with ON CONFLICT (product_id) DO UPDATE that sets the unit_price.
Tables in this practice shop
customersproductsordersorder_items