Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): Support subqueries in the FROM clause #3322

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Jille
Copy link
Contributor

@Jille Jille commented Apr 4, 2024

issue #2989, #2400 and probably others

This is without #3220 so we can separate which test failures are caused by which PR.

@Jille
Copy link
Contributor Author

Jille commented Apr 16, 2024

I've added a fix for unnamed subqueries. That panicked at HEAD and my branch, and works now :)

@alexrjones
Copy link

@Jille, I think the reason why 7d1b0c6 was required is because this test uses an active database to perform type inference for the query. All tests that use the managed-db config mutate the config to connect to the DB:

Mutate: func(t *testing.T, path string) func(*config.Config) {
return func(c *config.Config) {
for i := range c.SQL {
files := []string{}
for _, s := range c.SQL[i].Schema {
files = append(files, filepath.Join(path, s))
}
switch c.SQL[i].Engine {
case config.EnginePostgreSQL:
uri := local.ReadOnlyPostgreSQL(t, files)
c.SQL[i].Database = &config.Database{
URI: uri,
}
case config.EngineMySQL:
uri := local.MySQL(t, files)
c.SQL[i].Database = &config.Database{
URI: uri,
}
default:
// pass
}
}
}
},

Here is where analysis is performed for columns that are not part of a table:

dataType, err := a.formatType(ctx, field.DataTypeOID, field.TypeModifier)
if err != nil {
return nil, err
}
// debug.Dump(i, field, dataType)
notNull := false
name := field.Name
dt, isArray, dims := parseType(dataType)
result.Columns = append(result.Columns, &core.Column{
Name: name,
OriginalName: field.Name,
DataType: dt,
NotNull: notNull,
IsArray: isArray,
ArrayDims: int32(dims),
})
}

Notice that notNull is always false in this block. So, for people who do use this setup, the CI output would match this output. I believe this is the reason for the difference between your local sqlc generate output and the CI output, but I'm not sure what can be changed here to allow this analyzer to infer the nullability of this column.

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