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

Warn when selecting from a single table that's not defined in the same file #2540

Closed
vanniktech opened this issue Aug 23, 2021 · 2 comments · Fixed by #3126
Closed

Warn when selecting from a single table that's not defined in the same file #2540

vanniktech opened this issue Aug 23, 2021 · 2 comments · Fixed by #3126
Labels

Comments

@vanniktech
Copy link
Contributor

Description

I've got the following tables:

Coachee.sql:

CREATE TABLE coachee (
  id TEXT NOT NULL PRIMARY KEY,
  ...
)

Mandator.sql:

CREATE TABLE mandator (
  id TEXT NOT NULL PRIMARY KEY,
  ...
)

In Coachee.sql, I had the following statement:

singleId:
SELECT id
  FROM mandator
  LIMIT 1
;

I'd like to have a warning here as I was just copy pasting the same statement from Mandator.sql into Coachee.sql but forgot to change the statement:

-  FROM mandator
+  FROM coachee

Ideally this is done when interpreting the sq file so this is also exposed for the Gradle Plugin.

@AlecKazakova
Copy link
Collaborator

I can imagine cases where you would do this intentionally (sometimes we have an .sq file just for tests, or query a table in a different module)

@vanniktech
Copy link
Contributor Author

I'd confine that check to only tables that are also created from the same file. So if you have a separate sq file which just queries and does no table creation you're fine.

So it basically checks if in that particular file there's a table creation and you're querying from a different table using FROM, spit out a warning. JOIN on other tables should be allowed.

That would cover your case too, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants