Skip to content

Avoid appending a second FORMAT clause in client.query()#776

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-show-row-policies-syntax-error
Draft

Avoid appending a second FORMAT clause in client.query()#776
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-show-row-policies-syntax-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

Summary

client.query() unconditionally appended \nFORMAT <format> to the user-supplied SQL. This produced invalid statements when a query already carried its own FORMAT clause (e.g. SELECT 1 FORMAT CSV \nFORMAT JSON) and surfaced the server-side SHOW ROW POLICIES parser bug, which rejects a trailing FORMAT clause with a SYNTAX_ERROR when no row policies exist.

Changes

  • formatQuery (packages/client-common/src/client.ts): detect an existing trailing FORMAT <Name> clause via a new hasTrailingFormatClause helper and leave the query untouched instead of appending a second clause. Detection is case-insensitive, tolerates newlines, and does not misfire on identifiers like FORMATDateTime(...) or SELECT format FROM t.
  • query() JSDoc: document the FORMAT-append behavior and the SHOW ROW POLICIES limitation, recommending SELECT * FROM system.row_policies as the working alternative (the empty-result case is only fully fixable server-side, since the server rejects any trailing FORMAT there).
  • Unit tests (client.test.ts): cover default JSON append, omitted format, no double-append when a clause exists, case-insensitive/newline detection, trailing-semicolon stripping, and the format-as-identifier case.
  • CHANGELOG: added Bug Fixes entry.
// Before: SELECT 1 FORMAT CSV \nFORMAT JSON   (invalid)
// After:  SELECT 1 FORMAT CSV                 (untouched)
await client.query({ query: 'SELECT 1 FORMAT CSV' })

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Fix client.query() to handle SHOW ROW POLICIES correctly Avoid appending a second FORMAT clause in client.query() May 29, 2026
Copilot AI requested a review from peter-leonov-ch May 29, 2026 23:12
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

client.query() fails on SHOW ROW POLICIES when server has no policies (FORMAT clause causes SYNTAX_ERROR)

3 participants