MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_from_only

Method test_from_only

test/dialect/postgresql/test_compiler.py:2263–2322  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2261 )
2262
2263 def test_from_only(self):
2264 m = MetaData()
2265 tbl1 = Table("testtbl1", m, Column("id", Integer))
2266 tbl2 = Table("testtbl2", m, Column("id", Integer))
2267
2268 stmt = tbl1.select().with_hint(tbl1, "ONLY", "postgresql")
2269 expected = "SELECT testtbl1.id FROM ONLY testtbl1"
2270 self.assert_compile(stmt, expected)
2271
2272 talias1 = tbl1.alias("foo")
2273 stmt = talias1.select().with_hint(talias1, "ONLY", "postgresql")
2274 expected = "SELECT foo.id FROM ONLY testtbl1 AS foo"
2275 self.assert_compile(stmt, expected)
2276
2277 stmt = select(tbl1, tbl2).with_hint(tbl1, "ONLY", "postgresql")
2278 expected = (
2279 "SELECT testtbl1.id, testtbl2.id AS id_1 FROM ONLY testtbl1, "
2280 "testtbl2"
2281 )
2282 self.assert_compile(stmt, expected)
2283
2284 stmt = select(tbl1, tbl2).with_hint(tbl2, "ONLY", "postgresql")
2285 expected = (
2286 "SELECT testtbl1.id, testtbl2.id AS id_1 FROM testtbl1, ONLY "
2287 "testtbl2"
2288 )
2289 self.assert_compile(stmt, expected)
2290
2291 stmt = select(tbl1, tbl2)
2292 stmt = stmt.with_hint(tbl1, "ONLY", "postgresql")
2293 stmt = stmt.with_hint(tbl2, "ONLY", "postgresql")
2294 expected = (
2295 "SELECT testtbl1.id, testtbl2.id AS id_1 FROM ONLY testtbl1, "
2296 "ONLY testtbl2"
2297 )
2298 self.assert_compile(stmt, expected)
2299
2300 stmt = update(tbl1).values(dict(id=1))
2301 stmt = stmt.with_hint("ONLY", dialect_name="postgresql")
2302 expected = "UPDATE ONLY testtbl1 SET id=%(id)s"
2303 self.assert_compile(stmt, expected)
2304
2305 stmt = delete(tbl1).with_hint(
2306 "ONLY", selectable=tbl1, dialect_name="postgresql"
2307 )
2308 expected = "DELETE FROM ONLY testtbl1"
2309 self.assert_compile(stmt, expected)
2310
2311 tbl3 = Table("testtbl3", m, Column("id", Integer), schema="testschema")
2312 stmt = tbl3.select().with_hint(tbl3, "ONLY", "postgresql")
2313 expected = (
2314 "SELECT testschema.testtbl3.id FROM ONLY testschema.testtbl3"
2315 )
2316 self.assert_compile(stmt, expected)
2317
2318 assert_raises(
2319 exc.CompileError,
2320 tbl3.select().with_hint(tbl3, "FAKE", "postgresql").compile,

Callers

nothing calls this directly

Calls 13

MetaDataClass · 0.90
TableClass · 0.90
ColumnClass · 0.90
selectFunction · 0.90
updateFunction · 0.90
deleteFunction · 0.90
assert_raisesFunction · 0.90
assert_compileMethod · 0.80
with_hintMethod · 0.45
selectMethod · 0.45
aliasMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected