(self)
| 1360 | ) |
| 1361 | |
| 1362 | def test_where_subquery(self): |
| 1363 | s = ( |
| 1364 | select(addresses.c.street) |
| 1365 | .where(addresses.c.user_id == users.c.user_id) |
| 1366 | .alias("s") |
| 1367 | ) |
| 1368 | |
| 1369 | # don't correlate in a FROM list |
| 1370 | self.assert_compile( |
| 1371 | select(users, s.c.street).select_from(s), |
| 1372 | "SELECT users.user_id, users.user_name, users.password, s.street " |
| 1373 | "FROM (SELECT addresses.street AS street FROM addresses, users " |
| 1374 | "WHERE addresses.user_id = users.user_id) AS s, users", |
| 1375 | ) |
| 1376 | self.assert_compile( |
| 1377 | table1.select().where( |
| 1378 | table1.c.myid |
| 1379 | == select(table1.c.myid) |
| 1380 | .where(table1.c.name == "jack") |
| 1381 | .scalar_subquery() |
| 1382 | ), |
| 1383 | "SELECT mytable.myid, mytable.name, " |
| 1384 | "mytable.description FROM mytable WHERE " |
| 1385 | "mytable.myid = (SELECT mytable.myid FROM " |
| 1386 | "mytable WHERE mytable.name = :name_1)", |
| 1387 | ) |
| 1388 | self.assert_compile( |
| 1389 | table1.select().where( |
| 1390 | table1.c.myid |
| 1391 | == select(table2.c.otherid) |
| 1392 | .where(table1.c.name == table2.c.othername) |
| 1393 | .scalar_subquery() |
| 1394 | ), |
| 1395 | "SELECT mytable.myid, mytable.name, " |
| 1396 | "mytable.description FROM mytable WHERE " |
| 1397 | "mytable.myid = (SELECT " |
| 1398 | "myothertable.otherid FROM myothertable " |
| 1399 | "WHERE mytable.name = myothertable.othernam" |
| 1400 | "e)", |
| 1401 | ) |
| 1402 | self.assert_compile( |
| 1403 | table1.select().where( |
| 1404 | exists(1).where(table2.c.otherid == table1.c.myid) |
| 1405 | ), |
| 1406 | "SELECT mytable.myid, mytable.name, " |
| 1407 | "mytable.description FROM mytable WHERE " |
| 1408 | "EXISTS (SELECT 1 FROM myothertable WHERE " |
| 1409 | "myothertable.otherid = mytable.myid)", |
| 1410 | ) |
| 1411 | talias = table1.alias("ta") |
| 1412 | s = ( |
| 1413 | select(talias) |
| 1414 | .where(exists(1).where(table2.c.otherid == talias.c.myid)) |
| 1415 | .subquery("sq2") |
| 1416 | ) |
| 1417 | self.assert_compile( |
| 1418 | select(s, table1), |
| 1419 | "SELECT sq2.myid, sq2.name, " |
nothing calls this directly
no test coverage detected