(self)
| 1249 | ) |
| 1250 | |
| 1251 | def test_exists(self): |
| 1252 | s = select(table1.c.myid).where(table1.c.myid == 5) |
| 1253 | |
| 1254 | self.assert_compile( |
| 1255 | exists(s), |
| 1256 | "EXISTS (SELECT mytable.myid FROM mytable " |
| 1257 | "WHERE mytable.myid = :myid_1)", |
| 1258 | ) |
| 1259 | |
| 1260 | self.assert_compile( |
| 1261 | exists(s.scalar_subquery()), |
| 1262 | "EXISTS (SELECT mytable.myid FROM mytable " |
| 1263 | "WHERE mytable.myid = :myid_1)", |
| 1264 | ) |
| 1265 | |
| 1266 | self.assert_compile( |
| 1267 | exists(table1.c.myid).where(table1.c.myid == 5).select(), |
| 1268 | "SELECT EXISTS (SELECT mytable.myid FROM " |
| 1269 | "mytable WHERE mytable.myid = :myid_1) AS anon_1", |
| 1270 | params={"mytable_myid": 5}, |
| 1271 | ) |
| 1272 | self.assert_compile( |
| 1273 | select(table1, exists(1).select_from(table2)), |
| 1274 | "SELECT mytable.myid, mytable.name, " |
| 1275 | "mytable.description, EXISTS (SELECT 1 " |
| 1276 | "FROM myothertable) AS anon_1 FROM mytable", |
| 1277 | params={}, |
| 1278 | ) |
| 1279 | self.assert_compile( |
| 1280 | select(table1, exists(1).select_from(table2).label("foo")), |
| 1281 | "SELECT mytable.myid, mytable.name, " |
| 1282 | "mytable.description, EXISTS (SELECT 1 " |
| 1283 | "FROM myothertable) AS foo FROM mytable", |
| 1284 | params={}, |
| 1285 | ) |
| 1286 | |
| 1287 | self.assert_compile( |
| 1288 | table1.select().where( |
| 1289 | exists() |
| 1290 | .where(table2.c.otherid == table1.c.myid) |
| 1291 | .correlate(table1) |
| 1292 | ), |
| 1293 | "SELECT mytable.myid, mytable.name, " |
| 1294 | "mytable.description FROM mytable WHERE " |
| 1295 | "EXISTS (SELECT * FROM myothertable WHERE " |
| 1296 | "myothertable.otherid = mytable.myid)", |
| 1297 | ) |
| 1298 | self.assert_compile( |
| 1299 | table1.select().where( |
| 1300 | exists() |
| 1301 | .where(table2.c.otherid == table1.c.myid) |
| 1302 | .correlate(table1) |
| 1303 | ), |
| 1304 | "SELECT mytable.myid, mytable.name, " |
| 1305 | "mytable.description FROM mytable WHERE " |
| 1306 | "EXISTS (SELECT * FROM myothertable WHERE " |
| 1307 | "myothertable.otherid = mytable.myid)", |
| 1308 | ) |
nothing calls this directly
no test coverage detected