MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_exists

Method test_exists

test/sql/test_compiler.py:1250–1341  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1248 )
1249
1250 def test_exists(self):
1251 s = select(table1.c.myid).where(table1.c.myid == 5)
1252
1253 self.assert_compile(
1254 exists(s),
1255 "EXISTS (SELECT mytable.myid FROM mytable "
1256 "WHERE mytable.myid = :myid_1)",
1257 )
1258
1259 self.assert_compile(
1260 exists(s.scalar_subquery()),
1261 "EXISTS (SELECT mytable.myid FROM mytable "
1262 "WHERE mytable.myid = :myid_1)",
1263 )
1264
1265 self.assert_compile(
1266 exists(table1.c.myid).where(table1.c.myid == 5).select(),
1267 "SELECT EXISTS (SELECT mytable.myid FROM "
1268 "mytable WHERE mytable.myid = :myid_1) AS anon_1",
1269 params={"mytable_myid": 5},
1270 )
1271 self.assert_compile(
1272 select(table1, exists(1).select_from(table2)),
1273 "SELECT mytable.myid, mytable.name, "
1274 "mytable.description, EXISTS (SELECT 1 "
1275 "FROM myothertable) AS anon_1 FROM mytable",
1276 params={},
1277 )
1278 self.assert_compile(
1279 select(table1, exists(1).select_from(table2).label("foo")),
1280 "SELECT mytable.myid, mytable.name, "
1281 "mytable.description, EXISTS (SELECT 1 "
1282 "FROM myothertable) AS foo FROM mytable",
1283 params={},
1284 )
1285
1286 self.assert_compile(
1287 table1.select().where(
1288 exists()
1289 .where(table2.c.otherid == table1.c.myid)
1290 .correlate(table1)
1291 ),
1292 "SELECT mytable.myid, mytable.name, "
1293 "mytable.description FROM mytable WHERE "
1294 "EXISTS (SELECT * FROM myothertable WHERE "
1295 "myothertable.otherid = mytable.myid)",
1296 )
1297 self.assert_compile(
1298 table1.select().where(
1299 exists()
1300 .where(table2.c.otherid == table1.c.myid)
1301 .correlate(table1)
1302 ),
1303 "SELECT mytable.myid, mytable.name, "
1304 "mytable.description FROM mytable WHERE "
1305 "EXISTS (SELECT * FROM myothertable WHERE "
1306 "myothertable.otherid = mytable.myid)",
1307 )

Callers

nothing calls this directly

Calls 10

selectFunction · 0.90
existsFunction · 0.90
or_Function · 0.90
assert_compileMethod · 0.80
whereMethod · 0.45
scalar_subqueryMethod · 0.45
selectMethod · 0.45
select_fromMethod · 0.45
labelMethod · 0.45
correlateMethod · 0.45

Tested by

no test coverage detected