Skip to content

Commit 444e97c

Browse files
EliSauderCopilot
andcommitted
fix(core): find the family of a type given default arguments
A type the catalog holds no row for, as decimal(5,1) cast to before any column has it, is looked up by its family. Looking the family up by its bare name applied the dialect's default arguments again, as SQL Server's decimal is decimal(18,0), which held no row either, so the expression went untyped and its operators resolved against nothing. The family is now found by name when its bare name is no row. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2861faa commit 444e97c

5 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎internal/core/types.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,11 @@ func (c *Catalog) LookupTypeExpr(t *TypeExpr) (TypeLookup, bool) {
659659
// The family is known and the instance is not a row.
660660
familyOID, _, err := c.internType(&TypeExpr{Name: canonical.Name}, refuse, false)
661661
if err != nil {
662-
return TypeLookup{}, false
662+
// The bare name may take default arguments, as SQL Server's
663+
// decimal is decimal(18,0), and so name no row either.
664+
if familyOID, err = c.TypeOID(canonical.Name); err != nil {
665+
return TypeLookup{}, false
666+
}
663667
}
664668
return TypeLookup{OID: familyOID, FamilyOID: familyOID, Expr: canonical}, true
665669
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"command": "analyze",
3+
"args": ["--dialect", "mssql", "--schema", "schema.sql", "query.sql"],
4+
"contexts": ["base"]
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- name: Negated :many
2+
SELECT -CAST(i AS DECIMAL) AS nd, d * CAST(i AS DECIMAL(12,3)) AS product FROM p2;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE p2 (d DECIMAL(10,2) NOT NULL, i INT NOT NULL, f FLOAT NOT NULL);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[
2+
{
3+
"name": "Negated",
4+
"cmd": ":many",
5+
"columns": [
6+
{
7+
"name": "nd",
8+
"type": {
9+
"name": "decimal"
10+
}
11+
},
12+
{
13+
"name": "product",
14+
"type": {
15+
"name": "decimal"
16+
}
17+
}
18+
],
19+
"params": []
20+
}
21+
]

0 commit comments

Comments
 (0)