MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / test_plain_join

Method test_plain_join

test/sql/test_lateral.py:139–176  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

137 )
138
139 def test_plain_join(self):
140 table1 = self.tables.people
141 table2 = self.tables.books
142 subq = select(table2.c.book_id).where(
143 table2.c.book_owner_id == table1.c.people_id
144 )
145
146 # FROM books, people? isn't this wrong? No! Because
147 # this is only a fragment, books isn't in any other FROM clause
148 self.assert_compile(
149 join(table1, lateral(subq.subquery(), name="alias"), true()),
150 "people JOIN LATERAL (SELECT books.book_id AS book_id "
151 "FROM books, people WHERE books.book_owner_id = people.people_id) "
152 "AS alias ON true",
153 )
154
155 # put it in correct context, implicit correlation works fine
156 self.assert_compile(
157 select(table1).select_from(
158 join(table1, lateral(subq.subquery(), name="alias"), true())
159 ),
160 "SELECT people.people_id, people.age, people.name "
161 "FROM people JOIN LATERAL (SELECT books.book_id AS book_id "
162 "FROM books WHERE books.book_owner_id = people.people_id) "
163 "AS alias ON true",
164 )
165
166 # explicit correlation
167 subq = subq.correlate(table1)
168 self.assert_compile(
169 select(table1).select_from(
170 join(table1, lateral(subq.subquery(), name="alias"), true())
171 ),
172 "SELECT people.people_id, people.age, people.name "
173 "FROM people JOIN LATERAL (SELECT books.book_id AS book_id "
174 "FROM books WHERE books.book_owner_id = people.people_id) "
175 "AS alias ON true",
176 )
177
178 def test_plain_join_implicit_subquery(self):
179 table1 = self.tables.people

Callers

nothing calls this directly

Calls 9

selectFunction · 0.90
joinFunction · 0.90
lateralFunction · 0.90
trueFunction · 0.90
assert_compileMethod · 0.80
whereMethod · 0.45
subqueryMethod · 0.45
select_fromMethod · 0.45
correlateMethod · 0.45

Tested by

no test coverage detected