Skip to content

Postgres Create(...)` fix on identity columns, - #879

Merged
Thorium merged 2 commits into
fsprojects:masterfrom
Thorium:master
Nov 2, 2026
Merged

Thorium merged 2 commits into
fsprojects:masterfrom
Thorium:master

Conversation

@Thorium

@Thorium Thorium commented Nov 2, 2026

Copy link
Copy Markdown
Member

group-by fix on IsSome/IsNone

Proposed Changes

  • Fix: parameters of a sub-query nested in another sub-query are bound (IN, EXISTS, UNION and the like)
  • Fix: groupBy keys with option or value-option columns, and with x.IsSome / x.IsNone in a tuple key
  • PostgreSQL: identity columns count as generated, so the typed Create(...) no longer takes them. Breaking for code that passed a value to a BY DEFAULT identity column: use Create() and set it, or Create(data). A saved ContextSchemaPath cache keeps the old signature until regenerated.

group-by fix on IsSome/IsNone

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Single-table tuple grouping with two computed keys produces duplicate column names in PostgreSQL and SQL Server, causing one value to be overwritten and preventing reconstruction of the group-key tuple.

1 open issue
What changed in this PR

This PR fixes SQLProvider’s nested-query parameter binding, optional group-key handling, and PostgreSQL identity-column detection. It also expands guidance on querying, creating entities, and testing with mock contexts.

Changes:

  • Clone and rename nested-query parameters without modifying shared parameter objects.
  • Support optional and computed group keys, with regression tests.
  • Exclude PostgreSQL identity columns from typed Create(...) arguments and document the compatibility impact.
File Description
tests/​SqlProvider.Tests/​SqlProvider.Tests.fsproj Registers PostgreSQL schema tests.
tests/​SqlProvider.Tests/​QueryTests.fs Tests optional and computed group keys.
tests/​SqlProvider.Tests/​PostgreSqlSchemaTests.fs Tests identity-column metadata against PostgreSQL.
tests/​SqlProvider.Tests/​more/​SubqueryCompositionTests.fs Tests parameter binding across nested subqueries.
src/​SQLProvider.Runtime/​Providers.Postgresql.fs Recognizes identity columns as autogenerated.
src/​SQLProvider.Common/​Utils.fs Preserves optional types during value conversion.
src/​SQLProvider.Common/​SqlRuntime.Linq.fs Updates parameter renaming and tuple group-key translation.
docs/​RELEASE_NOTES.md Records fixes and identity-column compatibility guidance.
docs/​content/​index.fsx Clarifies query example comments.
docs/​content/​core/​unittest.fsx Expands mock-context setup and usage guidance.
docs/​content/​core/​querying.fsx Adds query-style guidance and focused projections.
docs/​content/​core/​general.fsx Links to recommended query practices.
docs/​content/​core/​crud.fsx Documents typed creation and updates without prior reads.
docs/​content/​core/​composable.fsx Clarifies nested-query syntax and mock compatibility.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Computed group-key aliases can collide with ordinary column names, breaking tuple-key reconstruction, and the assembly-wide SQL check incorrectly fails tests that emit no SQL events.

3 open issues
1 resolved since last review

Review effort: Balanced

/// `plain`, the provider's usual entry.
let groupKeyColumn (keys:(alias*SqlColumnType) list) (index:int) (column:SqlColumnType) (notation:string) (plain:string) =
match column with
| CanonicalOperation _ when keys.Length > 1 -> sprintf "%s as key%i" notation index
cmd.CommandText <- sql
cmd.ExecuteNonQuery() |> ignore

[<Test>]
Comment on lines +87 to +89
if not noSql then
if commands.IsEmpty then
Assert.Fail "The test sent no SQL: its query ran in memory. Mark it [<NoSql>] if that is meant."
@Thorium
Thorium merged commit 610af00 into fsprojects:master Nov 2, 2026
2 of 3 checks passed
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