Commit 1f13eed7 authored by Fernando Takagi's avatar Fernando Takagi
Browse files

Update core_storage.go

parent bde48e5a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -699,7 +699,7 @@ func storagePrepBatch(batch *pgx.Batch, authoritativeWrite bool, op *StorageOpWr
		query = `
		INSERT INTO storage (collection, key, user_id, value, version, read, write, create_time, update_time)
		SELECT $1, $2, $3, $4, $5, $6, $7, now(), now()
			WHERE NOT EXISTS(SELECT 1 FROM storage WHERE collection = $1 AND key = $2 AND user_id = $3) -- avoids ON CONFLICT hitting pre-existing object and immediately cancels insert
			WHERE NOT EXISTS(SELECT 1 FROM storage WHERE collection = $1 AND key = $2 AND user_id = $3) -- avoids ON CONFLICT hitting pre-existing object, and immediately cancels insert
		ON CONFLICT (collection, key, user_id) DO UPDATE
			SET version = excluded.version WHERE storage.version = excluded.version AND storage.read = excluded.read AND storage.write = excluded.write -- needed to return a row on concurrent write of same object
		RETURNING read, write, version, create_time, update_time`