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

fix cross join test and add docs #776

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,22 @@ Example of a join using `USING`

SELECT "history".* FROM "history" JOIN "customers" USING "customer_id" WHERE "customers"."id"=5

Example of a cross join
~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

history, customers = Tables('history', 'meta')
q = Query \
.from_(history) \
.cross_join(meta) \
.cross() \
.select(history.star)

.. code-block:: sql

SELECT "history".* FROM "history" CROSS JOIN "meta"


Example of a correlated subquery in the `SELECT`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
11 changes: 3 additions & 8 deletions pypika/tests/test_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,15 @@ def test_outer_join(self):
self.assertEqual(expected, str(query))

def test_cross_join(self):
expected = 'SELECT * FROM "abc" CROSS JOIN "efg" ON "abc"."foo"="efg"."bar"'
expected = 'SELECT * FROM "abc" CROSS JOIN "efg"'

with self.subTest("join with enum"):
query = (
Query.from_(self.table0)
.join(self.table1, how=JoinType.cross)
.on(self.table0.foo == self.table1.bar)
.select("*")
)
query = Query.from_(self.table0).join(self.table1, how=JoinType.cross).cross().select("*")

self.assertEqual(expected, str(query))

with self.subTest("join function"):
query = Query.from_(self.table0).cross_join(self.table1).on(self.table0.foo == self.table1.bar).select("*")
query = Query.from_(self.table0).cross_join(self.table1).cross().select("*")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be an API design item, but why does cross and cross_join have to be called?
Does cross take arguments?

self.assertEqual(expected, str(query))

def test_left_outer_join(self):
Expand Down