Skip to content

Commit 0a1b04e

Browse files
authored
fix: πŸ› Correctly switch coalesce() result .NotNull value (#1664)
* fix: πŸ› Correctly switch `coalesce()` result `.NotNull` value This change follows the previous implementation that mutates and returns the first column, but switches only the `.NotNull` value depending on the situation. BREAKING CHANGE: 🧨 `coalesce()` may assign nullable results βœ… Closes: #1663 * test: πŸ’ Follow breaking changes
1 parent fd2f5cc commit 0a1b04e

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

β€Žinternal/compiler/output_columns.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ func outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, error) {
148148
if res.Name != nil {
149149
name = *res.Name
150150
}
151-
var found bool
151+
var firstColumn *Column
152+
var shouldNotBeNull bool
152153
for _, arg := range n.Args.Items {
153-
if found {
154+
if _, ok := arg.(*ast.A_Const); ok {
155+
shouldNotBeNull = true
154156
continue
155157
}
156158
if ref, ok := arg.(*ast.ColumnRef); ok {
@@ -159,14 +161,18 @@ func outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, error) {
159161
return nil, err
160162
}
161163
for _, c := range columns {
162-
found = true
163-
c.NotNull = true
164-
c.skipTableRequiredCheck = true
165-
cols = append(cols, c)
164+
if firstColumn == nil {
165+
firstColumn = c
166+
}
167+
shouldNotBeNull = shouldNotBeNull || c.NotNull
166168
}
167169
}
168170
}
169-
if !found {
171+
if firstColumn != nil {
172+
firstColumn.NotNull = shouldNotBeNull
173+
firstColumn.skipTableRequiredCheck = true
174+
cols = append(cols, firstColumn)
175+
} else {
170176
cols = append(cols, &Column{Name: name, DataType: "any", NotNull: false})
171177
}
172178

β€Žinternal/endtoend/testdata/coalesce/postgresql/pgx/go/query.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žinternal/endtoend/testdata/coalesce/postgresql/stdlib/go/query.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)