diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2020-07-08 15:07:44 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-07-08 15:07:44 +0000 |
| commit | b330ffbc13ddb4274a004eab6a13ce40d641e555 (patch) | |
| tree | 88605188d6adac26c77defa544fc5cde208952f5 /test/sql | |
| parent | a6d8b674e92ef1cabdb2ab85490397f3ed12a42c (diff) | |
| parent | 91f376692d472a5bf0c4b4033816250ec1ce3ab6 (diff) | |
| download | sqlalchemy-b330ffbc13ddb4274a004eab6a13ce40d641e555.tar.gz | |
Merge "Add future=True to create_engine/Session; unify select()"
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_compare.py | 29 | ||||
| -rw-r--r-- | test/sql/test_compiler.py | 1068 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 308 | ||||
| -rw-r--r-- | test/sql/test_external_traversal.py | 195 | ||||
| -rw-r--r-- | test/sql/test_operators.py | 2 | ||||
| -rw-r--r-- | test/sql/test_resultset.py | 30 | ||||
| -rw-r--r-- | test/sql/test_roles.py | 69 | ||||
| -rw-r--r-- | test/sql/test_select.py | 66 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 482 |
9 files changed, 1109 insertions, 1140 deletions
diff --git a/test/sql/test_compare.py b/test/sql/test_compare.py index da588b988..fff5171ef 100644 --- a/test/sql/test_compare.py +++ b/test/sql/test_compare.py @@ -29,7 +29,6 @@ from sqlalchemy import util from sqlalchemy import values from sqlalchemy.dialects import mysql from sqlalchemy.dialects import postgresql -from sqlalchemy.future import select as future_select from sqlalchemy.schema import Sequence from sqlalchemy.sql import bindparam from sqlalchemy.sql import ColumnElement @@ -374,26 +373,20 @@ class CoreFixtures(object): .correlate_except(table_b), ), lambda: ( - future_select(table_a.c.a), - future_select(table_a.c.a).join( - table_b, table_a.c.a == table_b.c.a - ), - future_select(table_a.c.a).join_from( + select(table_a.c.a), + select(table_a.c.a).join(table_b, table_a.c.a == table_b.c.a), + select(table_a.c.a).join_from( table_a, table_b, table_a.c.a == table_b.c.a ), - future_select(table_a.c.a).join_from(table_a, table_b), - future_select(table_a.c.a).join_from(table_c, table_b), - future_select(table_a.c.a) + select(table_a.c.a).join_from(table_a, table_b), + select(table_a.c.a).join_from(table_c, table_b), + select(table_a.c.a) .join(table_b, table_a.c.a == table_b.c.a) .join(table_c, table_b.c.b == table_c.c.x), - future_select(table_a.c.a).join(table_b), - future_select(table_a.c.a).join(table_c), - future_select(table_a.c.a).join( - table_b, table_a.c.a == table_b.c.b - ), - future_select(table_a.c.a).join( - table_c, table_a.c.a == table_c.c.x - ), + select(table_a.c.a).join(table_b), + select(table_a.c.a).join(table_c), + select(table_a.c.a).join(table_b, table_a.c.a == table_b.c.b), + select(table_a.c.a).join(table_c, table_a.c.a == table_c.c.x), ), lambda: ( select([table_a.c.a]).cte(), @@ -841,7 +834,7 @@ class CoreFixtures(object): # lambda statements don't collect bindparameter objects # for fixed values, has to be in a variable value = random.randint(10, 20) - return lambda_stmt(lambda: future_select(table_a)) + ( + return lambda_stmt(lambda: select(table_a)) + ( lambda s: s.where(table_a.c.a == value) ) diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 28150d15e..7f06aa0d1 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -183,7 +183,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "columns; use this object directly within a " "column-level expression.", getattr, - select([table1.c.myid]).scalar_subquery().self_group(), + select(table1.c.myid).scalar_subquery().self_group(), "columns", ) @@ -193,7 +193,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "columns; use this object directly within a " "column-level expression.", getattr, - select([table1.c.myid]).scalar_subquery(), + select(table1.c.myid).scalar_subquery(), "columns", ) @@ -217,16 +217,12 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([table1, table2]), + select(table1, table2), "SELECT mytable.myid, mytable.name, mytable.description, " "myothertable.otherid, myothertable.othername FROM mytable, " "myothertable", ) - def test_invalid_col_argument(self): - assert_raises(exc.ArgumentError, select, table1) - assert_raises(exc.ArgumentError, select, table1.c.myid) - def test_int_limit_offset_coercion(self): for given, exp in [ ("5", 5), @@ -237,30 +233,26 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ]: eq_(select().limit(given)._limit, exp) eq_(select().offset(given)._offset, exp) - eq_(select(limit=given)._limit, exp) - eq_(select(offset=given)._offset, exp) assert_raises(ValueError, select().limit, "foo") assert_raises(ValueError, select().offset, "foo") - assert_raises(ValueError, select, offset="foo") - assert_raises(ValueError, select, limit="foo") def test_limit_offset_no_int_coercion_one(self): exp1 = literal_column("Q") exp2 = literal_column("Y") self.assert_compile( - select([1]).limit(exp1).offset(exp2), "SELECT 1 LIMIT Q OFFSET Y" + select(1).limit(exp1).offset(exp2), "SELECT 1 LIMIT Q OFFSET Y" ) self.assert_compile( - select([1]).limit(bindparam("x")).offset(bindparam("y")), + select(1).limit(bindparam("x")).offset(bindparam("y")), "SELECT 1 LIMIT :x OFFSET :y", ) def test_limit_offset_no_int_coercion_two(self): exp1 = literal_column("Q") exp2 = literal_column("Y") - sel = select([1]).limit(exp1).offset(exp2) + sel = select(1).limit(exp1).offset(exp2) assert_raises_message( exc.CompileError, @@ -283,7 +275,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_limit_offset_no_int_coercion_three(self): exp1 = bindparam("Q") exp2 = bindparam("Y") - sel = select([1]).limit(exp1).offset(exp2) + sel = select(1).limit(exp1).offset(exp2) assert_raises_message( exc.CompileError, @@ -321,19 +313,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ), ]: self.assert_compile( - select([1]).limit(lim).offset(offset), + select(1).limit(lim).offset(offset), "SELECT 1 " + exp, checkparams=params, ) def test_select_precol_compile_ordering(self): s1 = ( - select([column("x")]) + select(column("x")) .select_from(text("a")) .limit(5) .scalar_subquery() ) - s2 = select([s1]).limit(10) + s2 = select(s1).limit(10) class MyCompiler(compiler.SQLCompiler): def get_select_precolumns(self, select, **kw): @@ -367,9 +359,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): another select, for the purposes of selecting from the exported columns of that select.""" - s = select([table1], table1.c.name == "jack").subquery() + s = select(table1).where(table1.c.name == "jack").subquery() self.assert_compile( - select([s], s.c.myid == 7), + select(s).where(s.c.myid == 7), "SELECT anon_1.myid, anon_1.name, anon_1.description FROM " "(SELECT mytable.myid AS myid, " "mytable.name AS name, mytable.description AS description " @@ -378,7 +370,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "anon_1.myid = :myid_1", ) - sq = select([table1]) + sq = select(table1) self.assert_compile( sq.subquery().select(), "SELECT anon_1.myid, anon_1.name, anon_1.description FROM " @@ -387,21 +379,22 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "AS description FROM mytable) AS anon_1", ) - sq = select([table1]).alias("sq") + sq = select(table1).alias("sq") self.assert_compile( - sq.select(sq.c.myid == 7), + sq.select().where(sq.c.myid == 7), "SELECT sq.myid, sq.name, sq.description FROM " "(SELECT mytable.myid AS myid, mytable.name AS name, " "mytable.description AS description FROM mytable) AS sq " "WHERE sq.myid = :myid_1", ) - sq = select( - [table1, table2], - and_(table1.c.myid == 7, table2.c.otherid == table1.c.myid), - use_labels=True, - ).alias("sq") + sq = ( + select(table1, table2) + .where(and_(table1.c.myid == 7, table2.c.otherid == table1.c.myid)) + .apply_labels() + .alias("sq") + ) sqstring = ( "SELECT mytable.myid AS mytable_myid, mytable.name AS " @@ -419,7 +412,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "sq.myothertable_othername FROM (%s) AS sq" % sqstring, ) - sq2 = select([sq], use_labels=True).alias("sq2") + sq2 = select(sq).apply_labels().alias("sq2") self.assert_compile( sq2.select(), @@ -436,7 +429,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_from_clauselist(self): self.assert_compile( - select([ClauseList(column("a"), column("b"))]).select_from( + select(ClauseList(column("a"), column("b"))).select_from( text("sometable") ), "SELECT a, b FROM sometable", @@ -444,44 +437,43 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_use_labels(self): self.assert_compile( - select([table1.c.myid == 5], use_labels=True), + select(table1.c.myid == 5).apply_labels(), "SELECT mytable.myid = :myid_1 AS anon_1 FROM mytable", ) self.assert_compile( - select([func.foo()], use_labels=True), "SELECT foo() AS foo_1" + select(func.foo()).apply_labels(), "SELECT foo() AS foo_1" ) # this is native_boolean=False for default dialect self.assert_compile( - select([not_(True)], use_labels=True), - "SELECT :param_1 = 0 AS anon_1", + select(not_(True)).apply_labels(), "SELECT :param_1 = 0 AS anon_1", ) self.assert_compile( - select([cast("data", Integer)], use_labels=True), + select(cast("data", Integer)).apply_labels(), "SELECT CAST(:param_1 AS INTEGER) AS anon_1", ) self.assert_compile( select( - [func.sum(func.lala(table1.c.myid).label("foo")).label("bar")] + func.sum(func.lala(table1.c.myid).label("foo")).label("bar") ), "SELECT sum(lala(mytable.myid)) AS bar FROM mytable", ) self.assert_compile( - select([keyed]), "SELECT keyed.x, keyed.y" ", keyed.z FROM keyed" + select(keyed), "SELECT keyed.x, keyed.y" ", keyed.z FROM keyed" ) self.assert_compile( - select([keyed]).apply_labels(), + select(keyed).apply_labels(), "SELECT keyed.x AS keyed_x, keyed.y AS " "keyed_y, keyed.z AS keyed_z FROM keyed", ) self.assert_compile( - select([select([keyed]).apply_labels().subquery()]).apply_labels(), + select(select(keyed).apply_labels().subquery()).apply_labels(), "SELECT anon_1.keyed_x AS anon_1_keyed_x, " "anon_1.keyed_y AS anon_1_keyed_y, " "anon_1.keyed_z AS anon_1_keyed_z " @@ -535,21 +527,21 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): """as of 1.4, there's no deduping.""" self.assert_compile( - select([column("a"), column("a"), column("a")]), + select(column("a"), column("a"), column("a")), "SELECT a, a, a", dialect=default.DefaultDialect(), ) c = column("a") self.assert_compile( - select([c, c, c]), + select(c, c, c), "SELECT a, a, a", dialect=default.DefaultDialect(), ) a, b = column("a"), column("b") self.assert_compile( - select([a, b, b, b, a, a]), + select(a, b, b, b, a, a), "SELECT a, b, b, b, a, a", dialect=default.DefaultDialect(), ) @@ -561,28 +553,28 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): Column("c", Integer, key="a"), ) self.assert_compile( - select([a, b, c, a, b, c]), + select(a, b, c, a, b, c), "SELECT a, b, c, a, b, c", dialect=default.DefaultDialect(), ) self.assert_compile( - select([bindparam("a"), bindparam("b"), bindparam("c")]), + select(bindparam("a"), bindparam("b"), bindparam("c")), "SELECT :a AS anon_1, :b AS anon_2, :c AS anon_3", dialect=default.DefaultDialect(paramstyle="named"), ) self.assert_compile( - select([bindparam("a"), bindparam("b"), bindparam("c")]), + select(bindparam("a"), bindparam("b"), bindparam("c")), "SELECT ? AS anon_1, ? AS anon_2, ? AS anon_3", dialect=default.DefaultDialect(paramstyle="qmark"), ) self.assert_compile( - select([column("a"), column("a"), column("a")]), "SELECT a, a, a" + select(column("a"), column("a"), column("a")), "SELECT a, a, a" ) - s = select([bindparam("a"), bindparam("b"), bindparam("c")]) + s = select(bindparam("a"), bindparam("b"), bindparam("c")) s = s.compile(dialect=default.DefaultDialect(paramstyle="qmark")) eq_(s.positiontup, ["a", "b", "c"]) @@ -590,7 +582,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): foo = table("foo", column("id"), column("bar_id")) foo_bar = table("foo_bar", column("id")) - stmt = select([foo, foo_bar]).apply_labels() + stmt = select(foo, foo_bar).apply_labels() self.assert_compile( stmt, "SELECT foo.id AS foo_id, foo.bar_id AS foo_bar_id, " @@ -626,16 +618,14 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # robust behavior when dupes are present is still very useful. stmt = select( - [ - foo.c.id, - foo.c.bar_id, - foo_bar.c.id, - foo.c.bar_id, - foo.c.id, - foo.c.bar_id, - foo_bar.c.id, - foo_bar.c.id, - ] + foo.c.id, + foo.c.bar_id, + foo_bar.c.id, + foo.c.bar_id, + foo.c.id, + foo.c.bar_id, + foo_bar.c.id, + foo_bar.c.id, ).apply_labels() self.assert_compile( stmt, @@ -654,7 +644,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # of the same column are not used. only the label applied to the # first occurrence of each column is used self.assert_compile( - select([stmt.subquery()]), + select(stmt.subquery()), "SELECT " "anon_1.foo_id, " # from 1st foo.id in derived (line 1) "anon_1.foo_bar_id, " # from 1st foo.bar_id in derived (line 2) @@ -680,17 +670,17 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_dupe_columns_use_labels(self): t = table("t", column("a"), column("b")) self.assert_compile( - select([t.c.a, t.c.a, t.c.b, t.c.a]).apply_labels(), + select(t.c.a, t.c.a, t.c.b, t.c.a).apply_labels(), "SELECT t.a AS t_a, t.a AS t_a__1, t.b AS t_b, " "t.a AS t_a__1 FROM t", ) def test_dupe_columns_use_labels_derived_selectable(self): t = table("t", column("a"), column("b")) - stmt = select([t.c.a, t.c.a, t.c.b, t.c.a]).apply_labels().subquery() + stmt = select(t.c.a, t.c.a, t.c.b, t.c.a).apply_labels().subquery() self.assert_compile( - select([stmt]), + select(stmt), "SELECT anon_1.t_a, anon_1.t_a, anon_1.t_b, anon_1.t_a FROM " "(SELECT t.a AS t_a, t.a AS t_a__1, t.b AS t_b, t.a AS t_a__1 " "FROM t) AS anon_1", @@ -701,19 +691,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): a, b, a_a = t.c.a, t.c.b, t.c.a._annotate({"some_orm_thing": True}) self.assert_compile( - select([a, a_a, b, a_a]).apply_labels(), + select(a, a_a, b, a_a).apply_labels(), "SELECT t.a AS t_a, t.a AS t_a__1, t.b AS t_b, " "t.a AS t_a__1 FROM t", ) self.assert_compile( - select([a_a, a, b, a_a]).apply_labels(), + select(a_a, a, b, a_a).apply_labels(), "SELECT t.a AS t_a, t.a AS t_a__1, t.b AS t_b, " "t.a AS t_a__1 FROM t", ) self.assert_compile( - select([a_a, a_a, b, a]).apply_labels(), + select(a_a, a_a, b, a).apply_labels(), "SELECT t.a AS t_a, t.a AS t_a__1, t.b AS t_b, " "t.a AS t_a__1 FROM t", ) @@ -721,10 +711,10 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_dupe_columns_use_labels_derived_selectable_mix_annotations(self): t = table("t", column("a"), column("b")) a, b, a_a = t.c.a, t.c.b, t.c.a._annotate({"some_orm_thing": True}) - stmt = select([a, a_a, b, a_a]).apply_labels().subquery() + stmt = select(a, a_a, b, a_a).apply_labels().subquery() self.assert_compile( - select([stmt]), + select(stmt), "SELECT anon_1.t_a, anon_1.t_a, anon_1.t_b, anon_1.t_a FROM " "(SELECT t.a AS t_a, t.a AS t_a__1, t.b AS t_b, t.a AS t_a__1 " "FROM t) AS anon_1", @@ -737,13 +727,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): foo_bar__id = foo_bar.c.id._annotate({"some_orm_thing": True}) stmt = select( - [ - foo.c.bar_id, - foo_bar.c.id, - foo_bar.c.id, - foo_bar__id, - foo_bar__id, - ] + foo.c.bar_id, foo_bar.c.id, foo_bar.c.id, foo_bar__id, foo_bar__id, ).apply_labels() self.assert_compile( @@ -761,7 +745,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # second and third occurrences of a.c.a are labeled, but are # dupes of each other. self.assert_compile( - select([a.c.a, a.c.a, a.c.b, a.c.a]).apply_labels(), + select(a.c.a, a.c.a, a.c.b, a.c.a).apply_labels(), "SELECT t_1.a AS t_1_a, t_1.a AS t_1_a__1, t_1.b AS t_1_b, " "t_1.a AS t_1_a__1 " "FROM t AS t_1", @@ -773,9 +757,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): """ s1 = table1.select() s2 = s1.alias() - s3 = select([s2], use_labels=True) + s3 = select(s2).apply_labels() s4 = s3.alias() - s5 = select([s4], use_labels=True) + s5 = select(s4).apply_labels() self.assert_compile( s5, "SELECT anon_1.anon_2_myid AS " @@ -794,7 +778,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_nested_label_targeting_keyed(self): s1 = keyed.select() s2 = s1.alias() - s3 = select([s2], use_labels=True) + s3 = select(s2).apply_labels() self.assert_compile( s3, "SELECT anon_1.x AS anon_1_x, " @@ -805,7 +789,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) s4 = s3.alias() - s5 = select([s4], use_labels=True) + s5 = select(s4).apply_labels() self.assert_compile( s5, "SELECT anon_1.anon_2_x AS anon_1_anon_2_x, " @@ -819,7 +803,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_exists(self): - s = select([table1.c.myid]).where(table1.c.myid == 5) + s = select(table1.c.myid).where(table1.c.myid == 5) self.assert_compile( exists(s), @@ -834,20 +818,20 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - exists([table1.c.myid], table1.c.myid == 5).select(), + exists(table1.c.myid).where(table1.c.myid == 5).select(), "SELECT EXISTS (SELECT mytable.myid FROM " "mytable WHERE mytable.myid = :myid_1) AS anon_1", params={"mytable_myid": 5}, ) self.assert_compile( - select([table1, exists([1], from_obj=table2)]), + select(table1, exists(1).select_from(table2)), "SELECT mytable.myid, mytable.name, " "mytable.description, EXISTS (SELECT 1 " "FROM myothertable) AS anon_1 FROM mytable", params={}, ) self.assert_compile( - select([table1, exists([1], from_obj=table2).label("foo")]), + select(table1, exists(1).select_from(table2).label("foo")), "SELECT mytable.myid, mytable.name, " "mytable.description, EXISTS (SELECT 1 " "FROM myothertable) AS foo FROM mytable", @@ -855,7 +839,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table1.select( + table1.select().where( exists() .where(table2.c.otherid == table1.c.myid) .correlate(table1) @@ -866,7 +850,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "myothertable.otherid = mytable.myid)", ) self.assert_compile( - table1.select( + table1.select().where( exists() .where(table2.c.otherid == table1.c.myid) .correlate(table1) @@ -879,12 +863,10 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - or_( - exists().where(table2.c.otherid == "foo"), - exists().where(table2.c.otherid == "bar"), - ) - ] + or_( + exists().where(table2.c.otherid == "foo"), + exists().where(table2.c.otherid == "bar"), + ) ), "SELECT (EXISTS (SELECT * FROM myothertable " "WHERE myothertable.otherid = :otherid_1)) " @@ -893,28 +875,28 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([exists([1])]), "SELECT EXISTS (SELECT 1) AS anon_1" + select(exists(1)), "SELECT EXISTS (SELECT 1) AS anon_1" ) self.assert_compile( - select([~exists([1])]), "SELECT NOT (EXISTS (SELECT 1)) AS anon_1" + select(~exists(1)), "SELECT NOT (EXISTS (SELECT 1)) AS anon_1" ) self.assert_compile( - select([~(~exists([1]))]), + select(~(~exists(1))), "SELECT NOT (NOT (EXISTS (SELECT 1))) AS anon_1", ) def test_where_subquery(self): - s = select( - [addresses.c.street], - addresses.c.user_id == users.c.user_id, - correlate=True, - ).alias("s") + s = ( + select(addresses.c.street) + .where(addresses.c.user_id == users.c.user_id) + .alias("s") + ) # don't correlate in a FROM list self.assert_compile( - select([users, s.c.street], from_obj=s), + select(users, s.c.street).select_from(s), "SELECT users.user_id, users.user_name, " "users.password, s.street FROM users, " "(SELECT addresses.street AS street FROM " @@ -922,11 +904,11 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "users.user_id) AS s", ) self.assert_compile( - table1.select( + table1.select().where( table1.c.myid - == select( - [table1.c.myid], table1.c.name == "jack" - ).scalar_subquery() + == select(table1.c.myid) + .where(table1.c.name == "jack") + .scalar_subquery() ), "SELECT mytable.myid, mytable.name, " "mytable.description FROM mytable WHERE " @@ -934,11 +916,11 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "mytable WHERE mytable.name = :name_1)", ) self.assert_compile( - table1.select( + table1.select().where( table1.c.myid - == select( - [table2.c.otherid], table1.c.name == table2.c.othername - ).scalar_subquery() + == select(table2.c.otherid) + .where(table1.c.name == table2.c.othername) + .scalar_subquery() ), "SELECT mytable.myid, mytable.name, " "mytable.description FROM mytable WHERE " @@ -948,18 +930,22 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "e)", ) self.assert_compile( - table1.select(exists([1], table2.c.otherid == table1.c.myid)), + table1.select().where( + exists(1).where(table2.c.otherid == table1.c.myid) + ), "SELECT mytable.myid, mytable.name, " "mytable.description FROM mytable WHERE " "EXISTS (SELECT 1 FROM myothertable WHERE " "myothertable.otherid = mytable.myid)", ) talias = table1.alias("ta") - s = select( - [talias], exists([1], table2.c.otherid == talias.c.myid) - ).subquery("sq2") + s = ( + select(talias) + .where(exists(1).where(table2.c.otherid == talias.c.myid)) + .subquery("sq2") + ) self.assert_compile( - select([s, table1]), + select(s, table1), "SELECT sq2.myid, sq2.name, " "sq2.description, mytable.myid, " "mytable.name, mytable.description FROM " @@ -973,8 +959,10 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # test constructing the outer query via append_column(), which # occurs in the ORM's Query object - s = select( - [], exists([1], table2.c.otherid == table1.c.myid), from_obj=table1 + s = ( + select() + .where(exists(1).where(table2.c.otherid == table1.c.myid)) + .select_from(table1) ) s.add_columns.non_generative(s, table1) self.assert_compile( @@ -988,9 +976,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_orderby_subquery(self): self.assert_compile( table1.select().order_by( - select( - [table2.c.otherid], table1.c.myid == table2.c.otherid - ).scalar_subquery() + select(table2.c.otherid) + .where(table1.c.myid == table2.c.otherid) + .scalar_subquery() ), "SELECT mytable.myid, mytable.name, " "mytable.description FROM mytable ORDER BY " @@ -1001,9 +989,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( table1.select().order_by( desc( - select( - [table2.c.otherid], table1.c.myid == table2.c.otherid - ).scalar_subquery() + select(table2.c.otherid) + .where(table1.c.myid == table2.c.otherid) + .scalar_subquery() ) ), "SELECT mytable.myid, mytable.name, " @@ -1014,30 +1002,30 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_scalar_select(self): - s = select([table1.c.myid], correlate=False).scalar_subquery() + s = select(table1.c.myid).correlate(None).scalar_subquery() self.assert_compile( - select([table1, s]), + select(table1, s), "SELECT mytable.myid, mytable.name, " "mytable.description, (SELECT mytable.myid " "FROM mytable) AS anon_1 FROM mytable", ) - s = select([table1.c.myid]).scalar_subquery() + s = select(table1.c.myid).scalar_subquery() self.assert_compile( - select([table2, s]), + select(table2, s), "SELECT myothertable.otherid, " "myothertable.othername, (SELECT " "mytable.myid FROM mytable) AS anon_1 FROM " "myothertable", ) - s = select([table1.c.myid]).correlate(None).scalar_subquery() + s = select(table1.c.myid).correlate(None).scalar_subquery() self.assert_compile( - select([table1, s]), + select(table1, s), "SELECT mytable.myid, mytable.name, " "mytable.description, (SELECT mytable.myid " "FROM mytable) AS anon_1 FROM mytable", ) - s = select([table1.c.myid]).scalar_subquery() + s = select(table1.c.myid).scalar_subquery() s2 = s.where(table1.c.myid == 5) self.assert_compile( s2, @@ -1047,22 +1035,22 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # test that aliases use scalar_subquery() when used in an explicitly # scalar context - s = select([table1.c.myid]).scalar_subquery() + s = select(table1.c.myid).scalar_subquery() self.assert_compile( - select([table1.c.myid]).where(table1.c.myid == s), + select(table1.c.myid).where(table1.c.myid == s), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid = (SELECT mytable.myid FROM " "mytable)", ) self.assert_compile( - select([table1.c.myid]).where(table1.c.myid < s), + select(table1.c.myid).where(table1.c.myid < s), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid < (SELECT mytable.myid FROM " "mytable)", ) - s = select([table1.c.myid]).scalar_subquery() + s = select(table1.c.myid).scalar_subquery() self.assert_compile( - select([table2, s]), + select(table2, s), "SELECT myothertable.otherid, " "myothertable.othername, (SELECT " "mytable.myid FROM mytable) AS anon_1 FROM " @@ -1072,29 +1060,29 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # test expressions against scalar selects self.assert_compile( - select([s - literal(8)]), + select(s - literal(8)), "SELECT (SELECT mytable.myid FROM mytable) " "- :param_1 AS anon_1", ) self.assert_compile( - select([select([table1.c.name]).scalar_subquery() + literal("x")]), + select(select(table1.c.name).scalar_subquery() + literal("x")), "SELECT (SELECT mytable.name FROM mytable) " "|| :param_1 AS anon_1", ) self.assert_compile( - select([s > literal(8)]), + select(s > literal(8)), "SELECT (SELECT mytable.myid FROM mytable) " "> :param_1 AS anon_1", ) self.assert_compile( - select([select([table1.c.name]).label("foo")]), + select(select(table1.c.name).label("foo")), "SELECT (SELECT mytable.name FROM mytable) " "AS foo", ) # scalar selects should not have any attributes on their 'c' or # 'columns' attribute - s = select([table1.c.myid]).scalar_subquery() + s = select(table1.c.myid).scalar_subquery() assert_raises_message( exc.InvalidRequestError, "Scalar Select expression has no columns; use this " @@ -1114,25 +1102,27 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): places = table("places", column("id"), column("nm")) zipcode = "12345" qlat = ( - select([zips.c.latitude], zips.c.zipcode == zipcode) + select(zips.c.latitude) + .where(zips.c.zipcode == zipcode) .correlate(None) .scalar_subquery() ) qlng = ( - select([zips.c.longitude], zips.c.zipcode == zipcode) + select(zips.c.longitude) + .where(zips.c.zipcode == zipcode) .correlate(None) .scalar_subquery() ) - q = select( - [ + q = ( + select( places.c.id, places.c.nm, zips.c.zipcode, func.latlondist(qlat, qlng).label("dist"), - ], - zips.c.zipcode == zipcode, - order_by=["dist", places.c.nm], + ) + .where(zips.c.zipcode == zipcode) + .order_by("dist", places.c.nm) ) self.assert_compile( @@ -1148,21 +1138,22 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) zalias = zips.alias("main_zip") - qlat = select( - [zips.c.latitude], zips.c.zipcode == zalias.c.zipcode - ).scalar_subquery() - qlng = select( - [zips.c.longitude], zips.c.zipcode == zalias.c.zipcode - ).scalar_subquery() - q = select( - [ - places.c.id, - places.c.nm, - zalias.c.zipcode, - func.latlondist(qlat, qlng).label("dist"), - ], - order_by=["dist", places.c.nm], + qlat = ( + select(zips.c.latitude) + .where(zips.c.zipcode == zalias.c.zipcode) + .scalar_subquery() ) + qlng = ( + select(zips.c.longitude) + .where(zips.c.zipcode == zalias.c.zipcode) + .scalar_subquery() + ) + q = select( + places.c.id, + places.c.nm, + zalias.c.zipcode, + func.latlondist(qlat, qlng).label("dist"), + ).order_by("dist", places.c.nm) self.assert_compile( q, "SELECT places.id, places.nm, " @@ -1176,11 +1167,13 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) a1 = table2.alias("t2alias") - s1 = select( - [a1.c.otherid], table1.c.myid == a1.c.otherid - ).scalar_subquery() + s1 = ( + select(a1.c.otherid) + .where(table1.c.myid == a1.c.otherid) + .scalar_subquery() + ) j1 = table1.join(table2, table1.c.myid == table2.c.otherid) - s2 = select([table1, s1], from_obj=j1) + s2 = select(table1, s1).select_from(j1) self.assert_compile( s2, "SELECT mytable.myid, mytable.name, " @@ -1195,7 +1188,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_label_comparison_one(self): x = func.lala(table1.c.myid).label("foo") self.assert_compile( - select([x], x == 5), + select(x).where(x == 5), "SELECT lala(mytable.myid) AS foo FROM " "mytable WHERE lala(mytable.myid) = " ":param_1", @@ -1213,7 +1206,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): dialect = default.DefaultDialect() self.assert_compile( - select([lab1, lab2]).order_by(lab1, desc(lab2)), + select(lab1, lab2).order_by(lab1, desc(lab2)), "SELECT mytable.myid + :myid_1 AS foo, " "somefunc(mytable.name) AS bar FROM mytable " "ORDER BY foo, bar DESC", @@ -1222,7 +1215,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # the function embedded label renders as the function self.assert_compile( - select([lab1, lab2]).order_by(func.hoho(lab1), desc(lab2)), + select(lab1, lab2).order_by(func.hoho(lab1), desc(lab2)), "SELECT mytable.myid + :myid_1 AS foo, " "somefunc(mytable.name) AS bar FROM mytable " "ORDER BY hoho(mytable.myid + :myid_1), bar DESC", @@ -1231,7 +1224,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # binary expressions render as the expression without labels self.assert_compile( - select([lab1, lab2]).order_by(lab1 + "test"), + select(lab1, lab2).order_by(lab1 + "test"), "SELECT mytable.myid + :myid_1 AS foo, " "somefunc(mytable.name) AS bar FROM mytable " "ORDER BY mytable.myid + :myid_1 + :param_1", @@ -1241,7 +1234,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # labels within functions in the columns clause render # with the expression self.assert_compile( - select([lab1, func.foo(lab1)]).order_by(lab1, func.foo(lab1)), + select(lab1, func.foo(lab1)).order_by(lab1, func.foo(lab1)), "SELECT mytable.myid + :myid_1 AS foo, " "foo(mytable.myid + :myid_1) AS foo_1 FROM mytable " "ORDER BY foo, foo(mytable.myid + :myid_1)", @@ -1252,7 +1245,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ly = (func.lower(table1.c.name) + table1.c.description).label("ly") self.assert_compile( - select([lx, ly]).order_by(lx, ly.desc()), + select(lx, ly).order_by(lx, ly.desc()), "SELECT mytable.myid + mytable.myid AS lx, " "lower(mytable.name) || mytable.description AS ly " "FROM mytable ORDER BY lx, ly DESC", @@ -1261,7 +1254,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # expression isn't actually the same thing (even though label is) self.assert_compile( - select([lab1, lab2]).order_by( + select(lab1, lab2).order_by( table1.c.myid.label("foo"), desc(table1.c.name.label("bar")) ), "SELECT mytable.myid + :myid_1 AS foo, " @@ -1272,7 +1265,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # it's also an exact match, not aliased etc. self.assert_compile( - select([lab1, lab2]).order_by( + select(lab1, lab2).order_by( desc(table1.alias().c.name.label("bar")) ), "SELECT mytable.myid + :myid_1 AS foo, " @@ -1284,7 +1277,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # but! it's based on lineage lab2_lineage = lab2.element._clone() self.assert_compile( - select([lab1, lab2]).order_by(desc(lab2_lineage.label("bar"))), + select(lab1, lab2).order_by(desc(lab2_lineage.label("bar"))), "SELECT mytable.myid + :myid_1 AS foo, " "somefunc(mytable.name) AS bar FROM mytable " "ORDER BY bar DESC", @@ -1295,13 +1288,13 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # want to render a name that isn't specifically a Label elsewhere # in the query self.assert_compile( - select([table1.c.myid]).order_by(table1.c.name.label("name")), + select(table1.c.myid).order_by(table1.c.name.label("name")), "SELECT mytable.myid FROM mytable ORDER BY mytable.name", ) # as well as if it doesn't match self.assert_compile( - select([table1.c.myid]).order_by( + select(table1.c.myid).order_by( func.lower(table1.c.name).label("name") ), "SELECT mytable.myid FROM mytable ORDER BY lower(mytable.name)", @@ -1313,14 +1306,14 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): dialect = default.DefaultDialect() dialect.supports_simple_order_by_label = False self.assert_compile( - select([lab1, lab2]).order_by(lab1, desc(lab2)), + select(lab1, lab2).order_by(lab1, desc(lab2)), "SELECT mytable.myid + :myid_1 AS foo, " "somefunc(mytable.name) AS bar FROM mytable " "ORDER BY mytable.myid + :myid_1, somefunc(mytable.name) DESC", dialect=dialect, ) self.assert_compile( - select([lab1, lab2]).order_by(func.hoho(lab1), desc(lab2)), + select(lab1, lab2).order_by(func.hoho(lab1), desc(lab2)), "SELECT mytable.myid + :myid_1 AS foo, " "somefunc(mytable.name) AS bar FROM mytable " "ORDER BY hoho(mytable.myid + :myid_1), " @@ -1334,7 +1327,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): dialect = default.DefaultDialect() self.assert_compile( - select([lab1, lab2]).group_by(lab1, lab2), + select(lab1, lab2).group_by(lab1, lab2), "SELECT mytable.myid + :myid_1 AS foo, somefunc(mytable.name) " "AS bar FROM mytable GROUP BY mytable.myid + :myid_1, " "somefunc(mytable.name)", @@ -1347,7 +1340,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): assert isinstance(x.type, Boolean) assert str(x) == "a AND b AND c" self.assert_compile( - select([x.label("foo")]), "SELECT a AND b AND c AS foo" + select(x.label("foo")), "SELECT a AND b AND c AS foo" ) self.assert_compile( @@ -1399,21 +1392,21 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): t = table("t", column("x")) self.assert_compile( - select([t]).where(and_(t.c.x == 5, or_(and_(or_(t.c.x == 7))))), + select(t).where(and_(t.c.x == 5, or_(and_(or_(t.c.x == 7))))), "SELECT t.x FROM t WHERE t.x = :x_1 AND t.x = :x_2", ) self.assert_compile( - select([t]).where(and_(or_(t.c.x == 12, and_(or_(t.c.x == 8))))), + select(t).where(and_(or_(t.c.x == 12, and_(or_(t.c.x == 8))))), "SELECT t.x FROM t WHERE t.x = :x_1 OR t.x = :x_2", ) self.assert_compile( - select([t]).where( + select(t).where( and_(or_(or_(t.c.x == 12), and_(or_(and_(t.c.x == 8))))) ), "SELECT t.x FROM t WHERE t.x = :x_1 OR t.x = :x_2", ) self.assert_compile( - select([t]).where( + select(t).where( and_( or_( or_(t.c.x == 12), @@ -1432,45 +1425,45 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): t = table("t", column("x")) self.assert_compile( - select([t]).where(true()), + select(t).where(true()), "SELECT t.x FROM t WHERE 1 = 1", dialect=default.DefaultDialect(supports_native_boolean=False), ) self.assert_compile( - select([t]).where(true()), + select(t).where(true()), "SELECT t.x FROM t WHERE true", dialect=default.DefaultDialect(supports_native_boolean=True), ) self.assert_compile( - select([t]), + select(t), "SELECT t.x FROM t", dialect=default.DefaultDialect(supports_native_boolean=True), ) def test_distinct(self): self.assert_compile( - select([table1.c.myid.distinct()]), + select(table1.c.myid.distinct()), "SELECT DISTINCT mytable.myid FROM mytable", ) self.assert_compile( - select([distinct(table1.c.myid)]), + select(distinct(table1.c.myid)), "SELECT DISTINCT mytable.myid FROM mytable", ) self.assert_compile( - select([table1.c.myid]).distinct(), + select(table1.c.myid).distinct(), "SELECT DISTINCT mytable.myid FROM mytable", ) self.assert_compile( - select([func.count(table1.c.myid.distinct())]), + select(func.count(table1.c.myid.distinct())), "SELECT count(DISTINCT mytable.myid) AS count_1 FROM mytable", ) self.assert_compile( - select([func.count(distinct(table1.c.myid))]), + select(func.count(distinct(table1.c.myid))), "SELECT count(DISTINCT mytable.myid) AS count_1 FROM mytable", ) @@ -1479,17 +1472,17 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "DISTINCT ON is currently supported only by the PostgreSQL " "dialect" ): - select(["*"]).distinct(table1.c.myid).compile() + select("*").distinct(table1.c.myid).compile() def test_where_empty(self): self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( BooleanClauseList._construct_raw(operators.and_) ), "SELECT mytable.myid FROM mytable", ) self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( BooleanClauseList._construct_raw(operators.or_) ), "SELECT mytable.myid FROM mytable", @@ -1497,11 +1490,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_order_by_nulls(self): self.assert_compile( - table2.select( - order_by=[ - table2.c.otherid, - table2.c.othername.desc().nullsfirst(), - ] + table2.select().order_by( + table2.c.otherid, table2.c.othername.desc().nullsfirst(), ), "SELECT myothertable.otherid, myothertable.othername FROM " "myothertable ORDER BY myothertable.otherid, " @@ -1509,11 +1499,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table2.select( - order_by=[ - table2.c.otherid, - table2.c.othername.desc().nullslast(), - ] + table2.select().order_by( + table2.c.otherid, table2.c.othername.desc().nullslast(), ), "SELECT myothertable.otherid, myothertable.othername FROM " "myothertable ORDER BY myothertable.otherid, " @@ -1521,11 +1508,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table2.select( - order_by=[ - table2.c.otherid.nullslast(), - table2.c.othername.desc().nullsfirst(), - ] + table2.select().order_by( + table2.c.otherid.nullslast(), + table2.c.othername.desc().nullsfirst(), ), "SELECT myothertable.otherid, myothertable.othername FROM " "myothertable ORDER BY myothertable.otherid NULLS LAST, " @@ -1533,11 +1518,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table2.select( - order_by=[ - table2.c.otherid.nullsfirst(), - table2.c.othername.desc(), - ] + table2.select().order_by( + table2.c.otherid.nullsfirst(), table2.c.othername.desc(), ), "SELECT myothertable.otherid, myothertable.othername FROM " "myothertable ORDER BY myothertable.otherid NULLS FIRST, " @@ -1545,11 +1527,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table2.select( - order_by=[ - table2.c.otherid.nullsfirst(), - table2.c.othername.desc().nullslast(), - ] + table2.select().order_by( + table2.c.otherid.nullsfirst(), + table2.c.othername.desc().nullslast(), ), "SELECT myothertable.otherid, myothertable.othername FROM " "myothertable ORDER BY myothertable.otherid NULLS FIRST, " @@ -1558,8 +1538,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_orderby_groupby(self): self.assert_compile( - table2.select( - order_by=[table2.c.otherid, asc(table2.c.othername)] + table2.select().order_by( + table2.c.otherid, asc(table2.c.othername) ), "SELECT myothertable.otherid, myothertable.othername FROM " "myothertable ORDER BY myothertable.otherid, " @@ -1567,8 +1547,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table2.select( - order_by=[table2.c.otherid, table2.c.othername.desc()] + table2.select().order_by( + table2.c.otherid, table2.c.othername.desc() ), "SELECT myothertable.otherid, myothertable.othername FROM " "myothertable ORDER BY myothertable.otherid, " @@ -1595,9 +1575,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select( - [table2.c.othername, func.count(table2.c.otherid)], - group_by=[table2.c.othername], + select(table2.c.othername, func.count(table2.c.otherid)).group_by( + table2.c.othername ), "SELECT myothertable.othername, " "count(myothertable.otherid) AS count_1 " @@ -1606,16 +1585,16 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # generative group by self.assert_compile( - select( - [table2.c.othername, func.count(table2.c.otherid)] - ).group_by(table2.c.othername), + select(table2.c.othername, func.count(table2.c.otherid)).group_by( + table2.c.othername + ), "SELECT myothertable.othername, " "count(myothertable.otherid) AS count_1 " "FROM myothertable GROUP BY myothertable.othername", ) self.assert_compile( - select([table2.c.othername, func.count(table2.c.otherid)]) + select(table2.c.othername, func.count(table2.c.otherid)) .group_by(table2.c.othername) .group_by(None), "SELECT myothertable.othername, " @@ -1624,11 +1603,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select( - [table2.c.othername, func.count(table2.c.otherid)], - group_by=[table2.c.othername], - order_by=[table2.c.othername], - ), + select(table2.c.othername, func.count(table2.c.otherid)) + .group_by(table2.c.othername) + .order_by(table2.c.othername), "SELECT myothertable.othername, " "count(myothertable.otherid) AS count_1 " "FROM myothertable " @@ -1647,7 +1624,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): name = "custom" statement_compiler = CustomCompiler - stmt = select([table1.c.myid]).order_by(table1.c.myid) + stmt = select(table1.c.myid).order_by(table1.c.myid) self.assert_compile( stmt, "SELECT mytable.myid FROM mytable ORDER BY " @@ -1667,7 +1644,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): name = "custom" statement_compiler = CustomCompiler - stmt = select([table1.c.myid]).group_by(table1.c.myid) + stmt = select(table1.c.myid).group_by(table1.c.myid) self.assert_compile( stmt, "SELECT mytable.myid FROM mytable GROUP BY " @@ -1677,14 +1654,16 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_for_update(self): self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(), + table1.select().where(table1.c.myid == 7).with_for_update(), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE", ) # not supported by dialect, should just use update self.assert_compile( - table1.select(table1.c.myid == 7).with_for_update(nowait=True), + table1.select() + .where(table1.c.myid == 7) + .with_for_update(nowait=True), "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = :myid_1 FOR UPDATE", ) @@ -1693,19 +1672,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # test the alias for a table1. column names stay the same, # table name "changes" to "foo". self.assert_compile( - select([table1.alias("foo")]), + select(table1.alias("foo")), "SELECT foo.myid, foo.name, foo.description FROM mytable AS foo", ) for dialect in (oracle.dialect(),): self.assert_compile( - select([table1.alias("foo")]), + select(table1.alias("foo")), "SELECT foo.myid, foo.name, foo.description FROM mytable foo", dialect=dialect, ) self.assert_compile( - select([table1.alias()]), + select(table1.alias()), "SELECT mytable_1.myid, mytable_1.name, mytable_1.description " "FROM mytable AS mytable_1", ) @@ -1715,10 +1694,10 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # which become the column keys accessible off the Selectable object. # also, only use one column from the second table and all columns # from the first table1. - q = select( - [table1, table2.c.otherid], - table1.c.myid == table2.c.otherid, - use_labels=True, + q = ( + select(table1, table2.c.otherid) + .where(table1.c.myid == table2.c.otherid) + .apply_labels() ) # make an alias of the "selectable". column names @@ -1729,7 +1708,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # should produce two underscores. # also, reference the column "mytable_myid" off of the t2view alias. self.assert_compile( - a.select(a.c.mytable_myid == 9, use_labels=True), + a.select().where(a.c.mytable_myid == 9).apply_labels(), "SELECT t2view.mytable_myid AS t2view_mytable_myid, " "t2view.mytable_name " "AS t2view_mytable_name, " @@ -1747,43 +1726,43 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_alias_nesting_table(self): self.assert_compile( - select([table1.alias("foo").alias("bar").alias("bat")]), + select(table1.alias("foo").alias("bar").alias("bat")), "SELECT bat.myid, bat.name, bat.description FROM mytable AS bat", ) self.assert_compile( - select([table1.alias(None).alias("bar").alias("bat")]), + select(table1.alias(None).alias("bar").alias("bat")), "SELECT bat.myid, bat.name, bat.description FROM mytable AS bat", ) self.assert_compile( - select([table1.alias("foo").alias(None).alias("bat")]), + select(table1.alias("foo").alias(None).alias("bat")), "SELECT bat.myid, bat.name, bat.description FROM mytable AS bat", ) self.assert_compile( - select([table1.alias("foo").alias("bar").alias(None)]), + select(table1.alias("foo").alias("bar").alias(None)), "SELECT bar_1.myid, bar_1.name, bar_1.description " "FROM mytable AS bar_1", ) self.assert_compile( - select([table1.alias("foo").alias(None).alias(None)]), + select(table1.alias("foo").alias(None).alias(None)), "SELECT anon_1.myid, anon_1.name, anon_1.description " "FROM mytable AS anon_1", ) def test_alias_nesting_subquery(self): - stmt = select([table1]).subquery() + stmt = select(table1).subquery() self.assert_compile( - select([stmt.alias("foo").alias("bar").alias("bat")]), + select(stmt.alias("foo").alias("bar").alias("bat")), "SELECT bat.myid, bat.name, bat.description FROM " "(SELECT mytable.myid AS myid, mytable.name AS name, " "mytable.description AS description FROM mytable) AS bat", ) self.assert_compile( - select([stmt.alias("foo").alias(None).alias(None)]), + select(stmt.alias("foo").alias(None).alias(None)), "SELECT anon_1.myid, anon_1.name, anon_1.description FROM " "(SELECT mytable.myid AS myid, mytable.name AS name, " "mytable.description AS description FROM mytable) AS anon_1", @@ -1811,30 +1790,30 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_collate(self): # columns clause self.assert_compile( - select([column("x").collate("bar")]), + select(column("x").collate("bar")), "SELECT x COLLATE bar AS anon_1", ) # WHERE clause self.assert_compile( - select([column("x")]).where(column("x").collate("bar") == "foo"), + select(column("x")).where(column("x").collate("bar") == "foo"), "SELECT x WHERE (x COLLATE bar) = :param_1", ) # ORDER BY clause self.assert_compile( - select([column("x")]).order_by(column("x").collate("bar")), + select(column("x")).order_by(column("x").collate("bar")), "SELECT x ORDER BY x COLLATE bar", ) def test_literal(self): self.assert_compile( - select([literal("foo")]), "SELECT :param_1 AS anon_1" + select(literal("foo")), "SELECT :param_1 AS anon_1" ) self.assert_compile( - select([literal("foo") + literal("bar")], from_obj=[table1]), + select(literal("foo") + literal("bar")).select_from(table1), "SELECT :param_1 || :param_2 AS anon_1 FROM mytable", ) @@ -1848,18 +1827,15 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - value_tbl.c.id, - (value_tbl.c.val2 - value_tbl.c.val1) / value_tbl.c.val1, - ] + value_tbl.c.id, + (value_tbl.c.val2 - value_tbl.c.val1) / value_tbl.c.val1, ), "SELECT values.id, (values.val2 - values.val1) " "/ values.val1 AS anon_1 FROM values", ) self.assert_compile( - select( - [value_tbl.c.id], + select(value_tbl.c.id).where( (value_tbl.c.val2 - value_tbl.c.val1) / value_tbl.c.val1 > 2.0, ), "SELECT values.id FROM values WHERE " @@ -1867,8 +1843,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select( - [value_tbl.c.id], + select(value_tbl.c.id).where( value_tbl.c.val1 / (value_tbl.c.val2 - value_tbl.c.val1) / value_tbl.c.val1 @@ -1887,7 +1862,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): column("spaces % more spaces"), ) self.assert_compile( - t.select(use_labels=True), + t.select().apply_labels(), """SELECT "table%name"."percent%" AS "table%name_percent%", """ """"table%name"."%(oneofthese)s" AS """ """"table%name_%(oneofthese)s", """ @@ -1905,11 +1880,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select( - [table1], - from_obj=[ - join(table1, table2, table1.c.myid == table2.c.otherid) - ], + select(table1).select_from( + join(table1, table2, table1.c.myid == table2.c.otherid) ), "SELECT mytable.myid, mytable.name, mytable.description FROM " "mytable JOIN myothertable ON mytable.myid = myothertable.otherid", @@ -1917,15 +1889,11 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - join( - join( - table1, table2, table1.c.myid == table2.c.otherid - ), - table3, - table1.c.myid == table3.c.userid, - ) - ] + join( + join(table1, table2, table1.c.myid == table2.c.otherid), + table3, + table1.c.myid == table3.c.userid, + ) ), "SELECT mytable.myid, mytable.name, mytable.description, " "myothertable.otherid, myothertable.othername, " @@ -1948,13 +1916,10 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select( - [table1, table2, table3], - from_obj=[ - join( - table1, table2, table1.c.myid == table2.c.otherid - ).outerjoin(table3, table1.c.myid == table3.c.userid) - ], + select(table1, table2, table3).select_from( + join( + table1, table2, table1.c.myid == table2.c.otherid + ).outerjoin(table3, table1.c.myid == table3.c.userid) ), "SELECT mytable.myid, mytable.name, mytable.description, " "myothertable.otherid, myothertable.othername, " @@ -1966,17 +1931,12 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): " thirdtable.userid", ) self.assert_compile( - select( - [table1, table2, table3], - from_obj=[ - outerjoin( - table1, - join( - table2, table3, table2.c.otherid == table3.c.userid - ), - table1.c.myid == table2.c.otherid, - ) - ], + select(table1, table2, table3).select_from( + outerjoin( + table1, + join(table2, table3, table2.c.otherid == table3.c.userid), + table1.c.myid == table2.c.otherid, + ) ), "SELECT mytable.myid, mytable.name, mytable.description, " "myothertable.otherid, myothertable.othername, " @@ -1988,17 +1948,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "mytable.myid = myothertable.otherid", ) - query = select( - [table1, table2], - or_( - table1.c.name == "fred", - table1.c.myid == 10, - table2.c.othername != "jack", - text("EXISTS (select yay from foo where boo = lar)"), - ), - from_obj=[ + query = ( + select(table1, table2) + .where( + or_( + table1.c.name == "fred", + table1.c.myid == 10, + table2.c.othername != "jack", + text("EXISTS (select yay from foo where boo = lar)"), + ) + ) + .select_from( outerjoin(table1, table2, table1.c.myid == table2.c.otherid) - ], + ) ) self.assert_compile( query, @@ -2021,7 +1983,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): table2, table1.c.myid == table2.c.otherid, full=True ), ]: - stmt = select([table1]).select_from(spec) + stmt = select(table1).select_from(spec) self.assert_compile( stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM " @@ -2039,10 +2001,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) x = union( - select([table1], table1.c.myid == 5), - select([table1], table1.c.myid == 12), - order_by=[table1.c.myid], - ) + select(table1).where(table1.c.myid == 5), + select(table1).where(table1.c.myid == 12), + ).order_by(table1.c.myid) self.assert_compile( x, @@ -2055,8 +2016,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "ORDER BY myid", ) - x = union(select([table1]), select([table1])) - x = union(x, select([table1])) + x = union(select(table1), select(table1)) + x = union(x, select(table1)) self.assert_compile( x, "(SELECT mytable.myid, mytable.name, mytable.description " @@ -2066,9 +2027,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) u1 = union( - select([table1.c.myid, table1.c.name]), - select([table2]), - select([table3]), + select(table1.c.myid, table1.c.name), + select(table2), + select(table3), ).order_by("name") self.assert_compile( u1, @@ -2083,13 +2044,10 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): assert u1s.corresponding_column(table2.c.otherid) is u1s.c.myid self.assert_compile( - union( - select([table1.c.myid, table1.c.name]), - select([table2]), - order_by=["myid"], - offset=10, - limit=5, - ), + union(select(table1.c.myid, table1.c.name), select(table2)) + .order_by("myid") + .offset(10) + .limit(5), # note table name is omitted here. The CompoundSelect, inside of # _label_resolve_dict(), creates a subquery of itself and then # turns "named_with_column" off, so that we can order by the @@ -2110,25 +2068,21 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "Can't resolve label reference for ORDER BY / GROUP BY / " "DISTINCT etc. Textual " "SQL expression 'noname'", - union( - select([table1.c.myid, table1.c.name]), - select([table2]), - order_by=["noname"], - ).compile, + union(select(table1.c.myid, table1.c.name), select(table2),) + .order_by("noname") + .compile, ) self.assert_compile( union( select( - [ - table1.c.myid, - table1.c.name, - func.max(table1.c.description), - ], - table1.c.name == "name2", - group_by=[table1.c.myid, table1.c.name], - ), - table1.select(table1.c.name == "name1"), + table1.c.myid, + table1.c.name, + func.max(table1.c.description), + ) + .where(table1.c.name == "name2") + .group_by(table1.c.myid, table1.c.name), + table1.select().where(table1.c.name == "name1"), ), "SELECT mytable.myid, mytable.name, " "max(mytable.description) AS max_1 " @@ -2141,23 +2095,23 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( union( - select([literal(100).label("value")]), - select([literal(200).label("value")]), + select(literal(100).label("value")), + select(literal(200).label("value")), ), "SELECT :param_1 AS value UNION SELECT :param_2 AS value", ) self.assert_compile( union_all( - select([table1.c.myid]), - union(select([table2.c.otherid]), select([table3.c.userid])), + select(table1.c.myid), + union(select(table2.c.otherid), select(table3.c.userid)), ), "SELECT mytable.myid FROM mytable UNION ALL " "(SELECT myothertable.otherid FROM myothertable UNION " "SELECT thirdtable.userid FROM thirdtable)", ) - s = select([column("foo"), column("bar")]) + s = select(column("foo"), column("bar")) self.assert_compile( union(s.order_by("foo"), s.order_by("bar")), @@ -2177,8 +2131,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_dupe_cols_hey_we_can_union(self): """test the original inspiration for [ticket:4753].""" - s1 = select([table1, table1.c.myid]).where(table1.c.myid == 5) - s2 = select([table1, table2.c.otherid]).where( + s1 = select(table1, table1.c.myid).where(table1.c.myid == 5) + s2 = select(table1, table2.c.otherid).where( table1.c.myid == table2.c.otherid ) self.assert_compile( @@ -2191,7 +2145,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_compound_grouping(self): - s = select([column("foo"), column("bar")]).select_from(text("bat")) + s = select(column("foo"), column("bar")).select_from(text("bat")) self.assert_compile( union(union(union(s, s), s), s), @@ -2214,20 +2168,20 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([s.alias()]), + select(s.alias()), "SELECT anon_1.foo, anon_1.bar FROM " "(SELECT foo, bar FROM bat) AS anon_1", ) self.assert_compile( - select([union(s, s).alias()]), + select(union(s, s).alias()), "SELECT anon_1.foo, anon_1.bar FROM " "(SELECT foo, bar FROM bat UNION " "SELECT foo, bar FROM bat) AS anon_1", ) self.assert_compile( - select([except_(s, s).alias()]), + select(except_(s, s).alias()), "SELECT anon_1.foo, anon_1.bar FROM " "(SELECT foo, bar FROM bat EXCEPT " "SELECT foo, bar FROM bat) AS anon_1", @@ -2368,9 +2322,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # fixme: shoving all of this dialect-specific stuff in one test # is now officially completely ridiculous AND non-obviously omits # coverage on other dialects. - sel = select([tbl, cast(tbl.c.v1, Numeric)]).compile( - dialect=dialect - ) + sel = select(tbl, cast(tbl.c.v1, Numeric)).compile(dialect=dialect) if isinstance(dialect, type(mysql.dialect())): eq_( str(sel), @@ -2490,11 +2442,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( select( - [ - func.row_number() - .over(order_by=table1.c.description) - .label("foo") - ] + func.row_number() + .over(order_by=table1.c.description) + .label("foo") ), "SELECT row_number() OVER (ORDER BY mytable.description) " "AS foo FROM mytable", @@ -2503,21 +2453,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # test from_obj generation. # from func: self.assert_compile( - select( - [func.max(table1.c.name).over(partition_by=["description"])] - ), + select(func.max(table1.c.name).over(partition_by=["description"])), "SELECT max(mytable.name) OVER (PARTITION BY mytable.description) " "AS anon_1 FROM mytable", ) # from partition_by self.assert_compile( - select([func.row_number().over(partition_by=[table1.c.name])]), + select(func.row_number().over(partition_by=[table1.c.name])), "SELECT row_number() OVER (PARTITION BY mytable.name) " "AS anon_1 FROM mytable", ) # from order_by self.assert_compile( - select([func.row_number().over(order_by=table1.c.name)]), + select(func.row_number().over(order_by=table1.c.name)), "SELECT row_number() OVER (ORDER BY mytable.name) " "AS anon_1 FROM mytable", ) @@ -2525,16 +2473,16 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # this tests that _from_objects # concantenates OK self.assert_compile( - select([column("x") + over(func.foo())]), + select(column("x") + over(func.foo())), "SELECT x + foo() OVER () AS anon_1", ) # test a reference to a label that in the referecned selectable; # this resolves expr = (table1.c.myid + 5).label("sum") - stmt = select([expr]).alias() + stmt = select(expr).alias() self.assert_compile( - select([stmt.c.sum, func.row_number().over(order_by=stmt.c.sum)]), + select(stmt.c.sum, func.row_number().over(order_by=stmt.c.sum)), "SELECT anon_1.sum, row_number() OVER (ORDER BY anon_1.sum) " "AS anon_2 FROM (SELECT mytable.myid + :myid_1 AS sum " "FROM mytable) AS anon_1", @@ -2544,7 +2492,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # in the columns clause; doesn't resolve expr = (table1.c.myid + 5).label("sum") self.assert_compile( - select([expr, func.row_number().over(order_by=expr)]), + select(expr, func.row_number().over(order_by=expr)), "SELECT mytable.myid + :myid_1 AS sum, " "row_number() OVER " "(ORDER BY mytable.myid + :myid_1) AS anon_1 FROM mytable", @@ -2554,7 +2502,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): expr = table1.c.myid self.assert_compile( - select([func.row_number().over(order_by=expr, rows=(0, None))]), + select(func.row_number().over(order_by=expr, rows=(0, None))), "SELECT row_number() OVER " "(ORDER BY mytable.myid ROWS BETWEEN CURRENT " "ROW AND UNBOUNDED FOLLOWING)" @@ -2562,7 +2510,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([func.row_number().over(order_by=expr, rows=(None, None))]), + select(func.row_number().over(order_by=expr, rows=(None, None))), "SELECT row_number() OVER " "(ORDER BY mytable.myid ROWS BETWEEN UNBOUNDED " "PRECEDING AND UNBOUNDED FOLLOWING)" @@ -2570,7 +2518,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([func.row_number().over(order_by=expr, range_=(None, 0))]), + select(func.row_number().over(order_by=expr, range_=(None, 0))), "SELECT row_number() OVER " "(ORDER BY mytable.myid RANGE BETWEEN " "UNBOUNDED PRECEDING AND CURRENT ROW)" @@ -2578,7 +2526,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([func.row_number().over(order_by=expr, range_=(-5, 10))]), + select(func.row_number().over(order_by=expr, range_=(-5, 10))), "SELECT row_number() OVER " "(ORDER BY mytable.myid RANGE BETWEEN " ":param_1 PRECEDING AND :param_2 FOLLOWING)" @@ -2587,7 +2535,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([func.row_number().over(order_by=expr, range_=(1, 10))]), + select(func.row_number().over(order_by=expr, range_=(1, 10))), "SELECT row_number() OVER " "(ORDER BY mytable.myid RANGE BETWEEN " ":param_1 FOLLOWING AND :param_2 FOLLOWING)" @@ -2596,7 +2544,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([func.row_number().over(order_by=expr, range_=(-10, -1))]), + select(func.row_number().over(order_by=expr, range_=(-10, -1))), "SELECT row_number() OVER " "(ORDER BY mytable.myid RANGE BETWEEN " ":param_1 PRECEDING AND :param_2 PRECEDING)" @@ -2631,16 +2579,12 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): from sqlalchemy import within_group stmt = select( - [ - table1.c.myid, - within_group( - func.percentile_cont(0.5), table1.c.name.desc() - ).over( - range_=(1, 2), - partition_by=table1.c.name, - order_by=table1.c.myid, - ), - ] + table1.c.myid, + within_group(func.percentile_cont(0.5), table1.c.name.desc()).over( + range_=(1, 2), + partition_by=table1.c.name, + order_by=table1.c.myid, + ), ) eq_ignore_whitespace( str(stmt), @@ -2652,16 +2596,12 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) stmt = select( - [ - table1.c.myid, - within_group( - func.percentile_cont(0.5), table1.c.name.desc() - ).over( - rows=(1, 2), - partition_by=table1.c.name, - order_by=table1.c.myid, - ), - ] + table1.c.myid, + within_group(func.percentile_cont(0.5), table1.c.name.desc()).over( + rows=(1, 2), + partition_by=table1.c.name, + order_by=table1.c.myid, + ), ) eq_ignore_whitespace( str(stmt), @@ -2677,7 +2617,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): table = Table("dt", metadata, Column("date", Date)) self.assert_compile( - table.select( + table.select().where( table.c.date.between( datetime.date(2006, 6, 1), datetime.date(2006, 6, 5) ) @@ -2690,7 +2630,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table.select( + table.select().where( sql.between( table.c.date, datetime.date(2006, 6, 1), @@ -2707,7 +2647,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_delayed_col_naming(self): my_str = Column(String) - sel1 = select([my_str]) + sel1 = select(my_str) assert_raises_message( exc.InvalidRequestError, @@ -2717,7 +2657,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # calling label or scalar_subquery doesn't compile # anything. - sel2 = select([func.substr(my_str, 2, 3)]).label("my_substr") + sel2 = select(func.substr(my_str, 2, 3)).label("my_substr") assert_raises_message( exc.CompileError, @@ -2726,7 +2666,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): dialect=default.DefaultDialect(), ) - sel3 = select([my_str]).scalar_subquery() + sel3 = select(my_str).scalar_subquery() assert_raises_message( exc.CompileError, "Cannot compile Column object until its 'name' is assigned.", @@ -2750,12 +2690,10 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): f1 = func.hoho(table1.c.name) s1 = select( - [ - table1.c.myid, - table1.c.myid.label("foobar"), - f1, - func.lala(table1.c.name).label("gg"), - ] + table1.c.myid, + table1.c.myid.label("foobar"), + f1, + func.lala(table1.c.name).label("gg"), ) eq_(list(s1.subquery().c.keys()), ["myid", "foobar", str(f1), "gg"]) @@ -2793,7 +2731,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): else: t = table1 - s1 = select([col], from_obj=t) + s1 = select(col).select_from(t) assert list(s1.subquery().c.keys()) == [key], list(s1.c.keys()) if lbl: @@ -2803,7 +2741,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): else: self.assert_compile(s1, "SELECT %s FROM mytable" % (expr,)) - s1 = select([s1.subquery()]) + s1 = select(s1.subquery()) if lbl: alias_ = "anon_2" if lbl == "anon_1" else "anon_1" self.assert_compile( @@ -2826,19 +2764,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_hints(self): - s = select([table1.c.myid]).with_hint(table1, "test hint %(name)s") + s = select(table1.c.myid).with_hint(table1, "test hint %(name)s") s2 = ( - select([table1.c.myid]) + select(table1.c.myid) .with_hint(table1, "index(%(name)s idx)", "oracle") .with_hint(table1, "WITH HINT INDEX idx", "sybase") ) a1 = table1.alias() - s3 = select([a1.c.myid]).with_hint(a1, "index(%(name)s hint)") + s3 = select(a1.c.myid).with_hint(a1, "index(%(name)s hint)") subs4 = ( - select([table1, table2]) + select(table1, table2) .select_from( table1.join(table2, table1.c.myid == table2.c.otherid) ) @@ -2846,7 +2784,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ).subquery() s4 = ( - select([table3]) + select(table3) .select_from( table3.join(subs4, subs4.c.othername == table3.c.otherstuff) ) @@ -2855,13 +2793,13 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): t1 = table("QuotedName", column("col1")) s6 = ( - select([t1.c.col1]) + select(t1.c.col1) .where(t1.c.col1 > 10) .with_hint(t1, "%(name)s idx1") ) a2 = t1.alias("SomeName") s7 = ( - select([a2.c.col1]) + select(a2.c.col1) .where(a2.c.col1 > 10) .with_hint(a2, "%(name)s idx1") ) @@ -2972,7 +2910,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_statement_hints(self): stmt = ( - select([table1.c.myid]) + select(table1.c.myid) .with_statement_hint("test hint one") .with_statement_hint("test hint two", "mysql") ) @@ -3009,8 +2947,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): expected_test_params_list, ) in [ ( - select( - [table1, table2], + select(table1, table2).where( and_( table1.c.myid == table2.c.otherid, table1.c.name == bindparam("mytablename"), @@ -3031,8 +2968,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): [5], ), ( - select( - [table1], + select(table1).where( or_( table1.c.myid == bindparam("myid"), table2.c.otherid == bindparam("myid"), @@ -3070,8 +3006,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): [5, 5], ), ( - select( - [table1], + select(table1).where( or_( table1.c.myid == bindparam("myid", unique=True), table2.c.otherid == bindparam("myid", unique=True), @@ -3102,13 +3037,14 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ( # testing select.params() here - bindparam() objects # must get required flag set to False - select( - [table1], + select(table1) + .where( or_( table1.c.myid == bindparam("myid"), table2.c.otherid == bindparam("myotherid"), ), - ).params({"myid": 8, "myotherid": 7}), + ) + .params({"myid": 8, "myotherid": 7}), "SELECT mytable.myid, mytable.name, mytable.description FROM " "mytable, myothertable WHERE mytable.myid = " ":myid OR myothertable.otherid = :myotherid", @@ -3122,8 +3058,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): [5, 7], ), ( - select( - [table1], + select(table1).where( or_( table1.c.myid == bindparam("myid", value=7, unique=True), @@ -3170,8 +3105,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ) # check that params() doesn't modify original statement - s = select( - [table1], + s = select(table1).where( or_( table1.c.myid == bindparam("myid"), table2.c.otherid == bindparam("myotherid"), @@ -3184,12 +3118,8 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): assert s3.compile().params == {"myid": 9, "myotherid": 7} # test using same 'unique' param object twice in one compile - s = ( - select([table1.c.myid]) - .where(table1.c.myid == 12) - .scalar_subquery() - ) - s2 = select([table1, s], table1.c.myid == s) + s = select(table1.c.myid).where(table1.c.myid == 12).scalar_subquery() + s2 = select(table1, s).where(table1.c.myid == s) self.assert_compile( s2, "SELECT mytable.myid, mytable.name, mytable.description, " @@ -3203,8 +3133,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): assert [pp[k] for k in positional.positiontup] == [12, 12] # check that conflicts with "unique" params are caught - s = select( - [table1], + s = select(table1).where( or_(table1.c.myid == 7, table1.c.myid == bindparam("myid_1")), ) assert_raises_message( @@ -3214,8 +3143,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): s, ) - s = select( - [table1], + s = select(table1).where( or_( table1.c.myid == 7, table1.c.myid == 8, @@ -3303,7 +3231,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): l = c.label(None) # new case as of Id810f485c5f7ed971529489b84694e02a3356d6d - subq = select([l]).subquery() + subq = select(l).subquery() # this creates a ColumnClause as a proxy to the Label() that has # an anoymous name, so the column has one too. @@ -3324,7 +3252,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): def test_bind_as_col(self): t = table("foo", column("id")) - s = select([t, literal("lala").label("hoho")]) + s = select(t, literal("lala").label("hoho")) self.assert_compile(s, "SELECT foo.id, :param_1 AS hoho FROM foo") assert [str(c) for c in s.subquery().c] == ["anon_1.id", "anon_1.hoho"] @@ -3337,7 +3265,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): assert_raises_message( exc.InvalidRequestError, r"A value is required for bind parameter 'x'", - select([table1]) + select(table1) .where( and_( table1.c.myid == bindparam("x", required=True), @@ -3352,7 +3280,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): assert_raises_message( exc.InvalidRequestError, r"A value is required for bind parameter 'x'", - select([table1]) + select(table1) .where(table1.c.myid == bindparam("x", required=True)) .compile() .construct_params, @@ -3362,7 +3290,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): exc.InvalidRequestError, r"A value is required for bind parameter 'x', " "in parameter group 2", - select([table1]) + select(table1) .where( and_( table1.c.myid == bindparam("x", required=True), @@ -3379,7 +3307,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): exc.InvalidRequestError, r"A value is required for bind parameter 'x', " "in parameter group 2", - select([table1]) + select(table1) .where(table1.c.myid == bindparam("x", required=True)) .compile() .construct_params, @@ -3388,19 +3316,19 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): @testing.combinations( ( - select([table1]).where(table1.c.myid == 5), - select([table1]).where(table1.c.myid == 10), + select(table1).where(table1.c.myid == 5), + select(table1).where(table1.c.myid == 10), {"myid_1": 5}, {"myid_1": 10}, None, None, ), ( - select([table1]).where( + select(table1).where( table1.c.myid == bindparam(None, unique=True, callable_=lambda: 5) ), - select([table1]).where( + select(table1).where( table1.c.myid == bindparam(None, unique=True, callable_=lambda: 10) ), @@ -3445,12 +3373,12 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ), ( union( - select([table1]).where(table1.c.myid == 5), - select([table1]).where(table1.c.myid == 12), + select(table1).where(table1.c.myid == 5), + select(table1).where(table1.c.myid == 12), ), union( - select([table1]).where(table1.c.myid == 5), - select([table1]).where(table1.c.myid == 15), + select(table1).where(table1.c.myid == 5), + select(table1).where(table1.c.myid == 15), ), {"myid_1": 5, "myid_2": 12}, {"myid_1": 5, "myid_2": 15}, @@ -3512,7 +3440,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): """ - stmt = select([table1.c.myid]).where(table1.c.myid == 5) + stmt = select(table1.c.myid).where(table1.c.myid == 5) # get the original bindparam. original_bind = stmt._where_criteria[0].right @@ -3551,7 +3479,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ) # now make a totally new statement with the same cache key - new_stmt = select([table1.c.myid]).where(table1.c.myid == 10) + new_stmt = select(table1.c.myid).where(table1.c.myid == 10) new_cache_key = new_stmt._generate_cache_key() # cache keys match @@ -3580,7 +3508,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): """ - stmt = select([table1.c.myid]).where(table1.c.myid == 5) + stmt = select(table1.c.myid).where(table1.c.myid == 5) original_bind = stmt._where_criteria[0].right # it's anonymous so unique=True @@ -3593,7 +3521,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): # make a new statement that uses the clones as distinct # parameters - modified_stmt = select([table1.c.myid]).where( + modified_stmt = select(table1.c.myid).where( or_(table1.c.myid == b1, table1.c.myid == b2) ) @@ -3606,14 +3534,14 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): # make a new statement doing the same thing and make sure # the binds match up correctly - new_stmt = select([table1.c.myid]).where(table1.c.myid == 8) + new_stmt = select(table1.c.myid).where(table1.c.myid == 8) new_original_bind = new_stmt._where_criteria[0].right new_b1 = new_original_bind._clone() new_b1.value = 20 new_b2 = new_original_bind._clone() new_b2.value = 18 - modified_new_stmt = select([table1.c.myid]).where( + modified_new_stmt = select(table1.c.myid).where( or_(table1.c.myid == new_b1, table1.c.myid == new_b2) ) @@ -3711,7 +3639,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): self.assert_compile( tuple_(table1.c.myid, table1.c.name).in_( - select([table2.c.otherid, table2.c.othername]) + select(table2.c.otherid, table2.c.othername) ), "(mytable.myid, mytable.name) IN (SELECT " "myothertable.otherid, myothertable.othername FROM myothertable)", @@ -3741,13 +3669,13 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ) def test_limit_offset_select_literal_binds(self): - stmt = select([1]).limit(5).offset(6) + stmt = select(1).limit(5).offset(6) self.assert_compile( stmt, "SELECT 1 LIMIT 5 OFFSET 6", literal_binds=True ) def test_limit_offset_compound_select_literal_binds(self): - stmt = select([1]).union(select([2])).limit(5).offset(6) + stmt = select(1).union(select(2)).limit(5).offset(6) self.assert_compile( stmt, "SELECT 1 UNION SELECT 2 LIMIT 5 OFFSET 6", @@ -3756,8 +3684,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): def test_multiple_col_binds(self): self.assert_compile( - select( - [literal_column("*")], + select(literal_column("*")).where( or_( table1.c.myid == 12, table1.c.myid == "asdf", @@ -3782,7 +3709,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): @testing.combinations( ( "one", - select([literal("someliteral")]), + select(literal("someliteral")), "SELECT [POSTCOMPILE_param_1] AS anon_1", dict( check_literal_execute={"param_1": "someliteral"}, @@ -3791,14 +3718,14 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ), ( "two", - select([table1.c.myid + 3]), + select(table1.c.myid + 3), "SELECT mytable.myid + [POSTCOMPILE_myid_1] " "AS anon_1 FROM mytable", dict(check_literal_execute={"myid_1": 3}, check_post_param={}), ), ( "three", - select([table1.c.myid.in_([4, 5, 6])]), + select(table1.c.myid.in_([4, 5, 6])), "SELECT mytable.myid IN ([POSTCOMPILE_myid_1]) " "AS anon_1 FROM mytable", dict( @@ -3808,14 +3735,14 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ), ( "four", - select([func.mod(table1.c.myid, 5)]), + select(func.mod(table1.c.myid, 5)), "SELECT mod(mytable.myid, [POSTCOMPILE_mod_2]) " "AS mod_1 FROM mytable", dict(check_literal_execute={"mod_2": 5}, check_post_param={}), ), ( "five", - select([literal("foo").in_([])]), + select(literal("foo").in_([])), "SELECT [POSTCOMPILE_param_1] IN ([POSTCOMPILE_param_2]) " "AS anon_1", dict( @@ -3825,7 +3752,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ), ( "six", - select([literal(util.b("foo"))]), + select(literal(util.b("foo"))), "SELECT [POSTCOMPILE_param_1] AS anon_1", dict( check_literal_execute={"param_1": util.b("foo")}, @@ -3834,7 +3761,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): ), ( "seven", - select([table1.c.myid == bindparam("foo", callable_=lambda: 5)]), + select(table1.c.myid == bindparam("foo", callable_=lambda: 5)), "SELECT mytable.myid = [POSTCOMPILE_foo] AS anon_1 FROM mytable", dict(check_literal_execute={"foo": 5}, check_post_param={}), ), @@ -3853,7 +3780,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): def test_render_literal_execute_parameter(self): self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( table1.c.myid == bindparam("foo", 5, literal_execute=True) ), "SELECT mytable.myid FROM mytable " @@ -3862,7 +3789,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): def test_render_literal_execute_parameter_literal_binds(self): self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( table1.c.myid == bindparam("foo", 5, literal_execute=True) ), "SELECT mytable.myid FROM mytable " "WHERE mytable.myid = 5", @@ -3871,7 +3798,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): def test_render_literal_execute_parameter_render_postcompile(self): self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( table1.c.myid == bindparam("foo", 5, literal_execute=True) ), "SELECT mytable.myid FROM mytable " "WHERE mytable.myid = 5", @@ -3880,7 +3807,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): def test_render_expanding_parameter(self): self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( table1.c.myid.in_(bindparam("foo", expanding=True)) ), "SELECT mytable.myid FROM mytable " @@ -3889,7 +3816,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): def test_render_expanding_parameter_literal_binds(self): self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( table1.c.myid.in_(bindparam("foo", [1, 2, 3], expanding=True)) ), "SELECT mytable.myid FROM mytable " @@ -3902,7 +3829,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): # parameters on the fly. self.assert_compile( - select([table1.c.myid]).where( + select(table1.c.myid).where( table1.c.myid.in_(bindparam("foo", [1, 2, 3], expanding=True)) ), "SELECT mytable.myid FROM mytable " @@ -3959,7 +3886,7 @@ class UnsupportedTest(fixtures.TestBase): class StringifySpecialTest(fixtures.TestBase): def test_basic(self): - stmt = select([table1]).where(table1.c.myid == 10) + stmt = select(table1).where(table1.c.myid == 10) eq_ignore_whitespace( str(stmt), "SELECT mytable.myid, mytable.name, mytable.description " @@ -3972,8 +3899,8 @@ class StringifySpecialTest(fixtures.TestBase): def test_cte(self): # stringify of these was supported anyway by defaultdialect. - stmt = select([table1.c.myid]).cte() - stmt = select([stmt]) + stmt = select(table1.c.myid).cte() + stmt = select(stmt) eq_ignore_whitespace( str(stmt), "WITH anon_1 AS (SELECT mytable.myid AS myid FROM mytable) " @@ -4001,7 +3928,7 @@ class StringifySpecialTest(fixtures.TestBase): ) def test_array_index(self): - stmt = select([column("foo", types.ARRAY(Integer))[5]]) + stmt = select(column("foo", types.ARRAY(Integer))[5]) eq_ignore_whitespace(str(stmt), "SELECT foo[:foo_1] AS anon_1") @@ -4009,7 +3936,7 @@ class StringifySpecialTest(fixtures.TestBase): class MyType(types.TypeEngine): __visit_name__ = "mytype" - stmt = select([cast(table1.c.myid, MyType)]) + stmt = select(cast(table1.c.myid, MyType)) eq_ignore_whitespace( str(stmt), @@ -4021,10 +3948,8 @@ class StringifySpecialTest(fixtures.TestBase): from sqlalchemy import within_group stmt = select( - [ - table1.c.myid, - within_group(func.percentile_cont(0.5), table1.c.name.desc()), - ] + table1.c.myid, + within_group(func.percentile_cont(0.5), table1.c.name.desc()), ) eq_ignore_whitespace( str(stmt), @@ -4049,7 +3974,7 @@ class StringifySpecialTest(fixtures.TestBase): def test_with_hint_table(self): stmt = ( - select([table1]) + select(table1) .select_from( table1.join(table2, table1.c.myid == table2.c.otherid) ) @@ -4067,7 +3992,7 @@ class StringifySpecialTest(fixtures.TestBase): def test_with_hint_statement(self): stmt = ( - select([table1]) + select(table1) .select_from( table1.join(table2, table1.c.myid == table2.c.otherid) ) @@ -4117,7 +4042,7 @@ class KwargPropagationTest(fixtures.TestBase): def test_select(self): s = ( - select([self.column]) + select(self.column) .select_from(self.table) .where(self.column == self.criterion) .order_by(self.column) @@ -4149,7 +4074,7 @@ class ExecutionOptionsTest(fixtures.TestBase): def test_embedded_element_true_to_none(self): stmt = table1.insert().cte() eq_(stmt._execution_options, {"autocommit": True}) - s2 = select([table1]).select_from(stmt) + s2 = select(table1).select_from(stmt) eq_(s2._execution_options, {}) compiled = s2.compile() @@ -4159,7 +4084,7 @@ class ExecutionOptionsTest(fixtures.TestBase): stmt = table1.insert().cte() eq_(stmt._execution_options, {"autocommit": True}) s2 = ( - select([table1]) + select(table1) .select_from(stmt) .execution_options(autocommit=False) ) @@ -4425,7 +4350,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - table4.select( + table4.select().where( and_(table4.c.datatype_id == 7, table4.c.value == "hi") ), "SELECT remote_owner.remotetable.rem_id, " @@ -4436,9 +4361,10 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): " remote_owner.remotetable.value = :value_1", ) - s = table4.select( - and_(table4.c.datatype_id == 7, table4.c.value == "hi"), - use_labels=True, + s = ( + table4.select() + .where(and_(table4.c.datatype_id == 7, table4.c.value == "hi")) + .apply_labels() ) self.assert_compile( s, @@ -4464,7 +4390,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): # multi-part schema name labels - convert '.' to '_' self.assert_compile( - table5.select(use_labels=True), + table5.select().apply_labels(), 'SELECT "dbo.remote_owner".remotetable.rem_id AS' " dbo_remote_owner_remotetable_rem_id, " '"dbo.remote_owner".remotetable.datatype_id' @@ -4505,7 +4431,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): schema_translate_map = {"remote_owner": "foob"} self.assert_compile( - select([table1, table4]).select_from( + select(table1, table4).select_from( join(table1, table4, table1.c.myid == table4.c.rem_id) ), "SELECT mytable.myid, mytable.name, mytable.description, " @@ -4537,7 +4463,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): alias = table1.alias() stmt = ( - select([table2, alias]) + select(table2, alias) .select_from(table2.join(alias, table2.c.otherid == alias.c.myid)) .where(alias.c.name == "foo") ) @@ -4628,7 +4554,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): def test_alias(self): a = alias(table4, "remtable") self.assert_compile( - a.select(a.c.datatype_id == 7), + a.select().where(a.c.datatype_id == 7), "SELECT remtable.rem_id, remtable.datatype_id, " "remtable.value FROM" " remote_owner.remotetable AS remtable " @@ -4637,16 +4563,16 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): def test_update(self): self.assert_compile( - table4.update( - table4.c.value == "test", values={table4.c.datatype_id: 12} - ), + table4.update() + .where(table4.c.value == "test") + .values({table4.c.datatype_id: 12}), "UPDATE remote_owner.remotetable SET datatype_id=:datatype_id " "WHERE remote_owner.remotetable.value = :value_1", ) def test_insert(self): self.assert_compile( - table4.insert(values=(2, 5, "test")), + table4.insert().values((2, 5, "test")), "INSERT INTO remote_owner.remotetable " "(rem_id, datatype_id, value) VALUES " "(:rem_id, :datatype_id, :value)", @@ -4656,7 +4582,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): # test that "schema" works correctly when passed to table t1 = table("foo", column("a"), column("b"), schema="bar") self.assert_compile( - select([t1]).select_from(t1), + select(t1).select_from(t1), "SELECT bar.foo.a, bar.foo.b FROM bar.foo", ) @@ -4664,7 +4590,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): # test alias behavior t1 = table("foo", schema="bar") self.assert_compile( - select(["*"]).select_from(t1.alias("t")), + select("*").select_from(t1.alias("t")), "SELECT * FROM bar.foo AS t", ) @@ -4679,7 +4605,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([t1]).select_from(t1).apply_labels(), + select(t1).select_from(t1).apply_labels(), "SELECT here.baz.id AS here_baz_id, here.baz.name AS " "here_baz_name, here.baz.meta AS here_baz_meta FROM here.baz", ) @@ -4697,7 +4623,7 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): .columns(id=Integer, name=String) .subquery() ) - stmt = select([t1.c.anotherid]).select_from( + stmt = select(t1.c.anotherid).select_from( t1.join(s, t1.c.anotherid == s.c.id) ) compiled = stmt.compile() @@ -4732,7 +4658,7 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_dont_overcorrelate(self): self.assert_compile( - select([table1]) + select(table1) .select_from(table1) .select_from(table1.select().subquery()), "SELECT mytable.myid, mytable.name, " @@ -4745,7 +4671,7 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def _fixture(self): t1 = table("t1", column("a")) t2 = table("t2", column("a")) - return t1, t2, select([t1]).where(t1.c.a == t2.c.a) + return t1, t2, select(t1).where(t1.c.a == t2.c.a) def _assert_where_correlated(self, stmt): self.assert_compile( @@ -4838,29 +4764,29 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_correlate_semiauto_where(self): t1, t2, s1 = self._fixture() self._assert_where_correlated( - select([t2]).where(t2.c.a == s1.correlate(t2).scalar_subquery()) + select(t2).where(t2.c.a == s1.correlate(t2).scalar_subquery()) ) def test_correlate_semiauto_column(self): t1, t2, s1 = self._fixture() self._assert_column_correlated( - select([t2, s1.correlate(t2).scalar_subquery()]) + select(t2, s1.correlate(t2).scalar_subquery()) ) def test_correlate_semiauto_from(self): t1, t2, s1 = self._fixture() - self._assert_from_uncorrelated(select([t2, s1.correlate(t2).alias()])) + self._assert_from_uncorrelated(select(t2, s1.correlate(t2).alias())) def test_correlate_semiauto_having(self): t1, t2, s1 = self._fixture() self._assert_having_correlated( - select([t2]).having(t2.c.a == s1.correlate(t2).scalar_subquery()) + select(t2).having(t2.c.a == s1.correlate(t2).scalar_subquery()) ) def test_correlate_except_inclusion_where(self): t1, t2, s1 = self._fixture() self._assert_where_correlated( - select([t2]).where( + select(t2).where( t2.c.a == s1.correlate_except(t1).scalar_subquery() ) ) @@ -4868,7 +4794,7 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_correlate_except_exclusion_where(self): t1, t2, s1 = self._fixture() self._assert_where_uncorrelated( - select([t2]).where( + select(t2).where( t2.c.a == s1.correlate_except(t2).scalar_subquery() ) ) @@ -4876,31 +4802,31 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_correlate_except_inclusion_column(self): t1, t2, s1 = self._fixture() self._assert_column_correlated( - select([t2, s1.correlate_except(t1).scalar_subquery()]) + select(t2, s1.correlate_except(t1).scalar_subquery()) ) def test_correlate_except_exclusion_column(self): t1, t2, s1 = self._fixture() self._assert_column_uncorrelated( - select([t2, s1.correlate_except(t2).scalar_subquery()]) + select(t2, s1.correlate_except(t2).scalar_subquery()) ) def test_correlate_except_inclusion_from(self): t1, t2, s1 = self._fixture() self._assert_from_uncorrelated( - select([t2, s1.correlate_except(t1).alias()]) + select(t2, s1.correlate_except(t1).alias()) ) def test_correlate_except_exclusion_from(self): t1, t2, s1 = self._fixture() self._assert_from_uncorrelated( - select([t2, s1.correlate_except(t2).alias()]) + select(t2, s1.correlate_except(t2).alias()) ) def test_correlate_except_none(self): t1, t2, s1 = self._fixture() self._assert_where_all_correlated( - select([t1, t2]).where( + select(t1, t2).where( t2.c.a == s1.correlate_except(None).scalar_subquery() ) ) @@ -4908,7 +4834,7 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_correlate_except_having(self): t1, t2, s1 = self._fixture() self._assert_having_correlated( - select([t2]).having( + select(t2).having( t2.c.a == s1.correlate_except(t1).scalar_subquery() ) ) @@ -4916,51 +4842,49 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_correlate_auto_where(self): t1, t2, s1 = self._fixture() self._assert_where_correlated( - select([t2]).where(t2.c.a == s1.scalar_subquery()) + select(t2).where(t2.c.a == s1.scalar_subquery()) ) def test_correlate_auto_column(self): t1, t2, s1 = self._fixture() - self._assert_column_correlated(select([t2, s1.scalar_subquery()])) + self._assert_column_correlated(select(t2, s1.scalar_subquery())) def test_correlate_auto_from(self): t1, t2, s1 = self._fixture() - self._assert_from_uncorrelated(select([t2, s1.alias()])) + self._assert_from_uncorrelated(select(t2, s1.alias())) def test_correlate_auto_having(self): t1, t2, s1 = self._fixture() self._assert_having_correlated( - select([t2]).having(t2.c.a == s1.scalar_subquery()) + select(t2).having(t2.c.a == s1.scalar_subquery()) ) def test_correlate_disabled_where(self): t1, t2, s1 = self._fixture() self._assert_where_uncorrelated( - select([t2]).where(t2.c.a == s1.correlate(None).scalar_subquery()) + select(t2).where(t2.c.a == s1.correlate(None).scalar_subquery()) ) def test_correlate_disabled_column(self): t1, t2, s1 = self._fixture() self._assert_column_uncorrelated( - select([t2, s1.correlate(None).scalar_subquery()]) + select(t2, s1.correlate(None).scalar_subquery()) ) def test_correlate_disabled_from(self): t1, t2, s1 = self._fixture() - self._assert_from_uncorrelated( - select([t2, s1.correlate(None).alias()]) - ) + self._assert_from_uncorrelated(select(t2, s1.correlate(None).alias())) def test_correlate_disabled_having(self): t1, t2, s1 = self._fixture() self._assert_having_uncorrelated( - select([t2]).having(t2.c.a == s1.correlate(None).scalar_subquery()) + select(t2).having(t2.c.a == s1.correlate(None).scalar_subquery()) ) def test_correlate_all_where(self): t1, t2, s1 = self._fixture() self._assert_where_all_correlated( - select([t1, t2]).where( + select(t1, t2).where( t2.c.a == s1.correlate(t1, t2).scalar_subquery() ) ) @@ -4968,13 +4892,13 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_correlate_all_column(self): t1, t2, s1 = self._fixture() self._assert_column_all_correlated( - select([t1, t2, s1.correlate(t1, t2).scalar_subquery()]) + select(t1, t2, s1.correlate(t1, t2).scalar_subquery()) ) def test_correlate_all_from(self): t1, t2, s1 = self._fixture() self._assert_from_all_uncorrelated( - select([t1, t2, s1.correlate(t1, t2).alias()]) + select(t1, t2, s1.correlate(t1, t2).alias()) ) def test_correlate_where_all_unintentional(self): @@ -4982,21 +4906,21 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): assert_raises_message( exc.InvalidRequestError, "returned no FROM clauses due to auto-correlation", - select([t1, t2]).where(t2.c.a == s1.scalar_subquery()).compile, + select(t1, t2).where(t2.c.a == s1.scalar_subquery()).compile, ) def test_correlate_from_all_ok(self): t1, t2, s1 = self._fixture() self.assert_compile( - select([t1, t2, s1.subquery()]), + select(t1, t2, s1.subquery()), "SELECT t1.a, t2.a, anon_1.a FROM t1, t2, " "(SELECT t1.a AS a FROM t1, t2 WHERE t1.a = t2.a) AS anon_1", ) def test_correlate_auto_where_singlefrom(self): t1, t2, s1 = self._fixture() - s = select([t1.c.a]) - s2 = select([t1]).where(t1.c.a == s.scalar_subquery()) + s = select(t1.c.a) + s2 = select(t1).where(t1.c.a == s.scalar_subquery()) self.assert_compile( s2, "SELECT t1.a FROM t1 WHERE t1.a = " "(SELECT t1.a FROM t1)" ) @@ -5004,17 +4928,17 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): def test_correlate_semiauto_where_singlefrom(self): t1, t2, s1 = self._fixture() - s = select([t1.c.a]) + s = select(t1.c.a) - s2 = select([t1]).where(t1.c.a == s.correlate(t1).scalar_subquery()) + s2 = select(t1).where(t1.c.a == s.correlate(t1).scalar_subquery()) self._assert_where_single_full_correlated(s2) def test_correlate_except_semiauto_where_singlefrom(self): t1, t2, s1 = self._fixture() - s = select([t1.c.a]) + s = select(t1.c.a) - s2 = select([t1]).where( + s2 = select(t1).where( t1.c.a == s.correlate_except(t2).scalar_subquery() ) self._assert_where_single_full_correlated(s2) @@ -5030,11 +4954,11 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): # new as of #2748 t1 = table("t1", column("a")) t2 = table("t2", column("a"), column("b")) - s = select([t2.c.b]).where(t1.c.a == t2.c.a) + s = select(t2.c.b).where(t1.c.a == t2.c.a) s = s.correlate_except(t2).alias("s") - s2 = select([func.foo(s.c.b)]).scalar_subquery() - s3 = select([t1], order_by=s2) + s2 = select(func.foo(s.c.b)).scalar_subquery() + s3 = select(t1).order_by(s2) self.assert_compile( s3, @@ -5057,7 +4981,7 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): s = s.correlate(p).subquery() s = exists().select_from(s).where(s.c.id == 1) - s = select([p]).where(s) + s = select(p).where(s) self.assert_compile( s, "SELECT parent.id FROM parent WHERE EXISTS (SELECT * " @@ -5075,7 +4999,7 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): t3 = table("t3", column("z")) s = ( - select([t1]) + select(t1) .where(t1.c.x == t2.c.y) .where(t2.c.y == t3.c.z) .correlate_except(t1) @@ -5091,9 +5015,9 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): t2 = table("t2", column("y")) t3 = table("t3", column("z")) - s = select([t1.c.x]).where(t1.c.x == t2.c.y) - s2 = select([t3.c.z]).where(t3.c.z == s.scalar_subquery()) - s3 = select([t1]).where(t1.c.x == s2.scalar_subquery()) + s = select(t1.c.x).where(t1.c.x == t2.c.y) + s2 = select(t3.c.z).where(t3.c.z == s.scalar_subquery()) + s3 = select(t1).where(t1.c.x == s2.scalar_subquery()) self.assert_compile( s3, @@ -5111,9 +5035,9 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): t1 = table("t1", column("x")) t2 = table("t2", column("y")) - s = select([t1.c.x]).where(t1.c.x == t2.c.y) - s2 = select([t2, s.subquery()]) - s3 = select([t1, s2.subquery()]) + s = select(t1.c.x).where(t1.c.x == t2.c.y) + s2 = select(t2, s.subquery()) + s3 = select(t1, s2.subquery()) self.assert_compile( s3, @@ -5135,19 +5059,19 @@ class CoercionTest(fixtures.TestBase, AssertsCompiledSQL): def test_coerce_bool_where(self): self.assert_compile( - select([self.bool_table]).where(self.bool_table.c.x), + select(self.bool_table).where(self.bool_table.c.x), "SELECT t.x FROM t WHERE t.x", ) def test_coerce_bool_where_non_native(self): self.assert_compile( - select([self.bool_table]).where(self.bool_table.c.x), + select(self.bool_table).where(self.bool_table.c.x), "SELECT t.x FROM t WHERE t.x = 1", dialect=default.DefaultDialect(supports_native_boolean=False), ) self.assert_compile( - select([self.bool_table]).where(~self.bool_table.c.x), + select(self.bool_table).where(~self.bool_table.c.x), "SELECT t.x FROM t WHERE t.x = 0", dialect=default.DefaultDialect(supports_native_boolean=False), ) @@ -5194,7 +5118,7 @@ class ResultMapTest(fixtures.TestBase): def test_compound_populates(self): t = Table("t", MetaData(), Column("a", Integer), Column("b", Integer)) - stmt = select([t]).union(select([t])) + stmt = select(t).union(select(t)) comp = stmt.compile() eq_( comp._create_result_map(), @@ -5206,8 +5130,8 @@ class ResultMapTest(fixtures.TestBase): def test_compound_not_toplevel_doesnt_populate(self): t = Table("t", MetaData(), Column("a", Integer), Column("b", Integer)) - subq = select([t]).union(select([t])).subquery() - stmt = select([t.c.a]).select_from(t.join(subq, t.c.a == subq.c.a)) + subq = select(t).union(select(t)).subquery() + stmt = select(t.c.a).select_from(t.join(subq, t.c.a == subq.c.a)) comp = stmt.compile() eq_( comp._create_result_map(), @@ -5216,7 +5140,7 @@ class ResultMapTest(fixtures.TestBase): def test_compound_only_top_populates(self): t = Table("t", MetaData(), Column("a", Integer), Column("b", Integer)) - stmt = select([t.c.a]).union(select([t.c.b])) + stmt = select(t.c.a).union(select(t.c.b)) comp = stmt.compile() eq_( comp._create_result_map(), @@ -5227,7 +5151,7 @@ class ResultMapTest(fixtures.TestBase): t = Table("t", MetaData(), Column("a", Integer)) l1 = t.c.a.label("bar") tc = type_coerce(t.c.a + "str", String) - stmt = select([t.c.a, l1, tc]) + stmt = select(t.c.a, l1, tc) comp = stmt.compile() tc_anon_label = comp._create_result_map()["anon_1"][1][0] eq_( @@ -5248,11 +5172,11 @@ class ResultMapTest(fixtures.TestBase): "t1", MetaData(), Column("a", Integer), Column("b", Integer) ) t2 = Table("t2", MetaData(), Column("t1_a", Integer)) - union = select([t2]).union(select([t2])).alias() + union = select(t2).union(select(t2)).alias() t1_alias = t1.alias() stmt = ( - select([t1, t1_alias]) + select(t1, t1_alias) .select_from(t1.join(union, t1.c.a == union.c.t1_a)) .apply_labels() ) @@ -5272,7 +5196,7 @@ class ResultMapTest(fixtures.TestBase): stmt = ( t2.insert() - .values(a=select([astring]).scalar_subquery()) + .values(a=select(astring).scalar_subquery()) .returning(aint) ) comp = stmt.compile(dialect=postgresql.dialect()) @@ -5288,9 +5212,7 @@ class ResultMapTest(fixtures.TestBase): Table("t1", m, astring) t2 = Table("t2", m, aint) - stmt = ( - t2.insert().from_select(["a"], select([astring])).returning(aint) - ) + stmt = t2.insert().from_select(["a"], select(astring)).returning(aint) comp = stmt.compile(dialect=postgresql.dialect()) eq_( comp._create_result_map(), @@ -5300,9 +5222,9 @@ class ResultMapTest(fixtures.TestBase): def test_nested_api(self): from sqlalchemy.engine.cursor import CursorResultMetaData - stmt2 = select([table2]).subquery() + stmt2 = select(table2).subquery() - stmt1 = select([table1]).select_from(stmt2) + stmt1 = select(table1).select_from(stmt2) contexts = {} @@ -5387,13 +5309,13 @@ class ResultMapTest(fixtures.TestBase): l1, l2, l3 = t.c.z.label("a"), t.c.x.label("b"), t.c.x.label("c") orig = [t.c.x, t.c.y, l1, l2, l3] - stmt = select(orig) + stmt = select(*orig) wrapped = stmt._generate() wrapped = wrapped.add_columns( func.ROW_NUMBER().over(order_by=t.c.z) ).alias() - wrapped_again = select([c for c in wrapped.c]) + wrapped_again = select(*[c for c in wrapped.c]) dialect = default.DefaultDialect() @@ -5420,7 +5342,7 @@ class ResultMapTest(fixtures.TestBase): # create the statement with some duplicate columns. right now # the behavior is that these redundant columns are deduped. - stmt = select([t.c.x, t.c.y, l1, t.c.y, l2, t.c.x, l3]) + stmt = select(t.c.x, t.c.y, l1, t.c.y, l2, t.c.x, l3) # so the statement has 7 inner columns... eq_(len(list(stmt.selected_columns)), 7) @@ -5444,7 +5366,7 @@ class ResultMapTest(fixtures.TestBase): ).alias() # so when we wrap here we're going to have only 5 columns - wrapped_again = select([c for c in wrapped.c]) + wrapped_again = select(*[c for c in wrapped.c]) # so the compiler logic that matches up the "wrapper" to the # "select_wraps_for" can't use inner_columns to match because diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 16bd25b3f..0210f4d41 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -7,6 +7,7 @@ from sqlalchemy import CHAR from sqlalchemy import column from sqlalchemy import create_engine from sqlalchemy import exc +from sqlalchemy import exists from sqlalchemy import ForeignKey from sqlalchemy import func from sqlalchemy import INT @@ -180,7 +181,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_select_of_select(self): - stmt = select([self.table1.c.myid]) + stmt = select(self.table1.c.myid) with testing.expect_deprecated( r"The SelectBase.select\(\) method is deprecated and will be " @@ -192,63 +193,16 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): "FROM mytable) AS anon_1", ) - def test_join_of_select(self): - stmt = select([self.table1.c.myid]) - - with testing.expect_deprecated( - r"The SelectBase.join\(\) method is deprecated and will be " - "removed" - ): - self.assert_compile( - stmt.join( - self.table2, self.table2.c.otherid == self.table1.c.myid - ), - # note the SQL is wrong here as the subquery now has a name. - # however, even SQLite which accepts unnamed subqueries in a - # JOIN cannot actually join with how SQLAlchemy 1.3 and - # earlier would render: - # sqlite> select myid, otherid from (select myid from mytable) - # join myothertable on mytable.myid=myothertable.otherid; - # Error: no such column: mytable.myid - # if using stmt.c.col, that fails often as well if there are - # any naming overlaps: - # sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) - # ambiguous column name: id - # [SQL: SELECT id, data - # FROM (SELECT a.id AS id, a.data AS data - # FROM a) JOIN b ON b.a_id = id] - # so that shows that nobody is using this anyway - "(SELECT mytable.myid AS myid FROM mytable) AS anon_1 " - "JOIN myothertable ON myothertable.otherid = mytable.myid", - ) - - def test_outerjoin_of_select(self): - stmt = select([self.table1.c.myid]) - - with testing.expect_deprecated( - r"The SelectBase.outerjoin\(\) method is deprecated and will be " - "removed" - ): - self.assert_compile( - stmt.outerjoin( - self.table2, self.table2.c.otherid == self.table1.c.myid - ), - # note the SQL is wrong here as the subquery now has a name - "(SELECT mytable.myid AS myid FROM mytable) AS anon_1 " - "LEFT OUTER JOIN myothertable " - "ON myothertable.otherid = mytable.myid", - ) - def test_standalone_alias(self): with testing.expect_deprecated( "Implicit coercion of SELECT and textual SELECT constructs" ): - stmt = alias(select([self.table1.c.myid]), "foo") + stmt = alias(select(self.table1.c.myid), "foo") self.assert_compile(stmt, "SELECT mytable.myid FROM mytable") is_true( - stmt.compare(select([self.table1.c.myid]).subquery().alias("foo")) + stmt.compare(select(self.table1.c.myid).subquery().alias("foo")) ) def test_as_scalar(self): @@ -256,21 +210,21 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): r"The SelectBase.as_scalar\(\) method is deprecated and " "will be removed in a future release." ): - stmt = select([self.table1.c.myid]).as_scalar() + stmt = select(self.table1.c.myid).as_scalar() - is_true(stmt.compare(select([self.table1.c.myid]).scalar_subquery())) + is_true(stmt.compare(select(self.table1.c.myid).scalar_subquery())) def test_as_scalar_from_subquery(self): with testing.expect_deprecated( r"The Subquery.as_scalar\(\) method, which was previously " r"``Alias.as_scalar\(\)`` prior to version 1.4" ): - stmt = select([self.table1.c.myid]).subquery().as_scalar() + stmt = select(self.table1.c.myid).subquery().as_scalar() - is_true(stmt.compare(select([self.table1.c.myid]).scalar_subquery())) + is_true(stmt.compare(select(self.table1.c.myid).scalar_subquery())) def test_fromclause_subquery(self): - stmt = select([self.table1.c.myid]) + stmt = select(self.table1.c.myid) with testing.expect_deprecated( "Implicit coercion of SELECT and textual SELECT constructs " "into FROM clauses is deprecated" @@ -288,11 +242,11 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): ): element = coercions.expect( roles.FromClauseRole, - SelectStatementGrouping(select([self.table1])), + SelectStatementGrouping(select(self.table1)), ) is_true( element.compare( - SelectStatementGrouping(select([self.table1])).subquery() + SelectStatementGrouping(select(self.table1)).subquery() ) ) @@ -302,7 +256,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): "Implicit coercion of SELECT and textual SELECT constructs " "into FROM clauses is deprecated" ): - stmt = select(["*"]).select_from(expr.select()) + stmt = select("*").select_from(expr.select()) self.assert_compile( stmt, "SELECT * FROM (SELECT rows(:rows_2) AS rows_1) AS anon_1" ) @@ -311,11 +265,8 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): users = table( "users", column("id"), column("name"), column("fullname") ) - calculate = select( - [column("q"), column("z"), column("r")], - from_obj=[ - func.calculate(bindparam("x", None), bindparam("y", None)) - ], + calculate = select(column("q"), column("z"), column("r")).select_from( + func.calculate(bindparam("x", None), bindparam("y", None)) ) with testing.expect_deprecated( @@ -323,7 +274,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): "deprecated and will be removed" ): self.assert_compile( - select([users], users.c.id > calculate.c.z), + select(users).where(users.c.id > calculate.c.z), "SELECT users.id, users.name, users.fullname " "FROM users, (SELECT q, z, r " "FROM calculate(:x, :y)) AS anon_1 " @@ -397,6 +348,129 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): "deprecated" ) + def test_select_list_argument(self): + + with testing.expect_deprecated_20( + r"The legacy calling style of select\(\) is deprecated " + "and will be removed in SQLAlchemy 2.0" + ): + stmt = select([column("q")]) + self.assert_compile(stmt, "SELECT q") + + def test_select_kw_argument(self): + + with testing.expect_deprecated_20( + r"The legacy calling style of select\(\) is deprecated " + "and will be removed in SQLAlchemy 2.0" + ): + stmt = select(whereclause=column("q") == 5).add_columns( + column("q") + ) + self.assert_compile(stmt, "SELECT q WHERE q = :q_1") + + @testing.combinations( + ( + lambda table1: table1.select(table1.c.col1 == 5), + "FromClause", + "whereclause", + "SELECT table1.col1, table1.col2, table1.col3, table1.colx " + "FROM table1 WHERE table1.col1 = :col1_1", + ), + ( + lambda table1: table1.select(whereclause=table1.c.col1 == 5), + "FromClause", + "whereclause", + "SELECT table1.col1, table1.col2, table1.col3, table1.colx " + "FROM table1 WHERE table1.col1 = :col1_1", + ), + ( + lambda table1: table1.select(order_by=table1.c.col1), + "FromClause", + "kwargs", + "SELECT table1.col1, table1.col2, table1.col3, table1.colx " + "FROM table1 ORDER BY table1.col1", + ), + ( + lambda table1: exists().select(table1.c.col1 == 5), + "Exists", + "whereclause", + "SELECT EXISTS (SELECT *) AS anon_1 FROM table1 " + "WHERE table1.col1 = :col1_1", + ), + ( + lambda table1: exists().select(whereclause=table1.c.col1 == 5), + "Exists", + "whereclause", + "SELECT EXISTS (SELECT *) AS anon_1 FROM table1 " + "WHERE table1.col1 = :col1_1", + ), + ( + lambda table1: exists().select( + order_by=table1.c.col1, from_obj=table1 + ), + "Exists", + "kwargs", + "SELECT EXISTS (SELECT *) AS anon_1 FROM table1 " + "ORDER BY table1.col1", + ), + ( + lambda table1, table2: table1.join(table2).select( + table1.c.col1 == 5 + ), + "Join", + "whereclause", + "SELECT table1.col1, table1.col2, table1.col3, table1.colx, " + "table2.col1, table2.col2, table2.col3, table2.coly FROM table1 " + "JOIN table2 ON table1.col1 = table2.col2 " + "WHERE table1.col1 = :col1_1", + ), + ( + lambda table1, table2: table1.join(table2).select( + whereclause=table1.c.col1 == 5 + ), + "Join", + "whereclause", + "SELECT table1.col1, table1.col2, table1.col3, table1.colx, " + "table2.col1, table2.col2, table2.col3, table2.coly FROM table1 " + "JOIN table2 ON table1.col1 = table2.col2 " + "WHERE table1.col1 = :col1_1", + ), + ( + lambda table1, table2: table1.join(table2).select( + order_by=table1.c.col1 + ), + "Join", + "kwargs", + "SELECT table1.col1, table1.col2, table1.col3, table1.colx, " + "table2.col1, table2.col2, table2.col3, table2.coly FROM table1 " + "JOIN table2 ON table1.col1 = table2.col2 " + "ORDER BY table1.col1", + ), + ) + def test_select_method_parameters( + self, stmt, clsname, paramname, expected_sql + ): + if paramname == "whereclause": + warning_txt = ( + r"The %s.select\(\).whereclause parameter is deprecated " + "and will be removed in version 2.0" % clsname + ) + else: + warning_txt = ( + r"The %s.select\(\) method will no longer accept " + "keyword arguments in version 2.0. " % clsname + ) + with testing.expect_deprecated_20( + warning_txt, + r"The legacy calling style of select\(\) is deprecated " + "and will be removed in SQLAlchemy 2.0", + ): + stmt = testing.resolve_lambda( + stmt, table1=self.table1, table2=self.table2 + ) + + self.assert_compile(stmt, expected_sql) + def test_deprecated_subquery_standalone(self): from sqlalchemy import subquery @@ -410,12 +484,12 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([stmt]), + select(stmt), "SELECT anon_1.a FROM (SELECT 1 AS a ORDER BY 1) AS anon_1", ) def test_column(self): - stmt = select([column("x")]) + stmt = select(column("x")) with testing.expect_deprecated( r"The Select.column\(\) method is deprecated and will be " "removed in a future release." @@ -425,13 +499,13 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile(stmt, "SELECT x, q") def test_append_column_after_replace_selectable(self): - basesel = select([literal_column("1").label("a")]) + basesel = select(literal_column("1").label("a")) tojoin = select( - [literal_column("1").label("a"), literal_column("2").label("b")] + literal_column("1").label("a"), literal_column("2").label("b") ) basefrom = basesel.alias("basefrom") joinfrom = tojoin.alias("joinfrom") - sel = select([basefrom.c.a]) + sel = select(basefrom.c.a) with testing.expect_deprecated( r"The Selectable.replace_selectable\(\) " "method is deprecated" @@ -460,7 +534,7 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): # test that corresponding column digs across # clone boundaries with anonymous labeled elements col = func.count().label("foo") - sel = select([col]) + sel = select(col) sel2 = visitors.ReplacingCloningVisitor().traverse(sel) with testing.expect_deprecated("The SelectBase.c"): @@ -480,29 +554,25 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): u = ( select( - [ - self.table1.c.col1, - self.table1.c.col2, - self.table1.c.col3, - self.table1.c.colx, - null().label("coly"), - ] + self.table1.c.col1, + self.table1.c.col2, + self.table1.c.col3, + self.table1.c.colx, + null().label("coly"), ) .union( select( - [ - self.table2.c.col1, - self.table2.c.col2, - self.table2.c.col3, - null().label("colx"), - self.table2.c.coly, - ] + self.table2.c.col1, + self.table2.c.col2, + self.table2.c.col3, + null().label("colx"), + self.table2.c.coly, ) ) .alias("analias") ) - s1 = self.table1.select(use_labels=True) - s2 = self.table2.select(use_labels=True) + s1 = self.table1.select().apply_labels() + s2 = self.table2.select().apply_labels() with self._c_deprecated(): assert u.corresponding_column(s1.c.table1_col2) is u.c.col2 assert u.corresponding_column(s2.c.table2_col2) is u.c.col2 @@ -510,7 +580,7 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): assert s2.c.corresponding_column(u.c.coly) is s2.c.table2_coly def test_join_against_self_implicit_subquery(self): - jj = select([self.table1.c.col1.label("bar_col1")]) + jj = select(self.table1.c.col1.label("bar_col1")) with testing.expect_deprecated( "The SelectBase.c and SelectBase.columns attributes are " "deprecated and will be removed", @@ -536,7 +606,7 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL): assert j2.corresponding_column(self.table1.c.col1) is j2.c.table1_col1 def test_select_labels(self): - a = self.table1.select(use_labels=True) + a = self.table1.select().apply_labels() j = join(a._implicit_subquery, self.table2) criterion = a._implicit_subquery.c.table1_col1 == self.table2.c.col2 @@ -555,7 +625,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): r"The SelectBase.select\(\) method is deprecated" ): self.assert_compile( - select([col]).select(), + select(col).select(), 'SELECT anon_1."NEEDS QUOTES" FROM ' '(SELECT NEEDS QUOTES AS "NEEDS QUOTES") AS anon_1', ) @@ -676,7 +746,7 @@ class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): def test_append_whereclause(self): t = table("t", column("q")) - stmt = select([t]) + stmt = select(t) with self._expect_deprecated("Select", "whereclause", "where"): stmt.append_whereclause(t.c.q == 5) @@ -685,7 +755,7 @@ class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): def test_append_having(self): t = table("t", column("q")) - stmt = select([t]).group_by(t.c.q) + stmt = select(t).group_by(t.c.q) with self._expect_deprecated("Select", "having", "having"): stmt.append_having(t.c.q == 5) @@ -696,7 +766,7 @@ class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): def test_append_order_by(self): t = table("t", column("q"), column("x")) - stmt = select([t]).where(t.c.q == 5) + stmt = select(t).where(t.c.q == 5) with self._expect_deprecated( "GenerativeSelect", "order_by", "order_by" @@ -709,7 +779,7 @@ class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): def test_append_group_by(self): t = table("t", column("q")) - stmt = select([t]) + stmt = select(t) with self._expect_deprecated( "GenerativeSelect", "group_by", "group_by" @@ -726,11 +796,11 @@ class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): t1 = table("t1", column("q")) t2 = table("t2", column("q"), column("p")) - inner = select([t2.c.p]).where(t2.c.q == t1.c.q) + inner = select(t2.c.p).where(t2.c.q == t1.c.q) with self._expect_deprecated("Select", "correlation", "correlate"): inner.append_correlation(t1) - stmt = select([t1]).where(t1.c.q == inner.scalar_subquery()) + stmt = select(t1).where(t1.c.q == inner.scalar_subquery()) self.assert_compile( stmt, @@ -740,14 +810,14 @@ class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): def test_append_column(self): t1 = table("t1", column("q"), column("p")) - stmt = select([t1.c.q]) + stmt = select(t1.c.q) with self._expect_deprecated("Select", "column", "column"): stmt.append_column(t1.c.p) self.assert_compile(stmt, "SELECT t1.q, t1.p FROM t1") def test_append_prefix(self): t1 = table("t1", column("q"), column("p")) - stmt = select([t1.c.q]) + stmt = select(t1.c.q) with self._expect_deprecated("Select", "prefix", "prefix_with"): stmt.append_prefix("FOO BAR") self.assert_compile(stmt, "SELECT FOO BAR t1.q FROM t1") @@ -756,7 +826,7 @@ class DeprecatedAppendMethTest(fixtures.TestBase, AssertsCompiledSQL): t1 = table("t1", column("q")) t2 = table("t2", column("q")) - stmt = select([t1]) + stmt = select(t1) with self._expect_deprecated("Select", "from", "select_from"): stmt.append_from(t1.join(t2, t1.c.q == t2.c.q)) self.assert_compile(stmt, "SELECT t1.q FROM t1 JOIN t2 ON t1.q = t2.q") @@ -808,7 +878,7 @@ class KeyTargetingTest(fixtures.TablesTest): def test_column_label_overlap_fallback(self, connection): content, bar = self.tables.content, self.tables.bar row = connection.execute( - select([content.c.type.label("content_type")]) + select(content.c.type.label("content_type")) ).first() not_in_(content.c.type, row) @@ -821,7 +891,7 @@ class KeyTargetingTest(fixtures.TablesTest): in_(sql.column("content_type"), row) row = connection.execute( - select([func.now().label("content_type")]) + select(func.now().label("content_type")) ).first() not_in_(content.c.type, row) not_in_(bar.c.content_type, row) @@ -839,7 +909,7 @@ class KeyTargetingTest(fixtures.TablesTest): # columns which the statement is against to be lightweight # cols, which results in a more liberal comparison scheme a, b = sql.column("a"), sql.column("b") - stmt = select([a, b]).select_from(table("keyed2")) + stmt = select(a, b).select_from(table("keyed2")) row = connection.execute(stmt).first() with testing.expect_deprecated( @@ -857,7 +927,7 @@ class KeyTargetingTest(fixtures.TablesTest): keyed2 = self.tables.keyed2 a, b = sql.column("a"), sql.column("b") - stmt = select([keyed2.c.a, keyed2.c.b]) + stmt = select(keyed2.c.a, keyed2.c.b) row = connection.execute(stmt).first() with testing.expect_deprecated( @@ -1040,7 +1110,7 @@ class CursorResultTest(fixtures.TablesTest): # this will create column() objects inside # the select(), these need to match on name anyway r = connection.execute( - select([column("user_id"), column("user_name")]) + select(column("user_id"), column("user_name")) .select_from(table("users")) .where(text("user_id=2")) ).first() @@ -1104,7 +1174,7 @@ class CursorResultTest(fixtures.TablesTest): self.metadata.create_all(testing.db) connection.execute(content.insert().values(type="t1")) - row = connection.execute(content.select(use_labels=True)).first() + row = connection.execute(content.select().apply_labels()).first() in_(content.c.type, row._mapping) not_in_(bar.c.content_type, row) with testing.expect_deprecated( @@ -1114,7 +1184,7 @@ class CursorResultTest(fixtures.TablesTest): in_(sql.column("content_type"), row) row = connection.execute( - select([content.c.type.label("content_type")]) + select(content.c.type.label("content_type")) ).first() with testing.expect_deprecated( "Retrieving row values using Column objects " @@ -1131,7 +1201,7 @@ class CursorResultTest(fixtures.TablesTest): in_(sql.column("content_type"), row) row = connection.execute( - select([func.now().label("content_type")]) + select(func.now().label("content_type")) ).first() not_in_(content.c.type, row) @@ -1158,10 +1228,12 @@ class CursorResultTest(fixtures.TablesTest): for pickle in False, True: for use_labels in False, True: + stmt = users.select() + if use_labels: + stmt = stmt.apply_labels() + result = conn.execute( - users.select(use_labels=use_labels).order_by( - users.c.user_id - ) + stmt.order_by(users.c.user_id) ).fetchall() if pickle: @@ -1241,10 +1313,8 @@ class CursorResultTest(fixtures.TablesTest): with eng.connect() as conn: row = conn.execute( select( - [ - literal_column("1").label("SOMECOL"), - literal_column("1").label("SOMECOL"), - ] + literal_column("1").label("SOMECOL"), + literal_column("1").label("SOMECOL"), ) ).first() @@ -1261,7 +1331,7 @@ class CursorResultTest(fixtures.TablesTest): "Using non-integer/slice indices on Row is deprecated " "and will be removed in version 2.0;" ): - row = connection.execute(select([col])).first() + row = connection.execute(select(col)).first() eq_(row["foo"], 1) eq_(row._mapping["foo"], 1) @@ -1273,7 +1343,7 @@ class CursorResultTest(fixtures.TablesTest): "Using non-integer/slice indices on Row is deprecated " "and will be removed in version 2.0;" ): - row = connection.execute(select([col])).first() + row = connection.execute(select(col)).first() eq_(row[col], 1) eq_(row._mapping[col], 1) @@ -1471,7 +1541,7 @@ class DefaultTest(fixtures.TestBase): def mydefault_using_connection(ctx): conn = ctx.connection try: - return conn.execute(select([text("12")])).scalar() + return conn.execute(select(text("12"))).scalar() finally: # ensure a "close()" on this connection does nothing, # since its a "branched" connection @@ -1493,7 +1563,7 @@ class DefaultTest(fixtures.TestBase): ): conn.execute(table.insert().values(x=5)) - eq_(conn.execute(select([table])).first(), (5, 12)) + eq_(conn.execute(select(table)).first(), (5, 12)) class DMLTest(fixtures.TestBase, AssertsCompiledSQL): @@ -1510,7 +1580,7 @@ class DMLTest(fixtures.TestBase, AssertsCompiledSQL): Column( "col2", Integer, - default=select([func.coalesce(func.max(foo.c.id))]), + default=select(func.coalesce(func.max(foo.c.id))), ), ) @@ -1564,7 +1634,7 @@ class DMLTest(fixtures.TestBase, AssertsCompiledSQL): Column( "col2", Integer, - onupdate=select([func.coalesce(func.max(foo.c.id))]), + onupdate=select(func.coalesce(func.max(foo.c.id))), ), Column("col3", String(30)), ) diff --git a/test/sql/test_external_traversal.py b/test/sql/test_external_traversal.py index fb2501667..aefcaf252 100644 --- a/test/sql/test_external_traversal.py +++ b/test/sql/test_external_traversal.py @@ -17,7 +17,6 @@ from sqlalchemy import testing from sqlalchemy import text from sqlalchemy import tuple_ from sqlalchemy import union -from sqlalchemy.future import select as future_select from sqlalchemy.sql import ClauseElement from sqlalchemy.sql import column from sqlalchemy.sql import operators @@ -165,7 +164,7 @@ class TraversalTest(fixtures.TestBase, AssertsExecutionResults): from sqlalchemy.sql.elements import Grouping c1 = Grouping(literal_column("q")) - s1 = select([c1]) + s1 = select(c1) class Vis(CloningVisitor): def visit_grouping(self, elem): @@ -308,7 +307,7 @@ class BinaryEndpointTraversalTest(fixtures.TestBase): def test_subquery(self): a, b, c = column("a"), column("b"), column("c") - subq = select([c]).where(c == a).scalar_subquery() + subq = select(c).where(c == a).scalar_subquery() expr = and_(a == b, b == subq) self._assert_traversal( expr, [(operators.eq, a, b), (operators.eq, b, subq)] @@ -342,7 +341,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): f = t.c.col1 * 5 self.assert_compile( - select([f]), "SELECT t1.col1 * :col1_1 AS anon_1 FROM t1" + select(f), "SELECT t1.col1 * :col1_1 AS anon_1 FROM t1" ) f.anon_label @@ -351,7 +350,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): f = sql_util.ClauseAdapter(a).traverse(f) self.assert_compile( - select([f]), "SELECT t1_1.col1 * :col1_1 AS anon_1 FROM t1 AS t1_1" + select(f), "SELECT t1_1.col1 * :col1_1 AS anon_1 FROM t1 AS t1_1" ) def test_join(self): @@ -379,21 +378,21 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): aliased ) - s = select([aliased2]).select_from(aliased) + s = select(aliased2).select_from(aliased) eq_(str(s), str(f)) f = select([adapter.columns[func.count(aliased2.c.col1)]]).select_from( aliased ) eq_( - str(select([func.count(aliased2.c.col1)]).select_from(aliased)), + str(select(func.count(aliased2.c.col1)).select_from(aliased)), str(f), ) def test_aliased_cloned_column_adapt_inner(self): - clause = select([t1.c.col1, func.foo(t1.c.col2).label("foo")]) + clause = select(t1.c.col1, func.foo(t1.c.col2).label("foo")) c_sub = clause.subquery() - aliased1 = select([c_sub.c.col1, c_sub.c.foo]).subquery() + aliased1 = select(c_sub.c.col1, c_sub.c.foo).subquery() aliased2 = clause aliased2.selected_columns.col1, aliased2.selected_columns.foo aliased3 = cloned_traverse(aliased2, {}, {}) @@ -408,11 +407,9 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): eq_(str(f1), str(f2)) def test_aliased_cloned_column_adapt_exported(self): - clause = select( - [t1.c.col1, func.foo(t1.c.col2).label("foo")] - ).subquery() + clause = select(t1.c.col1, func.foo(t1.c.col2).label("foo")).subquery() - aliased1 = select([clause.c.col1, clause.c.foo]).subquery() + aliased1 = select(clause.c.col1, clause.c.foo).subquery() aliased2 = clause aliased2.c.col1, aliased2.c.foo aliased3 = cloned_traverse(aliased2, {}, {}) @@ -427,11 +424,9 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): eq_(str(f1), str(f2)) def test_aliased_cloned_schema_column_adapt_exported(self): - clause = select( - [t3.c.col1, func.foo(t3.c.col2).label("foo")] - ).subquery() + clause = select(t3.c.col1, func.foo(t3.c.col2).label("foo")).subquery() - aliased1 = select([clause.c.col1, clause.c.foo]).subquery() + aliased1 = select(clause.c.col1, clause.c.foo).subquery() aliased2 = clause aliased2.c.col1, aliased2.c.foo aliased3 = cloned_traverse(aliased2, {}, {}) @@ -456,20 +451,20 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): lblx_adapted = adapter.traverse(lbl_x) self.assert_compile( - select([lblx_adapted.self_group()]), + select(lblx_adapted.self_group()), "SELECT (table3_1.col1 = :col1_1) AS x FROM table3 AS table3_1", ) self.assert_compile( - select([lblx_adapted.is_(True)]), + select(lblx_adapted.is_(True)), "SELECT (table3_1.col1 = :col1_1) IS 1 AS anon_1 " "FROM table3 AS table3_1", ) def test_cte_w_union(self): - t = select([func.values(1).label("n")]).cte("t", recursive=True) - t = t.union_all(select([t.c.n + 1]).where(t.c.n < 100)) - s = select([func.sum(t.c.n)]) + t = select(func.values(1).label("n")).cte("t", recursive=True) + t = t.union_all(select(t.c.n + 1).where(t.c.n < 100)) + s = select(func.sum(t.c.n)) from sqlalchemy.sql.visitors import cloned_traverse @@ -487,12 +482,12 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): def test_aliased_cte_w_union(self): t = ( - select([func.values(1).label("n")]) + select(func.values(1).label("n")) .cte("t", recursive=True) .alias("foo") ) - t = t.union_all(select([t.c.n + 1]).where(t.c.n < 100)) - s = select([func.sum(t.c.n)]) + t = t.union_all(select(t.c.n + 1).where(t.c.n < 100)) + s = select(func.sum(t.c.n)) from sqlalchemy.sql.visitors import cloned_traverse @@ -523,7 +518,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): assert set(clause2._bindparams.keys()) == set(["bar", "lala"]) def test_select(self): - s2 = select([t1]) + s2 = select(t1) s2_assert = str(s2) s3_assert = str(select([t1], t1.c.col2 == 7)) @@ -587,7 +582,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): eq_([str(c) for c in u2.selected_columns], cols) s1 = select([t1], t1.c.col1 == bindparam("id_param")) - s2 = select([t2]) + s2 = select(t2) u = union(s1, s2) u2 = u.params(id_param=7) @@ -664,13 +659,13 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_extract(self): - s = select([extract("foo", t1.c.col1).label("col1")]) + s = select(extract("foo", t1.c.col1).label("col1")) self.assert_compile( s, "SELECT EXTRACT(foo FROM table1.col1) AS col1 FROM table1" ) s2 = CloningVisitor().traverse(s).alias() - s3 = select([s2.c.col1]) + s3 = select(s2.c.col1) self.assert_compile( s, "SELECT EXTRACT(foo FROM table1.col1) AS col1 FROM table1" ) @@ -683,9 +678,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): @testing.emits_warning(".*replaced by another column with the same key") def test_alias(self): subq = t2.select().alias("subq") - s = select( - [t1.c.col1, subq.c.col1], - from_obj=[t1, subq, t1.join(subq, t1.c.col1 == subq.c.col2)], + s = select(t1.c.col1, subq.c.col1).select_from( + t1, subq, t1.join(subq, t1.c.col1 == subq.c.col2) ) orig = str(s) s2 = CloningVisitor().traverse(s) @@ -707,9 +701,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): eq_(str(s), str(s4)) subq = subq.alias("subq") - s = select( - [t1.c.col1, subq.c.col1], - from_obj=[t1, subq, t1.join(subq, t1.c.col1 == subq.c.col2)], + s = select(t1.c.col1, subq.c.col1).select_from( + t1, subq, t1.join(subq, t1.c.col1 == subq.c.col2), ) s5 = CloningVisitor().traverse(s) eq_(str(s), str(s5)) @@ -724,9 +717,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): select.where.non_generative(select, t1.c.col2 == 7) self.assert_compile( - select([t2]).where( - t2.c.col1 == Vis().traverse(s).scalar_subquery() - ), + select(t2).where(t2.c.col1 == Vis().traverse(s).scalar_subquery()), "SELECT table2.col1, table2.col2, table2.col3 " "FROM table2 WHERE table2.col1 = " "(SELECT * FROM table1 WHERE table1.col1 = table2.col1 " @@ -734,8 +725,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_this_thing(self): - s = select([t1]).where(t1.c.col1 == "foo").alias() - s2 = select([s.c.col1]) + s = select(t1).where(t1.c.col1 == "foo").alias() + s2 = select(s.c.col1) self.assert_compile( s2, @@ -756,12 +747,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_this_thing_using_setup_joins_one(self): - s = ( - future_select(t1) - .join_from(t1, t2, t1.c.col1 == t2.c.col2) - .subquery() - ) - s2 = future_select(s.c.col1).join_from(t3, s, t3.c.col2 == s.c.col1) + s = select(t1).join_from(t1, t2, t1.c.col1 == t2.c.col2).subquery() + s2 = select(s.c.col1).join_from(t3, s, t3.c.col2 == s.c.col1) self.assert_compile( s2, @@ -781,12 +768,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_this_thing_using_setup_joins_two(self): - s = ( - future_select(t1.c.col1) - .join(t2, t1.c.col1 == t2.c.col2) - .subquery() - ) - s2 = future_select(s.c.col1) + s = select(t1.c.col1).join(t2, t1.c.col1 == t2.c.col2).subquery() + s2 = select(s.c.col1) self.assert_compile( s2, @@ -812,7 +795,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): t1a = t1.alias() s = select([1], t1.c.col1 == t1a.c.col1, from_obj=t1a).correlate(t1a) - s = select([t1]).where(t1.c.col1 == s.scalar_subquery()) + s = select(t1).where(t1.c.col1 == s.scalar_subquery()) self.assert_compile( s, "SELECT table1.col1, table1.col2, table1.col3 FROM table1 " @@ -830,10 +813,10 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_select_fromtwice_two(self): - s = select([t1]).where(t1.c.col1 == "foo").alias() + s = select(t1).where(t1.c.col1 == "foo").alias() s2 = select([1], t1.c.col1 == s.c.col1, from_obj=s).correlate(t1) - s3 = select([t1]).where(t1.c.col1 == s2.scalar_subquery()) + s3 = select(t1).where(t1.c.col1 == s2.scalar_subquery()) self.assert_compile( s3, "SELECT table1.col1, table1.col2, table1.col3 " @@ -858,7 +841,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_select_setup_joins_adapt_element_one(self): - s = future_select(t1).join(t2, t1.c.col1 == t2.c.col2) + s = select(t1).join(t2, t1.c.col1 == t2.c.col2) t1a = t1.alias() @@ -877,7 +860,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_select_setup_joins_adapt_element_two(self): - s = future_select(literal_column("1")).join_from( + s = select(literal_column("1")).join_from( t1, t2, t1.c.col1 == t2.c.col2 ) @@ -895,7 +878,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_select_setup_joins_adapt_element_three(self): - s = future_select(literal_column("1")).join_from( + s = select(literal_column("1")).join_from( t1, t2, t1.c.col1 == t2.c.col2 ) @@ -913,7 +896,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_select_setup_joins_straight_clone(self): - s = future_select(t1).join(t2, t1.c.col1 == t2.c.col2) + s = select(t1).join(t2, t1.c.col1 == t2.c.col2) s2 = CloningVisitor().traverse(s) @@ -948,7 +931,7 @@ class ColumnAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1a = t1.alias() adapter = sql_util.ColumnAdapter(t1a, anonymize_labels=True) - expr = select([t1a.c.col1]).label("x") + expr = select(t1a.c.col1).label("x") expr_adapted = adapter.traverse(expr) is_not_(expr, expr_adapted) is_(adapter.columns[expr], expr_adapted) @@ -957,7 +940,7 @@ class ColumnAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1a = t1.alias() adapter = sql_util.ColumnAdapter(t1a, anonymize_labels=True) - expr = select([t1a.c.col1]).label("x") + expr = select(t1a.c.col1).label("x") expr_adapted = adapter.traverse(expr) is_not_(expr, expr_adapted) is_(adapter.traverse(expr), expr_adapted) @@ -966,7 +949,7 @@ class ColumnAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1a = t1.alias() adapter = sql_util.ColumnAdapter(t1a, anonymize_labels=True) - expr = select([t1a.c.col1]).label("x") + expr = select(t1a.c.col1).label("x") expr_adapted = adapter.columns[expr] is_not_(expr, expr_adapted) is_(adapter.columns[expr], expr_adapted) @@ -976,7 +959,7 @@ class ColumnAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t2a = t2.alias(name="t2a") a1 = sql_util.ColumnAdapter(t1a) - s1 = select([t1a.c.col1, t2a.c.col1]).apply_labels().alias() + s1 = select(t1a.c.col1, t2a.c.col1).apply_labels().alias() a2 = sql_util.ColumnAdapter(s1) a3 = a2.wrap(a1) a4 = a1.wrap(a2) @@ -1024,10 +1007,10 @@ class ColumnAdapterTest(fixtures.TestBase, AssertsCompiledSQL): """ - stmt = select([t1.c.col1, t2.c.col1]).apply_labels().subquery() + stmt = select(t1.c.col1, t2.c.col1).apply_labels().subquery() sa = stmt.alias() - stmt2 = select([t2, sa]).subquery() + stmt2 = select(t2, sa).subquery() a1 = sql_util.ColumnAdapter(stmt) a2 = sql_util.ColumnAdapter(stmt2) @@ -1061,7 +1044,7 @@ class ColumnAdapterTest(fixtures.TestBase, AssertsCompiledSQL): a2 = sql_util.ColumnAdapter(t2a) a3 = a2.wrap(a1) - stmt = select([t1.c.col1, t2.c.col2]) + stmt = select(t1.c.col1, t2.c.col2) self.assert_compile( a3.traverse(stmt), @@ -1086,7 +1069,7 @@ class ColumnAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1a, include_fn=lambda col: "a1" in col._annotations ) - s1 = select([t1a, t2a]).apply_labels().alias() + s1 = select(t1a, t2a).apply_labels().alias() a2 = sql_util.ColumnAdapter( s1, include_fn=lambda col: "a2" in col._annotations ) @@ -1184,12 +1167,12 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ) s = ( - select([literal_column("*")]) + select(literal_column("*")) .where(t1.c.col1 == t2.c.col1) .scalar_subquery() ) self.assert_compile( - select([t1.c.col1, s]), + select(t1.c.col1, s), "SELECT table1.col1, (SELECT * FROM table2 " "WHERE table1.col1 = table2.col1) AS " "anon_1 FROM table1", @@ -1197,26 +1180,26 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): vis = sql_util.ClauseAdapter(t1alias) s = vis.traverse(s) self.assert_compile( - select([t1alias.c.col1, s]), + select(t1alias.c.col1, s), "SELECT t1alias.col1, (SELECT * FROM " "table2 WHERE t1alias.col1 = table2.col1) " "AS anon_1 FROM table1 AS t1alias", ) s = CloningVisitor().traverse(s) self.assert_compile( - select([t1alias.c.col1, s]), + select(t1alias.c.col1, s), "SELECT t1alias.col1, (SELECT * FROM " "table2 WHERE t1alias.col1 = table2.col1) " "AS anon_1 FROM table1 AS t1alias", ) s = ( - select([literal_column("*")]) + select(literal_column("*")) .where(t1.c.col1 == t2.c.col1) .correlate(t1) .scalar_subquery() ) self.assert_compile( - select([t1.c.col1, s]), + select(t1.c.col1, s), "SELECT table1.col1, (SELECT * FROM table2 " "WHERE table1.col1 = table2.col1) AS " "anon_1 FROM table1", @@ -1224,14 +1207,14 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): vis = sql_util.ClauseAdapter(t1alias) s = vis.traverse(s) self.assert_compile( - select([t1alias.c.col1, s]), + select(t1alias.c.col1, s), "SELECT t1alias.col1, (SELECT * FROM " "table2 WHERE t1alias.col1 = table2.col1) " "AS anon_1 FROM table1 AS t1alias", ) s = CloningVisitor().traverse(s) self.assert_compile( - select([t1alias.c.col1, s]), + select(t1alias.c.col1, s), "SELECT t1alias.col1, (SELECT * FROM " "table2 WHERE t1alias.col1 = table2.col1) " "AS anon_1 FROM table1 AS t1alias", @@ -1248,7 +1231,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): # "control" subquery - uses correlate which has worked w/ adaption # for a long time control_s = ( - select([t2.c.col1]) + select(t2.c.col1) .where(t2.c.col1 == t1.c.col1) .correlate(t2) .scalar_subquery() @@ -1258,18 +1241,18 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): # will do the same thing as the "control" query since the correlation # works out the same s = ( - select([t2.c.col1]) + select(t2.c.col1) .where(t2.c.col1 == t1.c.col1) .correlate_except(t1) .scalar_subquery() ) # use both subqueries in statements - control_stmt = select([control_s, t1.c.col1, t2.c.col1]).select_from( + control_stmt = select(control_s, t1.c.col1, t2.c.col1).select_from( t1.join(t2, t1.c.col1 == t2.c.col1) ) - stmt = select([s, t1.c.col1, t2.c.col1]).select_from( + stmt = select(s, t1.c.col1, t2.c.col1).select_from( t1.join(t2, t1.c.col1 == t2.c.col1) ) # they are the same @@ -1391,7 +1374,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( - select([t1alias, t2]).where( + select(t1alias, t2).where( t1alias.c.col1 == vis.traverse( select( @@ -1413,7 +1396,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( - select([t1alias, t2]).where( + select(t1alias, t2).where( t1alias.c.col1 == vis.traverse( select( @@ -1479,14 +1462,14 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): vis = sql_util.ClauseAdapter(t1alias) ff = vis.traverse(func.count(t1.c.col1).label("foo")) self.assert_compile( - select([ff]), + select(ff), "SELECT count(t1alias.col1) AS foo FROM " "table1 AS t1alias", ) assert list(_from_objects(ff)) == [t1alias] # def test_table_to_alias_2(self): - # TODO: self.assert_compile(vis.traverse(select([func.count(t1.c - # .col1).l abel('foo')]), clone=True), "SELECT + # TODO: self.assert_compile(vis.traverse(select(func.count(t1.c + # .col1).l abel('foo')), clone=True), "SELECT # count(t1alias.col1) AS foo FROM table1 AS t1alias") def test_table_to_alias_13(self): @@ -1523,7 +1506,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t2alias = t2.alias("t2alias") vis.chain(sql_util.ClauseAdapter(t2alias)) self.assert_compile( - select([t1alias, t2alias]).where( + select(t1alias, t2alias).where( t1alias.c.col1 == vis.traverse( select(["*"], t1.c.col1 == t2.c.col2, from_obj=[t1, t2]) @@ -1604,7 +1587,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): b = Table("b", m, Column("x", Integer), Column("y", Integer)) c = Table("c", m, Column("x", Integer), Column("y", Integer)) - alias = select([a]).select_from(a.join(b, a.c.x == b.c.x)).alias() + alias = select(a).select_from(a.join(b, a.c.x == b.c.x)).alias() # two levels of indirection from c.x->b.x->a.x, requires recursive # corresponding_column call @@ -1671,13 +1654,13 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_derived_from(self): - assert select([t1]).is_derived_from(t1) - assert not select([t2]).is_derived_from(t1) - assert not t1.is_derived_from(select([t1])) + assert select(t1).is_derived_from(t1) + assert not select(t2).is_derived_from(t1) + assert not t1.is_derived_from(select(t1)) assert t1.alias().is_derived_from(t1) - s1 = select([t1, t2]).alias("foo") - s2 = select([s1]).limit(5).offset(10).alias() + s1 = select(t1, t2).alias("foo") + s2 = select(s1).limit(5).offset(10).alias() assert s2.is_derived_from(s1) s2 = s2._clone() assert s2.is_derived_from(s1) @@ -1686,8 +1669,8 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): # original issue from ticket #904 - s1 = select([t1]).alias("foo") - s2 = select([s1]).limit(5).offset(10).alias() + s1 = select(t1).alias("foo") + s2 = select(s1).limit(5).offset(10).alias() self.assert_compile( sql_util.ClauseAdapter(s2).traverse(s1), "SELECT foo.col1, foo.col2, foo.col3 FROM " @@ -1698,8 +1681,8 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_aliasedselect_to_aliasedselect_join(self): - s1 = select([t1]).alias("foo") - s2 = select([s1]).limit(5).offset(10).alias() + s1 = select(t1).alias("foo") + s2 = select(s1).limit(5).offset(10).alias() j = s1.outerjoin(t2, s1.c.col1 == t2.c.col1) self.assert_compile( sql_util.ClauseAdapter(s2).traverse(j).select(), @@ -1716,8 +1699,8 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_aliasedselect_to_aliasedselect_join_nested_table(self): - s1 = select([t1]).alias("foo") - s2 = select([s1]).limit(5).offset(10).alias() + s1 = select(t1).alias("foo") + s2 = select(s1).limit(5).offset(10).alias() talias = t1.alias("bar") # here is the problem. s2 is derived from s1 which is derived @@ -1753,7 +1736,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): sql_util.ClauseAdapter(t1.alias()).traverse(func.count(t1.c.col1)), "count(table1_1.col1)", ) - s = select([func.count(t1.c.col1)]) + s = select(func.count(t1.c.col1)) self.assert_compile( sql_util.ClauseAdapter(t1.alias()).traverse(s), "SELECT count(table1_1.col1) AS count_1 " @@ -1790,7 +1773,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( sql_util.ClauseAdapter(u).traverse( - select([c.c.bid]).where(c.c.bid == u.c.b_aid) + select(c.c.bid).where(c.c.bid == u.c.b_aid) ), "SELECT c.bid " "FROM c, (SELECT a.id AS a_id, b.id AS b_id, b.aid AS b_aid " @@ -1804,10 +1787,10 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1a = t1.alias() adapter = sql_util.ClauseAdapter(t1a, anonymize_labels=True) - expr = select([t1.c.col2]).where(t1.c.col3 == 5).label("expr") + expr = select(t1.c.col2).where(t1.c.col3 == 5).label("expr") expr_adapted = adapter.traverse(expr) - stmt = select([expr, expr_adapted]).order_by(expr, expr_adapted) + stmt = select(expr, expr_adapted).order_by(expr, expr_adapted) self.assert_compile( stmt, "SELECT " @@ -1822,10 +1805,10 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1a = t1.alias() adapter = sql_util.ClauseAdapter(t1a, anonymize_labels=True) - expr = select([t1.c.col2]).where(t1.c.col3 == 5).label(None) + expr = select(t1.c.col2).where(t1.c.col3 == 5).label(None) expr_adapted = adapter.traverse(expr) - stmt = select([expr, expr_adapted]).order_by(expr, expr_adapted) + stmt = select(expr, expr_adapted).order_by(expr, expr_adapted) self.assert_compile( stmt, "SELECT " @@ -1842,7 +1825,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1a, anonymize_labels=True, allow_label_resolve=False ) - expr = select([t1.c.col2]).where(t1.c.col3 == 5).label(None) + expr = select(t1.c.col2).where(t1.c.col3 == 5).label(None) l1 = expr is_(l1._order_by_label_element, l1) eq_(l1._allow_label_resolve, True) @@ -1878,7 +1861,7 @@ class SpliceJoinsTest(fixtures.TestBase, AssertsCompiledSQL): .join(t3, t2.c.col1 == t3.c.col1) .join(t4, t4.c.col1 == t1.c.col1) ) - s = select([t1]).where(t1.c.col2 < 5).alias() + s = select(t1).where(t1.c.col2 < 5).alias() self.assert_compile( sql_util.splice_joins(s, j), "(SELECT table1.col1 AS col1, table1.col2 " @@ -1894,7 +1877,7 @@ class SpliceJoinsTest(fixtures.TestBase, AssertsCompiledSQL): t1, t2, t3 = table1, table2, table3 j1 = t1.join(t2, t1.c.col1 == t2.c.col1) j2 = j1.join(t3, t2.c.col1 == t3.c.col1) - s = select([t1]).select_from(j1).alias() + s = select(t1).select_from(j1).alias() self.assert_compile( sql_util.splice_joins(s, j2), "(SELECT table1.col1 AS col1, table1.col2 " diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 4c5c51b4a..7a027e28a 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -2896,7 +2896,7 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): r"Coercing CTE object into a select\(\) for use in " r"IN\(\); please pass a select\(\) construct explicitly", ): - s2 = select([column("q").in_(stmt)]) + s2 = select(column("q").in_(stmt)) self.assert_compile( s2, diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 6428b7dbe..5642797e7 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -29,7 +29,6 @@ from sqlalchemy.engine import cursor as _cursor from sqlalchemy.engine import default from sqlalchemy.engine import Row from sqlalchemy.ext.compiler import compiles -from sqlalchemy.future import select as future_select from sqlalchemy.sql import ColumnElement from sqlalchemy.sql import expression from sqlalchemy.sql.selectable import TextualSelect @@ -1088,6 +1087,15 @@ class CursorResultTest(fixtures.TablesTest): eq_(dict(row), {"user_id": 1, "user_name": "foo"}) eq_(row.keys(), ["user_id", "user_name"]) + def test_row_namedtuple_legacy_ok(self, connection): + users = self.tables.users + + connection.execute(users.insert(), user_id=1, user_name="foo") + result = connection.execute(users.select()) + row = result.first() + eq_(row.user_id, 1) + eq_(row.user_name, "foo") + def test_keys_anon_labels(self, connection): """test [ticket:3483]""" @@ -2575,9 +2583,7 @@ class GenerativeResultTest(fixtures.TablesTest): ], ) - result = connection.execute( - future_select(users).order_by(users.c.user_id) - ) + result = connection.execute(select(users).order_by(users.c.user_id)) eq_( result.all(), [(7, "jack", 1, 2), (8, "ed", 2, 3), (9, "fred", 15, 20)], @@ -2600,9 +2606,7 @@ class GenerativeResultTest(fixtures.TablesTest): ], ) - result = connection.execute( - future_select(users).order_by(users.c.user_id) - ) + result = connection.execute(select(users).order_by(users.c.user_id)) all_ = result.columns(*columns).all() eq_(all_, expected) @@ -2617,9 +2621,7 @@ class GenerativeResultTest(fixtures.TablesTest): [{"user_id": 7, "user_name": "jack", "x": 1, "y": 2}], ) - result = connection.execute( - future_select(users).order_by(users.c.user_id) - ) + result = connection.execute(select(users).order_by(users.c.user_id)) all_ = ( result.columns("x", "y", "user_name", "user_id") @@ -2638,9 +2640,7 @@ class GenerativeResultTest(fixtures.TablesTest): [{"user_id": 7, "user_name": "jack", "x": 1, "y": 2}], ) - result = connection.execute( - future_select(users).order_by(users.c.user_id) - ) + result = connection.execute(select(users).order_by(users.c.user_id)) result = result.columns("x", "y", "user_name") getter = result._metadata._getter("y") @@ -2662,9 +2662,7 @@ class GenerativeResultTest(fixtures.TablesTest): ], ) - result = connection.execute( - future_select(users).order_by(users.c.user_id) - ) + result = connection.execute(select(users).order_by(users.c.user_id)) start = 0 for partition in result.columns(0, 1).partitions(20): diff --git a/test/sql/test_roles.py b/test/sql/test_roles.py index a49854e96..c9f179ed1 100644 --- a/test/sql/test_roles.py +++ b/test/sql/test_roles.py @@ -135,8 +135,8 @@ class RoleTest(fixtures.TestBase): is_true( expect( roles.LabeledColumnExprRole, - select([column("q")]).scalar_subquery(), - ).compare(select([column("q")]).label(None)) + select(column("q")).scalar_subquery(), + ).compare(select(column("q")).label(None)) ) is_true( @@ -150,14 +150,14 @@ class RoleTest(fixtures.TestBase): "implicitly coercing SELECT object to scalar subquery" ): expect( - roles.LabeledColumnExprRole, select([column("q")]), + roles.LabeledColumnExprRole, select(column("q")), ) with testing.expect_warnings( "implicitly coercing SELECT object to scalar subquery" ): expect( - roles.LabeledColumnExprRole, select([column("q")]).alias(), + roles.LabeledColumnExprRole, select(column("q")).alias(), ) def test_statement_no_text_coercion(self): @@ -193,25 +193,23 @@ class RoleTest(fixtures.TestBase): "constructs into FROM clauses is deprecated;" ): element = expect( - roles.FromClauseRole, SelectStatementGrouping(select([t])) + roles.FromClauseRole, SelectStatementGrouping(select(t)) ) is_true( - element.compare( - SelectStatementGrouping(select([t])).subquery() - ) + element.compare(SelectStatementGrouping(select(t)).subquery()) ) def test_offset_or_limit_role_only_ints_or_clauseelement(self): - assert_raises(ValueError, select([t]).limit, "some limit") + assert_raises(ValueError, select(t).limit, "some limit") - assert_raises(ValueError, select([t]).offset, "some offset") + assert_raises(ValueError, select(t).offset, "some offset") def test_offset_or_limit_role_clauseelement(self): bind = bindparam("x") - stmt = select([t]).limit(bind) + stmt = select(t).limit(bind) is_(stmt._limit_clause, bind) - stmt = select([t]).offset(bind) + stmt = select(t).offset(bind) is_(stmt._offset_clause, bind) def test_from_clause_is_not_a_select(self): @@ -233,9 +231,7 @@ class RoleTest(fixtures.TestBase): def test_statement_coercion_select(self): is_true( - expect(roles.CoerceTextStatementRole, select([t])).compare( - select([t]) - ) + expect(roles.CoerceTextStatementRole, select(t)).compare(select(t)) ) def test_statement_coercion_ddl(self): @@ -243,15 +239,15 @@ class RoleTest(fixtures.TestBase): is_(expect(roles.CoerceTextStatementRole, d1), d1) def test_strict_from_clause_role(self): - stmt = select([t]).subquery() + stmt = select(t).subquery() is_true( expect(roles.StrictFromClauseRole, stmt).compare( - select([t]).subquery() + select(t).subquery() ) ) def test_strict_from_clause_role_disallow_select(self): - stmt = select([t]) + stmt = select(t) assert_raises_message( exc.ArgumentError, r"FROM expression, such as a Table or alias\(\) " @@ -271,8 +267,8 @@ class RoleTest(fixtures.TestBase): # than just replacing the outer alias. is_true( expect( - roles.AnonymizedFromClauseRole, select([t]).subquery() - ).compare(select([t]).subquery().alias()) + roles.AnonymizedFromClauseRole, select(t).subquery() + ).compare(select(t).subquery().alias()) ) def test_statement_coercion_sequence(self): @@ -313,7 +309,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_column_roles(self): - stmt = select([self.table1.c.myid]) + stmt = select(self.table1.c.myid) for role in [ roles.WhereHavingRole, @@ -335,7 +331,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): is_true(coerced.compare(stmt.scalar_subquery())) def test_labeled_role(self): - stmt = select([self.table1.c.myid]) + stmt = select(self.table1.c.myid) with testing.expect_warnings( "implicitly coercing SELECT object to scalar subquery" @@ -357,16 +353,16 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): "implicitly coercing SELECT object to scalar subquery" ): self.assert_compile( - func.coalesce(select([self.table1.c.myid])), + func.coalesce(select(self.table1.c.myid)), "coalesce((SELECT mytable.myid FROM mytable))", ) with testing.expect_warnings( "implicitly coercing SELECT object to scalar subquery" ): - s = select([self.table1.c.myid]).alias() + s = select(self.table1.c.myid).alias() self.assert_compile( - select([self.table1.c.myid]).where(self.table1.c.myid == s), + select(self.table1.c.myid).where(self.table1.c.myid == s), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid = (SELECT mytable.myid FROM " "mytable)", @@ -376,7 +372,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): "implicitly coercing SELECT object to scalar subquery" ): self.assert_compile( - select([self.table1.c.myid]).where(s > self.table1.c.myid), + select(self.table1.c.myid).where(s > self.table1.c.myid), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid < (SELECT mytable.myid FROM " "mytable)", @@ -385,9 +381,9 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): with testing.expect_warnings( "implicitly coercing SELECT object to scalar subquery" ): - s = select([self.table1.c.myid]).alias() + s = select(self.table1.c.myid).alias() self.assert_compile( - select([self.table1.c.myid]).where(self.table1.c.myid == s), + select(self.table1.c.myid).where(self.table1.c.myid == s), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid = (SELECT mytable.myid FROM " "mytable)", @@ -397,7 +393,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): "implicitly coercing SELECT object to scalar subquery" ): self.assert_compile( - select([self.table1.c.myid]).where(s > self.table1.c.myid), + select(self.table1.c.myid).where(s > self.table1.c.myid), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid < (SELECT mytable.myid FROM " "mytable)", @@ -429,11 +425,10 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): with testing.expect_warnings( "implicitly coercing SELECT object to scalar subquery" ): - u = update( - table1, - values={ - table1.c.name: select( - [mt.c.name], mt.c.myid == table1.c.myid + u = update(table1).values( + { + table1.c.name: select(mt.c.name).where( + mt.c.myid == table1.c.myid ) }, ) @@ -452,8 +447,10 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): with testing.expect_warnings( "implicitly coercing SELECT object to scalar subquery" ): - u = update( - table1, table1.c.name == "jack", values={table1.c.name: s} + u = ( + update(table1) + .where(table1.c.name == "jack") + .values({table1.c.name: s}) ) self.assert_compile( u, diff --git a/test/sql/test_select.py b/test/sql/test_select.py index 7bac921a1..be39fe46b 100644 --- a/test/sql/test_select.py +++ b/test/sql/test_select.py @@ -3,9 +3,9 @@ from sqlalchemy import exc from sqlalchemy import ForeignKey from sqlalchemy import Integer from sqlalchemy import MetaData +from sqlalchemy import select from sqlalchemy import String from sqlalchemy import Table -from sqlalchemy.future import select as future_select from sqlalchemy.sql import column from sqlalchemy.sql import table from sqlalchemy.testing import assert_raises_message @@ -44,11 +44,49 @@ child = Table( class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): __dialect__ = "default" - def test_join_nofrom_implicit_left_side_explicit_onclause(self): - stmt = future_select(table1).join( - table2, table1.c.myid == table2.c.otherid + def test_legacy_calling_style_kw_only(self): + stmt = select( + whereclause=table1.c.myid == table2.c.otherid + ).add_columns(table1.c.myid) + + self.assert_compile( + stmt, + "SELECT mytable.myid FROM mytable, myothertable " + "WHERE mytable.myid = myothertable.otherid", + ) + + def test_legacy_calling_style_col_seq_only(self): + stmt = select([table1.c.myid]).where(table1.c.myid == table2.c.otherid) + + self.assert_compile( + stmt, + "SELECT mytable.myid FROM mytable, myothertable " + "WHERE mytable.myid = myothertable.otherid", + ) + + def test_new_calling_style(self): + stmt = select(table1.c.myid).where(table1.c.myid == table2.c.otherid) + + self.assert_compile( + stmt, + "SELECT mytable.myid FROM mytable, myothertable " + "WHERE mytable.myid = myothertable.otherid", ) + def test_kw_triggers_old_style(self): + + assert_raises_message( + exc.ArgumentError, + r"select\(\) construct created in legacy mode, " + "i.e. with keyword arguments", + select, + table1.c.myid, + whereclause=table1.c.myid == table2.c.otherid, + ) + + def test_join_nofrom_implicit_left_side_explicit_onclause(self): + stmt = select(table1).join(table2, table1.c.myid == table2.c.otherid) + self.assert_compile( stmt, "SELECT mytable.myid, mytable.name, mytable.description " @@ -57,7 +95,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_join_nofrom_explicit_left_side_explicit_onclause(self): - stmt = future_select(table1).join_from( + stmt = select(table1).join_from( table1, table2, table1.c.myid == table2.c.otherid ) @@ -69,7 +107,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_join_nofrom_implicit_left_side_implicit_onclause(self): - stmt = future_select(parent).join(child) + stmt = select(parent).join(child) self.assert_compile( stmt, @@ -78,7 +116,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_join_nofrom_explicit_left_side_implicit_onclause(self): - stmt = future_select(parent).join_from(parent, child) + stmt = select(parent).join_from(parent, child) self.assert_compile( stmt, @@ -88,7 +126,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_join_froms_implicit_left_side_explicit_onclause(self): stmt = ( - future_select(table1) + select(table1) .select_from(table1) .join(table2, table1.c.myid == table2.c.otherid) ) @@ -102,7 +140,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_join_froms_explicit_left_side_explicit_onclause(self): stmt = ( - future_select(table1) + select(table1) .select_from(table1) .join_from(table1, table2, table1.c.myid == table2.c.otherid) ) @@ -115,7 +153,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_join_froms_implicit_left_side_implicit_onclause(self): - stmt = future_select(parent).select_from(parent).join(child) + stmt = select(parent).select_from(parent).join(child) self.assert_compile( stmt, @@ -124,9 +162,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_join_froms_explicit_left_side_implicit_onclause(self): - stmt = ( - future_select(parent).select_from(parent).join_from(parent, child) - ) + stmt = select(parent).select_from(parent).join_from(parent, child) self.assert_compile( stmt, @@ -136,7 +172,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_joins_w_filter_by(self): stmt = ( - future_select(parent) + select(parent) .filter_by(data="p1") .join(child) .filter_by(data="c1") @@ -158,6 +194,6 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): assert_raises_message( exc.InvalidRequestError, 'Entity namespace for "mytable" has no property "foo"', - future_select(table1).filter_by, + select(table1).filter_by, foo="bar", ) diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index d53ee3385..55875632a 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -88,11 +88,9 @@ class SelectableTest( # same column three times s = select( - [ - table1.c.col1.label("c2"), - table1.c.col1, - table1.c.col1.label("c1"), - ] + table1.c.col1.label("c2"), + table1.c.col1, + table1.c.col1.label("c1"), ).subquery() # this tests the same thing as @@ -104,10 +102,10 @@ class SelectableTest( assert s.corresponding_column(s.c.c1) is s.c.c1 def test_labeled_select_twice(self): - scalar_select = select([table1.c.col1]).label("foo") + scalar_select = select(table1.c.col1).label("foo") - s1 = select([scalar_select]) - s2 = select([scalar_select, scalar_select]) + s1 = select(scalar_select) + s2 = select(scalar_select, scalar_select) eq_( s1.selected_columns.foo.proxy_set, @@ -130,10 +128,10 @@ class SelectableTest( ) def test_labeled_subquery_twice(self): - scalar_select = select([table1.c.col1]).label("foo") + scalar_select = select(table1.c.col1).label("foo") - s1 = select([scalar_select]).subquery() - s2 = select([scalar_select, scalar_select]).subquery() + s1 = select(scalar_select).subquery() + s2 = select(scalar_select, scalar_select).subquery() eq_( s1.c.foo.proxy_set, @@ -148,10 +146,10 @@ class SelectableTest( assert s2.corresponding_column(scalar_select) is s2.c.foo def test_labels_name_w_separate_key(self): - label = select([table1.c.col1]).label("foo") + label = select(table1.c.col1).label("foo") label.key = "bar" - s1 = select([label]) + s1 = select(label) assert s1.corresponding_column(label) is s1.selected_columns.bar # renders as foo @@ -160,10 +158,10 @@ class SelectableTest( ) def test_labels_anon_w_separate_key(self): - label = select([table1.c.col1]).label(None) + label = select(table1.c.col1).label(None) label.key = "bar" - s1 = select([label]) + s1 = select(label) # .bar is there assert s1.corresponding_column(label) is s1.selected_columns.bar @@ -174,14 +172,14 @@ class SelectableTest( ) def test_labels_anon_w_separate_key_subquery(self): - label = select([table1.c.col1]).label(None) + label = select(table1.c.col1).label(None) label.key = label._key_label = "bar" - s1 = select([label]) + s1 = select(label) subq = s1.subquery() - s2 = select([subq]).where(subq.c.bar > 5) + s2 = select(subq).where(subq.c.bar > 5) self.assert_compile( s2, "SELECT anon_2.anon_1 FROM (SELECT (SELECT table1.col1 " @@ -191,14 +189,14 @@ class SelectableTest( ) def test_labels_anon_generate_binds_subquery(self): - label = select([table1.c.col1]).label(None) + label = select(table1.c.col1).label(None) label.key = label._key_label = "bar" - s1 = select([label]) + s1 = select(label) subq = s1.subquery() - s2 = select([subq]).where(subq.c[0] > 5) + s2 = select(subq).where(subq.c[0] > 5) self.assert_compile( s2, "SELECT anon_2.anon_1 FROM (SELECT (SELECT table1.col1 " @@ -208,20 +206,20 @@ class SelectableTest( ) def test_select_label_grouped_still_corresponds(self): - label = select([table1.c.col1]).label("foo") + label = select(table1.c.col1).label("foo") label2 = label.self_group() - s1 = select([label]) - s2 = select([label2]) + s1 = select(label) + s2 = select(label2) assert s1.corresponding_column(label) is s1.selected_columns.foo assert s2.corresponding_column(label) is s2.selected_columns.foo def test_subquery_label_grouped_still_corresponds(self): - label = select([table1.c.col1]).label("foo") + label = select(table1.c.col1).label("foo") label2 = label.self_group() - s1 = select([label]).subquery() - s2 = select([label2]).subquery() + s1 = select(label).subquery() + s2 = select(label2).subquery() assert s1.corresponding_column(label) is s1.c.foo assert s2.corresponding_column(label) is s2.c.foo @@ -230,20 +228,20 @@ class SelectableTest( # of the proxy set to get the right result l1, l2 = table1.c.col1.label("foo"), table1.c.col1.label("bar") - sel = select([l1, l2]) + sel = select(l1, l2) sel2 = sel.alias() assert sel2.corresponding_column(l1) is sel2.c.foo assert sel2.corresponding_column(l2) is sel2.c.bar - sel2 = select([table1.c.col1.label("foo"), table1.c.col2.label("bar")]) + sel2 = select(table1.c.col1.label("foo"), table1.c.col2.label("bar")) sel3 = sel.union(sel2).alias() assert sel3.corresponding_column(l1) is sel3.c.foo assert sel3.corresponding_column(l2) is sel3.c.bar def test_keyed_gen(self): - s = select([keyed]) + s = select(keyed) eq_(s.selected_columns.colx.key, "colx") eq_(s.selected_columns.colx.name, "x") @@ -267,7 +265,7 @@ class SelectableTest( assert sel2.corresponding_column(keyed.c.z) is sel2.c.z def test_keyed_label_gen(self): - s = select([keyed]).apply_labels() + s = select(keyed).apply_labels() assert ( s.selected_columns.corresponding_column(keyed.c.colx) @@ -301,20 +299,20 @@ class SelectableTest( def test_clone_c_proxy_key_upper(self): c = Column("foo", Integer, key="bar") t = Table("t", MetaData(), c) - s = select([t])._clone() + s = select(t)._clone() assert c in s.selected_columns.bar.proxy_set - s = select([t]).subquery()._clone() + s = select(t).subquery()._clone() assert c in s.c.bar.proxy_set def test_clone_c_proxy_key_lower(self): c = column("foo") c.key = "bar" t = table("t", c) - s = select([t])._clone() + s = select(t)._clone() assert c in s.selected_columns.bar.proxy_set - s = select([t]).subquery()._clone() + s = select(t).subquery()._clone() assert c in s.c.bar.proxy_set def test_no_error_on_unsupported_expr_key(self): @@ -327,14 +325,14 @@ class SelectableTest( expr = BinaryExpression(t.c.x, t.c.y, myop) - s = select([t, expr]) + s = select(t, expr) # anon_label, e.g. a truncated_label, is used here because # the expr has no name, no key, and myop() can't create a # string, so this is the last resort eq_(s.selected_columns.keys(), ["x", "y", expr.anon_label]) - s = select([t, expr]).subquery() + s = select(t, expr).subquery() eq_(s.c.keys(), ["x", "y", expr.anon_label]) def test_cloned_intersection(self): @@ -380,7 +378,7 @@ class SelectableTest( assert s.corresponding_column(a1.c.col1) is s.c.a1_col1 def test_join_against_self(self): - jj = select([table1.c.col1.label("bar_col1")]).subquery() + jj = select(table1.c.col1.label("bar_col1")).subquery() jjj = join(table1, jj, table1.c.col1 == jj.c.bar_col1) # test column directly against itself @@ -403,7 +401,7 @@ class SelectableTest( assert j2.corresponding_column(table1.c.col1) is j2.c.table1_col1 def test_clone_append_column(self): - sel = select([literal_column("1").label("a")]) + sel = select(literal_column("1").label("a")) eq_(list(sel.selected_columns.keys()), ["a"]) cloned = visitors.ReplacingCloningVisitor().traverse(sel) cloned.add_columns.non_generative( @@ -414,7 +412,7 @@ class SelectableTest( def test_clone_col_list_changes_then_proxy(self): t = table("t", column("q"), column("p")) - stmt = select([t.c.q]).subquery() + stmt = select(t.c.q).subquery() def add_column(stmt): stmt.add_columns.non_generative(stmt, t.c.p) @@ -425,7 +423,7 @@ class SelectableTest( def test_clone_col_list_changes_then_schema_proxy(self): t = Table("t", MetaData(), Column("q", Integer), Column("p", Integer)) - stmt = select([t.c.q]).subquery() + stmt = select(t.c.q).subquery() def add_column(stmt): stmt.add_columns.non_generative(stmt, t.c.p) @@ -437,13 +435,13 @@ class SelectableTest( def test_append_column_after_visitor_replace(self): # test for a supported idiom that matches the deprecated / removed # replace_selectable method - basesel = select([literal_column("1").label("a")]) + basesel = select(literal_column("1").label("a")) tojoin = select( - [literal_column("1").label("a"), literal_column("2").label("b")] + literal_column("1").label("a"), literal_column("2").label("b") ) basefrom = basesel.alias("basefrom") joinfrom = tojoin.alias("joinfrom") - sel = select([basefrom.c.a]) + sel = select(basefrom.c.a) replace_from = basefrom.join(joinfrom, basefrom.c.a == joinfrom.c.a) @@ -470,7 +468,7 @@ class SelectableTest( # test that corresponding column digs across # clone boundaries with anonymous labeled elements col = func.count().label("foo") - sel = select([col]).subquery() + sel = select(col).subquery() sel2 = visitors.ReplacingCloningVisitor().traverse(sel) assert sel2.corresponding_column(col) is sel2.c.foo @@ -490,7 +488,7 @@ class SelectableTest( class MyType(TypeDecorator): impl = Integer - stmt = select([type_coerce(column("x"), MyType).label("foo")]) + stmt = select(type_coerce(column("x"), MyType).label("foo")) subq = stmt.subquery() stmt2 = subq.select() subq2 = stmt2.subquery() @@ -553,14 +551,14 @@ class SelectableTest( j2 = t4.join(j, onclause=t4.c.d == t2.c.b) - stmt = select([t1, t2, t3, t4]).select_from(j2) + stmt = select(t1, t2, t3, t4).select_from(j2) self.assert_compile( stmt, "SELECT t1.a, t2.b, t3.c, t4.d FROM t3, " "t4 JOIN (t1 JOIN t2 ON t1.a = t3.c) ON t4.d = t2.b", ) - stmt = select([t1]).select_from(t3).select_from(j2) + stmt = select(t1).select_from(t3).select_from(j2) self.assert_compile( stmt, "SELECT t1.a FROM t3, t4 JOIN (t1 JOIN t2 ON t1.a = t3.c) " @@ -572,7 +570,7 @@ class SelectableTest( # not quite a use case yet but this is expected to become # prominent w/ PostgreSQL's tuple functions - stmt = select([table1.c.col1, table1.c.col2]) + stmt = select(table1.c.col1, table1.c.col2) a = stmt.alias("a") # TODO: this case is crazy, sending SELECT or FROMCLAUSE has to @@ -580,7 +578,7 @@ class SelectableTest( # statements go into functions in PG. seems likely select statement, # but not alias, subquery or other FROM object self.assert_compile( - select([func.foo(a)]), + select(func.foo(a)), "SELECT foo(SELECT table1.col1, table1.col2 FROM table1) " "AS foo_1 FROM " "(SELECT table1.col1 AS col1, table1.col2 AS col2 FROM table1) " @@ -594,22 +592,18 @@ class SelectableTest( # its underlying Selects matches to that same Table u = select( - [ - table1.c.col1, - table1.c.col2, - table1.c.col3, - table1.c.colx, - null().label("coly"), - ] + table1.c.col1, + table1.c.col2, + table1.c.col3, + table1.c.colx, + null().label("coly"), ).union( select( - [ - table2.c.col1, - table2.c.col2, - table2.c.col3, - null().label("colx"), - table2.c.coly, - ] + table2.c.col1, + table2.c.col2, + table2.c.col3, + null().label("colx"), + table2.c.coly, ) ) s1 = table1.select(use_labels=True) @@ -648,10 +642,10 @@ class SelectableTest( # conflicting column correspondence should be resolved based on # the order of the select()s in the union - s1 = select([table1.c.col1, table1.c.col2]) - s2 = select([table1.c.col2, table1.c.col1]) - s3 = select([table1.c.col3, table1.c.colx]) - s4 = select([table1.c.colx, table1.c.col3]) + s1 = select(table1.c.col1, table1.c.col2) + s2 = select(table1.c.col2, table1.c.col1) + s3 = select(table1.c.col3, table1.c.colx) + s4 = select(table1.c.colx, table1.c.col3) u1 = union(s1, s2).subquery() assert u1.corresponding_column(table1.c.col1) is u1.c.col1 @@ -664,8 +658,8 @@ class SelectableTest( assert u1.corresponding_column(table1.c.col3) is u1.c.col1 def test_proxy_set_pollution(self): - s1 = select([table1.c.col1, table1.c.col2]) - s2 = select([table1.c.col2, table1.c.col1]) + s1 = select(table1.c.col1, table1.c.col2) + s2 = select(table1.c.col2, table1.c.col1) for c in s1.selected_columns: c.proxy_set @@ -677,10 +671,10 @@ class SelectableTest( def test_singular_union(self): u = union( - select([table1.c.col1, table1.c.col2, table1.c.col3]), - select([table1.c.col1, table1.c.col2, table1.c.col3]), + select(table1.c.col1, table1.c.col2, table1.c.col3), + select(table1.c.col1, table1.c.col2, table1.c.col3), ) - u = union(select([table1.c.col1, table1.c.col2, table1.c.col3])) + u = union(select(table1.c.col1, table1.c.col2, table1.c.col3)) assert u.selected_columns.col1 is not None assert u.selected_columns.col2 is not None assert u.selected_columns.col3 is not None @@ -691,23 +685,19 @@ class SelectableTest( u = ( select( - [ - table1.c.col1, - table1.c.col2, - table1.c.col3, - table1.c.colx, - null().label("coly"), - ] + table1.c.col1, + table1.c.col2, + table1.c.col3, + table1.c.colx, + null().label("coly"), ) .union( select( - [ - table2.c.col1, - table2.c.col2, - table2.c.col3, - null().label("colx"), - table2.c.coly, - ] + table2.c.col1, + table2.c.col2, + table2.c.col3, + null().label("colx"), + table2.c.coly, ) ) .alias("analias") @@ -720,8 +710,8 @@ class SelectableTest( assert s2.corresponding_column(u.c.coly) is s2.c.table2_coly def test_union_of_alias(self): - s1 = select([table1.c.col1, table1.c.col2]) - s2 = select([table1.c.col1, table1.c.col2]).alias() + s1 = select(table1.c.col1, table1.c.col2) + s2 = select(table1.c.col1, table1.c.col2).alias() # previously this worked assert_raises_message( @@ -734,7 +724,7 @@ class SelectableTest( ) def test_union_of_text(self): - s1 = select([table1.c.col1, table1.c.col2]) + s1 = select(table1.c.col1, table1.c.col2) s2 = text("select col1, col2 from foo").columns( column("col1"), column("col2") ) @@ -748,8 +738,8 @@ class SelectableTest( assert u2.corresponding_column(s2.selected_columns.col1) is u2.c.col1 def test_foo(self): - s1 = select([table1.c.col1, table1.c.col2]) - s2 = select([table1.c.col2, table1.c.col1]) + s1 = select(table1.c.col1, table1.c.col2) + s2 = select(table1.c.col2, table1.c.col1) u1 = union(s1, s2).subquery() assert u1.corresponding_column(table1.c.col2) is u1.c.col2 @@ -765,16 +755,16 @@ class SelectableTest( ) # table1_new = table1 - s1 = select([table1_new.c.col1, table1_new.c.col2]) - s2 = select([table1_new.c.col2, table1_new.c.col1]) + s1 = select(table1_new.c.col1, table1_new.c.col2) + s2 = select(table1_new.c.col2, table1_new.c.col1) u1 = union(s1, s2).subquery() # TODO: failing due to proxy_set not correct assert u1.corresponding_column(table1_new.c.col2) is u1.c.col2 def test_union_alias_dupe_keys(self): - s1 = select([table1.c.col1, table1.c.col2, table2.c.col1]) - s2 = select([table2.c.col1, table2.c.col2, table2.c.col3]) + s1 = select(table1.c.col1, table1.c.col2, table2.c.col1) + s2 = select(table2.c.col1, table2.c.col2, table2.c.col3) u1 = union(s1, s2).subquery() assert ( @@ -818,13 +808,13 @@ class SelectableTest( assert u1.corresponding_column(table2.c.col3) is u1.c._all_columns[2] def test_union_alias_dupe_keys_disambiguates_in_subq_compile_one(self): - s1 = select([table1.c.col1, table1.c.col2, table2.c.col1]).limit(1) - s2 = select([table2.c.col1, table2.c.col2, table2.c.col3]).limit(1) + s1 = select(table1.c.col1, table1.c.col2, table2.c.col1).limit(1) + s2 = select(table2.c.col1, table2.c.col2, table2.c.col3).limit(1) u1 = union(s1, s2).subquery() eq_(u1.c.keys(), ["col1", "col2", "col1_1"]) - stmt = select([u1]) + stmt = select(u1) eq_(stmt.selected_columns.keys(), ["col1", "col2", "col1_1"]) @@ -850,7 +840,7 @@ class SelectableTest( eq_(u1.c.keys(), ["a_id", "b_id", "b_aid"]) - stmt = select([u1]) + stmt = select(u1) eq_(stmt.selected_columns.keys(), ["a_id", "b_id", "b_aid"]) @@ -866,8 +856,8 @@ class SelectableTest( ) def test_union_alias_dupe_keys_grouped(self): - s1 = select([table1.c.col1, table1.c.col2, table2.c.col1]).limit(1) - s2 = select([table2.c.col1, table2.c.col2, table2.c.col3]).limit(1) + s1 = select(table1.c.col1, table1.c.col2, table2.c.col1).limit(1) + s2 = select(table2.c.col1, table2.c.col2, table2.c.col3).limit(1) u1 = union(s1, s2).subquery() assert ( @@ -916,28 +906,24 @@ class SelectableTest( u = ( select( - [ - table1.c.col1, - table1.c.col2, - table1.c.col3, - table1.c.colx, - null().label("coly"), - ] + table1.c.col1, + table1.c.col2, + table1.c.col3, + table1.c.colx, + null().label("coly"), ) .union( select( - [ - table2.c.col1, - table2.c.col2, - table2.c.col3, - null().label("colx"), - table2.c.coly, - ] + table2.c.col1, + table2.c.col2, + table2.c.col3, + null().label("colx"), + table2.c.coly, ) ) .alias("analias") ) - s = select([u]).subquery() + s = select(u).subquery() s1 = table1.select(use_labels=True).subquery() s2 = table2.select(use_labels=True).subquery() assert s.corresponding_column(s1.c.table1_col2) is s.c.col2 @@ -949,23 +935,19 @@ class SelectableTest( u = ( select( - [ - table1.c.col1, - table1.c.col2, - table1.c.col3, - table1.c.colx, - null().label("coly"), - ] + table1.c.col1, + table1.c.col2, + table1.c.col3, + table1.c.colx, + null().label("coly"), ) .union( select( - [ - table2.c.col1, - table2.c.col2, - table2.c.col3, - null().label("colx"), - table2.c.coly, - ] + table2.c.col1, + table2.c.col2, + table2.c.col3, + null().label("colx"), + table2.c.coly, ) ) .alias("analias") @@ -998,7 +980,7 @@ class SelectableTest( self.assert_(criterion.compare(j.onclause)) def test_scalar_cloned_comparator(self): - sel = select([table1.c.col1]).scalar_subquery() + sel = select(table1.c.col1).scalar_subquery() sel == table1.c.col1 sel2 = visitors.ReplacingCloningVisitor().traverse(sel) @@ -1008,32 +990,30 @@ class SelectableTest( def test_column_labels(self): a = select( - [ - table1.c.col1.label("acol1"), - table1.c.col2.label("acol2"), - table1.c.col3.label("acol3"), - ] + table1.c.col1.label("acol1"), + table1.c.col2.label("acol2"), + table1.c.col3.label("acol3"), ).subquery() j = join(a, table2) criterion = a.c.acol1 == table2.c.col2 self.assert_(criterion.compare(j.onclause)) def test_labeled_select_corresponding(self): - l1 = select([func.max(table1.c.col1)]).label("foo") + l1 = select(func.max(table1.c.col1)).label("foo") - s = select([l1]) + s = select(l1) eq_(s.corresponding_column(l1), s.selected_columns.foo) - s = select([table1.c.col1, l1]) + s = select(table1.c.col1, l1) eq_(s.corresponding_column(l1), s.selected_columns.foo) def test_labeled_subquery_corresponding(self): - l1 = select([func.max(table1.c.col1)]).label("foo") - s = select([l1]).subquery() + l1 = select(func.max(table1.c.col1)).label("foo") + s = select(l1).subquery() eq_(s.corresponding_column(l1), s.c.foo) - s = select([table1.c.col1, l1]).subquery() + s = select(table1.c.col1, l1).subquery() eq_(s.corresponding_column(l1), s.c.foo) def test_select_alias_labels(self): @@ -1047,11 +1027,11 @@ class SelectableTest( metadata = MetaData() a = Table("a", metadata, Column("id", Integer, primary_key=True)) - j2 = select([a.c.id.label("aid")]).alias("bar") + j2 = select(a.c.id.label("aid")).alias("bar") j3 = a.join(j2, j2.c.aid == a.c.id) - j4 = select([j3]).alias("foo") + j4 = select(j3).alias("foo") assert j4.corresponding_column(j2.c.aid) is j4.c.aid assert j4.corresponding_column(a.c.id) is j4.c.id @@ -1070,8 +1050,8 @@ class SelectableTest( def test_multi_label_chain_naming_col(self): # See [ticket:2167] for this one. l1 = table1.c.col1.label("a") - l2 = select([l1]).label("b") - s = select([l2]).subquery() + l2 = select(l1).label("b") + s = select(l2).subquery() assert s.c.b is not None self.assert_compile( s.select(), @@ -1079,7 +1059,7 @@ class SelectableTest( "(SELECT (SELECT table1.col1 AS a FROM table1) AS b) AS anon_1", ) - s2 = select([s.element.label("c")]).subquery() + s2 = select(s.element.label("c")).subquery() self.assert_compile( s2.select(), "SELECT anon_1.c FROM (SELECT (SELECT (" @@ -1093,7 +1073,7 @@ class SelectableTest( # style to the select, eliminating the self-referential call unless # the select already had labeling applied - s = select([t]).apply_labels() + s = select(t).apply_labels() with testing.expect_deprecated("The SelectBase.c"): s.where.non_generative(s, s.c.t_x > 5) @@ -1107,7 +1087,7 @@ class SelectableTest( def test_unusual_column_elements_text(self): """test that .c excludes text().""" - s = select([table1.c.col1, text("foo")]).subquery() + s = select(table1.c.col1, text("foo")).subquery() eq_(list(s.c), [s.c.col1]) def test_unusual_column_elements_clauselist(self): @@ -1116,7 +1096,7 @@ class SelectableTest( from sqlalchemy.sql.expression import ClauseList s = select( - [table1.c.col1, ClauseList(table1.c.col2, table1.c.col3)] + table1.c.col1, ClauseList(table1.c.col2, table1.c.col3) ).subquery() eq_(list(s.c), [s.c.col1, s.c.col2, s.c.col3]) @@ -1124,56 +1104,56 @@ class SelectableTest( """test that BooleanClauseList is placed as single element in .c.""" c2 = and_(table1.c.col2 == 5, table1.c.col3 == 4) - s = select([table1.c.col1, c2]).subquery() + s = select(table1.c.col1, c2).subquery() eq_(list(s.c), [s.c.col1, s.corresponding_column(c2)]) def test_from_list_deferred_constructor(self): c1 = Column("c1", Integer) c2 = Column("c2", Integer) - select([c1]) + select(c1) t = Table("t", MetaData(), c1, c2) eq_(c1._from_objects, [t]) eq_(c2._from_objects, [t]) - self.assert_compile(select([c1]), "SELECT t.c1 FROM t") - self.assert_compile(select([c2]), "SELECT t.c2 FROM t") + self.assert_compile(select(c1), "SELECT t.c1 FROM t") + self.assert_compile(select(c2), "SELECT t.c2 FROM t") def test_from_list_deferred_whereclause(self): c1 = Column("c1", Integer) c2 = Column("c2", Integer) - select([c1]).where(c1 == 5) + select(c1).where(c1 == 5) t = Table("t", MetaData(), c1, c2) eq_(c1._from_objects, [t]) eq_(c2._from_objects, [t]) - self.assert_compile(select([c1]), "SELECT t.c1 FROM t") - self.assert_compile(select([c2]), "SELECT t.c2 FROM t") + self.assert_compile(select(c1), "SELECT t.c1 FROM t") + self.assert_compile(select(c2), "SELECT t.c2 FROM t") def test_from_list_deferred_fromlist(self): m = MetaData() t1 = Table("t1", m, Column("x", Integer)) c1 = Column("c1", Integer) - select([c1]).where(c1 == 5).select_from(t1) + select(c1).where(c1 == 5).select_from(t1) t2 = Table("t2", MetaData(), c1) eq_(c1._from_objects, [t2]) - self.assert_compile(select([c1]), "SELECT t2.c1 FROM t2") + self.assert_compile(select(c1), "SELECT t2.c1 FROM t2") def test_from_list_deferred_cloning(self): c1 = Column("c1", Integer) c2 = Column("c2", Integer) - s = select([c1]) - s2 = select([c2]) + s = select(c1) + s2 = select(c2) s3 = sql_util.ClauseAdapter(s).traverse(s2) Table("t", MetaData(), c1, c2) @@ -1183,7 +1163,7 @@ class SelectableTest( def test_from_list_with_columns(self): table1 = table("t1", column("a")) table2 = table("t2", column("b")) - s1 = select([table1.c.a, table2.c.b]) + s1 = select(table1.c.a, table2.c.b) self.assert_compile(s1, "SELECT t1.a, t2.b FROM t1, t2") s2 = s1.with_only_columns([table2.c.b]) self.assert_compile(s2, "SELECT t2.b FROM t2") @@ -1195,7 +1175,7 @@ class SelectableTest( def test_from_list_against_existing_one(self): c1 = Column("c1", Integer) - s = select([c1]) + s = select(c1) # force a compile. self.assert_compile(s, "SELECT c1") @@ -1208,7 +1188,7 @@ class SelectableTest( c1 = Column("c1", Integer) c2 = Column("c2", Integer) - s = select([c1]) + s = select(c1) # force a compile. eq_(str(s), "SELECT c1") @@ -1219,8 +1199,8 @@ class SelectableTest( eq_(c2._from_objects, [t]) self.assert_compile(s, "SELECT t.c1 FROM t") - self.assert_compile(select([c1]), "SELECT t.c1 FROM t") - self.assert_compile(select([c2]), "SELECT t.c2 FROM t") + self.assert_compile(select(c1), "SELECT t.c1 FROM t") + self.assert_compile(select(c2), "SELECT t.c2 FROM t") def test_label_gen_resets_on_table(self): c1 = Column("c1", Integer) @@ -1243,13 +1223,13 @@ class SelectableTest( def test_whereclause_adapted(self): table1 = table("t1", column("a")) - s1 = select([table1]).subquery() + s1 = select(table1).subquery() - s2 = select([s1]).where(s1.c.a == 5) + s2 = select(s1).where(s1.c.a == 5) assert s2._whereclause.left.table is s1 - ta = select([table1]).subquery() + ta = select(table1).subquery() s3 = sql_util.ClauseAdapter(ta).traverse(s2) @@ -1297,7 +1277,7 @@ class RefreshForNewColTest(fixtures.TestBase): def test_select_samename_init(self): a = table("a", column("x")) b = table("b", column("y")) - s = select([a, b]).apply_labels() + s = select(a, b).apply_labels() s.selected_columns q = column("x") b.append_column(q) @@ -1307,7 +1287,7 @@ class RefreshForNewColTest(fixtures.TestBase): def test_alias_alias_samename_init(self): a = table("a", column("x")) b = table("b", column("y")) - s1 = select([a, b]).apply_labels().alias() + s1 = select(a, b).apply_labels().alias() s2 = s1.alias() s1.c @@ -1326,7 +1306,7 @@ class RefreshForNewColTest(fixtures.TestBase): def test_aliased_select_samename_uninit(self): a = table("a", column("x")) b = table("b", column("y")) - s = select([a, b]).apply_labels().alias() + s = select(a, b).apply_labels().alias() q = column("x") b.append_column(q) s._refresh_for_new_column(q) @@ -1335,7 +1315,7 @@ class RefreshForNewColTest(fixtures.TestBase): def test_aliased_select_samename_init(self): a = table("a", column("x")) b = table("b", column("y")) - s = select([a, b]).apply_labels().alias() + s = select(a, b).apply_labels().alias() s.c q = column("x") b.append_column(q) @@ -1346,7 +1326,7 @@ class RefreshForNewColTest(fixtures.TestBase): a = table("a", column("x")) b = table("b", column("y")) c = table("c", column("z")) - s = select([a, b]).apply_labels().alias() + s = select(a, b).apply_labels().alias() s.c q = column("x") c.append_column(q) @@ -1355,7 +1335,7 @@ class RefreshForNewColTest(fixtures.TestBase): def test_aliased_select_no_cols_clause(self): a = table("a", column("x")) - s = select([a.c.x]).apply_labels().alias() + s = select(a.c.x).apply_labels().alias() s.c q = column("q") a.append_column(q) @@ -1364,8 +1344,8 @@ class RefreshForNewColTest(fixtures.TestBase): def test_union_uninit(self): a = table("a", column("x")) - s1 = select([a]) - s2 = select([a]) + s1 = select(a) + s2 = select(a) s3 = s1.union(s2) q = column("q") a.append_column(q) @@ -1374,8 +1354,8 @@ class RefreshForNewColTest(fixtures.TestBase): def test_union_init(self): a = table("a", column("x")) - s1 = select([a]) - s2 = select([a]) + s1 = select(a) + s2 = select(a) s3 = s1.union(s2) s3.selected_columns q = column("q") @@ -1453,29 +1433,29 @@ class AnonLabelTest(fixtures.TestBase): c1 = column("x") assert c1.label(None) is not c1 - eq_(str(select([c1.label(None)])), "SELECT x AS x_1") + eq_(str(select(c1.label(None))), "SELECT x AS x_1") def test_anon_labels_literal_column(self): c1 = literal_column("x") assert c1.label(None) is not c1 - eq_(str(select([c1.label(None)])), "SELECT x AS x_1") + eq_(str(select(c1.label(None))), "SELECT x AS x_1") def test_anon_labels_func(self): c1 = func.count("*") assert c1.label(None) is not c1 - eq_(str(select([c1])), "SELECT count(:count_2) AS count_1") - select([c1]).compile() + eq_(str(select(c1)), "SELECT count(:count_2) AS count_1") + select(c1).compile() - eq_(str(select([c1.label(None)])), "SELECT count(:count_2) AS count_1") + eq_(str(select(c1.label(None))), "SELECT count(:count_2) AS count_1") def test_named_labels_named_column(self): c1 = column("x") - eq_(str(select([c1.label("y")])), "SELECT x AS y") + eq_(str(select(c1.label("y"))), "SELECT x AS y") def test_named_labels_literal_column(self): c1 = literal_column("x") - eq_(str(select([c1.label("y")])), "SELECT x AS y") + eq_(str(select(c1.label("y"))), "SELECT x AS y") class JoinAliasingTest(fixtures.TestBase, AssertsCompiledSQL): @@ -1544,7 +1524,7 @@ class JoinAliasingTest(fixtures.TestBase, AssertsCompiledSQL): j1 = a.join(b, a.c.a == b.c.b) j2 = c.join(d, c.c.c == d.c.d) self.assert_compile( - select([j1.join(j2, b.c.b == c.c.c).alias()]), + select(j1.join(j2, b.c.b == c.c.c).alias()), "SELECT anon_1.a_a, anon_1.b_b, anon_1.c_c, anon_1.d_d " "FROM (SELECT a.a AS a_a, b.b AS b_b, c.c AS c_c, d.d AS d_d " "FROM a JOIN b ON a.a = b.b " @@ -2013,7 +1993,7 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): Column("manager_name", String(50)), ) s = ( - select([engineers, managers]) + select(engineers, managers) .where(engineers.c.engineer_name == managers.c.manager_name) .subquery() ) @@ -2038,7 +2018,7 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): Column("z", Integer, ForeignKey("t1.x")), Column("q", Integer), ) - s1 = select([t1, t2]) + s1 = select(t1, t2) s2 = s1.reduce_columns(only_synonyms=False) eq_(set(s2.selected_columns), set([t1.c.x, t1.c.y, t2.c.q])) @@ -2059,7 +2039,7 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): Column("x", Integer, ForeignKey("t1.x")), Column("q", Integer, ForeignKey("t1.y")), ) - s1 = select([t1, t2]) + s1 = select(t1, t2) s1 = s1.reduce_columns(only_synonyms=True) eq_( set(s1.selected_columns), @@ -2083,16 +2063,16 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): ) # test that the first appearance in the columns clause # wins - t1 is first, t1.c.x wins - s1 = select([t1]).subquery() - s2 = select([t1, s1]).where(t1.c.x == s1.c.x).where(s1.c.y == t1.c.z) + s1 = select(t1).subquery() + s2 = select(t1, s1).where(t1.c.x == s1.c.x).where(s1.c.y == t1.c.z) eq_( set(s2.reduce_columns().selected_columns), set([t1.c.x, t1.c.y, t1.c.z, s1.c.y, s1.c.z]), ) # reverse order, s1.c.x wins - s1 = select([t1]).subquery() - s2 = select([s1, t1]).where(t1.c.x == s1.c.x).where(s1.c.y == t1.c.z) + s1 = select(t1).subquery() + s2 = select(s1, t1).where(t1.c.x == s1.c.x).where(s1.c.y == t1.c.z) eq_( set(s2.reduce_columns().selected_columns), set([s1.c.x, t1.c.y, t1.c.z, s1.c.y, s1.c.z]), @@ -2229,22 +2209,18 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): pjoin = union( select( - [ - page_table.c.id, - magazine_page_table.c.page_id, - classified_page_table.c.magazine_page_id, - ] + page_table.c.id, + magazine_page_table.c.page_id, + classified_page_table.c.magazine_page_id, ).select_from( page_table.join(magazine_page_table).join( classified_page_table ) ), select( - [ - page_table.c.id, - magazine_page_table.c.page_id, - cast(null(), Integer).label("magazine_page_id"), - ] + page_table.c.id, + magazine_page_table.c.page_id, + cast(null(), Integer).label("magazine_page_id"), ).select_from(page_table.join(magazine_page_table)), ).alias("pjoin") eq_( @@ -2265,18 +2241,14 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): pjoin = union( select( - [ - page_table.c.id, - magazine_page_table.c.page_id, - cast(null(), Integer).label("magazine_page_id"), - ] + page_table.c.id, + magazine_page_table.c.page_id, + cast(null(), Integer).label("magazine_page_id"), ).select_from(page_table.join(magazine_page_table)), select( - [ - page_table.c.id, - magazine_page_table.c.page_id, - classified_page_table.c.magazine_page_id, - ] + page_table.c.id, + magazine_page_table.c.page_id, + classified_page_table.c.magazine_page_id, ).select_from( page_table.join(magazine_page_table).join( classified_page_table @@ -2352,10 +2324,10 @@ class DerivedTest(fixtures.TestBase, AssertsExecutionResults): assert t1.select().is_derived_from(t1) assert not t2.select().is_derived_from(t1) - assert select([t1, t2]).is_derived_from(t1) + assert select(t1, t2).is_derived_from(t1) assert t1.select().alias("foo").is_derived_from(t1) - assert select([t1, t2]).alias("foo").is_derived_from(t1) + assert select(t1, t2).alias("foo").is_derived_from(t1) assert not t2.select().alias("foo").is_derived_from(t1) @@ -2385,7 +2357,7 @@ class AnnotationsTest(fixtures.TestBase): c1 = Column("foo", Integer) - stmt = select([c1]).alias() + stmt = select(c1).alias() proxy = stmt.c.foo proxy.proxy_set @@ -2406,7 +2378,7 @@ class AnnotationsTest(fixtures.TestBase): c1 = Column("foo", Integer) - stmt = select([c1]).alias() + stmt = select(c1).alias() proxy = stmt.c.foo c1.proxy_set @@ -2462,7 +2434,7 @@ class AnnotationsTest(fixtures.TestBase): assert isinstance(s1.c.foo, Column) annot_1 = t1.c.foo._annotate({}) - s2 = select([annot_1]).subquery() + s2 = select(annot_1).subquery() assert isinstance(s2.c.foo, Column) annot_2 = s1._annotate({}) assert isinstance(annot_2.c.foo, Column) @@ -2496,7 +2468,7 @@ class AnnotationsTest(fixtures.TestBase): def test_annotated_corresponding_column(self): table1 = table("table1", column("col1")) - s1 = select([table1.c.col1]).subquery() + s1 = select(table1.c.col1).subquery() t1 = s1._annotate({}) t2 = s1 @@ -2507,7 +2479,7 @@ class AnnotationsTest(fixtures.TestBase): assert t1.c is t2.c assert t1.c.col1 is t2.c.col1 - inner = select([s1]).subquery() + inner = select(s1).subquery() assert ( inner.corresponding_column(t2.c.col1, require_embedded=False) @@ -2555,7 +2527,7 @@ class AnnotationsTest(fixtures.TestBase): def test_annotate_aliased(self): t1 = table("t1", column("c1")) - s = select([(t1.c.c1 + 3).label("bat")]) + s = select((t1.c.c1 + 3).label("bat")) a = s.alias() a = sql_util._deep_annotate(a, {"foo": "bar"}) eq_(a._annotations["foo"], "bar") @@ -2614,11 +2586,9 @@ class AnnotationsTest(fixtures.TestBase): table1 = table("table1", column("col1"), column("col2")) subq = ( - select([table1]) - .where(table1.c.col1 == bindparam("foo")) - .subquery() + select(table1).where(table1.c.col1 == bindparam("foo")).subquery() ) - stmt = select([subq]) + stmt = select(subq) s2 = sql_util._deep_annotate(stmt, {"_orm_adapt": True}) s3 = sql_util._deep_deannotate(s2) @@ -2654,7 +2624,7 @@ class AnnotationsTest(fixtures.TestBase): table1 = table("table1", column("x")) table2 = table("table2", column("y")) a1 = table1.alias() - s = select([a1.c.x]).select_from(a1.join(table2, a1.c.x == table2.c.y)) + s = select(a1.c.x).select_from(a1.join(table2, a1.c.x == table2.c.y)) for sel in ( sql_util._deep_deannotate(s), visitors.cloned_traverse(s, {}, {}), @@ -2687,8 +2657,8 @@ class AnnotationsTest(fixtures.TestBase): """ t1 = table("table1", column("col1"), column("col2")) - s = select([t1.c.col1._annotate({"foo": "bar"})]) - s2 = select([t1.c.col1._annotate({"bat": "hoho"})]) + s = select(t1.c.col1._annotate({"foo": "bar"})) + s2 = select(t1.c.col1._annotate({"bat": "hoho"})) s3 = s.union(s2) sel = sql_util._deep_annotate(s3, {"new": "thing"}) @@ -2740,9 +2710,9 @@ class AnnotationsTest(fixtures.TestBase): table1 = table("table1", column("x")) table2 = table("table2", column("y")) a1 = table1.alias() - s = select([a1.c.x]).select_from(a1.join(table2, a1.c.x == table2.c.y)) + s = select(a1.c.x).select_from(a1.join(table2, a1.c.x == table2.c.y)) - assert_s = select([select([s.subquery()]).subquery()]) + assert_s = select([select(s.subquery()).subquery()]) for fn in ( sql_util._deep_deannotate, lambda s: sql_util._deep_annotate(s, {"foo": "bar"}), @@ -2750,7 +2720,7 @@ class AnnotationsTest(fixtures.TestBase): lambda s: visitors.replacement_traverse(s, {}, lambda x: None), ): - sel = fn(select([fn(select([fn(s.subquery())]).subquery())])) + sel = fn(select([fn(select(fn(s.subquery())).subquery())])) eq_(str(assert_s), str(sel)) def test_bind_unique_test(self): @@ -2832,7 +2802,7 @@ class WithLabelsTest(fixtures.TestBase): m = MetaData() t1 = Table("t1", m, Column("x", Integer)) t2 = Table("t2", m, Column("x", Integer)) - return select([t1, t2]) + return select(t1, t2) def test_names_overlap_nolabel(self): sel = self._names_overlap() @@ -2850,7 +2820,7 @@ class WithLabelsTest(fixtures.TestBase): m = MetaData() t1 = Table("t1", m, Column("x", Integer, key="a")) t2 = Table("t2", m, Column("x", Integer, key="b")) - return select([t1, t2]) + return select(t1, t2) def test_names_overlap_keys_dont_nolabel(self): sel = self._names_overlap_keys_dont() @@ -2869,7 +2839,7 @@ class WithLabelsTest(fixtures.TestBase): m = MetaData() t1 = Table("t", m, Column("x_id", Integer)) t2 = Table("t_x", m, Column("id", Integer)) - return select([t1, t2]) + return select(t1, t2) def test_labels_overlap_nolabel(self): sel = self._labels_overlap() @@ -2894,7 +2864,7 @@ class WithLabelsTest(fixtures.TestBase): m = MetaData() t1 = Table("t", m, Column("x_id", Integer, key="a")) t2 = Table("t_x", m, Column("id", Integer, key="b")) - return select([t1, t2]) + return select(t1, t2) def test_labels_overlap_keylabels_dont_nolabel(self): sel = self._labels_overlap_keylabels_dont() @@ -2912,7 +2882,7 @@ class WithLabelsTest(fixtures.TestBase): m = MetaData() t1 = Table("t", m, Column("a", Integer, key="x_id")) t2 = Table("t_x", m, Column("b", Integer, key="id")) - return select([t1, t2]) + return select(t1, t2) def test_keylabels_overlap_labels_dont_nolabel(self): sel = self._keylabels_overlap_labels_dont() @@ -2935,7 +2905,7 @@ class WithLabelsTest(fixtures.TestBase): m = MetaData() t1 = Table("t", m, Column("x_id", Integer, key="x_a")) t2 = Table("t_x", m, Column("id", Integer, key="a")) - return select([t1, t2]) + return select(t1, t2) def test_keylabels_overlap_labels_overlap_nolabel(self): sel = self._keylabels_overlap_labels_overlap() @@ -2963,7 +2933,7 @@ class WithLabelsTest(fixtures.TestBase): m = MetaData() t1 = Table("t1", m, Column("a", Integer, key="x")) t2 = Table("t2", m, Column("b", Integer, key="x")) - return select([t1, t2]) + return select(t1, t2) def test_keys_overlap_names_dont_nolabel(self): sel = self._keys_overlap_names_dont() @@ -2993,7 +2963,7 @@ class ResultMapTest(fixtures.TestBase): def test_select_label_alt_name(self): t = self._fixture() l1, l2 = t.c.x.label("a"), t.c.y.label("b") - s = select([l1, l2]) + s = select(l1, l2) mapping = self._mapping(s) assert l1 in mapping @@ -3002,7 +2972,7 @@ class ResultMapTest(fixtures.TestBase): def test_select_alias_label_alt_name(self): t = self._fixture() l1, l2 = t.c.x.label("a"), t.c.y.label("b") - s = select([l1, l2]).alias() + s = select(l1, l2).alias() mapping = self._mapping(s) assert l1 in mapping @@ -3011,7 +2981,7 @@ class ResultMapTest(fixtures.TestBase): def test_select_alias_column(self): t = self._fixture() x, y = t.c.x, t.c.y - s = select([x, y]).alias() + s = select(x, y).alias() mapping = self._mapping(s) assert t.c.x in mapping @@ -3019,7 +2989,7 @@ class ResultMapTest(fixtures.TestBase): def test_select_alias_column_apply_labels(self): t = self._fixture() x, y = t.c.x, t.c.y - s = select([x, y]).apply_labels().alias() + s = select(x, y).apply_labels().alias() mapping = self._mapping(s) assert t.c.x in mapping @@ -3028,7 +2998,7 @@ class ResultMapTest(fixtures.TestBase): x = t.c.x ta = t.alias() - s = select([ta.c.x, ta.c.y]) + s = select(ta.c.x, ta.c.y) mapping = self._mapping(s) assert x not in mapping @@ -3039,7 +3009,7 @@ class ResultMapTest(fixtures.TestBase): ta = t.alias() l1, l2 = ta.c.x.label("a"), ta.c.y.label("b") - s = select([l1, l2]) + s = select(l1, l2) mapping = self._mapping(s) assert x not in mapping assert l1 in mapping @@ -3061,7 +3031,7 @@ class ResultMapTest(fixtures.TestBase): eq_( [ type(entry[-1]) - for entry in select([expr]).compile()._result_columns + for entry in select(expr).compile()._result_columns ], [Boolean], ) @@ -3072,7 +3042,7 @@ class ResultMapTest(fixtures.TestBase): eq_( [ type(entry[-1]) - for entry in select([expr]).compile()._result_columns + for entry in select(expr).compile()._result_columns ], [Boolean], ) @@ -3083,15 +3053,15 @@ class ResultMapTest(fixtures.TestBase): eq_( [ type(entry[-1]) - for entry in select([expr]).compile()._result_columns + for entry in select(expr).compile()._result_columns ], [Boolean], ) def test_column_subquery_plain(self): t = self._fixture() - s1 = select([t.c.x]).where(t.c.x > 5).scalar_subquery() - s2 = select([s1]) + s1 = select(t.c.x).where(t.c.x > 5).scalar_subquery() + s2 = select(s1) mapping = self._mapping(s2) assert t.c.x not in mapping assert s1 in mapping @@ -3114,7 +3084,7 @@ class ForUpdateTest(fixtures.TestBase, AssertsCompiledSQL): def test_basic_clone(self): t = table("t", column("c")) - s = select([t]).with_for_update(read=True, of=t.c.c) + s = select(t).with_for_update(read=True, of=t.c.c) s2 = visitors.ReplacingCloningVisitor().traverse(s) assert s2._for_update_arg is not s._for_update_arg eq_(s2._for_update_arg.read, True) @@ -3125,7 +3095,7 @@ class ForUpdateTest(fixtures.TestBase, AssertsCompiledSQL): def test_adapt(self): t = table("t", column("c")) - s = select([t]).with_for_update(read=True, of=t.c.c) + s = select(t).with_for_update(read=True, of=t.c.c) a = t.alias() s2 = sql_util.ClauseAdapter(a).traverse(s) eq_(s2._for_update_arg.of, [a.c.c]) @@ -3151,14 +3121,14 @@ class AliasTest(fixtures.TestBase, AssertsCompiledSQL): def test_get_children_preserves_multiple_nesting(self): t = table("t", column("c")) - stmt = select([t]) + stmt = select(t) a1 = stmt.alias() a2 = a1.alias() eq_(set(a2.get_children(column_collections=False)), {a1}) def test_correspondence_multiple_nesting(self): t = table("t", column("c")) - stmt = select([t]) + stmt = select(t) a1 = stmt.alias() a2 = a1.alias() @@ -3166,7 +3136,7 @@ class AliasTest(fixtures.TestBase, AssertsCompiledSQL): def test_copy_internals_multiple_nesting(self): t = table("t", column("c")) - stmt = select([t]) + stmt = select(t) a1 = stmt.alias() a2 = a1.alias() |
