(self)
| 1473 | ) |
| 1474 | |
| 1475 | def test_scalar_select(self): |
| 1476 | s = select(table1.c.myid).correlate(None).scalar_subquery() |
| 1477 | self.assert_compile( |
| 1478 | select(table1, s), |
| 1479 | "SELECT mytable.myid, mytable.name, " |
| 1480 | "mytable.description, (SELECT mytable.myid " |
| 1481 | "FROM mytable) AS anon_1 FROM mytable", |
| 1482 | ) |
| 1483 | s = select(table1.c.myid).scalar_subquery() |
| 1484 | self.assert_compile( |
| 1485 | select(table2, s), |
| 1486 | "SELECT myothertable.otherid, " |
| 1487 | "myothertable.othername, (SELECT " |
| 1488 | "mytable.myid FROM mytable) AS anon_1 FROM " |
| 1489 | "myothertable", |
| 1490 | ) |
| 1491 | s = select(table1.c.myid).correlate(None).scalar_subquery() |
| 1492 | self.assert_compile( |
| 1493 | select(table1, s), |
| 1494 | "SELECT mytable.myid, mytable.name, " |
| 1495 | "mytable.description, (SELECT mytable.myid " |
| 1496 | "FROM mytable) AS anon_1 FROM mytable", |
| 1497 | ) |
| 1498 | |
| 1499 | s = select(table1.c.myid).scalar_subquery() |
| 1500 | s2 = s.where(table1.c.myid == 5) |
| 1501 | self.assert_compile( |
| 1502 | s2, |
| 1503 | "(SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1)", |
| 1504 | ) |
| 1505 | self.assert_compile(s, "(SELECT mytable.myid FROM mytable)") |
| 1506 | # test that aliases use scalar_subquery() when used in an explicitly |
| 1507 | # scalar context |
| 1508 | |
| 1509 | s = select(table1.c.myid).scalar_subquery() |
| 1510 | self.assert_compile( |
| 1511 | select(table1.c.myid).where(table1.c.myid == s), |
| 1512 | "SELECT mytable.myid FROM mytable WHERE " |
| 1513 | "mytable.myid = (SELECT mytable.myid FROM " |
| 1514 | "mytable)", |
| 1515 | ) |
| 1516 | self.assert_compile( |
| 1517 | select(table1.c.myid).where(table1.c.myid < s), |
| 1518 | "SELECT mytable.myid FROM mytable WHERE " |
| 1519 | "mytable.myid < (SELECT mytable.myid FROM " |
| 1520 | "mytable)", |
| 1521 | ) |
| 1522 | s = select(table1.c.myid).scalar_subquery() |
| 1523 | self.assert_compile( |
| 1524 | select(table2, s), |
| 1525 | "SELECT myothertable.otherid, " |
| 1526 | "myothertable.othername, (SELECT " |
| 1527 | "mytable.myid FROM mytable) AS anon_1 FROM " |
| 1528 | "myothertable", |
| 1529 | ) |
| 1530 | |
| 1531 | # test expressions against scalar selects |
| 1532 |
nothing calls this directly
no test coverage detected