(self)
| 2351 | ) |
| 2352 | |
| 2353 | def test_from_only(self): |
| 2354 | m = MetaData() |
| 2355 | tbl1 = Table("testtbl1", m, Column("id", Integer)) |
| 2356 | tbl2 = Table("testtbl2", m, Column("id", Integer)) |
| 2357 | |
| 2358 | stmt = tbl1.select().with_hint(tbl1, "ONLY", "postgresql") |
| 2359 | expected = "SELECT testtbl1.id FROM ONLY testtbl1" |
| 2360 | self.assert_compile(stmt, expected) |
| 2361 | |
| 2362 | talias1 = tbl1.alias("foo") |
| 2363 | stmt = talias1.select().with_hint(talias1, "ONLY", "postgresql") |
| 2364 | expected = "SELECT foo.id FROM ONLY testtbl1 AS foo" |
| 2365 | self.assert_compile(stmt, expected) |
| 2366 | |
| 2367 | stmt = select(tbl1, tbl2).with_hint(tbl1, "ONLY", "postgresql") |
| 2368 | expected = ( |
| 2369 | "SELECT testtbl1.id, testtbl2.id AS id_1 FROM ONLY testtbl1, " |
| 2370 | "testtbl2" |
| 2371 | ) |
| 2372 | self.assert_compile(stmt, expected) |
| 2373 | |
| 2374 | stmt = select(tbl1, tbl2).with_hint(tbl2, "ONLY", "postgresql") |
| 2375 | expected = ( |
| 2376 | "SELECT testtbl1.id, testtbl2.id AS id_1 FROM testtbl1, ONLY " |
| 2377 | "testtbl2" |
| 2378 | ) |
| 2379 | self.assert_compile(stmt, expected) |
| 2380 | |
| 2381 | stmt = select(tbl1, tbl2) |
| 2382 | stmt = stmt.with_hint(tbl1, "ONLY", "postgresql") |
| 2383 | stmt = stmt.with_hint(tbl2, "ONLY", "postgresql") |
| 2384 | expected = ( |
| 2385 | "SELECT testtbl1.id, testtbl2.id AS id_1 FROM ONLY testtbl1, " |
| 2386 | "ONLY testtbl2" |
| 2387 | ) |
| 2388 | self.assert_compile(stmt, expected) |
| 2389 | |
| 2390 | stmt = update(tbl1).values(dict(id=1)) |
| 2391 | stmt = stmt.with_hint("ONLY", dialect_name="postgresql") |
| 2392 | expected = "UPDATE ONLY testtbl1 SET id=%(id)s::INTEGER" |
| 2393 | self.assert_compile(stmt, expected) |
| 2394 | |
| 2395 | stmt = delete(tbl1).with_hint( |
| 2396 | "ONLY", selectable=tbl1, dialect_name="postgresql" |
| 2397 | ) |
| 2398 | expected = "DELETE FROM ONLY testtbl1" |
| 2399 | self.assert_compile(stmt, expected) |
| 2400 | |
| 2401 | tbl3 = Table("testtbl3", m, Column("id", Integer), schema="testschema") |
| 2402 | stmt = tbl3.select().with_hint(tbl3, "ONLY", "postgresql") |
| 2403 | expected = ( |
| 2404 | "SELECT testschema.testtbl3.id FROM ONLY testschema.testtbl3" |
| 2405 | ) |
| 2406 | self.assert_compile(stmt, expected) |
| 2407 | |
| 2408 | assert_raises( |
| 2409 | exc.CompileError, |
| 2410 | tbl3.select().with_hint(tbl3, "FAKE", "postgresql").compile, |
nothing calls this directly
no test coverage detected