Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4300
SELECT id, ARRAY_AGG(whatever.*) FROM workercompiles and generates Go code even thoughwhateveris not a relation in scope. PostgreSQL rejects it withmissing FROM-clause entry for table "whatever".This adds a check in the FuncCall branch of
outputColumns: when an argument is a qualified star (x.*) andxis not a table, alias, CTE, OLD/NEW RETURNING table, or a relation of an enclosing query, sqlc returnstable alias "x" does not exist. This is the same message sqlc already uses for other references to an unknown table alias.To avoid rejecting valid queries:
SELECT (SELECT ARRAY_AGG(o.*) FROM b) FROM ostill compiles. A smallouterfield onQueryCatalogcarries them.Tests (endtoend, PostgreSQL engine):
agg_unknown_relation: fails before the change, passes after. It hasstderr/base.txtandstderr/managed-db.txtand nogo/output.agg_correlated_subquery: must still compile. A first version of the check rejected this query, so the case guards against that.agg_unresolved_func_alias:FROM some_unknown_func() AS umust still compile.The two positive cases run in the base context only (
exec.json), because I could not get them to pass in the managed-db context in my local setup, and a real database rejects an unknown function anyway. I am happy to add managed-db coverage if you can point me to the right way to set it up.What I ran locally:
go vet ./internal/compiler/..., theTestReplayend-to-end tests (base and managed-db, the latter against a local PostgreSQL 18) and the rest ofgo test ./internal/...andgo test --tags=examples ./.... In my environment there was no MySQL, so the tests that need one (TestValidSchemaMySQL cases andTestExamplesVet) could not pass and I could not compare them with main.Not tested or not covered: MySQL and SQLite engines (the check is in shared compiler code, so
f(x.*)there goes through it too, but I did not add cases),schema.table.*arguments (skipped), stars nested inside other expressions such asCOALESCE(ARRAY_AGG(x.*), ...)(only direct function arguments are checked), and stars in WHERE or HAVING.Please let me know if you would prefer the check somewhere else. Thank you for sqlc!