sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

feat(compiler): Support subqueries in the FROM clause

Open Jille opened this issue 1 year ago • 2 comments

issue #2989, #2400 and probably others

This is without https://github.com/sqlc-dev/sqlc/pull/3220 so we can separate which test failures are caused by which PR.

Jille avatar Apr 04 '24 22:04 Jille

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

Jille avatar Apr 16 '24 10:04 Jille

@Jille, I think the reason why https://github.com/sqlc-dev/sqlc/pull/3322/commits/7d1b0c648ee30d22d698109bb2e229303043494e 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:

https://github.com/sqlc-dev/sqlc/blob/e8405b5bb25c7d612af244fc3958f8f3f7bdc4a0/internal/endtoend/endtoend_test.go#L121-L144

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

https://github.com/sqlc-dev/sqlc/blob/caaaacc6faaec2ab893c24328cad260b6a68c6f8/internal/engine/postgresql/analyzer/analyze.go#L272-L288

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.

alexrjones avatar May 07 '24 06:05 alexrjones