MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_plain_join_implicit_subquery

Method test_plain_join_implicit_subquery

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

Source from the content-addressed store, hash-verified

176 )
177
178 def test_plain_join_implicit_subquery(self):
179 table1 = self.tables.people
180 table2 = self.tables.books
181 subq = select(table2.c.book_id).where(
182 table2.c.book_owner_id == table1.c.people_id
183 )
184
185 # FROM books, people? isn't this wrong? No! Because
186 # this is only a fragment, books isn't in any other FROM clause
187 self.assert_compile(
188 join(table1, lateral(subq, name="alias"), true()),
189 "people JOIN LATERAL (SELECT books.book_id AS book_id "
190 "FROM books, people WHERE books.book_owner_id = people.people_id) "
191 "AS alias ON true",
192 )
193
194 # put it in correct context, implicit correlation works fine
195 self.assert_compile(
196 select(table1).select_from(
197 join(table1, lateral(subq, name="alias"), true())
198 ),
199 "SELECT people.people_id, people.age, people.name "
200 "FROM people JOIN LATERAL (SELECT books.book_id AS book_id "
201 "FROM books WHERE books.book_owner_id = people.people_id) "
202 "AS alias ON true",
203 )
204
205 # explicit correlation
206 subq = subq.correlate(table1)
207 self.assert_compile(
208 select(table1).select_from(
209 join(table1, lateral(subq, name="alias"), true())
210 ),
211 "SELECT people.people_id, people.age, people.name "
212 "FROM people JOIN LATERAL (SELECT books.book_id AS book_id "
213 "FROM books WHERE books.book_owner_id = people.people_id) "
214 "AS alias ON true",
215 )
216
217 def test_join_lateral_w_select_subquery(self):
218 table1 = self.tables.people

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected