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