test for :ticket:`12987` Test that using in_() with a nested CompoundSelect works correctly. This occurs when a CompoundSelect is the first argument to another CompoundSelect.
(self)
| 2557 | ) |
| 2558 | |
| 2559 | def test_in_scalar_grouping(self): |
| 2560 | """test for :ticket:`12987` |
| 2561 | |
| 2562 | Test that using in_() with a nested CompoundSelect works correctly. |
| 2563 | This occurs when a CompoundSelect is the first argument to another |
| 2564 | CompoundSelect. |
| 2565 | |
| 2566 | """ |
| 2567 | |
| 2568 | t = self.table1 |
| 2569 | |
| 2570 | # Create nested compound selects |
| 2571 | inner_compound_stmt = union( |
| 2572 | select(t.c.myid).where(t.c.myid == 5), |
| 2573 | select(t.c.myid).where(t.c.myid == 6), |
| 2574 | ) |
| 2575 | simple_stmt = select(t.c.myid).where(t.c.myid == 7) |
| 2576 | |
| 2577 | # When simple statement is first, should work |
| 2578 | outer_compound_stmt = intersect(simple_stmt, inner_compound_stmt) |
| 2579 | self.assert_compile( |
| 2580 | select(t).where(t.c.myid.in_(outer_compound_stmt)), |
| 2581 | "SELECT mytable.myid FROM mytable " |
| 2582 | "WHERE mytable.myid IN (" |
| 2583 | "SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1 " |
| 2584 | "INTERSECT (SELECT mytable.myid FROM mytable " |
| 2585 | "WHERE mytable.myid = :myid_2 " |
| 2586 | "UNION SELECT mytable.myid FROM mytable " |
| 2587 | "WHERE mytable.myid = :myid_3))", |
| 2588 | ) |
| 2589 | |
| 2590 | # When compound statement is first, previously raised |
| 2591 | # NotImplementedError |
| 2592 | outer_compound_stmt = intersect(inner_compound_stmt, simple_stmt) |
| 2593 | self.assert_compile( |
| 2594 | select(t).where(t.c.myid.in_(outer_compound_stmt)), |
| 2595 | "SELECT mytable.myid FROM mytable " |
| 2596 | "WHERE mytable.myid IN (" |
| 2597 | "(SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1 " |
| 2598 | "UNION SELECT mytable.myid FROM mytable " |
| 2599 | "WHERE mytable.myid = :myid_2) " |
| 2600 | "INTERSECT SELECT mytable.myid FROM mytable " |
| 2601 | "WHERE mytable.myid = :myid_3)", |
| 2602 | ) |
| 2603 | |
| 2604 | @testing.combinations(True, False, argnames="is_in") |
| 2605 | @testing.combinations(True, False, argnames="negate") |