Skip to content

Fix Sync Streams division by zero semantics#646

Open
sravan27 wants to merge 1 commit into
powersync-ja:mainfrom
sravan27:fix-sync-streams-division-by-zero
Open

Fix Sync Streams division by zero semantics#646
sravan27 wants to merge 1 commit into
powersync-ja:mainfrom
sravan27:fix-sync-streams-division-by-zero

Conversation

@sravan27
Copy link
Copy Markdown

Summary

This fixes a Sync Streams JavaScript evaluator divergence from SQLite around division by zero.

SQLite returns NULL for divide-by-zero expressions:

  • 5 / 0
  • 5 / 0.0
  • 5 / '0'
  • 0 / 0

The current JavaScript evaluator can instead return Infinity for real division by zero or throw for bigint division by zero. In filter expressions this can create evaluator errors or non-SQLite truthiness instead of SQLite's NULL result.

Changes

  • Return null from the shared math operator implementation when the division RHS casts to zero.
  • Add regression coverage for bigint, number, string-cast, negative, and zero-over-zero cases.
  • Add a patch changeset for @powersync/service-sync-rules.

Verification

sqlite3 :memory: "select typeof(5/0), 5/0, typeof(5/0.0), 5/0.0, typeof(5/'0'), 5/'0';"
# null||null||null|

corepack pnpm --dir packages/sync-rules exec vitest test/src/sql_operators.test.ts --run
# 15 passed

corepack pnpm --dir packages/sync-rules exec vitest test/src/sql_functions.test.ts --run --testTimeout=10000
# 25 passed

corepack pnpm --dir packages/sync-rules run build:tsc
# passed

git diff --check
# passed

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: 421ae90

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@powersync/service-sync-rules Patch
@powersync/service-core Patch
@powersync/lib-services-framework Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mssql Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
@powersync/service-module-core Patch
@powersync/service-image Patch
test-client Patch
@powersync/service-rsocket-router Patch
@powersync/lib-service-mongodb Patch
@powersync/lib-service-postgres Patch
@powersync/service-schema Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant