Skip to content

Conversation

simolus3
Copy link
Contributor

As reported on Discord, using sync streams with a subquery having a table alias results in now rows being synced.

Sync rules avoid this issue by making aliases in parameter queries illegal and checking for that. We could do the same for sync streams, but that feels like an unecessary restriction. The actual bug here is that it's not consistently clear whether a tableName: string refers to the name in the source schema or the aliased name it has when parsing expressions. Because sync streams reference the aliased name when checking whether a given row can be a parameter input, this caused input tables to not be recognized.

This refactors SqlTools and related structures in sync-rules to always be aware of whether a name refers to an alias or the source table. When looking up values to create parameter lookups or bucket ids, we should always use the schema name. For output names, we use aliased names. By introducing the AvailableTable class for tables that have been added to a result set via FROM, we're guaranteed to always have both names available.

This could be used to lift the restriction of aliases for sync rules, but that feels unecessary given the eventual migration to sync streams.

Copy link

changeset-bot bot commented Oct 15, 2025

🦋 Changeset detected

Latest commit: 31c296b

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

This PR includes changesets to release 17 packages
Name Type
@powersync/service-sync-rules Patch
@powersync/service-jpgwire Patch
@powersync/service-core-tests Patch
@powersync/service-core Patch
@powersync/lib-services-framework Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
@powersync/lib-service-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/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

@simolus3 simolus3 requested a review from rkistner October 15, 2025 13:52
Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that we don't specifically need this for parameter queries. In sync rules, aliases were primarily used to customize the name of the table when synced. With sync streams, I'm guessing it could become much more common to want to use aliases to refer to the tables inside the query, since you're not just working with a single table in the query anymore, so it makes sense to support this.

I'm also wondering if we should have some way to make it obvious that the alias used in the data query / outer sync stream query is used for syncing? I've seen it least one user not realize that, and wondering why their data isn't available on the client.

@simolus3 simolus3 merged commit a98cecb into main Oct 16, 2025
21 checks passed
@simolus3 simolus3 deleted the sync-streams-aliases branch October 16, 2025 17:43
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.

2 participants