From 160b2cdc0aa285e5348a752ab2f4136f2fe4d6fe Mon Sep 17 00:00:00 2001 From: rayuu83 Date: Sat, 2 Dec 2023 01:00:51 +0100 Subject: [PATCH] fix cross join test and add docs --- README.rst | 16 ++++++++++++++++ pypika/tests/test_joins.py | 11 +++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index f36f34b5..c7634002 100644 --- a/README.rst +++ b/README.rst @@ -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` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/pypika/tests/test_joins.py b/pypika/tests/test_joins.py index 6e54f883..fe582faa 100644 --- a/pypika/tests/test_joins.py +++ b/pypika/tests/test_joins.py @@ -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("*") self.assertEqual(expected, str(query)) def test_left_outer_join(self):