-
Notifications
You must be signed in to change notification settings - Fork 305
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
Cannot join with a Query #755
Comments
JonathanCabezas
changed the title
Uncorrelated subquery not working
Cannot join with a Query
Sep 27, 2023
Here is a quick fix: class Subquery(Table):
def __init__(self, query: QueryBuilder) -> None:
self._query = query
self._table_name = query._from[0].get_table_name()
# Using the original table name as alias for the subquery
# for my use case, you can use something else
self._query.alias = self._table_name
super().__init__(self._table_name)
def get_sql(self, **kwargs: Any) -> str:
return self._query.get_sql(**kwargs)
order=Table("order")
product=Table("product")
subquery=Subquery(Query.from_(product).select(product.id).groupby(product.id))
Query.from_(order).join(subquery).on(order.id==product.id).select("*") |
Would you like to create a pull request? |
I don't think this code is anywhere near production-ready, this is just a quick workaround I used in my facade module. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an example which triggers a
pypika.utils.JoinException
The join seems to only work with Tables
The text was updated successfully, but these errors were encountered: