Skip to content

refactor: Make Postgres-specific query features explicit to allow reusing its query builder for SQLite - #4764

Merged
marcelomendoncasoares merged 2 commits into
serverpod:mainfrom
marcelomendoncasoares:postgres-query-behavior-explicit
Feb 27, 2026
Merged

marcelomendoncasoares merged 2 commits into
serverpod:mainfrom
marcelomendoncasoares:postgres-query-behavior-explicit

Conversation

@marcelomendoncasoares

Copy link
Copy Markdown
Collaborator

SQLite aims to be Postgres-compatible, but there are subtle changes in implicit behaviors between them. Two of them are the handling of nulls on sorting (which is inverted) and the row_number() alias on queries. This PR makes such Postgres implicit behaviors explicit so that queries produces by its query builder can be reused on SQLite to produce the same results.

  • Nulls sorting: now writes DESC NULLS FIRST and ASC NULLS LAST explicitly so that SQLite sorts equally. If the null handling is omitted, SQLite would sort as the opposite by default.
  • row_number() alias: now writes row_number() OVER ( PARTITION BY $wrappedBaseQueryAlias."$relationalFieldName") AS row_number explicitly so that SQLite can use it. If the alias is omitted, SQLite would not be able to use it.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None.

@marcelomendoncasoares
marcelomendoncasoares marked this pull request as ready for review February 24, 2026 15:07

@nielsenko nielsenko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Makes the implicit ordering explicit.

@marcelomendoncasoares
marcelomendoncasoares merged commit d688637 into serverpod:main Feb 27, 2026
72 checks passed
@marcelomendoncasoares
marcelomendoncasoares deleted the postgres-query-behavior-explicit branch February 27, 2026 09:36
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants