Skip to content

test: check query validation#20

Merged
tisonkun merged 4 commits intomainfrom
pg-query
Feb 8, 2026
Merged

test: check query validation#20
tisonkun merged 4 commits intomainfrom
pg-query

Conversation

@tisonkun
Copy link
Copy Markdown
Collaborator

@tisonkun tisonkun commented Feb 7, 2026

Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds PostgreSQL syntax validation to the pqb integration test suite so that snapshot-tested SQL is parsed/validated (closing the gap described in #10: “Validate syntax of generated SQL”).

Changes:

  • Introduce a ValidateSQL helper trait in pqb/tests/common.rs that parses SQL with pg_query.
  • Update most SQL snapshot assertions across test modules to call .validate() on the generated SQL.
  • Add pg_query as a dev-dependency (and update Cargo.lock accordingly).

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pqb/tests/common.rs Adds ValidateSQL helper that parses SQL via pg_query.
pqb/tests/select.rs Applies .validate() to generated SELECT SQL snapshots (and a couple of statement snapshots).
pqb/tests/insert.rs Applies .validate() to INSERT snapshots; leaves one known-invalid ON CONFLICT case unvalidated with a FIXME.
pqb/tests/create_table.rs Applies .validate() to CREATE TABLE snapshots; leaves generated-column case unvalidated due to dialect/version mismatch.
pqb/tests/index.rs Applies .validate() to CREATE INDEX snapshots.
pqb/tests/drop.rs Applies .validate() to DROP statements.
pqb/tests/explain.rs Applies .validate() to EXPLAIN statements.
pqb/tests/expr.rs Applies .validate() to expression-driven SELECT snapshots.
pqb/tests/types.rs Applies .validate() to identifier/qualified name rendering snapshots.
pqb/Cargo.toml Adds pg_query = 6.1.1 under dev-dependencies.
Cargo.lock Locks the new dependency graph introduced by pg_query.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: tison <wander4096@gmail.com>
.generated_as_virtual(Expr::column("sum").div(Expr::value(2))),
)
.to_sql(),
// .validate(), // TODO: Before PostgreSQL 18, STORED is the only supported kind and must be specified.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun merged commit 98bf92c into main Feb 8, 2026
9 checks passed
@tisonkun tisonkun deleted the pg-query branch February 8, 2026 02:23
/// SQL value variants.
#[derive(Debug, Clone, PartialEq)]
#[expect(missing_docs)]
#[allow(missing_docs)]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

match on Result<T,E> and return the error

2 participants