test #9173
(self, dialect)
| 1366 | ("postgresql+asyncpg",), |
| 1367 | ) |
| 1368 | def test_insert_w_cte_in_scalar_subquery(self, dialect): |
| 1369 | """test #9173""" |
| 1370 | |
| 1371 | customer = table( |
| 1372 | "customer", |
| 1373 | column("id"), |
| 1374 | column("name"), |
| 1375 | ) |
| 1376 | order = table( |
| 1377 | "order", |
| 1378 | column("id"), |
| 1379 | column("price"), |
| 1380 | column("customer_id"), |
| 1381 | ) |
| 1382 | |
| 1383 | inst = ( |
| 1384 | customer.insert() |
| 1385 | .values(name="John") |
| 1386 | .returning(customer.c.id) |
| 1387 | .cte("inst") |
| 1388 | ) |
| 1389 | |
| 1390 | stmt = ( |
| 1391 | order.insert() |
| 1392 | .values( |
| 1393 | price=1, |
| 1394 | customer_id=select(inst.c.id).scalar_subquery(), |
| 1395 | ) |
| 1396 | .add_cte(inst) |
| 1397 | ) |
| 1398 | |
| 1399 | if dialect == "default_enhanced": |
| 1400 | self.assert_compile( |
| 1401 | stmt, |
| 1402 | "WITH inst AS (INSERT INTO customer (name) VALUES (:param_1) " |
| 1403 | 'RETURNING customer.id) INSERT INTO "order" ' |
| 1404 | "(price, customer_id) VALUES " |
| 1405 | "(:price, (SELECT inst.id FROM inst))", |
| 1406 | dialect=dialect, |
| 1407 | ) |
| 1408 | elif dialect == "postgresql": |
| 1409 | self.assert_compile( |
| 1410 | stmt, |
| 1411 | "WITH inst AS (INSERT INTO customer (name) " |
| 1412 | "VALUES (%(param_1)s) " |
| 1413 | 'RETURNING customer.id) INSERT INTO "order" ' |
| 1414 | "(price, customer_id) " |
| 1415 | "VALUES (%(price)s, (SELECT inst.id FROM inst))", |
| 1416 | dialect=dialect, |
| 1417 | ) |
| 1418 | elif dialect == "postgresql+asyncpg": |
| 1419 | self.assert_compile( |
| 1420 | stmt, |
| 1421 | "WITH inst AS (INSERT INTO customer (name) VALUES ($2) " |
| 1422 | 'RETURNING customer.id) INSERT INTO "order" ' |
| 1423 | "(price, customer_id) VALUES ($1, (SELECT inst.id FROM inst))", |
| 1424 | dialect=dialect, |
| 1425 | ) |
nothing calls this directly
no test coverage detected