From 8703e7758a5c59d8a669d4c15e3cff3199cdeb81 Mon Sep 17 00:00:00 2001 From: Eric Gullickson <16152721+ericgullickson@users.noreply.github.com> Date: Sun, 11 Jan 2026 18:08:49 -0600 Subject: [PATCH] fix: Replace COUNT(*) with SELECT id in FOR UPDATE query (refs #23) PostgreSQL error 0A000 (feature_not_supported) occurs when using FOR UPDATE with aggregate functions like COUNT(*). Row-level locking requires actual rows to lock. Changes: - Select id column instead of COUNT(*) aggregate - Count rows in application using .length - Maintains transaction isolation and race condition prevention Co-Authored-By: Claude Sonnet 4.5 --- backend/src/features/vehicles/domain/vehicles.service.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/features/vehicles/domain/vehicles.service.ts b/backend/src/features/vehicles/domain/vehicles.service.ts index a03ebc1..cde91b5 100644 --- a/backend/src/features/vehicles/domain/vehicles.service.ts +++ b/backend/src/features/vehicles/domain/vehicles.service.ts @@ -86,11 +86,12 @@ export class VehiclesService { await client.query('BEGIN'); // Lock user's vehicle rows and get count - const countResult = await client.query( - 'SELECT COUNT(*) as count FROM vehicles WHERE user_id = $1 AND is_active = true FOR UPDATE', + // Note: Cannot use COUNT(*) with FOR UPDATE, so we select IDs and count in app + const lockResult = await client.query( + 'SELECT id FROM vehicles WHERE user_id = $1 AND is_active = true FOR UPDATE', [userId] ); - const currentCount = parseInt(countResult.rows[0].count, 10); + const currentCount = lockResult.rows.length; // Check if user can add another vehicle if (!canAddVehicle(userTier, currentCount)) {