Skip to content

Commit ec6061e

Browse files
chuckcarpenterRobbieTheWagner
authored andcommitted
Fix multi-row INSERT RETURNING to capture all UUIDs
PostgreSQL only populates INTO from the first returned row in a multi-row INSERT. Split into three separate INSERT statements so each color UUID variable is properly populated.
1 parent b3ec416 commit ec6061e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

supabase-schema.sql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,18 @@ BEGIN
155155
)
156156
RETURNING id INTO palette_uuid;
157157

158-
-- Create sample colors
158+
-- Create sample colors (separate inserts to capture each UUID)
159159
INSERT INTO colors (user_id, palette_id, name, r, g, b, a)
160-
VALUES
161-
(user_uuid, palette_uuid, 'Pure Black', 0, 0, 0, 1.0),
162-
(user_uuid, palette_uuid, 'Pure White', 255, 255, 255, 1.0),
163-
(user_uuid, palette_uuid, 'Pure Red', 255, 0, 0, 1.0)
164-
RETURNING id INTO color_uuid1, color_uuid2, color_uuid3;
160+
VALUES (user_uuid, palette_uuid, 'Pure Black', 0, 0, 0, 1.0)
161+
RETURNING id INTO color_uuid1;
162+
163+
INSERT INTO colors (user_id, palette_id, name, r, g, b, a)
164+
VALUES (user_uuid, palette_uuid, 'Pure White', 255, 255, 255, 1.0)
165+
RETURNING id INTO color_uuid2;
166+
167+
INSERT INTO colors (user_id, palette_id, name, r, g, b, a)
168+
VALUES (user_uuid, palette_uuid, 'Pure Red', 255, 0, 0, 1.0)
169+
RETURNING id INTO color_uuid3;
165170

166171
-- Update color_order with the color references
167172
UPDATE palettes

0 commit comments

Comments
 (0)