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

Missing quotes when joining tables #87

Closed
mouchar opened this issue Mar 6, 2021 · 2 comments
Closed

Missing quotes when joining tables #87

mouchar opened this issue Mar 6, 2021 · 2 comments
Assignees
Labels

Comments

@mouchar
Copy link

mouchar commented Mar 6, 2021

When joining two tables by columns with different names, generated SQL lacks double quotes around table and column specifiers:

E.g.

'.user, .org | j(.org.id == .user.org_id)'

>> SELECT * FROM "user" INNER JOIN "org"  ON org.id = user.org_id

Joining by the common column name works fine:

'.user, .org | j(.id)'
>>> SELECT * FROM "user" INNER JOIN "org"  ON "user"."id" = "org"."id"

Double quotes are necessary if you have to operate on such an unfortunate schema that uses reserved keywords as table names (like user in this case).

mouchar added a commit to mouchar/sq that referenced this issue Mar 7, 2021
Both sides of the JOIN should be quoted properly also
for explicit joins `join(.tbl1.col1 == .tbl2.col2)`

Fixes: neilotoole#87
neilotoole added a commit that referenced this issue Mar 8, 2021
…join statement (#89)

* BaseFragmentBuilder now quotes table and col names for joins

* Refactored libsq.engine so that the SQL generated from SLQ input can be tested

* Deleted dead code; additional comments
@neilotoole neilotoole self-assigned this Mar 8, 2021
@neilotoole neilotoole added the bug label Mar 8, 2021
@neilotoole
Copy link
Owner

@mouchar As mentioned on one of the PRs, this has been fixed and released in sq v0.15.2. Would you mind verifying that the new release addresses the issue, and if so, I'll close this issue out. Again, thanks.

@mouchar
Copy link
Author

mouchar commented Mar 8, 2021

Now it works as expected, thank you for your fix.

@mouchar mouchar closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants