From 812584fa15fe41f5b608f950a9f65686f008dd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez=20Di=20Antonio?= Date: Sat, 24 Oct 2026 19:27:37 +0200 Subject: [PATCH] fix: the PostgreSQL dialect names its version DialectSQLStandard says SQL:2023 and DialectPostgreSQL said PostgreSQL: the grammar is PostgreSQL 18's, checked against PostgreSQL 18, and its name, the package doc, the guides and the documentation index's diagram now say so. Only a caller that compares String() changes. Co-Authored-By: Claude Opus 5.5 --- dialect.go | 12 +++++++----- dialect_test.go | 6 +++--- docs.go | 2 +- docs/README.md | 2 +- docs/configuration.md | 5 +++-- docs/getting-started.md | 2 +- docs/migration.md | 10 ++++++++-- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/dialect.go b/dialect.go index 820bb4a..dfa9c31 100644 --- a/dialect.go +++ b/dialect.go @@ -14,8 +14,9 @@ package qfv // (https://www.postgresql.org/docs/current/features-sql-standard.html), and // against what its manual calls an extension. // -// A Dialect is one of the values below; the zero value is DialectPostgreSQL, -// the grammar this package has always parsed. +// A Dialect is one of the values below, each a version of its SQL: PostgreSQL +// 18, SQL:2023. The zero value is DialectPostgreSQL, the grammar this package +// has always parsed. type Dialect struct { name string } @@ -27,7 +28,7 @@ var ( DialectPostgreSQL = Dialect{} // DialectSQLStandard is the SQL standard, ISO/IEC 9075:2023 (SQL:2023), - // Part 2 (Foundation). It is PostgreSQL's grammar without what + // Part 2 (Foundation). It is PostgreSQL 18's grammar without what // PostgreSQL's manual calls its own: // // - != (the standard's "not equal" is <>); @@ -50,10 +51,11 @@ var ( DialectSQLStandard = Dialect{name: "SQL:2023"} ) -// String is the dialect's name, as error messages write it. +// String is the dialect's name with its version, as error messages write it: +// "PostgreSQL 18", "SQL:2023". func (d Dialect) String() string { if d.name == "" { - return "PostgreSQL" + return "PostgreSQL 18" } return d.name diff --git a/dialect_test.go b/dialect_test.go index e73b435..0b09c9a 100644 --- a/dialect_test.go +++ b/dialect_test.go @@ -55,8 +55,8 @@ func TestTheDefaultDialectIsPostgreSQL(t *testing.T) { t.Parallel() var zero Dialect - if zero != DialectPostgreSQL || zero.String() != "PostgreSQL" { - t.Errorf("the zero Dialect is %q, want PostgreSQL", zero) + if zero != DialectPostgreSQL || zero.String() != "PostgreSQL 18" { + t.Errorf("the zero Dialect is %q, want PostgreSQL 18", zero) } if got := DialectPostgreSQL.Operators(); !slices.Equal(got, AllOperators()) { @@ -73,7 +73,7 @@ func TestTheDefaultDialectIsPostgreSQL(t *testing.T) { } { for _, tt := range postgresOnly { if _, err := parser.Parse(tt.input); err != nil { - t.Errorf("Parse(%q): %v, want it accepted in PostgreSQL", tt.input, err) + t.Errorf("Parse(%q): %v, want it accepted in PostgreSQL 18", tt.input, err) } } } diff --git a/docs.go b/docs.go index d619065..21758f2 100644 --- a/docs.go +++ b/docs.go @@ -4,7 +4,7 @@ // // The filter parser reads an SQL boolean expression and returns its AST. It // checks an expression and does not translate one, so what it accepts is -// what the SQL it will run as accepts: by default PostgreSQL's grammar, as +// what the SQL it will run as accepts: by default PostgreSQL 18's grammar, as // PostgreSQL 18 runs it; with WithDialect(DialectSQLStandard), the SQL // standard's (ISO/IEC 9075:2023), which refuses PostgreSQL's own spellings // such as != and ILIKE. WithAllowedOperators and WithAllowedOperatorGroups diff --git a/docs/README.md b/docs/README.md index 3a2c08d..a436db4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,7 +25,7 @@ flowchart TB allow -. gates .-> FilterParser allow -. gates .-> SortParser - dialect(["SQL dialect
PostgreSQL (default) · SQL:2023"]) + dialect(["SQL dialect
PostgreSQL 18 (default) · SQL:2023"]) dialect -. grammar .-> FilterParser ``` diff --git a/docs/configuration.md b/docs/configuration.md index 85b2cf8..070f1ff 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,6 +1,6 @@ # Configuration -By default the filter parser reads PostgreSQL's grammar and accepts every +By default the filter parser reads PostgreSQL 18's grammar and accepts every operator, and the sort parser accepts both `ASC` and `DESC`. You can choose the SQL dialect, and narrow either, with functional options at construction time. @@ -50,7 +50,8 @@ The dialect comes before the allow-list: an operator the dialect does not have is refused whether `WithAllowedOperators` allows it or not. A dialect is a value of the `Dialect` type, and the zero value is -`DialectPostgreSQL`; there is no way to name one that does not exist. +`DialectPostgreSQL`; there is no way to name one that does not exist. Each +names its version: `String()` is `PostgreSQL 18` or `SQL:2023`. Another database's grammar (MySQL's, for instance: `REGEXP`, `<=>`, backslash escapes in strings) is a dialect to add, with its own tests run against that database. diff --git a/docs/getting-started.md b/docs/getting-started.md index 4dfda0b..7b6c917 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -33,7 +33,7 @@ explicitly permit can appear in a query. This is the primary defense against invalid or malicious input reaching your database. The filter parser checks an expression in the grammar of the SQL it will run -as, and does not translate it: **PostgreSQL's by default**, or the SQL +as, and does not translate it: **PostgreSQL 18's by default**, or the SQL standard's with `WithDialect(qfv.DialectSQLStandard)`. See [the SQL dialect](configuration.md#the-sql-dialect). diff --git a/docs/migration.md b/docs/migration.md index 607f6c8..8943a3b 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -1,15 +1,21 @@ # Migration Guide +## v1.1.0 → v1.1.1 + +`DialectPostgreSQL.String()` is `PostgreSQL 18`, where it was `PostgreSQL`: +each dialect names its version, as `DialectSQLStandard`'s `SQL:2023` does. +Only a caller that compares the string changes; the grammar does not. + ## v1.0.5 → v1.1.0 Two additions: the SQL dialect a filter is written in, and the `ESCAPE` -clause. A caller that changes nothing gets PostgreSQL's grammar, as before, +clause. A caller that changes nothing gets PostgreSQL 18's grammar, as before, with `ESCAPE` accepted. ### The SQL dialect `WithDialect` chooses the grammar a filter is checked in: -`DialectPostgreSQL`, the default and what every earlier version parsed, or +`DialectPostgreSQL` (PostgreSQL 18), the default and what every earlier version parsed, or `DialectSQLStandard`, ISO/IEC 9075:2023, which refuses PostgreSQL's own spellings (`!=`, `ILIKE`, the `~~` and `~` operators, `ISNULL`/`NOTNULL`, an empty `ESCAPE`). The table is in