(self)
| 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 |
nothing calls this directly
no test coverage detected