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

select_raw builds invalid syntax if not last in chain #377

Closed
circulon opened this issue Feb 10, 2021 · 0 comments · Fixed by #382
Closed

select_raw builds invalid syntax if not last in chain #377

circulon opened this issue Feb 10, 2021 · 0 comments · Fixed by #382
Labels
bug An existing feature is not working as intended

Comments

@circulon
Copy link
Contributor

Describe the bug
If using select_raw, the statement must be the last statement in the chain or the compiled query in syntactically invalid

To Reproduce

builder = (
            QueryBuilder()
                .select_raw("max(updated_at) as test").from_("some_table")
                .add_select(
                "other_test",
                lambda query: (
                    query.max("updated_at")
                        .from_("different_table")
                        .where(
                        "some_id", "=",
                        "3"
                    )
                ),
            )
        )
    
print("{}".format(builder.to_sql()))

Produces
SELECT max(updated_at) as test(SELECT MAX("different_table"."updated_at") AS updated_at FROM "different_table" WHERE "different_table"."some_id" = '?') as other_test FROM "some_table"

Which you can note there is no comma after "as test"

Expected behavior
A valid query would be generated like this

SELECT max(updated_at) as test, (SELECT MAX("different_table"."updated_at") AS updated_at FROM "different_table" WHERE "different_table"."some_id" = '?') as other_test FROM "some_table"

Desktop (please complete the following information):

  • OS: Mac OSX,
  • Version Catalina 10.15.7

What database are you using?

  • Type: Postgres,
  • Version 10.7

Additional context
Masonite-orm version 1.0.22

@circulon circulon added the bug An existing feature is not working as intended label Feb 10, 2021
@josephmancuso josephmancuso mentioned this issue Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant