diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2020-09-02 23:46:06 +0200 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-09-08 17:13:48 -0400 |
| commit | e8600608669d90c4a6385b312d271aed63eb5854 (patch) | |
| tree | ef984a01c536b2c81d2283b3ca5d9f4395f41dd0 /test/sql | |
| parent | 0d56a62f721ee6c91d8a8b6a407b959c9215b3b6 (diff) | |
| download | sqlalchemy-e8600608669d90c4a6385b312d271aed63eb5854.tar.gz | |
Update select usage to use the new 1.4 format
This change includes mainly that the bracketed use within
select() is moved to positional, and keyword arguments are
removed from calls to the select() function. it does not
yet fully address other issues such as keyword arguments passed
to the table.select().
Additionally, allows False / None to both be considered
as "disable" for all of select.correlate(), select.correlate_except(),
query.correlate(), which establishes consistency with
passing of ``False`` for the legact select(correlate=False)
argument.
Change-Id: Ie6c6e6abfbd3d75d4c8de504c0cf0159e6999108
Diffstat (limited to 'test/sql')
31 files changed, 1068 insertions, 1220 deletions
diff --git a/test/sql/test_case_statement.py b/test/sql/test_case_statement.py index f2a88bd73..74fe8876d 100644 --- a/test/sql/test_case_statement.py +++ b/test/sql/test_case_statement.py @@ -55,16 +55,13 @@ class CaseTest(fixtures.TestBase, AssertsCompiledSQL): @testing.requires.subqueries def test_case(self): inner = select( - [ - case( - (info_table.c.pk < 3, "lessthan3"), - (and_(info_table.c.pk >= 3, info_table.c.pk < 7), "gt3"), - ).label("x"), - info_table.c.pk, - info_table.c.info, - ], - from_obj=[info_table], - ) + case( + (info_table.c.pk < 3, "lessthan3"), + (and_(info_table.c.pk >= 3, info_table.c.pk < 7), "gt3"), + ).label("x"), + info_table.c.pk, + info_table.c.info, + ).select_from(info_table) inner_result = inner.execute().fetchall() @@ -87,7 +84,7 @@ class CaseTest(fixtures.TestBase, AssertsCompiledSQL): ], ) - outer = select([inner.alias("q_inner")]) + outer = select(inner.alias("q_inner")) outer_result = outer.execute().fetchall() @@ -101,17 +98,14 @@ class CaseTest(fixtures.TestBase, AssertsCompiledSQL): ] w_else = select( - [ - case( - [info_table.c.pk < 3, cast(3, Integer)], - [and_(info_table.c.pk >= 3, info_table.c.pk < 6), 6], - else_=0, - ).label("x"), - info_table.c.pk, - info_table.c.info, - ], - from_obj=[info_table], - ) + case( + [info_table.c.pk < 3, cast(3, Integer)], + [and_(info_table.c.pk >= 3, info_table.c.pk < 6), 6], + else_=0, + ).label("x"), + info_table.c.pk, + info_table.c.info, + ).select_from(info_table) else_result = w_else.execute().fetchall() @@ -159,23 +153,19 @@ class CaseTest(fixtures.TestBase, AssertsCompiledSQL): for s in [ select( - [ - case( - (info_table.c.info == "pk_4_data", text("'yes'")), - else_=text("'no'"), - ) - ] + case( + (info_table.c.info == "pk_4_data", text("'yes'")), + else_=text("'no'"), + ) ).order_by(info_table.c.info), select( - [ - case( - ( - info_table.c.info == "pk_4_data", - literal_column("'yes'"), - ), - else_=literal_column("'no'"), - ) - ] + case( + ( + info_table.c.info == "pk_4_data", + literal_column("'yes'"), + ), + else_=literal_column("'no'"), + ) ).order_by(info_table.c.info), ]: eq_( @@ -185,19 +175,16 @@ class CaseTest(fixtures.TestBase, AssertsCompiledSQL): def testcase_with_dict(self): query = select( - [ - case( - { - info_table.c.pk < 3: "lessthan3", - info_table.c.pk >= 3: "gt3", - }, - else_="other", - ), - info_table.c.pk, - info_table.c.info, - ], - from_obj=[info_table], - ) + case( + { + info_table.c.pk < 3: "lessthan3", + info_table.c.pk >= 3: "gt3", + }, + else_="other", + ), + info_table.c.pk, + info_table.c.info, + ).select_from(info_table) eq_( query.execute().fetchall(), [ diff --git a/test/sql/test_compare.py b/test/sql/test_compare.py index b5b6a4a52..098606a91 100644 --- a/test/sql/test_compare.py +++ b/test/sql/test_compare.py @@ -213,13 +213,13 @@ class CoreFixtures(object): {"orm": True, "parententity": MyEntity("b", table_a)} ), table_a.c.a._annotate( - {"orm": True, "parententity": MyEntity("b", select([table_a]))} + {"orm": True, "parententity": MyEntity("b", select(table_a))} ), table_a.c.a._annotate( { "orm": True, "parententity": MyEntity( - "b", select([table_a]).where(table_a.c.a == 5) + "b", select(table_a).where(table_a.c.a == 5) ), } ), @@ -235,7 +235,7 @@ class CoreFixtures(object): {"orm": True, "parententity": MyEntity("b", table_a)} ), table_a._annotate( - {"orm": True, "parententity": MyEntity("b", select([table_a]))} + {"orm": True, "parententity": MyEntity("b", select(table_a))} ), ), lambda: ( @@ -350,25 +350,25 @@ class CoreFixtures(object): Slice(2, 10, 15), ), lambda: ( - select([table_a.c.a]), - select([table_a.c.a, table_a.c.b]), - select([table_a.c.b, table_a.c.a]), - select([table_a.c.b, table_a.c.a]).limit(5), - select([table_a.c.b, table_a.c.a]).limit(5).offset(10), - select([table_a.c.b, table_a.c.a]) + select(table_a.c.a), + select(table_a.c.a, table_a.c.b), + select(table_a.c.b, table_a.c.a), + select(table_a.c.b, table_a.c.a).limit(5), + select(table_a.c.b, table_a.c.a).limit(5).offset(10), + select(table_a.c.b, table_a.c.a) .limit(literal_column("foobar")) .offset(10), - select([table_a.c.b, table_a.c.a]).apply_labels(), - select([table_a.c.a]).where(table_a.c.b == 5), - select([table_a.c.a]) + select(table_a.c.b, table_a.c.a).apply_labels(), + select(table_a.c.a).where(table_a.c.b == 5), + select(table_a.c.a) .where(table_a.c.b == 5) .where(table_a.c.a == 10), - select([table_a.c.a]).where(table_a.c.b == 5).with_for_update(), - select([table_a.c.a]) + select(table_a.c.a).where(table_a.c.b == 5).with_for_update(), + select(table_a.c.a) .where(table_a.c.b == 5) .with_for_update(nowait=True), - select([table_a.c.a]).where(table_a.c.b == 5).correlate(table_b), - select([table_a.c.a]) + select(table_a.c.a).where(table_a.c.b == 5).correlate(table_b), + select(table_a.c.a) .where(table_a.c.b == 5) .correlate_except(table_b), ), @@ -389,19 +389,19 @@ class CoreFixtures(object): select(table_a.c.a).join(table_c, table_a.c.a == table_c.c.x), ), lambda: ( - select([table_a.c.a]).cte(), - select([table_a.c.a]).cte(recursive=True), - select([table_a.c.a]).cte(name="some_cte", recursive=True), - select([table_a.c.a]).cte(name="some_cte"), - select([table_a.c.a]).cte(name="some_cte").alias("other_cte"), - select([table_a.c.a]) + select(table_a.c.a).cte(), + select(table_a.c.a).cte(recursive=True), + select(table_a.c.a).cte(name="some_cte", recursive=True), + select(table_a.c.a).cte(name="some_cte"), + select(table_a.c.a).cte(name="some_cte").alias("other_cte"), + select(table_a.c.a) .cte(name="some_cte") - .union_all(select([table_a.c.a])), - select([table_a.c.a]) + .union_all(select(table_a.c.a)), + select(table_a.c.a) .cte(name="some_cte") - .union_all(select([table_a.c.b])), - select([table_a.c.a]).lateral(), - select([table_a.c.a]).lateral(name="bar"), + .union_all(select(table_a.c.b)), + select(table_a.c.a).lateral(), + select(table_a.c.a).lateral(name="bar"), table_a.tablesample(func.bernoulli(1)), table_a.tablesample(func.bernoulli(1), seed=func.random()), table_a.tablesample(func.bernoulli(1), seed=func.other_random()), @@ -416,12 +416,12 @@ class CoreFixtures(object): table_a.insert().values({})._annotate({"nocache": True}), table_b.insert(), table_b.insert().with_dialect_options(sqlite_foo="some value"), - table_b.insert().from_select(["a", "b"], select([table_a])), + table_b.insert().from_select(["a", "b"], select(table_a)), table_b.insert().from_select( - ["a", "b"], select([table_a]).where(table_a.c.a > 5) + ["a", "b"], select(table_a).where(table_a.c.a > 5) ), - table_b.insert().from_select(["a", "b"], select([table_b])), - table_b.insert().from_select(["c", "d"], select([table_a])), + table_b.insert().from_select(["a", "b"], select(table_b)), + table_b.insert().from_select(["c", "d"], select(table_a)), table_b.insert().returning(table_b.c.a), table_b.insert().returning(table_b.c.a, table_b.c.b), table_b.insert().inline(), @@ -524,31 +524,31 @@ class CoreFixtures(object): # ), ), lambda: ( - select([table_a.c.a]), - select([table_a.c.a]).prefix_with("foo"), - select([table_a.c.a]).prefix_with("foo", dialect="mysql"), - select([table_a.c.a]).prefix_with("foo", dialect="postgresql"), - select([table_a.c.a]).prefix_with("bar"), - select([table_a.c.a]).suffix_with("bar"), + select(table_a.c.a), + select(table_a.c.a).prefix_with("foo"), + select(table_a.c.a).prefix_with("foo", dialect="mysql"), + select(table_a.c.a).prefix_with("foo", dialect="postgresql"), + select(table_a.c.a).prefix_with("bar"), + select(table_a.c.a).suffix_with("bar"), ), lambda: ( - select([table_a_2.c.a]), - select([table_a_2_fs.c.a]), - select([table_a_2_bs.c.a]), + select(table_a_2.c.a), + select(table_a_2_fs.c.a), + select(table_a_2_bs.c.a), ), lambda: ( - select([table_a.c.a]), - select([table_a.c.a]).with_hint(None, "some hint"), - select([table_a.c.a]).with_hint(None, "some other hint"), - select([table_a.c.a]).with_hint(table_a, "some hint"), - select([table_a.c.a]) + select(table_a.c.a), + select(table_a.c.a).with_hint(None, "some hint"), + select(table_a.c.a).with_hint(None, "some other hint"), + select(table_a.c.a).with_hint(table_a, "some hint"), + select(table_a.c.a) .with_hint(table_a, "some hint") .with_hint(None, "some other hint"), - select([table_a.c.a]).with_hint(table_a, "some other hint"), - select([table_a.c.a]).with_hint( + select(table_a.c.a).with_hint(table_a, "some other hint"), + select(table_a.c.a).with_hint( table_a, "some hint", dialect_name="mysql" ), - select([table_a.c.a]).with_hint( + select(table_a.c.a).with_hint( table_a, "some hint", dialect_name="postgresql" ), ), @@ -564,32 +564,32 @@ class CoreFixtures(object): table_a.alias("b"), table_a.alias(), table_b.alias("a"), - select([table_a.c.a]).alias("a"), + select(table_a.c.a).alias("a"), ), lambda: ( FromGrouping(table_a.alias("a")), FromGrouping(table_a.alias("b")), ), lambda: ( - SelectStatementGrouping(select([table_a])), - SelectStatementGrouping(select([table_b])), + SelectStatementGrouping(select(table_a)), + SelectStatementGrouping(select(table_b)), ), lambda: ( - select([table_a.c.a]).scalar_subquery(), - select([table_a.c.a]).where(table_a.c.b == 5).scalar_subquery(), + select(table_a.c.a).scalar_subquery(), + select(table_a.c.a).where(table_a.c.b == 5).scalar_subquery(), ), lambda: ( exists().where(table_a.c.a == 5), exists().where(table_a.c.b == 5), ), lambda: ( - union(select([table_a.c.a]), select([table_a.c.b])), - union(select([table_a.c.a]), select([table_a.c.b])).order_by("a"), - union_all(select([table_a.c.a]), select([table_a.c.b])), - union(select([table_a.c.a])), + union(select(table_a.c.a), select(table_a.c.b)), + union(select(table_a.c.a), select(table_a.c.b)).order_by("a"), + union_all(select(table_a.c.a), select(table_a.c.b)), + union(select(table_a.c.a)), union( - select([table_a.c.a]), - select([table_a.c.b]).where(table_a.c.b > 5), + select(table_a.c.a), + select(table_a.c.b).where(table_a.c.b > 5), ), ), lambda: ( @@ -626,7 +626,7 @@ class CoreFixtures(object): a2 = table_b_like_a.alias() stmt = ( - select([table_a.c.a, a1.c.b, a2.c.b]) + select(table_a.c.a, a1.c.b, a2.c.b) .where(table_a.c.b == a1.c.b) .where(a1.c.b == a2.c.b) .where(a1.c.a == 5) @@ -639,7 +639,7 @@ class CoreFixtures(object): a2 = table_a.alias() stmt = ( - select([table_a.c.a, a1.c.b, a2.c.b]) + select(table_a.c.a, a1.c.b, a2.c.b) .where(table_a.c.b == a1.c.b) .where(a1.c.b == a2.c.b) .where(a1.c.a == 5) @@ -650,7 +650,7 @@ class CoreFixtures(object): def two(): inner = one().subquery() - stmt = select([table_b.c.a, inner.c.a, inner.c.b]).select_from( + stmt = select(table_b.c.a, inner.c.a, inner.c.b).select_from( table_b.join(inner, table_b.c.b == inner.c.b) ) @@ -663,7 +663,7 @@ class CoreFixtures(object): ex = exists().where(table_b.c.b == a1.c.a) stmt = ( - select([a1.c.a, a2.c.a]) + select(a1.c.a, a2.c.a) .select_from(a1.join(a2, a1.c.b == a2.c.b)) .where(ex) ) @@ -676,15 +676,15 @@ class CoreFixtures(object): def _statements_w_context_options_fixtures(): return [ - select([table_a])._add_context_option(opt1, True), - select([table_a])._add_context_option(opt1, 5), - select([table_a]) + select(table_a)._add_context_option(opt1, True), + select(table_a)._add_context_option(opt1, 5), + select(table_a) ._add_context_option(opt1, True) ._add_context_option(opt2, True), - select([table_a]) + select(table_a) ._add_context_option(opt1, True) ._add_context_option(opt2, 5), - select([table_a])._add_context_option(opt3, True), + select(table_a)._add_context_option(opt3, True), ] fixtures.append(_statements_w_context_options_fixtures) @@ -696,7 +696,7 @@ class CoreFixtures(object): 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. @@ -712,7 +712,7 @@ class CoreFixtures(object): 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. @@ -726,10 +726,10 @@ class CoreFixtures(object): l1, l2 = table_a.c.a.label(None), table_a.c.b.label(None) - stmt = select([table_a.c.a, table_a.c.b, l1, l2]) + stmt = select(table_a.c.a, table_a.c.b, l1, l2) subq = stmt.subquery() - return select([subq]).where(subq.c[2] == 10) + return select(subq).where(subq.c[2] == 10) return ( one(), @@ -1060,7 +1060,7 @@ class CacheKeyTest(CacheKeyFixture, CoreFixtures, fixtures.TestBase): f2 = Foobar2() eq_(f2._generate_cache_key(), None) - s1 = select([column("q"), Foobar2()]) + s1 = select(column("q"), Foobar2()) eq_(s1._generate_cache_key(), None) @@ -1093,7 +1093,7 @@ class CacheKeyTest(CacheKeyFixture, CoreFixtures, fixtures.TestBase): def test_generative_cache_key_regen(self): t1 = table("t1", column("a"), column("b")) - s1 = select([t1]) + s1 = select(t1) ck1 = s1._generate_cache_key() @@ -1108,7 +1108,7 @@ class CacheKeyTest(CacheKeyFixture, CoreFixtures, fixtures.TestBase): def test_generative_cache_key_regen_w_del(self): t1 = table("t1", column("a"), column("b")) - s1 = select([t1]) + s1 = select(t1) ck1 = s1._generate_cache_key() @@ -1196,17 +1196,17 @@ class CompareAndCopyTest(CoreFixtures, fixtures.TestBase): def test_compare_col_identity(self): stmt1 = ( - select([table_a.c.a, table_b.c.b]) + select(table_a.c.a, table_b.c.b) .where(table_a.c.a == table_b.c.b) .alias() ) stmt1_c = ( - select([table_a.c.a, table_b.c.b]) + select(table_a.c.a, table_b.c.b) .where(table_a.c.a == table_b.c.b) .alias() ) - stmt2 = union(select([table_a]), select([table_b])) + stmt2 = union(select(table_a), select(table_b)) equivalents = {table_a.c.a: [table_b.c.a]} @@ -1389,12 +1389,12 @@ class CompareClausesTest(fixtures.TestBase): is_false(l1.compare(l2)) def test_cache_key_limit_offset_values(self): - s1 = select([column("q")]).limit(10) - s2 = select([column("q")]).limit(25) - s3 = select([column("q")]).limit(25).offset(5) - s4 = select([column("q")]).limit(25).offset(18) - s5 = select([column("q")]).limit(7).offset(12) - s6 = select([column("q")]).limit(literal_column("q")).offset(12) + s1 = select(column("q")).limit(10) + s2 = select(column("q")).limit(25) + s3 = select(column("q")).limit(25).offset(5) + s4 = select(column("q")).limit(25).offset(18) + s5 = select(column("q")).limit(7).offset(12) + s6 = select(column("q")).limit(literal_column("q")).offset(12) for should_eq_left, should_eq_right in [(s1, s2), (s3, s4), (s3, s5)]: eq_( @@ -1481,8 +1481,8 @@ class CompareClausesTest(fixtures.TestBase): x_a.compare(x_b._annotate({"bar": True}), compare_annotations=True) ) - s1 = select([t.c.x])._annotate({"foo": True}) - s2 = select([t.c.x])._annotate({"foo": True}) + s1 = select(t.c.x)._annotate({"foo": True}) + s2 = select(t.c.x)._annotate({"foo": True}) is_true(s1.compare(s2, compare_annotations=True)) @@ -1504,7 +1504,7 @@ class CompareClausesTest(fixtures.TestBase): is_true((t.c.x == 5).compare(x_a == 5)) is_false((t.c.y == 5).compare(x_a == 5)) - s = select([t]).subquery() + s = select(t).subquery() x_p = s.c.x is_false(x_a.compare(x_p)) is_false(t.c.x.compare(x_p)) diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index b43d09045..a6118c03f 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -4901,11 +4901,12 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): select(t2, s1.correlate_except(t2).alias()) ) - def test_correlate_except_none(self): + @testing.combinations(False, None) + def test_correlate_except_none(self, value): t1, t2, s1 = self._fixture() self._assert_where_all_correlated( select(t1, t2).where( - t2.c.a == s1.correlate_except(None).scalar_subquery() + t2.c.a == s1.correlate_except(value).scalar_subquery() ) ) @@ -4937,10 +4938,11 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL): select(t2).having(t2.c.a == s1.scalar_subquery()) ) - def test_correlate_disabled_where(self): + @testing.combinations(False, None) + def test_correlate_disabled_where(self, value): 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(value).scalar_subquery()) ) def test_correlate_disabled_column(self): diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py index c9178d580..410f49f2a 100644 --- a/test/sql/test_cte.py +++ b/test/sql/test_cte.py @@ -34,21 +34,19 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): regional_sales = ( select( - [ - orders.c.region, - func.sum(orders.c.amount).label("total_sales"), - ] + orders.c.region, + func.sum(orders.c.amount).label("total_sales"), ) .group_by(orders.c.region) .cte("regional_sales") ) top_regions = ( - select([regional_sales.c.region]) + select(regional_sales.c.region) .where( regional_sales.c.total_sales > select( - [func.sum(regional_sales.c.total_sales) / 10] + func.sum(regional_sales.c.total_sales) / 10 ).scalar_subquery() ) .cte("top_regions") @@ -56,14 +54,12 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): s = ( select( - [ - orders.c.region, - orders.c.product, - func.sum(orders.c.quantity).label("product_units"), - func.sum(orders.c.amount).label("product_sales"), - ] + orders.c.region, + orders.c.product, + func.sum(orders.c.quantity).label("product_units"), + func.sum(orders.c.amount).label("product_sales"), ) - .where(orders.c.region.in_(select([top_regions.c.region]))) + .where(orders.c.region.in_(select(top_regions.c.region))) .group_by(orders.c.region, orders.c.product) ) @@ -93,7 +89,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) included_parts = ( - select([parts.c.sub_part, parts.c.part, parts.c.quantity]) + select(parts.c.sub_part, parts.c.part, parts.c.quantity) .where(parts.c.part == "our part") .cte(recursive=True) ) @@ -102,22 +98,16 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): parts_alias = parts.alias() included_parts = included_parts.union( select( - [ - parts_alias.c.sub_part, - parts_alias.c.part, - parts_alias.c.quantity, - ] + parts_alias.c.sub_part, + parts_alias.c.part, + parts_alias.c.quantity, ).where(parts_alias.c.part == incl_alias.c.sub_part) ) s = ( select( - [ - included_parts.c.sub_part, - func.sum(included_parts.c.quantity).label( - "total_quantity" - ), - ] + included_parts.c.sub_part, + func.sum(included_parts.c.quantity).label("total_quantity"), ) .select_from( included_parts.join( @@ -167,7 +157,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) included_parts = ( - select([parts.c.sub_part, parts.c.part, parts.c.quantity]) + select(parts.c.sub_part, parts.c.part, parts.c.quantity) .where(parts.c.part == "our part") .cte(recursive=True) ) @@ -176,22 +166,16 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): parts_alias = parts.alias() included_parts = incl_alias.union( select( - [ - parts_alias.c.sub_part, - parts_alias.c.part, - parts_alias.c.quantity, - ] + parts_alias.c.sub_part, + parts_alias.c.part, + parts_alias.c.quantity, ).where(parts_alias.c.part == incl_alias.c.sub_part) ) s = ( select( - [ - included_parts.c.sub_part, - func.sum(included_parts.c.quantity).label( - "total_quantity" - ), - ] + included_parts.c.sub_part, + func.sum(included_parts.c.quantity).label("total_quantity"), ) .select_from( included_parts.join( @@ -217,10 +201,10 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) def test_recursive_union_no_alias_one(self): - s1 = select([literal(0).label("x")]) + s1 = select(literal(0).label("x")) cte = s1.cte(name="cte", recursive=True) - cte = cte.union_all(select([cte.c.x + 1]).where(cte.c.x < 10)) - s2 = select([cte]) + cte = cte.union_all(select(cte.c.x + 1).where(cte.c.x < 10)) + s2 = select(cte) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -231,12 +215,12 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) def test_recursive_union_alias_one(self): - s1 = select([literal(0).label("x")]) + s1 = select(literal(0).label("x")) cte = s1.cte(name="cte", recursive=True) - cte = cte.union_all(select([cte.c.x + 1]).where(cte.c.x < 10)).alias( + cte = cte.union_all(select(cte.c.x + 1).where(cte.c.x < 10)).alias( "cr1" ) - s2 = select([cte]) + s2 = select(cte) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -263,9 +247,9 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # I know, this is the PG VALUES keyword, # we're cheating here. also yes we need the SELECT, # sorry PG. - 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)) self.assert_compile( s, "WITH RECURSIVE t(n) AS " @@ -284,9 +268,9 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # I know, this is the PG VALUES keyword, # we're cheating here. also yes we need the SELECT, # sorry PG. - 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)).alias("ta") - 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)).alias("ta") + s = select(func.sum(t.c.n)) self.assert_compile( s, "WITH RECURSIVE t(n) AS " @@ -301,15 +285,15 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # like test one, but let's refer to the CTE # in a sibling CTE. - s1 = select([literal(0).label("x")]) + s1 = select(literal(0).label("x")) cte = s1.cte(name="cte", recursive=True) # can't do it here... - # bar = select([cte]).cte('bar') - cte = cte.union_all(select([cte.c.x + 1]).where(cte.c.x < 10)) - bar = select([cte]).cte("bar") + # bar = select(cte).cte('bar') + cte = cte.union_all(select(cte.c.x + 1).where(cte.c.x < 10)) + bar = select(cte).cte("bar") - s2 = select([cte, bar]) + s2 = select(cte, bar) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -324,17 +308,17 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # like test one, but let's refer to the CTE # in a sibling CTE. - s1 = select([literal(0).label("x")]) + s1 = select(literal(0).label("x")) cte = s1.cte(name="cte", recursive=True) # can't do it here... - # bar = select([cte]).cte('bar') - cte = cte.union_all(select([cte.c.x + 1]).where(cte.c.x < 10)).alias( + # bar = select(cte).cte('bar') + cte = cte.union_all(select(cte.c.x + 1).where(cte.c.x < 10)).alias( "cs1" ) - bar = select([cte]).cte("bar").alias("cs2") + bar = select(cte).cte("bar").alias("cs2") - s2 = select([cte, bar]) + s2 = select(cte, bar) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -351,15 +335,15 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # how the compiler resolves multiple instances # of "cte". - s1 = select([literal(0).label("x")]) + s1 = select(literal(0).label("x")) cte = s1.cte(name="cte", recursive=True) - bar = select([cte]).cte("bar") - cte = cte.union_all(select([cte.c.x + 1]).where(cte.c.x < 10)) + bar = select(cte).cte("bar") + cte = cte.union_all(select(cte.c.x + 1).where(cte.c.x < 10)) # outer cte rendered first, then bar, which # includes "inner" cte - s2 = select([cte, bar]) + s2 = select(cte, bar) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -372,7 +356,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # bar rendered, only includes "inner" cte, # "outer" cte isn't present - s2 = select([bar]) + s2 = select(bar) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -383,7 +367,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # bar rendered, but then the "outer" # cte is rendered. - s2 = select([bar, cte]) + s2 = select(bar, cte) self.assert_compile( s2, "WITH RECURSIVE bar AS (SELECT cte.x AS x FROM cte), " @@ -400,17 +384,17 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # how the compiler resolves multiple instances # of "cte". - s1 = select([literal(0).label("x")]) + s1 = select(literal(0).label("x")) cte = s1.cte(name="cte", recursive=True) - bar = select([cte]).cte("bar").alias("cs1") - cte = cte.union_all(select([cte.c.x + 1]).where(cte.c.x < 10)).alias( + bar = select(cte).cte("bar").alias("cs1") + cte = cte.union_all(select(cte.c.x + 1).where(cte.c.x < 10)).alias( "cs2" ) # outer cte rendered first, then bar, which # includes "inner" cte - s2 = select([cte, bar]) + s2 = select(cte, bar) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -423,7 +407,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # bar rendered, only includes "inner" cte, # "outer" cte isn't present - s2 = select([bar]) + s2 = select(bar) self.assert_compile( s2, "WITH RECURSIVE cte(x) AS " @@ -434,7 +418,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): # bar rendered, but then the "outer" # cte is rendered. - s2 = select([bar, cte]) + s2 = select(bar, cte) self.assert_compile( s2, "WITH RECURSIVE bar AS (SELECT cte.x AS x FROM cte), " @@ -448,12 +432,12 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_conflicting_names(self): """test a flat out name conflict.""" - s1 = select([1]) + s1 = select(1) c1 = s1.cte(name="cte1", recursive=True) - s2 = select([1]) + s2 = select(1) c2 = s2.cte(name="cte1", recursive=True) - s = select([c1, c2]) + s = select(c1, c2) assert_raises_message( CompileError, "Multiple, unrelated CTEs found " "with the same name: 'cte1'", @@ -463,11 +447,11 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_union(self): orders = table("orders", column("region"), column("amount")) - regional_sales = select([orders.c.region, orders.c.amount]).cte( + regional_sales = select(orders.c.region, orders.c.amount).cte( "regional_sales" ) - s = select([regional_sales.c.region]).where( + s = select(regional_sales.c.region).where( regional_sales.c.amount > 500 ) @@ -482,7 +466,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) s = s.union_all( - select([regional_sales.c.region]).where( + select(regional_sales.c.region).where( regional_sales.c.amount < 300 ) ) @@ -502,12 +486,12 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): orders = table("orders", column("region"), column("amount")) regional_sales = ( - select([orders.c.region, orders.c.amount]) + select(orders.c.region, orders.c.amount) .cte("regional_sales") .alias("rs") ) - s = select([regional_sales.c.region]).where( + s = select(regional_sales.c.region).where( regional_sales.c.amount > 500 ) @@ -522,7 +506,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) s = s.union_all( - select([regional_sales.c.region]).where( + select(regional_sales.c.region).where( regional_sales.c.amount < 300 ) ) @@ -558,7 +542,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): tag = table("tag", column("tag"), column("entity_id")) tags = ( - select([tag.c.entity_id, func.array_agg(tag.c.tag).label("tags")]) + select(tag.c.entity_id, func.array_agg(tag.c.tag).label("tags")) .group_by(tag.c.entity_id) .cte("unaliased_tags") ) @@ -567,7 +551,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): employer_tags = tags.alias(name="employer_tags") q = ( - select([entity.c.name]) + select(entity.c.name) .select_from( entity.outerjoin( entity_tags, tags.c.entity_id == entity.c.id @@ -612,8 +596,8 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_reserved_quote(self): orders = table("orders", column("order")) - s = select([orders.c.order]).cte("regional_sales", recursive=True) - s = select([s.c.order]) + s = select(orders.c.order).cte("regional_sales", recursive=True) + s = select(s.c.order) self.assert_compile( s, 'WITH RECURSIVE regional_sales("order") AS ' @@ -624,12 +608,12 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) def test_multi_subq_quote(self): - cte = select([literal(1).label("id")]).cte(name="CTE") + cte = select(literal(1).label("id")).cte(name="CTE") - s1 = select([cte.c.id]).alias() - s2 = select([cte.c.id]).alias() + s1 = select(cte.c.id).alias() + s2 = select(cte.c.id).alias() - s = select([s1, s2]) + s = select(s1, s2) self.assert_compile( s, 'WITH "CTE" AS (SELECT :param_1 AS id) ' @@ -639,12 +623,12 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) def test_multi_subq_alias(self): - cte = select([literal(1).label("id")]).cte(name="cte1").alias("aa") + cte = select(literal(1).label("id")).cte(name="cte1").alias("aa") - s1 = select([cte.c.id]).alias() - s2 = select([cte.c.id]).alias() + s1 = select(cte.c.id).alias() + s2 = select(cte.c.id).alias() - s = select([s1, s2]) + s = select(s1, s2) self.assert_compile( s, "WITH cte1 AS (SELECT :param_1 AS id) " @@ -659,23 +643,23 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): b = table("b", column("id"), column("fid")) c = table("c", column("id"), column("fid")) - cte1 = select([a.c.id]).cte(name="cte1") + cte1 = select(a.c.id).cte(name="cte1") aa = cte1.alias("aa") cte2 = ( - select([b.c.id]) + select(b.c.id) .select_from(b.join(aa, b.c.fid == aa.c.id)) .cte(name="cte2") ) cte3 = ( - select([c.c.id]) + select(c.c.id) .select_from(c.join(aa, c.c.fid == aa.c.id)) .cte(name="cte3") ) - stmt = select([cte3.c.id, cte2.c.id]).select_from( + stmt = select(cte3.c.id, cte2.c.id).select_from( cte2.join(cte3, cte2.c.id == cte3.c.id) ) self.assert_compile( @@ -689,11 +673,11 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) def test_named_alias_no_quote(self): - cte = select([literal(1).label("id")]).cte(name="CTE") + cte = select(literal(1).label("id")).cte(name="CTE") - s1 = select([cte.c.id]).alias(name="no_quotes") + s1 = select(cte.c.id).alias(name="no_quotes") - s = select([s1]) + s = select(s1) self.assert_compile( s, 'WITH "CTE" AS (SELECT :param_1 AS id) ' @@ -702,11 +686,11 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) def test_named_alias_quote(self): - cte = select([literal(1).label("id")]).cte(name="CTE") + cte = select(literal(1).label("id")).cte(name="CTE") - s1 = select([cte.c.id]).alias(name="Quotes Required") + s1 = select(cte.c.id).alias(name="Quotes Required") - s = select([s1]) + s = select(s1) self.assert_compile( s, 'WITH "CTE" AS (SELECT :param_1 AS id) ' @@ -715,15 +699,13 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) def test_named_alias_disable_quote(self): - cte = select([literal(1).label("id")]).cte( + cte = select(literal(1).label("id")).cte( name=quoted_name("CTE", quote=False) ) - s1 = select([cte.c.id]).alias( - name=quoted_name("DontQuote", quote=False) - ) + s1 = select(cte.c.id).alias(name=quoted_name("DontQuote", quote=False)) - s = select([s1]) + s = select(s1) self.assert_compile( s, "WITH CTE AS (SELECT :param_1 AS id) " @@ -733,8 +715,8 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_positional_binds(self): orders = table("orders", column("order")) - s = select([orders.c.order, literal("x")]).cte("regional_sales") - s = select([s.c.order, literal("y")]) + s = select(orders.c.order, literal("x")).cte("regional_sales") + s = select(s.c.order, literal("y")) dialect = default.DefaultDialect() dialect.positional = True dialect.paramstyle = "numeric" @@ -759,11 +741,11 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): ) s = ( - select([orders.c.order]) + select(orders.c.order) .where(orders.c.order == "x") .cte("regional_sales") ) - s = select([s.c.order]).where(s.c.order == "y") + s = select(s.c.order).where(s.c.order == "y") self.assert_compile( s, 'WITH regional_sales AS (SELECT orders."order" AS ' @@ -776,13 +758,13 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_positional_binds_2(self): orders = table("orders", column("order")) - s = select([orders.c.order, literal("x")]).cte("regional_sales") - s = select([s.c.order, literal("y")]) + s = select(orders.c.order, literal("x")).cte("regional_sales") + s = select(s.c.order, literal("y")) dialect = default.DefaultDialect() dialect.positional = True dialect.paramstyle = "numeric" s1 = ( - select([orders.c.order]) + select(orders.c.order) .where(orders.c.order == "x") .cte("regional_sales_1") ) @@ -791,18 +773,13 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): s2 = ( select( - [ - orders.c.order == "y", - s1a.c.order, - orders.c.order, - s1.c.order, - ] + orders.c.order == "y", s1a.c.order, orders.c.order, s1.c.order, ) .where(orders.c.order == "z") .cte("regional_sales_2") ) - s3 = select([s2]) + s3 = select(s2) self.assert_compile( s3, @@ -823,13 +800,13 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_positional_binds_2_asliteral(self): orders = table("orders", column("order")) - s = select([orders.c.order, literal("x")]).cte("regional_sales") - s = select([s.c.order, literal("y")]) + s = select(orders.c.order, literal("x")).cte("regional_sales") + s = select(s.c.order, literal("y")) dialect = default.DefaultDialect() dialect.positional = True dialect.paramstyle = "numeric" s1 = ( - select([orders.c.order]) + select(orders.c.order) .where(orders.c.order == "x") .cte("regional_sales_1") ) @@ -838,18 +815,13 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): s2 = ( select( - [ - orders.c.order == "y", - s1a.c.order, - orders.c.order, - s1.c.order, - ] + orders.c.order == "y", s1a.c.order, orders.c.order, s1.c.order, ) .where(orders.c.order == "z") .cte("regional_sales_2") ) - s3 = select([s2]) + s3 = select(s2) self.assert_compile( s3, @@ -873,12 +845,12 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_all_aliases(self): orders = table("order", column("order")) - s = select([orders.c.order]).cte("regional_sales") + s = select(orders.c.order).cte("regional_sales") r1 = s.alias() r2 = s.alias() - s2 = select([r1, r2]).where(r1.c.order > r2.c.order) + s2 = select(r1, r2).where(r1.c.order > r2.c.order) self.assert_compile( s2, @@ -889,7 +861,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): 'regional_sales AS anon_2 WHERE anon_1."order" > anon_2."order"', ) - s3 = select([orders]).select_from( + s3 = select(orders).select_from( orders.join(r1, r1.c.order == orders.c.order) ) @@ -905,9 +877,9 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_prefixes(self): orders = table("order", column("order")) - s = select([orders.c.order]).cte("regional_sales") + s = select(orders.c.order).cte("regional_sales") s = s.prefix_with("NOT MATERIALIZED", dialect="postgresql") - stmt = select([orders]).where(orders.c.order > s.c.order) + stmt = select(orders).where(orders.c.order > s.c.order) self.assert_compile( stmt, @@ -927,10 +899,10 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_suffixes(self): orders = table("order", column("order")) - s = select([orders.c.order]).cte("regional_sales") + s = select(orders.c.order).cte("regional_sales") s = s.suffix_with("pg suffix", dialect="postgresql") s = s.suffix_with("oracle suffix", dialect="oracle") - stmt = select([orders]).where(orders.c.order > s.c.order) + stmt = select(orders).where(orders.c.order > s.c.order) self.assert_compile( stmt, @@ -976,12 +948,10 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): insert = orders.insert().from_select( orders.c.keys(), select( - [ - literal("Region1"), - literal(1.0), - literal("Product1"), - literal(1), - ] + literal("Region1"), + literal(1.0), + literal("Product1"), + literal(1), ).where(~exists(upsert.select())), ) @@ -1115,7 +1085,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): parts = table("parts", column("part"), column("sub_part")) included_parts = ( - select([parts.c.sub_part, parts.c.part]) + select(parts.c.sub_part, parts.c.part) .where(parts.c.part == "our part") .cte("included_parts", recursive=True) ) @@ -1123,11 +1093,11 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): pr = included_parts.alias("pr") p = parts.alias("p") included_parts = included_parts.union_all( - select([p.c.sub_part, p.c.part]).where(p.c.part == pr.c.sub_part) + select(p.c.sub_part, p.c.part).where(p.c.part == pr.c.sub_part) ) stmt = ( parts.delete() - .where(parts.c.part.in_(select([included_parts.c.part]))) + .where(parts.c.part.in_(select(included_parts.c.part))) .returning(parts.c.part) ) @@ -1156,7 +1126,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): .cte("pd") ) - stmt = select([cte]) + stmt = select(cte) assert "autocommit" not in stmt._execution_options eq_(stmt.compile().execution_options["autocommit"], True) @@ -1192,9 +1162,9 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_standalone_function(self): a = table("a", column("x")) - a_stmt = select([a]) + a_stmt = select(a) - stmt = select([cte(a_stmt)]) + stmt = select(cte(a_stmt)) self.assert_compile( stmt, @@ -1204,7 +1174,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): def test_no_alias_construct(self): a = table("a", column("x")) - a_stmt = select([a]) + a_stmt = select(a) assert_raises_message( NotImplementedError, diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index aa1c0d48d..3733d70c7 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -384,11 +384,11 @@ class DefaultRoundTripTest(fixtures.TablesTest): def myupdate_with_ctx(ctx): conn = ctx.connection - return conn.execute(sa.select([sa.text("13")])).scalar() + return conn.execute(sa.select(sa.text("13"))).scalar() def mydefault_using_connection(ctx): conn = ctx.connection - return conn.execute(sa.select([sa.text("12")])).scalar() + return conn.execute(sa.select(sa.text("12"))).scalar() use_function_defaults = testing.against("postgresql", "mssql") is_oracle = testing.against("oracle") @@ -413,13 +413,11 @@ class DefaultRoundTripTest(fixtures.TablesTest): if is_oracle: ts = conn.scalar( sa.select( - [ - func.trunc( - func.current_timestamp(), - sa.literal_column("'DAY'"), - type_=sa.Date, - ) - ] + func.trunc( + func.current_timestamp(), + sa.literal_column("'DAY'"), + type_=sa.Date, + ) ) ) currenttime = cls.currenttime = func.trunc( @@ -530,7 +528,7 @@ class DefaultRoundTripTest(fixtures.TablesTest): connection.execute(t.insert()) ctexec = connection.execute( - sa.select([self.currenttime.label("now")]) + sa.select(self.currenttime.label("now")) ).scalar() result = connection.execute(t.select().order_by(t.c.col1)) today = datetime.date.today() @@ -897,14 +895,14 @@ class CTEDefaultTest(fixtures.TablesTest): expected = (7, 5) elif a == "select": conn.execute(q.insert().values(x=5, y=10, z=1)) - cte = sa.select([q.c.z]).cte("c") + cte = sa.select(q.c.z).cte("c") expected = (5, 10) if b == "select": conn.execute(p.insert().values(s=1)) - stmt = select([p.c.s, cte.c.z]).where(p.c.s == cte.c.z) + stmt = select(p.c.s, cte.c.z).where(p.c.s == cte.c.z) elif b == "insert": - sel = select([1, cte.c.z]) + sel = select(1, cte.c.z) stmt = ( p.insert().from_select(["s", "t"], sel).returning(p.c.s, p.c.t) ) @@ -920,7 +918,7 @@ class CTEDefaultTest(fixtures.TablesTest): ) eq_(list(conn.execute(stmt)), [(1, 1)]) - eq_(conn.execute(select([q.c.x, q.c.y])).first(), expected) + eq_(conn.execute(select(q.c.x, q.c.y)).first(), expected) class PKDefaultTest(fixtures.TablesTest): @@ -938,7 +936,7 @@ class PKDefaultTest(fixtures.TablesTest): "id", Integer, primary_key=True, - default=sa.select([func.max(t2.c.nextid)]).scalar_subquery(), + default=sa.select(func.max(t2.c.nextid)).scalar_subquery(), ), Column("data", String(30)), ) @@ -1079,7 +1077,7 @@ class EmptyInsertTest(fixtures.TestBase): connection.execute(t1.insert()) eq_( 1, - connection.scalar(select([func.count(text("*"))]).select_from(t1)), + connection.scalar(select(func.count(text("*"))).select_from(t1)), ) eq_(True, connection.scalar(t1.select())) @@ -1098,7 +1096,7 @@ class AutoIncrementTest(fixtures.TestBase): r = connection.execute(single.insert()) id_ = r.inserted_primary_key[0] eq_(id_, 1) - eq_(connection.scalar(sa.select([single.c.id])), 1) + eq_(connection.scalar(sa.select(single.c.id)), 1) def test_autoinc_detection_no_affinity(self): class MyType(TypeDecorator): @@ -1191,7 +1189,7 @@ class AutoIncrementTest(fixtures.TestBase): connection.execute(dataset_no_autoinc.insert()) eq_( connection.scalar( - select([func.count("*")]).select_from(dataset_no_autoinc) + select(func.count("*")).select_from(dataset_no_autoinc) ), 1, ) @@ -1209,7 +1207,7 @@ class AutoIncrementTest(fixtures.TestBase): connection.execute(dataset_no_autoinc.insert()) eq_( connection.scalar( - select([func.count("*")]).select_from(dataset_no_autoinc) + select(func.count("*")).select_from(dataset_no_autoinc) ), 1, ) @@ -1312,7 +1310,7 @@ class SpecialTypePKTest(fixtures.TestBase): self._run_test(server_default="1", autoincrement=False) def test_clause(self): - stmt = select([cast("INT_1", type_=self.MyInteger)]).scalar_subquery() + stmt = select(cast("INT_1", type_=self.MyInteger)).scalar_subquery() self._run_test(default=stmt) @testing.requires.returning @@ -1500,7 +1498,7 @@ class InsertFromSelectTest(fixtures.TablesTest): table.create(connection) - sel = select([data.c.x, data.c.y]) + sel = select(data.c.x, data.c.y) ins = table.insert().from_select(["x", "y"], sel) connection.execute(ins) @@ -1529,7 +1527,7 @@ class InsertFromSelectTest(fixtures.TablesTest): table.create(connection) - sel = select([data.c.x, data.c.y]) + sel = select(data.c.x, data.c.y) ins = table.insert().from_select(["x", "y"], sel) connection.execute(ins) diff --git a/test/sql/test_delete.py b/test/sql/test_delete.py index 5dcc0d112..2e3ba4245 100644 --- a/test/sql/test_delete.py +++ b/test/sql/test_delete.py @@ -116,7 +116,7 @@ class DeleteTest(_DeleteTestBase, fixtures.TablesTest, AssertsCompiledSQL): table1, table2 = self.tables.mytable, self.tables.myothertable # test a non-correlated WHERE clause - s = select([table2.c.othername], table2.c.otherid == 7) + s = select(table2.c.othername).where(table2.c.otherid == 7) self.assert_compile( delete(table1, table1.c.name == s.scalar_subquery()), "DELETE FROM mytable " @@ -131,7 +131,7 @@ class DeleteTest(_DeleteTestBase, fixtures.TablesTest, AssertsCompiledSQL): table1, table2 = self.tables.mytable, self.tables.myothertable # test one that is actually correlated... - s = select([table2.c.othername], table2.c.otherid == table1.c.myid) + s = select(table2.c.othername).where(table2.c.otherid == table1.c.myid) self.assert_compile( table1.delete(table1.c.name == s.scalar_subquery()), "DELETE FROM mytable " diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 04fed9b6e..2bac963e4 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -749,7 +749,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', ) @@ -761,7 +761,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', ) @@ -773,7 +773,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', ) @@ -800,7 +800,7 @@ class TextualSelectTest(fixtures.TestBase, AssertsCompiledSQL): with testing.expect_deprecated( "The SelectBase.c and SelectBase.columns", "Implicit coercion" ): - stmt = select([table1.c.myid]).select_from( + stmt = select(table1.c.myid).select_from( table1.join(t, table1.c.myid == t.c.id) ) compiled = stmt.compile() @@ -1468,10 +1468,8 @@ class CursorResultTest(fixtures.TablesTest): ).connect() as ins_conn: row = ins_conn.execute( select( - [ - literal_column("1").label("case_insensitive"), - literal_column("2").label("CaseSensitive"), - ] + literal_column("1").label("case_insensitive"), + literal_column("2").label("CaseSensitive"), ) ).first() @@ -1498,11 +1496,9 @@ class CursorResultTest(fixtures.TablesTest): ).connect() as ins_conn: row = ins_conn.execute( select( - [ - literal_column("1").label("case_insensitive"), - literal_column("2").label("CaseSensitive"), - text("3 AS screw_up_the_cols"), - ] + literal_column("1").label("case_insensitive"), + literal_column("2").label("CaseSensitive"), + text("3 AS screw_up_the_cols"), ) ).first() diff --git a/test/sql/test_external_traversal.py b/test/sql/test_external_traversal.py index 3307f0f1e..c67b45203 100644 --- a/test/sql/test_external_traversal.py +++ b/test/sql/test_external_traversal.py @@ -374,14 +374,14 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): adapter = sql_util.ColumnAdapter(aliased) - f = select([adapter.columns[c] for c in aliased2.c]).select_from( + f = select(*[adapter.columns[c] for c in aliased2.c]).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( + f = select(adapter.columns[func.count(aliased2.c.col1)]).select_from( aliased ) eq_( @@ -402,8 +402,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): # aliased2. corresponding_column checks these # now. adapter = sql_util.ColumnAdapter(aliased1) - f1 = select([adapter.columns[c] for c in aliased2._raw_columns]) - f2 = select([adapter.columns[c] for c in aliased3._raw_columns]) + f1 = select(*[adapter.columns[c] for c in aliased2._raw_columns]) + f2 = select(*[adapter.columns[c] for c in aliased3._raw_columns]) eq_(str(f1), str(f2)) def test_aliased_cloned_column_adapt_exported(self): @@ -419,8 +419,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): # have an _is_clone_of pointer. But we now modified _make_proxy # to assign this. adapter = sql_util.ColumnAdapter(aliased1) - f1 = select([adapter.columns[c] for c in aliased2.c]) - f2 = select([adapter.columns[c] for c in aliased3.c]) + f1 = select(*[adapter.columns[c] for c in aliased2.c]) + f2 = select(*[adapter.columns[c] for c in aliased3.c]) eq_(str(f1), str(f2)) def test_aliased_cloned_schema_column_adapt_exported(self): @@ -436,8 +436,8 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): # have an _is_clone_of pointer. But we now modified _make_proxy # to assign this. adapter = sql_util.ColumnAdapter(aliased1) - f1 = select([adapter.columns[c] for c in aliased2.c]) - f2 = select([adapter.columns[c] for c in aliased3.c]) + f1 = select(*[adapter.columns[c] for c in aliased2.c]) + f2 = select(*[adapter.columns[c] for c in aliased3.c]) eq_(str(f1), str(f2)) def test_labeled_expression_adapt(self): @@ -520,7 +520,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): def test_select(self): s2 = select(t1) s2_assert = str(s2) - s3_assert = str(select([t1], t1.c.col2 == 7)) + s3_assert = str(select(t1).where(t1.c.col2 == 7)) class Vis(CloningVisitor): def visit_select(self, select): @@ -539,7 +539,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): Vis().traverse(s2) assert str(s2) == s3_assert - s4_assert = str(select([t1], and_(t1.c.col2 == 7, t1.c.col3 == 9))) + s4_assert = str(select(t1).where(and_(t1.c.col2 == 7, t1.c.col3 == 9))) class Vis(CloningVisitor): def visit_select(self, select): @@ -551,7 +551,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): assert str(s4) == s4_assert assert str(s3) == s3_assert - s5_assert = str(select([t1], and_(t1.c.col2 == 7, t1.c.col1 == 9))) + s5_assert = str(select(t1).where(and_(t1.c.col2 == 7, t1.c.col1 == 9))) class Vis(CloningVisitor): def visit_binary(self, binary): @@ -581,7 +581,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): eq_(str(u), str(u2)) eq_([str(c) for c in u2.selected_columns], cols) - s1 = select([t1], t1.c.col1 == bindparam("id_param")) + s1 = select(t1).where(t1.c.col1 == bindparam("id_param")) s2 = select(t2) u = union(s1, s2) @@ -629,9 +629,9 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): """test that unique bindparams change their name upon clone() to prevent conflicts""" - s = select([t1], t1.c.col1 == bindparam(None, unique=True)).alias() + s = select(t1).where(t1.c.col1 == bindparam(None, unique=True)).alias() s2 = CloningVisitor().traverse(s).alias() - s3 = select([s], s.c.col2 == s2.c.col2) + s3 = select(s).where(s.c.col2 == s2.c.col2) self.assert_compile( s3, @@ -644,9 +644,9 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): "WHERE anon_1.col2 = anon_2.col2", ) - s = select([t1], t1.c.col1 == 4).alias() + s = select(t1).where(t1.c.col1 == 4).alias() s2 = CloningVisitor().traverse(s).alias() - s3 = select([s], s.c.col2 == s2.c.col2) + s3 = select(s).where(s.c.col2 == s2.c.col2) self.assert_compile( s3, "SELECT anon_1.col1, anon_1.col2, anon_1.col3 FROM " @@ -708,9 +708,12 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): eq_(str(s), str(s5)) def test_correlated_select(self): - s = select( - [literal_column("*")], t1.c.col1 == t2.c.col1, from_obj=[t1, t2] - ).correlate(t2) + s = ( + select(literal_column("*")) + .where(t1.c.col1 == t2.c.col1) + .select_from(t1, t2) + .correlate(t2) + ) class Vis(CloningVisitor): def visit_select(self, select): @@ -878,7 +881,12 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_fromtwice_one(self): t1a = t1.alias() - s = select([1], t1.c.col1 == t1a.c.col1, from_obj=t1a).correlate(t1a) + s = ( + select(1) + .where(t1.c.col1 == t1a.c.col1) + .select_from(t1a) + .correlate(t1a) + ) s = select(t1).where(t1.c.col1 == s.scalar_subquery()) self.assert_compile( s, @@ -899,7 +907,9 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_fromtwice_two(self): s = select(t1).where(t1.c.col1 == "foo").alias() - s2 = select([1], t1.c.col1 == s.c.col1, from_obj=s).correlate(t1) + s2 = ( + select(1).where(t1.c.col1 == s.c.col1).select_from(s).correlate(t1) + ) s3 = select(t1).where(t1.c.col1 == s2.scalar_subquery()) self.assert_compile( s3, @@ -1194,16 +1204,18 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t2alias = t2.alias("t2alias") vis = sql_util.ClauseAdapter(t1alias) - s = select( - [literal_column("*")], from_obj=[t1alias, t2alias] - ).scalar_subquery() + s = ( + select(literal_column("*")) + .select_from(t1alias, t2alias) + .scalar_subquery() + ) froms = list(s._iterate_from_elements()) assert t2alias in froms assert t1alias in froms self.assert_compile( - select([literal_column("*")], t2alias.c.col1 == s), + select(literal_column("*")).where(t2alias.c.col1 == s), "SELECT * FROM table2 AS t2alias WHERE " "t2alias.col1 = (SELECT * FROM table1 AS " "t1alias)", @@ -1219,32 +1231,33 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): # _cloned_set for each element in _froms when correlating self.assert_compile( - select([literal_column("*")], t2alias.c.col1 == s), + select(literal_column("*")).where(t2alias.c.col1 == s), "SELECT * FROM table2 AS t2alias WHERE " "t2alias.col1 = (SELECT * FROM table1 AS " "t1alias)", ) s = ( - select([literal_column("*")], from_obj=[t1alias, t2alias]) + select(literal_column("*")) + .select_from(t1alias, t2alias) .correlate(t2alias) .scalar_subquery() ) self.assert_compile( - select([literal_column("*")], t2alias.c.col1 == s), + select(literal_column("*")).where(t2alias.c.col1 == s), "SELECT * FROM table2 AS t2alias WHERE " "t2alias.col1 = (SELECT * FROM table1 AS " "t1alias)", ) s = vis.traverse(s) self.assert_compile( - select([literal_column("*")], t2alias.c.col1 == s), + select(literal_column("*")).where(t2alias.c.col1 == s), "SELECT * FROM table2 AS t2alias WHERE " "t2alias.col1 = (SELECT * FROM table1 AS " "t1alias)", ) s = CloningVisitor().traverse(s) self.assert_compile( - select([literal_column("*")], t2alias.c.col1 == s), + select(literal_column("*")).where(t2alias.c.col1 == s), "SELECT * FROM table2 AS t2alias WHERE " "t2alias.col1 = (SELECT * FROM table1 AS " "t1alias)", @@ -1399,9 +1412,11 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ualias = users.alias() - s = select( - [func.count(addresses.c.id)], users.c.id == addresses.c.user_id - ).correlate(users) + s = ( + select(func.count(addresses.c.id)) + .where(users.c.id == addresses.c.user_id) + .correlate(users) + ) s = sql_util.ClauseAdapter(ualias).traverse(s) j1 = addresses.join(ualias, addresses.c.user_id == ualias.c.id) @@ -1424,7 +1439,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( - vis.traverse(select([literal_column("*")], from_obj=[t1])), + vis.traverse(select(literal_column("*")).select_from(t1)), "SELECT * FROM table1 AS t1alias", ) @@ -1433,7 +1448,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( vis.traverse( - select([literal_column("*")], t1.c.col1 == t2.c.col2) + select(literal_column("*")).where(t1.c.col1 == t2.c.col2) ), "SELECT * FROM table1 AS t1alias, table2 " "WHERE t1alias.col1 = table2.col2", @@ -1444,11 +1459,9 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( vis.traverse( - select( - [literal_column("*")], - t1.c.col1 == t2.c.col2, - from_obj=[t1, t2], - ) + select(literal_column("*")) + .where(t1.c.col1 == t2.c.col2) + .select_from(t1, t2) ), "SELECT * FROM table1 AS t1alias, table2 " "WHERE t1alias.col1 = table2.col2", @@ -1461,11 +1474,9 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): select(t1alias, t2).where( t1alias.c.col1 == vis.traverse( - select( - [literal_column("*")], - t1.c.col1 == t2.c.col2, - from_obj=[t1, t2], - ) + select(literal_column("*")) + .where(t1.c.col1 == t2.c.col2) + .select_from(t1, t2) .correlate(t1) .scalar_subquery() ) @@ -1483,11 +1494,9 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): select(t1alias, t2).where( t1alias.c.col1 == vis.traverse( - select( - [literal_column("*")], - t1.c.col1 == t2.c.col2, - from_obj=[t1, t2], - ) + select(literal_column("*")) + .where(t1.c.col1 == t2.c.col2) + .select_from(t1, t2) .correlate(t2) .scalar_subquery() ) @@ -1521,13 +1530,13 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_table_to_alias_9(self): - s = select([literal_column("*")], from_obj=[t1]).alias("foo") + s = select(literal_column("*")).select_from(t1).alias("foo") self.assert_compile( s.select(), "SELECT foo.* FROM (SELECT * FROM table1) " "AS foo" ) def test_table_to_alias_10(self): - s = select([literal_column("*")], from_obj=[t1]).alias("foo") + s = select(literal_column("*")).select_from(t1).alias("foo") t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( @@ -1536,7 +1545,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_table_to_alias_11(self): - s = select([literal_column("*")], from_obj=[t1]).alias("foo") + s = select(literal_column("*")).select_from(t1).alias("foo") self.assert_compile( s.select(), "SELECT foo.* FROM (SELECT * FROM table1) " "AS foo" ) @@ -1563,7 +1572,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): vis.chain(sql_util.ClauseAdapter(t2alias)) self.assert_compile( vis.traverse( - select([literal_column("*")], t1.c.col1 == t2.c.col2) + select(literal_column("*")).where(t1.c.col1 == t2.c.col2) ), "SELECT * FROM table1 AS t1alias, table2 " "AS t2alias WHERE t1alias.col1 = " @@ -1577,7 +1586,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): vis.chain(sql_util.ClauseAdapter(t2alias)) self.assert_compile( vis.traverse( - select(["*"], t1.c.col1 == t2.c.col2, from_obj=[t1, t2]) + select("*").where(t1.c.col1 == t2.c.col2).select_from(t1, t2) ), "SELECT * FROM table1 AS t1alias, table2 " "AS t2alias WHERE t1alias.col1 = " @@ -1593,7 +1602,9 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): select(t1alias, t2alias).where( t1alias.c.col1 == vis.traverse( - select(["*"], t1.c.col1 == t2.c.col2, from_obj=[t1, t2]) + select("*") + .where(t1.c.col1 == t2.c.col2) + .select_from(t1, t2) .correlate(t1) .scalar_subquery() ) @@ -1615,7 +1626,9 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t2alias.select().where( t2alias.c.col2 == vis.traverse( - select(["*"], t1.c.col1 == t2.c.col2, from_obj=[t1, t2]) + select("*") + .where(t1.c.col1 == t2.c.col2) + .select_from(t1, t2) .correlate(t2) .scalar_subquery() ) @@ -1705,7 +1718,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ) j1 = a.outerjoin(b) - j2 = select([j1], use_labels=True).subquery() + j2 = select(j1).apply_labels().subquery() j3 = c.join(j2, j2.c.b_id == c.c.bid) diff --git a/test/sql/test_from_linter.py b/test/sql/test_from_linter.py index 416f89de3..6afe41aac 100644 --- a/test/sql/test_from_linter.py +++ b/test/sql/test_from_linter.py @@ -33,7 +33,7 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): def test_everything_is_connected(self): query = ( - select([self.a]) + select(self.a) .select_from(self.a.join(self.b, self.a.c.col_a == self.b.c.col_b)) .select_from(self.c) .select_from(self.d) @@ -49,7 +49,7 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert not froms def test_plain_cartesian(self): - query = select([self.a]).where(self.b.c.col_b == 5) + query = select(self.a).where(self.b.c.col_b == 5) froms, start = find_unmatching_froms(query, self.a) assert start == self.a assert froms == {self.b} @@ -59,20 +59,20 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert froms == {self.a} def test_count_non_eq_comparison_operators(self): - query = select([self.a]).where(self.a.c.col_a > self.b.c.col_b) + query = select(self.a).where(self.a.c.col_a > self.b.c.col_b) froms, start = find_unmatching_froms(query, self.a) is_(start, None) is_(froms, None) def test_dont_count_non_comparison_operators(self): - query = select([self.a]).where(self.a.c.col_a + self.b.c.col_b == 5) + query = select(self.a).where(self.a.c.col_a + self.b.c.col_b == 5) froms, start = find_unmatching_froms(query, self.a) assert start == self.a assert froms == {self.b} def test_disconnect_between_ab_cd(self): query = ( - select([self.a]) + select(self.a) .select_from(self.a.join(self.b, self.a.c.col_a == self.b.c.col_b)) .select_from(self.c) .select_from(self.d) @@ -90,7 +90,7 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): def test_c_and_d_both_disconnected(self): query = ( - select([self.a]) + select(self.a) .select_from(self.a.join(self.b, self.a.c.col_a == self.b.c.col_b)) .where(self.c.c.col_c == 5) .where(self.d.c.col_d == 10) @@ -110,7 +110,7 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): def test_now_connected(self): query = ( - select([self.a]) + select(self.a) .select_from(self.a.join(self.b, self.a.c.col_a == self.b.c.col_b)) .select_from(self.c.join(self.d, self.c.c.col_c == self.d.c.col_d)) .where(self.c.c.col_c == self.b.c.col_b) @@ -126,9 +126,9 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): def test_disconnected_subquery(self): subq = ( - select([self.a]).where(self.a.c.col_a == self.b.c.col_b).subquery() + select(self.a).where(self.a.c.col_a == self.b.c.col_b).subquery() ) - stmt = select([self.c]).select_from(subq) + stmt = select(self.c).select_from(subq) froms, start = find_unmatching_froms(stmt, self.c) assert start == self.c @@ -140,10 +140,10 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): def test_now_connect_it(self): subq = ( - select([self.a]).where(self.a.c.col_a == self.b.c.col_b).subquery() + select(self.a).where(self.a.c.col_a == self.b.c.col_b).subquery() ) stmt = ( - select([self.c]) + select(self.c) .select_from(subq) .where(self.c.c.col_c == subq.c.col_a) ) @@ -156,7 +156,7 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert not froms def test_right_nested_join_without_issue(self): - query = select([self.a]).select_from( + query = select(self.a).select_from( self.a.join( self.b.join(self.c, self.b.c.col_b == self.c.c.col_c), self.a.c.col_a == self.b.c.col_b, @@ -174,13 +174,13 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): # actually a join condition. this essentially allows a cartesian # product to be added explicitly. - query = select([self.a]).select_from(self.a.join(self.b, true())) + query = select(self.a).select_from(self.a.join(self.b, true())) froms, start = find_unmatching_froms(query) assert not froms def test_right_nested_join_with_an_issue(self): query = ( - select([self.a]) + select(self.a) .select_from( self.a.join( self.b.join(self.c, self.b.c.col_b == self.c.c.col_c), @@ -200,7 +200,7 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert froms == {self.a, self.b, self.c} def test_no_froms(self): - query = select([1]) + query = select(1) froms, start = find_unmatching_froms(query) assert not froms @@ -223,12 +223,12 @@ class TestLinter(fixtures.TablesTest): def test_does_not_modify_query(self): with self.bind.connect() as conn: - [result] = conn.execute(select([1])).fetchone() + [result] = conn.execute(select(1)).fetchone() assert result == 1 def test_warn_simple(self): a, b = self.tables("table_a", "table_b") - query = select([a.c.col_a]).where(b.c.col_b == 5) + query = select(a.c.col_a).where(b.c.col_b == 5) with expect_warnings( r"SELECT statement has a cartesian product between FROM " @@ -242,7 +242,7 @@ class TestLinter(fixtures.TablesTest): a, b = self.tables("table_a", "table_b") b_alias = b.alias() - query = select([a.c.col_a]).where(b_alias.c.col_b == 5) + query = select(a.c.col_a).where(b_alias.c.col_b == 5) with expect_warnings( r"SELECT statement has a cartesian product between FROM " @@ -255,8 +255,8 @@ class TestLinter(fixtures.TablesTest): def test_warn_anon_cte(self): a, b = self.tables("table_a", "table_b") - b_cte = select([b]).cte() - query = select([a.c.col_a]).where(b_cte.c.col_b == 5) + b_cte = select(b).cte() + query = select(a.c.col_a).where(b_cte.c.col_b == 5) with expect_warnings( r"SELECT statement has a cartesian product between " @@ -271,7 +271,7 @@ class TestLinter(fixtures.TablesTest): eng = engines.testing_engine(options={"enable_from_linting": False}) eng.pool = self.bind.pool # needed for SQLite a, b = self.tables("table_a", "table_b") - query = select([a.c.col_a]).where(b.c.col_b == 5) + query = select(a.c.col_a).where(b.c.col_b == 5) with eng.connect() as conn: conn.execute(query) diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index e0a0dd8a5..717fc47af 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -95,7 +95,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_use_labels(self): self.assert_compile( - select([func.foo()], use_labels=True), "SELECT foo() AS foo_1" + select(func.foo()).apply_labels(), "SELECT foo() AS foo_1" ) def test_use_labels_function_element(self): @@ -109,7 +109,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): return "max(%s)" % compiler.process(element.clauses, **kw) self.assert_compile( - select([max_(5, 6)], use_labels=True), + select(max_(5, 6)).apply_labels(), "SELECT max(:max_2, :max_3) AS max_1", ) @@ -187,7 +187,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): column("q"), ) - stmt = select([func.sum(t.c.value)]) + stmt = select(func.sum(t.c.value)) self.assert_compile( stmt.group_by(func.cube(t.c.x, t.c.y)), @@ -440,20 +440,20 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # test it in a SELECT self.assert_compile( - select([func.count(table1.c.myid)]), + select(func.count(table1.c.myid)), "SELECT count(mytable.myid) AS count_1 FROM mytable", ) # test a "dotted" function name self.assert_compile( - select([func.foo.bar.lala(table1.c.myid)]), + select(func.foo.bar.lala(table1.c.myid)), "SELECT foo.bar.lala(mytable.myid) AS lala_1 FROM mytable", ) # test the bind parameter name with a "dotted" function name is # only the name (limits the length of the bind param name) self.assert_compile( - select([func.foo.bar.lala(12)]), + select(func.foo.bar.lala(12)), "SELECT foo.bar.lala(:lala_2) AS lala_1", ) @@ -487,23 +487,23 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): users = table( "users", column("id"), column("name"), column("fullname") ) - calculate = select( - [column("q"), column("z"), column("r")], - from_obj=[ + calculate = ( + select(column("q"), column("z"), column("r")) + .select_from( func.calculate(bindparam("x", None), bindparam("y", None)) - ], - ).subquery() + ) + .subquery() + ) 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 " "WHERE users.id > anon_1.z", ) - s = select( - [users], + s = select(users).where( users.c.id.between( calculate.alias("c1").unique_params(x=17, y=45).c.z, calculate.alias("c2").unique_params(x=5, y=12).c.z, @@ -538,21 +538,21 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_method_two(self): expr = func.rows("foo") self.assert_compile( - select(["*"]).select_from(expr.select().subquery()), + select("*").select_from(expr.select().subquery()), "SELECT * FROM (SELECT rows(:rows_2) AS rows_1) AS anon_1", ) def test_select_method_three(self): expr = func.rows("foo") self.assert_compile( - select([column("foo")]).select_from(expr), + select(column("foo")).select_from(expr), "SELECT foo FROM rows(:rows_1)", ) def test_alias_method_two(self): expr = func.rows("foo") self.assert_compile( - select(["*"]).select_from(expr.alias("bar")), + select("*").select_from(expr.alias("bar")), "SELECT * FROM rows(:rows_1) AS bar", ) @@ -564,7 +564,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # testing here that the expression exports its column # list in a way that at least doesn't break. self.assert_compile( - select([expr]), "SELECT bar.rows_1 FROM rows(:rows_2) AS bar" + select(expr), "SELECT bar.rows_1 FROM rows(:rows_2) AS bar" ) def test_alias_method_columns_two(self): @@ -601,11 +601,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_label(self): self.assert_compile( select( - [ - func.count(1) - .filter(table1.c.description != None) # noqa - .label("foo") - ] + func.count(1) + .filter(table1.c.description != None) # noqa + .label("foo") ), "SELECT count(:count_1) FILTER (WHERE mytable.description " "IS NOT NULL) AS foo FROM mytable", @@ -616,11 +614,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # from func: self.assert_compile( select( - [ - func.max(table1.c.name).filter( - literal_column("description") != None # noqa - ) - ] + func.max(table1.c.name).filter( + literal_column("description") != None # noqa + ) ), "SELECT max(mytable.name) FILTER (WHERE description " "IS NOT NULL) AS anon_1 FROM mytable", @@ -629,7 +625,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_fromobj_fromcriterion(self): # from criterion: self.assert_compile( - select([func.count(1).filter(table1.c.name == "name")]), + select(func.count(1).filter(table1.c.name == "name")), "SELECT count(:count_1) FILTER (WHERE mytable.name = :name_1) " "AS anon_1 FROM mytable", ) @@ -638,11 +634,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # test chaining: self.assert_compile( select( - [ - func.count(1) - .filter(table1.c.name == "name") - .filter(table1.c.description == "description") - ] + func.count(1) + .filter(table1.c.name == "name") + .filter(table1.c.description == "description") ), "SELECT count(:count_1) FILTER (WHERE " "mytable.name = :name_1 AND mytable.description = :description_1) " @@ -653,11 +647,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # test filtered windowing: self.assert_compile( select( - [ - func.rank() - .filter(table1.c.name > "foo") - .over(order_by=table1.c.name) - ] + func.rank() + .filter(table1.c.name > "foo") + .over(order_by=table1.c.name) ), "SELECT rank() FILTER (WHERE mytable.name > :name_1) " "OVER (ORDER BY mytable.name) AS anon_1 FROM mytable", @@ -666,11 +658,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_windowing_orderby_partitionby(self): self.assert_compile( select( - [ - func.rank() - .filter(table1.c.name > "foo") - .over(order_by=table1.c.name, partition_by=["description"]) - ] + func.rank() + .filter(table1.c.name > "foo") + .over(order_by=table1.c.name, partition_by=["description"]) ), "SELECT rank() FILTER (WHERE mytable.name > :name_1) " "OVER (PARTITION BY mytable.description ORDER BY mytable.name) " @@ -680,11 +670,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_windowing_range(self): self.assert_compile( select( - [ - func.rank() - .filter(table1.c.name > "foo") - .over(range_=(1, 5), partition_by=["description"]) - ] + func.rank() + .filter(table1.c.name > "foo") + .over(range_=(1, 5), partition_by=["description"]) ), "SELECT rank() FILTER (WHERE mytable.name > :name_1) " "OVER (PARTITION BY mytable.description RANGE BETWEEN :param_1 " @@ -695,11 +683,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_windowing_rows(self): self.assert_compile( select( - [ - func.rank() - .filter(table1.c.name > "foo") - .over(rows=(1, 5), partition_by=["description"]) - ] + func.rank() + .filter(table1.c.name > "foo") + .over(rows=(1, 5), partition_by=["description"]) ), "SELECT rank() FILTER (WHERE mytable.name > :name_1) " "OVER (PARTITION BY mytable.description ROWS BETWEEN :param_1 " @@ -709,10 +695,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_within_group(self): stmt = select( - [ - table1.c.myid, - func.percentile_cont(0.5).within_group(table1.c.name), - ] + table1.c.myid, + func.percentile_cont(0.5).within_group(table1.c.name), ) self.assert_compile( stmt, @@ -725,12 +709,10 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_within_group_multi(self): stmt = select( - [ - table1.c.myid, - func.percentile_cont(0.5).within_group( - table1.c.name, table1.c.description - ), - ] + table1.c.myid, + func.percentile_cont(0.5).within_group( + table1.c.name, table1.c.description + ), ) self.assert_compile( stmt, @@ -743,10 +725,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_within_group_desc(self): stmt = select( - [ - table1.c.myid, - func.percentile_cont(0.5).within_group(table1.c.name.desc()), - ] + table1.c.myid, + func.percentile_cont(0.5).within_group(table1.c.name.desc()), ) self.assert_compile( stmt, @@ -759,12 +739,10 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_funcfilter_within_group_w_over(self): stmt = select( - [ - table1.c.myid, - func.percentile_cont(0.5) - .within_group(table1.c.name.desc()) - .over(partition_by=table1.c.description), - ] + table1.c.myid, + func.percentile_cont(0.5) + .within_group(table1.c.name.desc()) + .over(partition_by=table1.c.description), ) self.assert_compile( stmt, @@ -1031,7 +1009,7 @@ class ExecuteTest(fixtures.TestBase): stuff="hi", ) - res = sorted(connection.execute(select([t2.c.value, t2.c.stuff]))) + res = sorted(connection.execute(select(t2.c.value, t2.c.stuff))) eq_(res, [(-14, "hi"), (3, None), (7, None)]) connection.execute( @@ -1039,7 +1017,7 @@ class ExecuteTest(fixtures.TestBase): stuff="some stuff", ) eq_( - connection.execute(select([t2.c.value, t2.c.stuff])).fetchall(), + connection.execute(select(t2.c.value, t2.c.stuff)).fetchall(), [(9, "some stuff"), (9, "some stuff"), (9, "some stuff")], ) @@ -1052,7 +1030,7 @@ class ExecuteTest(fixtures.TestBase): connection.execute(t2.update(values=dict(value=func.length("asfda")))) eq_( - connection.execute(select([t2.c.value, t2.c.stuff])).first(), + connection.execute(select(t2.c.value, t2.c.stuff)).first(), (5, "thisisstuff"), ) @@ -1066,7 +1044,7 @@ class ExecuteTest(fixtures.TestBase): ) eq_( - connection.execute(select([t2.c.value, t2.c.stuff])).first(), + connection.execute(select(t2.c.value, t2.c.stuff)).first(), (9, "foo"), ) @@ -1079,7 +1057,7 @@ class ExecuteTest(fixtures.TestBase): ).scalar() z = connection.scalar(func.current_date(bind=testing.db)) w = connection.scalar( - select(["*"], from_obj=[func.current_date(bind=testing.db)]) + select("*").select_from(func.current_date(bind=testing.db)) ) assert x == y == z == w @@ -1090,7 +1068,7 @@ class ExecuteTest(fixtures.TestBase): date = datetime.date(2010, 5, 1) def execute(field): - return connection.execute(select([extract(field, date)])).scalar() + return connection.execute(select(extract(field, date))).scalar() assert execute("year") == 2010 assert execute("month") == 5 @@ -1115,7 +1093,7 @@ class ExecuteTest(fixtures.TestBase): }, ) rs = connection.execute( - select([extract("year", table.c.dt), extract("month", table.c.d)]) + select(extract("year", table.c.dt), extract("month", table.c.d)) ) row = rs.first() assert row[0] == 2010 diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py index e5f2fbe6d..3cdf291ec 100644 --- a/test/sql/test_insert.py +++ b/test/sql/test_insert.py @@ -131,7 +131,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column( "col2", Integer, - default=select([func.coalesce(func.max(foo.c.id))]), + default=select(func.coalesce(func.max(foo.c.id))), ), ) @@ -332,7 +332,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): def test_insert_from_select_returning(self): table1 = self.tables.mytable - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == "foo" ) ins = ( @@ -351,7 +351,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): def test_insert_from_select_select(self): table1 = self.tables.mytable - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == "foo" ) ins = self.tables.myothertable.insert().from_select( @@ -375,7 +375,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column("data", String), ) - stmt = t1.insert().from_select(("data",), select([t1.c.data])) + stmt = t1.insert().from_select(("data",), select(t1.c.data)) self.assert_compile( stmt, @@ -387,9 +387,9 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): def test_insert_from_select_cte_one(self): table1 = self.tables.mytable - cte = select([table1.c.name]).where(table1.c.name == "bar").cte() + cte = select(table1.c.name).where(table1.c.name == "bar").cte() - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == cte.c.name ) @@ -413,9 +413,9 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): table1 = self.tables.mytable - cte = select([table1.c.name]).where(table1.c.name == "bar").cte() + cte = select(table1.c.name).where(table1.c.name == "bar").cte() - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == cte.c.name ) @@ -469,7 +469,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): def test_insert_from_select_select_alt_ordering(self): table1 = self.tables.mytable - sel = select([table1.c.name, table1.c.myid]).where( + sel = select(table1.c.name, table1.c.myid).where( table1.c.name == "foo" ) ins = self.tables.myothertable.insert().from_select( @@ -492,7 +492,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column("foo", Integer, default=func.foobar()), ) table1 = self.tables.mytable - sel = select([table1.c.myid]).where(table1.c.name == "foo") + sel = select(table1.c.myid).where(table1.c.name == "foo") ins = table.insert().from_select(["id"], sel, include_defaults=False) self.assert_compile( ins, @@ -510,7 +510,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column("foo", Integer, default=func.foobar()), ) table1 = self.tables.mytable - sel = select([table1.c.myid]).where(table1.c.name == "foo") + sel = select(table1.c.myid).where(table1.c.name == "foo") ins = table.insert().from_select(["id"], sel) self.assert_compile( ins, @@ -529,7 +529,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column("foo", Integer, default=12), ) table1 = self.tables.mytable - sel = select([table1.c.myid]).where(table1.c.name == "foo") + sel = select(table1.c.myid).where(table1.c.name == "foo") ins = table.insert().from_select(["id"], sel) self.assert_compile( ins, @@ -549,7 +549,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column("foo", Integer, default=12), ) table1 = self.tables.mytable - sel = select([table1.c.myid, table1.c.myid.label("q")]).where( + sel = select(table1.c.myid, table1.c.myid.label("q")).where( table1.c.name == "foo" ) ins = table.insert().from_select(["id", "foo"], sel) @@ -574,7 +574,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column("foo", Integer, default=foo), ) table1 = self.tables.mytable - sel = select([table1.c.myid]).where(table1.c.name == "foo") + sel = select(table1.c.myid).where(table1.c.name == "foo") ins = table.insert().from_select(["id"], sel) self.assert_compile( ins, @@ -595,7 +595,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): Column("bar", String, default="baz"), ) - stmt = select([table_.c.foo]) + stmt = select(table_.c.foo) insert = table_.insert().from_select(["foo"], stmt) self.assert_compile(stmt, "SELECT mytable.foo FROM mytable") @@ -613,7 +613,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): def test_insert_mix_select_values_exception(self): table1 = self.tables.mytable - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == "foo" ) ins = self.tables.myothertable.insert().from_select( @@ -628,7 +628,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): def test_insert_mix_values_select_exception(self): table1 = self.tables.mytable - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == "foo" ) ins = self.tables.myothertable.insert().values(othername="5") @@ -659,8 +659,8 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): name = column("name") description = column("desc") - sel = select([name, mytable.c.description]).union( - select([name, description]) + sel = select(name, mytable.c.description).union( + select(name, description) ) ins = mytable.insert().from_select( [mytable.c.name, mytable.c.description], sel @@ -675,7 +675,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): def test_insert_from_select_col_values(self): table1 = self.tables.mytable table2 = self.tables.myothertable - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == "foo" ) ins = table2.insert().from_select( @@ -831,7 +831,7 @@ class InsertImplicitReturningTest( def test_insert_select(self): table1 = self.tables.mytable - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == "foo" ) ins = self.tables.myothertable.insert().from_select( @@ -847,7 +847,7 @@ class InsertImplicitReturningTest( def test_insert_select_return_defaults(self): table1 = self.tables.mytable - sel = select([table1.c.myid, table1.c.name]).where( + sel = select(table1.c.myid, table1.c.name).where( table1.c.name == "foo" ) ins = ( diff --git a/test/sql/test_labels.py b/test/sql/test_labels.py index e45895817..731f8fcb5 100644 --- a/test/sql/test_labels.py +++ b/test/sql/test_labels.py @@ -198,7 +198,7 @@ class MaxIdentTest(fixtures.TestBase, AssertsCompiledSQL): ta = table2.alias() on = table1.c.this_is_the_data_column == ta.c.this_is_the_data_column self.assert_compile( - select([table1, ta]) + select(table1, ta) .select_from(table1.join(ta, on)) .where(ta.c.this_is_the_data_column == "data3"), "SELECT " @@ -283,7 +283,7 @@ class MaxIdentTest(fixtures.TestBase, AssertsCompiledSQL): s = table1.select(table1.c.this_is_the_primarykey_column == 4).alias( "foo" ) - s2 = select([s]) + s2 = select(s) compiled = s2.compile(dialect=self._length_fixture()) assert set( compiled._create_result_map()["this_is_the_data_column"][1] @@ -303,7 +303,7 @@ class MaxIdentTest(fixtures.TestBase, AssertsCompiledSQL): dialect = self._length_fixture() q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias() - s = select([q]).apply_labels() + s = select(q).apply_labels() self.assert_compile( s, @@ -476,7 +476,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias( "foo" ) - x = select([q]) + x = select(q) compile_dialect = default.DefaultDialect(label_length=10) self.assert_compile( x, @@ -504,7 +504,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias( "foo" ) - x = select([q]) + x = select(q) compile_dialect = default.DefaultDialect(label_length=10) self.assert_compile( @@ -534,7 +534,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias( "foo" ) - x = select([q]) + x = select(q) self.assert_compile( x, @@ -560,7 +560,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): table1 = self.table1 q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias() - x = select([q], use_labels=True) + x = select(q).apply_labels() compile_dialect = default.DefaultDialect(label_length=10) self.assert_compile( @@ -587,7 +587,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): def test_adjustable_5(self): table1 = self.table1 q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias() - x = select([q], use_labels=True) + x = select(q).apply_labels() compile_dialect = default.DefaultDialect(label_length=4) self.assert_compile( @@ -645,7 +645,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias( "foo" ) - x = select([q]) + x = select(q) dialect = default.DefaultDialect(label_length=10) compiled = x.compile(dialect=dialect) @@ -688,7 +688,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([other_table, anon]).select_from(j1).apply_labels(), + select(other_table, anon).select_from(j1).apply_labels(), "SELECT " "other_thirty_characters_table_.id " "AS other_thirty_characters__1, " @@ -720,9 +720,9 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): # 'abcde' is longer than 4, but rendered as itself # needs to have all characters - s = select([a1]) + s = select(a1) self.assert_compile( - select([a1]), "SELECT asdf.abcde FROM a AS asdf", dialect=dialect + select(a1), "SELECT asdf.abcde FROM a AS asdf", dialect=dialect ) compiled = s.compile(dialect=dialect) assert set(compiled._create_result_map()["abcde"][1]).issuperset( @@ -730,7 +730,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): ) # column still there, but short label - s = select([a1]).apply_labels() + s = select(a1).apply_labels() self.assert_compile( s, "SELECT asdf.abcde AS _1 FROM a AS asdf", dialect=dialect ) @@ -746,7 +746,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): "tablename", column("columnname_one"), column("columnn_1") ) - stmt = select([table1]).apply_labels() + stmt = select(table1).apply_labels() dialect = default.DefaultDialect(label_length=23) self.assert_compile( @@ -797,12 +797,10 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - table1.c.name, - table1.c.name, - expr(table1.c.name), - expr(table1.c.name), - ] + table1.c.name, + table1.c.name, + expr(table1.c.name), + expr(table1.c.name), ), "SELECT some_table.name, some_table.name, " "SOME_COL_THING(some_table.name) AS name, " @@ -814,7 +812,7 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): table1 = self.table1 self.assert_compile( - select([table1.c.name + "foo", expr(table1.c.name + "foo")]), + select(table1.c.name + "foo", expr(table1.c.name + "foo")), "SELECT some_table.name || :name_1 AS anon_1, " "SOME_COL_THING(some_table.name || :name_2) AS anon_2 " "FROM some_table", @@ -826,7 +824,7 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [table1.c.name + "foo", expr(table1.c.name + "foo")] + table1.c.name + "foo", expr(table1.c.name + "foo") ).apply_labels(), "SELECT some_table.name || :name_1 AS anon_1, " "SOME_COL_THING(some_table.name || :name_2) AS anon_2 " @@ -839,11 +837,9 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - expr(table1.c.name.label("foo")), - table1.c.name.label("bar"), - table1.c.value, - ] + expr(table1.c.name.label("foo")), + table1.c.name.label("bar"), + table1.c.value, ), "SELECT SOME_COL_THING(some_table.name) AS foo, " "some_table.name AS bar, some_table.value FROM some_table", @@ -854,11 +850,9 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - cast(table1.c.name, Integer), - cast(table1.c.name, String), - table1.c.name, - ] + cast(table1.c.name, Integer), + cast(table1.c.name, String), + table1.c.name, ), "SELECT CAST(some_table.name AS INTEGER) AS name, " "CAST(some_table.name AS VARCHAR) AS name, " @@ -870,11 +864,9 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - type_coerce(table1.c.name, Integer), - type_coerce(table1.c.name, String), - table1.c.name, - ] + type_coerce(table1.c.name, Integer), + type_coerce(table1.c.name, String), + table1.c.name, ), # ideally type_coerce wouldn't label at all... "SELECT some_table.name AS name, " @@ -886,7 +878,7 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): col = column("value", Boolean) self.assert_compile( - select([~col, col]), + select(~col, col), # not sure if this SQL is right but this is what it was # before the new labeling, just different label name "SELECT value = 0 AS value, value", @@ -898,11 +890,9 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - expr(table1.c.name.label("foo")), - table1.c.name.label("bar"), - table1.c.value, - ] + expr(table1.c.name.label("foo")), + table1.c.name.label("bar"), + table1.c.value, ).apply_labels(), # the expr around label is treated the same way as plain column # with label @@ -917,12 +907,10 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( select( - [ - table1.c.name, - table1.c.name, - expr(table1.c.name), - expr(table1.c.name), - ] + table1.c.name, + table1.c.name, + expr(table1.c.name), + expr(table1.c.name), ).apply_labels(), "SELECT some_table.name AS some_table_name, " "some_table.name AS some_table_name__1, " @@ -936,7 +924,7 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL): table1 = self.table1 self.assert_compile( - select([table1.c.name, expr(table1.c.value)]).apply_labels(), + select(table1.c.name, expr(table1.c.value)).apply_labels(), "SELECT some_table.name AS some_table_name, " "SOME_COL_THING(some_table.value) " "AS some_table_value FROM some_table", diff --git a/test/sql/test_lambdas.py b/test/sql/test_lambdas.py index a91242de5..c283e804e 100644 --- a/test/sql/test_lambdas.py +++ b/test/sql/test_lambdas.py @@ -38,7 +38,7 @@ class DeferredLambdaTest( y = 5 def go(): - return select([t1]).where(lambda: and_(t1.c.q == x, t1.c.p == y)) + return select(t1).where(lambda: and_(t1.c.q == x, t1.c.p == y)) self.assert_compile( go(), "SELECT t1.q, t1.p FROM t1 WHERE t1.q = :x_1 AND t1.p = :y_1" @@ -57,7 +57,7 @@ class DeferredLambdaTest( global_y = 17 def go(): - return select([t1]).where( + return select(t1).where( lambda: and_(t1.c.q == global_x, t1.c.p == global_y) ) @@ -567,7 +567,7 @@ class DeferredLambdaTest( assert_raises_message( exc.ArgumentError, "SQL expression for WHERE/HAVING role expected, got 5", - select([column("q")]).where, + select(column("q")).where, 5, ) @@ -577,7 +577,7 @@ class DeferredLambdaTest( {"compile_state_plugin": "x", "plugin_subject": "y"} ) - stmt = lambdas.lambda_stmt(lambda: select([col])) + stmt = lambdas.lambda_stmt(lambda: select(col)) eq_( stmt._propagate_attrs, @@ -590,7 +590,7 @@ class DeferredLambdaTest( {"compile_state_plugin": "x", "plugin_subject": "y"} ) - stmt = select([lambda: col]) + stmt = select(lambda: col) eq_( stmt._propagate_attrs, @@ -616,7 +616,7 @@ class DeferredLambdaTest( def test_select_legacy_expanding_columns(self): q, p, r = column("q"), column("p"), column("r") - stmt = select([lambda: (q, p, r)]) + stmt = select(lambda: (q, p, r)) self.assert_compile(stmt, "SELECT q, p, r") @@ -632,7 +632,7 @@ class DeferredLambdaTest( t2 = table("t2", column("y")) def go(): - return select([t1]).select_from( + return select(t1).select_from( lambda: join(t1, t2, lambda: t1.c.q == t2.c.y) ) @@ -646,7 +646,7 @@ class DeferredLambdaTest( def test_in_parameters_one(self): - expr1 = select([1]).where(column("q").in_(["a", "b", "c"])) + expr1 = select(1).where(column("q").in_(["a", "b", "c"])) self.assert_compile(expr1, "SELECT 1 WHERE q IN ([POSTCOMPILE_q_1])") self.assert_compile( @@ -657,7 +657,7 @@ class DeferredLambdaTest( ) def test_in_parameters_two(self): - expr2 = select([1]).where(lambda: column("q").in_(["a", "b", "c"])) + expr2 = select(1).where(lambda: column("q").in_(["a", "b", "c"])) self.assert_compile(expr2, "SELECT 1 WHERE q IN ([POSTCOMPILE_q_1])") self.assert_compile( expr2, @@ -668,7 +668,7 @@ class DeferredLambdaTest( def test_in_parameters_three(self): expr3 = lambdas.lambda_stmt( - lambda: select([1]).where(column("q").in_(["a", "b", "c"])) + lambda: select(1).where(column("q").in_(["a", "b", "c"])) ) self.assert_compile(expr3, "SELECT 1 WHERE q IN ([POSTCOMPILE_q_1])") self.assert_compile( @@ -681,7 +681,7 @@ class DeferredLambdaTest( def test_in_parameters_four(self): def go(names): return lambdas.lambda_stmt( - lambda: select([1]).where(column("q").in_(names)) + lambda: select(1).where(column("q").in_(names)) ) expr4 = go(["a", "b", "c"]) @@ -698,7 +698,7 @@ class DeferredLambdaTest( def test_in_parameters_five(self): def go(n1, n2): stmt = lambdas.lambda_stmt( - lambda: select([1]).where(column("q").in_(n1)) + lambda: select(1).where(column("q").in_(n1)) ) stmt += lambda s: s.where(column("y").in_(n2)) return stmt @@ -725,7 +725,7 @@ class DeferredLambdaTest( g = 5 def go(): - return select([lambda: t1.c.q, lambda: t1.c.p + g]) + return select(lambda: t1.c.q, lambda: t1.c.p + g) stmt = go() self.assert_compile( @@ -765,7 +765,7 @@ class DeferredLambdaTest( users, addresses = user_address_fixture stmt = ( - select([users]) + select(users) .select_from( users.join( addresses, lambda: users.c.id == addresses.c.user_id @@ -962,7 +962,7 @@ class DeferredLambdaTest( users, addresses = user_address_fixture def go(name): - stmt = select([lambda: users.c.id]).where( + stmt = select(lambda: users.c.id).where( lambda: users.c.name == name ) with testing.db.connect().execution_options( @@ -1000,9 +1000,7 @@ class DeferredLambdaTest( def go(name): stmt = lambda_stmt( - lambda: select([users.c.id]).where( # noqa - users.c.name == name - ) + lambda: select(users.c.id).where(users.c.name == name) # noqa ) with testing.db.connect().execution_options( @@ -1041,7 +1039,7 @@ class DeferredLambdaTest( cache = {} def go(name): - stmt = select([lambda: users.c.id]).where( + stmt = select(lambda: users.c.id).where( lambda: users.c.name == name ) @@ -1082,9 +1080,7 @@ class DeferredLambdaTest( def go(name): stmt = lambda_stmt( - lambda: select([users.c.id]).where( # noqa - users.c.name == name - ) + lambda: select(users.c.id).where(users.c.name == name) # noqa ) with testing.db.connect().execution_options( diff --git a/test/sql/test_lateral.py b/test/sql/test_lateral.py index b18dde57b..c5700fff2 100644 --- a/test/sql/test_lateral.py +++ b/test/sql/test_lateral.py @@ -57,7 +57,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): def test_standalone(self): table1 = self.tables.people - subq = select([table1.c.people_id]).subquery() + subq = select(table1.c.people_id).subquery() # alias name is not rendered because subquery is not # in the context of a FROM clause @@ -73,7 +73,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): def test_standalone_implicit_subquery(self): table1 = self.tables.people - subq = select([table1.c.people_id]) + subq = select(table1.c.people_id) # alias name is not rendered because subquery is not # in the context of a FROM clause @@ -89,22 +89,22 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): def test_select_from(self): table1 = self.tables.people - subq = select([table1.c.people_id]).subquery() + subq = select(table1.c.people_id).subquery() # in a FROM context, now you get "AS alias" and column labeling self.assert_compile( - select([subq.lateral(name="alias")]), + select(subq.lateral(name="alias")), "SELECT alias.people_id FROM LATERAL " "(SELECT people.people_id AS people_id FROM people) AS alias", ) def test_select_from_implicit_subquery(self): table1 = self.tables.people - subq = select([table1.c.people_id]) + subq = select(table1.c.people_id) # in a FROM context, now you get "AS alias" and column labeling self.assert_compile( - select([subq.lateral(name="alias")]), + select(subq.lateral(name="alias")), "SELECT alias.people_id FROM LATERAL " "(SELECT people.people_id AS people_id FROM people) AS alias", ) @@ -115,7 +115,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): # in a FROM context, now you get "AS alias" and column labeling self.assert_compile( - select([subq.lateral(name="alias")]), + select(subq.lateral(name="alias")), "SELECT alias.people_id FROM LATERAL " "(SELECT people_id FROM people) AS alias", ) @@ -123,7 +123,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): def test_plain_join(self): table1 = self.tables.people table2 = self.tables.books - subq = select([table2.c.book_id]).where( + subq = select(table2.c.book_id).where( table2.c.book_owner_id == table1.c.people_id ) @@ -138,7 +138,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): # put it in correct context, implicit correlation works fine self.assert_compile( - select([table1]).select_from( + select(table1).select_from( join(table1, lateral(subq.subquery(), name="alias"), true()) ), "SELECT people.people_id, people.age, people.name " @@ -150,7 +150,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): # explicit correlation subq = subq.correlate(table1) self.assert_compile( - select([table1]).select_from( + select(table1).select_from( join(table1, lateral(subq.subquery(), name="alias"), true()) ), "SELECT people.people_id, people.age, people.name " @@ -162,7 +162,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): def test_plain_join_implicit_subquery(self): table1 = self.tables.people table2 = self.tables.books - subq = select([table2.c.book_id]).where( + subq = select(table2.c.book_id).where( table2.c.book_owner_id == table1.c.people_id ) @@ -177,7 +177,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): # put it in correct context, implicit correlation works fine self.assert_compile( - select([table1]).select_from( + select(table1).select_from( join(table1, lateral(subq, name="alias"), true()) ), "SELECT people.people_id, people.age, people.name " @@ -189,7 +189,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): # explicit correlation subq = subq.correlate(table1) self.assert_compile( - select([table1]).select_from( + select(table1).select_from( join(table1, lateral(subq, name="alias"), true()) ), "SELECT people.people_id, people.age, people.name " @@ -203,13 +203,13 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): table2 = self.tables.books subq = ( - select([table2.c.book_id]) + select(table2.c.book_id) .correlate(table1) .where(table1.c.people_id == table2.c.book_owner_id) .subquery() .lateral() ) - stmt = select([table1, subq.c.book_id]).select_from( + stmt = select(table1, subq.c.book_id).select_from( table1.join(subq, true()) ) @@ -226,12 +226,12 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): table2 = self.tables.books subq = ( - select([table2.c.book_id]) + select(table2.c.book_id) .correlate(table1) .where(table1.c.people_id == table2.c.book_owner_id) .lateral() ) - stmt = select([table1, subq.c.book_id]).select_from( + stmt = select(table1, subq.c.book_id).select_from( table1.join(subq, true()) ) @@ -250,7 +250,7 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): srf = lateral(func.generate_series(1, bookcases.c.bookcase_shelves)) self.assert_compile( - select([bookcases]).select_from(bookcases.join(srf, true())), + select(bookcases).select_from(bookcases.join(srf, true())), "SELECT bookcases.bookcase_id, bookcases.bookcase_owner_id, " "bookcases.bookcase_shelves, bookcases.bookcase_width " "FROM bookcases JOIN " diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index dc4e342fd..c1db9d296 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -2801,7 +2801,7 @@ class ConstraintTest(fixtures.TestBase): def test_column_references_derived(self): t1, t2, t3 = self._single_fixture() - s1 = tsa.select([tsa.select([t1]).alias()]).subquery() + s1 = tsa.select(tsa.select(t1).alias()).subquery() assert t2.c.a.references(s1.c.a) assert not t2.c.a.references(s1.c.b) @@ -2813,7 +2813,7 @@ class ConstraintTest(fixtures.TestBase): def test_derived_column_references(self): t1, t2, t3 = self._single_fixture() - s1 = tsa.select([tsa.select([t2]).alias()]).subquery() + s1 = tsa.select(tsa.select(t2).alias()).subquery() assert s1.c.a.references(t1.c.a) assert not s1.c.a.references(t1.c.b) @@ -2932,7 +2932,7 @@ class ConstraintTest(fixtures.TestBase): Column("id", Integer, ForeignKey("t1.id"), primary_key=True), ) - s = tsa.select([t2]).subquery() + s = tsa.select(t2).subquery() t2fk = list(t2.c.id.foreign_keys)[0] sfk = list(s.c.id.foreign_keys)[0] @@ -3770,14 +3770,14 @@ class ColumnDefinitionTest(AssertsCompiledSQL, fixtures.TestBase): eq_(t1.c.name.my_goofy_thing(), "hi") # create proxy - s = select([t1.select().alias()]) + s = select(t1.select().alias()) # proxy has goofy thing eq_(s.subquery().c.name.my_goofy_thing(), "hi") # compile works self.assert_compile( - select([t1.select().alias()]), + select(t1.select().alias()), "SELECT anon_1.id-, anon_1.name- FROM " "(SELECT foo.id- AS id, foo.name- AS name " "FROM foo) AS anon_1", @@ -3802,7 +3802,7 @@ class ColumnDefinitionTest(AssertsCompiledSQL, fixtures.TestBase): "'test.sql.test_metadata..*MyColumn'> " "object. Ensure the class includes a _constructor()", getattr, - select([t1.select().alias()]).subquery(), + select(t1.select().alias()).subquery(), "c", ) diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 8521b9555..c011b961c 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -918,7 +918,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_one(self): c = column("x", Boolean) self.assert_compile( - select([c]).where(c), + select(c).where(c), "SELECT x WHERE x", dialect=self._dialect(True), ) @@ -926,7 +926,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_two_a(self): c = column("x", Boolean) self.assert_compile( - select([c]).where(c), + select(c).where(c), "SELECT x WHERE x = 1", dialect=self._dialect(False), ) @@ -934,7 +934,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_two_b(self): c = column("x", Boolean) self.assert_compile( - select([c], whereclause=c), + select(c).where(c), "SELECT x WHERE x = 1", dialect=self._dialect(False), ) @@ -942,7 +942,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_three_a(self): c = column("x", Boolean) self.assert_compile( - select([c]).where(~c), + select(c).where(~c), "SELECT x WHERE x = 0", dialect=self._dialect(False), ) @@ -950,7 +950,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_three_a_double(self): c = column("x", Boolean) self.assert_compile( - select([c]).where(~~c), + select(c).where(~~c), "SELECT x WHERE x = 1", dialect=self._dialect(False), ) @@ -958,7 +958,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_three_b(self): c = column("x", Boolean) self.assert_compile( - select([c], whereclause=~c), + select(c).where(~c), "SELECT x WHERE x = 0", dialect=self._dialect(False), ) @@ -966,7 +966,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_four(self): c = column("x", Boolean) self.assert_compile( - select([c]).where(~c), + select(c).where(~c), "SELECT x WHERE NOT x", dialect=self._dialect(True), ) @@ -974,7 +974,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_four_double(self): c = column("x", Boolean) self.assert_compile( - select([c]).where(~~c), + select(c).where(~~c), "SELECT x WHERE x", dialect=self._dialect(True), ) @@ -982,7 +982,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_five_a(self): c = column("x", Boolean) self.assert_compile( - select([c]).having(c), + select(c).having(c), "SELECT x HAVING x = 1", dialect=self._dialect(False), ) @@ -990,7 +990,7 @@ class BooleanEvalTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_five_b(self): c = column("x", Boolean) self.assert_compile( - select([c], having=c), + select(c).having(c), "SELECT x HAVING x = 1", dialect=self._dialect(False), ) @@ -1155,11 +1155,11 @@ class ConjunctionTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_six_pt_five(self): x = column("x") self.assert_compile( - select([x]).where(or_(x == 7, true())), "SELECT x WHERE true" + select(x).where(or_(x == 7, true())), "SELECT x WHERE true" ) self.assert_compile( - select([x]).where(or_(x == 7, true())), + select(x).where(or_(x == 7, true())), "SELECT x WHERE 1 = 1", dialect=default.DefaultDialect(supports_native_boolean=False), ) @@ -1187,26 +1187,26 @@ class ConjunctionTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_eleven(self): x = column("x") self.assert_compile( - select([x]).where(None).where(None), "SELECT x WHERE NULL AND NULL" + select(x).where(None).where(None), "SELECT x WHERE NULL AND NULL" ) def test_twelve(self): x = column("x") self.assert_compile( - select([x]).where(and_(None, None)), "SELECT x WHERE NULL AND NULL" + select(x).where(and_(None, None)), "SELECT x WHERE NULL AND NULL" ) def test_thirteen(self): x = column("x") self.assert_compile( - select([x]).where(~and_(None, None)), + select(x).where(~and_(None, None)), "SELECT x WHERE NOT (NULL AND NULL)", ) def test_fourteen(self): x = column("x") self.assert_compile( - select([x]).where(~null()), "SELECT x WHERE NOT NULL" + select(x).where(~null()), "SELECT x WHERE NOT NULL" ) def test_constants_are_singleton(self): @@ -1216,27 +1216,27 @@ class ConjunctionTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_constant_render_distinct(self): self.assert_compile( - select([null(), null()]), "SELECT NULL AS anon_1, NULL AS anon__1" + select(null(), null()), "SELECT NULL AS anon_1, NULL AS anon__1" ) self.assert_compile( - select([true(), true()]), "SELECT true AS anon_1, true AS anon__1" + select(true(), true()), "SELECT true AS anon_1, true AS anon__1" ) self.assert_compile( - select([false(), false()]), + select(false(), false()), "SELECT false AS anon_1, false AS anon__1", ) def test_constant_render_distinct_use_labels(self): self.assert_compile( - select([null(), null()]).apply_labels(), + select(null(), null()).apply_labels(), "SELECT NULL AS anon_1, NULL AS anon__1", ) self.assert_compile( - select([true(), true()]).apply_labels(), + select(true(), true()).apply_labels(), "SELECT true AS anon_1, true AS anon__1", ) self.assert_compile( - select([false(), false()]).apply_labels(), + select(false(), false()).apply_labels(), "SELECT false AS anon_1, false AS anon__1", ) @@ -1409,7 +1409,7 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_collate_5(self): self.assert_compile( - select([self.table1.c.name]).order_by( + select(self.table1.c.name).order_by( self.table1.c.name.collate("utf-8").desc() ), "SELECT mytable.name FROM mytable " @@ -1418,7 +1418,7 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_collate_6(self): self.assert_compile( - select([self.table1.c.name]).order_by( + select(self.table1.c.name).order_by( self.table1.c.name.collate("utf-8").desc().nullslast() ), "SELECT mytable.name FROM mytable " @@ -1427,7 +1427,7 @@ class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_operator_precedence_collate_7(self): self.assert_compile( - select([self.table1.c.name]).order_by( + select(self.table1.c.name).order_by( self.table1.c.name.collate("utf-8").asc() ), "SELECT mytable.name FROM mytable " @@ -1780,13 +1780,13 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_20(self): self.assert_compile( - self.table1.c.myid.in_(select([self.table2.c.otherid])), + self.table1.c.myid.in_(select(self.table2.c.otherid)), "mytable.myid IN (SELECT myothertable.otherid FROM myothertable)", ) def test_in_21(self): self.assert_compile( - ~self.table1.c.myid.in_(select([self.table2.c.otherid])), + ~self.table1.c.myid.in_(select(self.table2.c.otherid)), "mytable.myid NOT IN " "(SELECT myothertable.otherid FROM myothertable)", ) @@ -1802,7 +1802,7 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_24(self): self.assert_compile( - select([self.table1.c.myid.in_(select([self.table2.c.otherid]))]), + select(self.table1.c.myid.in_(select(self.table2.c.otherid))), "SELECT mytable.myid IN (SELECT myothertable.otherid " "FROM myothertable) AS anon_1 FROM mytable", ) @@ -1810,11 +1810,9 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_25(self): self.assert_compile( select( - [ - self.table1.c.myid.in_( - select([self.table2.c.otherid]).scalar_subquery() - ) - ] + self.table1.c.myid.in_( + select(self.table2.c.otherid).scalar_subquery() + ) ), "SELECT mytable.myid IN (SELECT myothertable.otherid " "FROM myothertable) AS anon_1 FROM mytable", @@ -1824,8 +1822,8 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL): self.assert_compile( self.table1.c.myid.in_( union( - select([self.table1.c.myid], self.table1.c.myid == 5), - select([self.table1.c.myid], self.table1.c.myid == 12), + select(self.table1.c.myid).where(self.table1.c.myid == 5), + select(self.table1.c.myid).where(self.table1.c.myid == 12), ) ), "mytable.myid IN (" @@ -1838,24 +1836,21 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL): # test that putting a select in an IN clause does not # blow away its ORDER BY clause self.assert_compile( - select( - [self.table1, self.table2], + select(self.table1, self.table2) + .where( self.table2.c.otherid.in_( - select( - [self.table2.c.otherid], - order_by=[self.table2.c.othername], - limit=10, - correlate=False, - ) - ), - from_obj=[ - self.table1.join( - self.table2, - self.table1.c.myid == self.table2.c.otherid, - ) - ], - order_by=[self.table1.c.myid], - ), + select(self.table2.c.otherid) + .order_by(self.table2.c.othername) + .limit(10) + .correlate(False), + ) + ) + .select_from( + self.table1.join( + self.table2, self.table1.c.myid == self.table2.c.otherid, + ) + ) + .order_by(self.table1.c.myid), "SELECT mytable.myid, " "myothertable.otherid, myothertable.othername FROM mytable " "JOIN myothertable ON mytable.myid = myothertable.otherid " @@ -2166,7 +2161,7 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL): assert not (self.table1.c.myid + 5)._is_implicitly_boolean assert not not_(column("x", Boolean))._is_implicitly_boolean assert ( - not select([self.table1.c.myid]) + not select(self.table1.c.myid) .scalar_subquery() ._is_implicitly_boolean ) @@ -2988,14 +2983,14 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_select(self): t = table("t", column("x")) - stmt = select([t.c.x]) + stmt = select(t.c.x) self.assert_compile(column("q").in_(stmt), "q IN (SELECT t.x FROM t)") def test_in_subquery_warning(self): t = table("t", column("x")) - stmt = select([t.c.x]).subquery() + stmt = select(t.c.x).subquery() with expect_warnings( r"Coercing Subquery object into a select\(\) for use in " @@ -3010,7 +3005,7 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_subquery_explicit(self): t = table("t", column("x")) - stmt = select([t.c.x]).subquery() + stmt = select(t.c.x).subquery() self.assert_compile( column("q").in_(stmt.select()), @@ -3021,7 +3016,7 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_subquery_alias_implicit(self): t = table("t", column("x")) - stmt = select([t.c.x]).subquery().alias() + stmt = select(t.c.x).subquery().alias() with expect_warnings( r"Coercing Alias object into a select\(\) for use in " @@ -3036,7 +3031,7 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_subquery_alias_explicit(self): t = table("t", column("x")) - stmt = select([t.c.x]).subquery().alias() + stmt = select(t.c.x).subquery().alias() self.assert_compile( column("q").in_(stmt.select().scalar_subquery()), @@ -3066,7 +3061,7 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_cte_implicit(self): t = table("t", column("x")) - stmt = select([t.c.x]).cte() + stmt = select(t.c.x).cte() with expect_warnings( r"Coercing CTE object into a select\(\) for use in " @@ -3083,9 +3078,9 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_cte_explicit(self): t = table("t", column("x")) - stmt = select([t.c.x]).cte() + stmt = select(t.c.x).cte() - s2 = select([column("q").in_(stmt.select().scalar_subquery())]) + s2 = select(column("q").in_(stmt.select().scalar_subquery())) self.assert_compile( s2, @@ -3096,9 +3091,9 @@ class InSelectableTest(fixtures.TestBase, testing.AssertsCompiledSQL): def test_in_cte_select(self): t = table("t", column("x")) - stmt = select([t.c.x]).cte() + stmt = select(t.c.x).cte() - s2 = select([column("q").in_(stmt.select())]) + s2 = select(column("q").in_(stmt.select())) self.assert_compile( s2, @@ -3285,8 +3280,7 @@ class AnyAllTest(fixtures.TestBase, testing.AssertsCompiledSQL): t = t_fixture self.assert_compile( - 5 - == any_(select([t.c.data]).where(t.c.data < 10).scalar_subquery()), + 5 == any_(select(t.c.data).where(t.c.data < 10).scalar_subquery()), ":param_1 = ANY (SELECT tab1.data " "FROM tab1 WHERE tab1.data < :data_1)", checkparams={"data_1": 10, "param_1": 5}, @@ -3297,10 +3291,7 @@ class AnyAllTest(fixtures.TestBase, testing.AssertsCompiledSQL): self.assert_compile( 5 - == select([t.c.data]) - .where(t.c.data < 10) - .scalar_subquery() - .any_(), + == select(t.c.data).where(t.c.data < 10).scalar_subquery().any_(), ":param_1 = ANY (SELECT tab1.data " "FROM tab1 WHERE tab1.data < :data_1)", checkparams={"data_1": 10, "param_1": 5}, @@ -3310,8 +3301,7 @@ class AnyAllTest(fixtures.TestBase, testing.AssertsCompiledSQL): t = t_fixture self.assert_compile( - 5 - == all_(select([t.c.data]).where(t.c.data < 10).scalar_subquery()), + 5 == all_(select(t.c.data).where(t.c.data < 10).scalar_subquery()), ":param_1 = ALL (SELECT tab1.data " "FROM tab1 WHERE tab1.data < :data_1)", checkparams={"data_1": 10, "param_1": 5}, @@ -3322,10 +3312,7 @@ class AnyAllTest(fixtures.TestBase, testing.AssertsCompiledSQL): self.assert_compile( 5 - == select([t.c.data]) - .where(t.c.data < 10) - .scalar_subquery() - .all_(), + == select(t.c.data).where(t.c.data < 10).scalar_subquery().all_(), ":param_1 = ALL (SELECT tab1.data " "FROM tab1 WHERE tab1.data < :data_1)", checkparams={"data_1": 10, "param_1": 5}, diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 3662a6e72..9b3ededcd 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -114,23 +114,19 @@ class QueryTest(fixtures.TestBase): concat = ("test: " + users.c.user_name).label("thedata") eq_( - connection.execute( - select([concat]).order_by("thedata") - ).fetchall(), + connection.execute(select(concat).order_by("thedata")).fetchall(), [("test: ed",), ("test: fred",), ("test: jack",)], ) eq_( - connection.execute( - select([concat]).order_by("thedata") - ).fetchall(), + connection.execute(select(concat).order_by("thedata")).fetchall(), [("test: ed",), ("test: fred",), ("test: jack",)], ) concat = ("test: " + users.c.user_name).label("thedata") eq_( connection.execute( - select([concat]).order_by(desc("thedata")) + select(concat).order_by(desc("thedata")) ).fetchall(), [("test: jack",), ("test: fred",), ("test: ed",)], ) @@ -147,7 +143,7 @@ class QueryTest(fixtures.TestBase): concat = ("test: " + users.c.user_name).label("thedata") eq_( connection.execute( - select([concat]).order_by(literal_column("thedata") + "x") + select(concat).order_by(literal_column("thedata") + "x") ).fetchall(), [("test: ed",), ("test: fred",), ("test: jack",)], ) @@ -156,25 +152,22 @@ class QueryTest(fixtures.TestBase): def test_or_and_as_columns(self, connection): true, false = literal(True), literal(False) - eq_(connection.execute(select([and_(true, false)])).scalar(), False) - eq_(connection.execute(select([and_(true, true)])).scalar(), True) - eq_(connection.execute(select([or_(true, false)])).scalar(), True) - eq_(connection.execute(select([or_(false, false)])).scalar(), False) + eq_(connection.execute(select(and_(true, false))).scalar(), False) + eq_(connection.execute(select(and_(true, true))).scalar(), True) + eq_(connection.execute(select(or_(true, false))).scalar(), True) + eq_(connection.execute(select(or_(false, false))).scalar(), False) eq_( - connection.execute(select([not_(or_(false, false))])).scalar(), - True, + connection.execute(select(not_(or_(false, false)))).scalar(), True, ) row = connection.execute( - select( - [or_(false, false).label("x"), and_(true, false).label("y")] - ) + select(or_(false, false).label("x"), and_(true, false).label("y")) ).first() assert row.x == False # noqa assert row.y == False # noqa row = connection.execute( - select([or_(true, false).label("x"), and_(true, false).label("y")]) + select(or_(true, false).label("x"), and_(true, false).label("y")) ).first() assert row.x == True # noqa assert row.y == False # noqa @@ -203,25 +196,25 @@ class QueryTest(fixtures.TestBase): for expr, result in ( ( - select([users.c.user_id]).where( + select(users.c.user_id).where( users.c.user_name.startswith("apple") ), [(1,)], ), ( - select([users.c.user_id]).where( + select(users.c.user_id).where( users.c.user_name.contains("i % t") ), [(5,)], ), ( - select([users.c.user_id]).where( + select(users.c.user_id).where( users.c.user_name.endswith("anas") ), [(3,)], ), ( - select([users.c.user_id]).where( + select(users.c.user_id).where( users.c.user_name.contains("i % t", escape="&") ), [(5,)], @@ -253,14 +246,14 @@ class QueryTest(fixtures.TestBase): eq_( connection.execute( - select([users.c.user_id]).where(users.c.user_name.ilike("one")) + select(users.c.user_id).where(users.c.user_name.ilike("one")) ).fetchall(), [(1,), (3,), (4,)], ) eq_( connection.execute( - select([users.c.user_id]).where(users.c.user_name.ilike("TWO")) + select(users.c.user_id).where(users.c.user_name.ilike("TWO")) ).fetchall(), [(2,)], ) @@ -268,7 +261,7 @@ class QueryTest(fixtures.TestBase): if testing.against("postgresql"): eq_( connection.execute( - select([users.c.user_id]).where( + select(users.c.user_id).where( users.c.user_name.like("one") ) ).fetchall(), @@ -276,7 +269,7 @@ class QueryTest(fixtures.TestBase): ) eq_( connection.execute( - select([users.c.user_id]).where( + select(users.c.user_id).where( users.c.user_name.like("TWO") ) ).fetchall(), @@ -285,14 +278,14 @@ class QueryTest(fixtures.TestBase): def test_compiled_execute(self, connection): connection.execute(users.insert(), user_id=7, user_name="jack") - s = select([users], users.c.user_id == bindparam("id")).compile() + s = select(users).where(users.c.user_id == bindparam("id")).compile() eq_(connection.execute(s, id=7).first()._mapping["user_id"], 7) def test_compiled_insert_execute(self, connection): connection.execute( users.insert().compile(), user_id=7, user_name="jack" ) - s = select([users], users.c.user_id == bindparam("id")).compile() + s = select(users).where(users.c.user_id == bindparam("id")).compile() eq_(connection.execute(s, id=7).first()._mapping["user_id"], 7) def test_repeated_bindparams(self, connection): @@ -358,12 +351,11 @@ class QueryTest(fixtures.TestBase): return "INT_%d" % value eq_( - connection.scalar(select([cast("INT_5", type_=MyInteger)])), - "INT_5", + connection.scalar(select(cast("INT_5", type_=MyInteger))), "INT_5", ) eq_( connection.scalar( - select([cast("INT_5", type_=MyInteger).label("foo")]) + select(cast("INT_5", type_=MyInteger).label("foo")) ), "INT_5", ) @@ -383,6 +375,12 @@ class QueryTest(fixtures.TestBase): eq_(got, wanted) for labels in False, True: + + def go(stmt): + if labels: + stmt = stmt.apply_labels() + return stmt + a_eq( users.select(order_by=[users.c.user_id], use_labels=labels), [(1, "c"), (2, "b"), (3, "a")], @@ -397,19 +395,19 @@ class QueryTest(fixtures.TestBase): ) a_eq( - select( - [users.c.user_id.label("foo")], - use_labels=labels, - order_by=[users.c.user_id], + go( + select(users.c.user_id.label("foo")).order_by( + users.c.user_id + ) ), [(1,), (2,), (3,)], ) a_eq( - select( - [users.c.user_id.label("foo"), users.c.user_name], - use_labels=labels, - order_by=[users.c.user_name, users.c.user_id], + go( + select( + users.c.user_id.label("foo"), users.c.user_name + ).order_by(users.c.user_name, users.c.user_id), ), [(3, "a"), (2, "b"), (1, "c")], ) @@ -424,24 +422,21 @@ class QueryTest(fixtures.TestBase): ) a_eq( - select( - [users.c.user_id.label("foo")], - distinct=True, - use_labels=labels, - order_by=[users.c.user_id], + go( + select(users.c.user_id.label("foo")) + .distinct() + .order_by(users.c.user_id), ), [(1,), (2,), (3,)], ) a_eq( - select( - [ + go( + select( users.c.user_id.label("a"), users.c.user_id.label("b"), users.c.user_name, - ], - use_labels=labels, - order_by=[users.c.user_id], + ).order_by(users.c.user_id), ), [(1, 1, "c"), (2, 2, "b"), (3, 3, "a")], ) @@ -456,11 +451,10 @@ class QueryTest(fixtures.TestBase): ) a_eq( - select( - [users.c.user_id.label("foo")], - distinct=True, - use_labels=labels, - order_by=[users.c.user_id.desc()], + go( + select(users.c.user_id.label("foo")) + .distinct() + .order_by(users.c.user_id.desc()), ), [(3,), (2,), (1,)], ) @@ -596,7 +590,7 @@ class QueryTest(fixtures.TestBase): ) stmt = ( - select([users]) + select(users) .where(users.c.user_name.in_(bindparam("uname", expanding=True))) .order_by(users.c.user_id) ) @@ -634,7 +628,7 @@ class QueryTest(fixtures.TestBase): ) stmt = ( - select([users]) + select(users) .where(users.c.user_name.in_(bindparam("u35", expanding=True))) .where(users.c.user_id == bindparam("u46")) .order_by(users.c.user_id) @@ -648,7 +642,7 @@ class QueryTest(fixtures.TestBase): ) stmt = ( - select([users]) + select(users) .where(users.c.user_name.in_(bindparam("u.35", expanding=True))) .where(users.c.user_id == bindparam("u.46")) .order_by(users.c.user_id) @@ -672,7 +666,7 @@ class QueryTest(fixtures.TestBase): ) stmt = ( - select([users]) + select(users) .where(users.c.user_name.in_(bindparam("uname", expanding=True))) .where(users.c.user_id.in_(bindparam("userid", expanding=True))) .order_by(users.c.user_id) @@ -696,7 +690,7 @@ class QueryTest(fixtures.TestBase): ) stmt = ( - select([users]) + select(users) .where( users.c.user_name.in_(bindparam("uname", expanding=True)) | users.c.user_name.in_(bindparam("uname2", expanding=True)) @@ -704,7 +698,7 @@ class QueryTest(fixtures.TestBase): .where(users.c.user_id == 8) ) stmt = stmt.union( - select([users]) + select(users) .where( users.c.user_name.in_(bindparam("uname", expanding=True)) | users.c.user_name.in_(bindparam("uname2", expanding=True)) @@ -736,7 +730,7 @@ class QueryTest(fixtures.TestBase): ) stmt = ( - select([users]) + select(users) .where( tuple_(users.c.user_id, users.c.user_name).in_( bindparam("uname", expanding=True) @@ -783,7 +777,7 @@ class QueryTest(fixtures.TestBase): ) stmt = ( - select([users]) + select(users) .where(users.c.user_name.in_(bindparam("uname", expanding=True))) .order_by(users.c.user_id) ) @@ -901,7 +895,7 @@ class RequiredBindTest(fixtures.TablesTest): def test_select_where(self): stmt = ( - select([self.tables.foo]) + select(self.tables.foo) .where(self.tables.foo.c.data == bindparam("data")) .where(self.tables.foo.c.x == bindparam("x")) ) @@ -909,7 +903,7 @@ class RequiredBindTest(fixtures.TablesTest): @testing.requires.standalone_binds def test_select_columns(self): - stmt = select([bindparam("data"), bindparam("x")]) + stmt = select(bindparam("data"), bindparam("x")) self._assert_raises(stmt, {"data": "data"}) def test_text(self): @@ -1012,7 +1006,7 @@ class LimitTest(fixtures.TestBase): [ x[0] for x in connection.execute( - select([addresses.c.address]).distinct().limit(3) + select(addresses.c.address).distinct().limit(3) ) ] ) @@ -1027,7 +1021,7 @@ class LimitTest(fixtures.TestBase): [ x[0] for x in connection.execute( - select([addresses.c.address]) + select(addresses.c.address) .distinct() .offset(1) .order_by(addresses.c.address) @@ -1042,7 +1036,7 @@ class LimitTest(fixtures.TestBase): """Test the interaction between limit and limit/offset""" r = connection.execute( - select([addresses.c.address]) + select(addresses.c.address) .order_by(addresses.c.address) .distinct() .offset(2) @@ -1144,12 +1138,10 @@ class CompoundTest(fixtures.TestBase): @testing.requires.subqueries def test_union(self, connection): (s1, s2) = ( - select( - [t1.c.col3.label("col3"), t1.c.col4.label("col4")], + select(t1.c.col3.label("col3"), t1.c.col4.label("col4")).where( t1.c.col2.in_(["t1col2r1", "t1col2r2"]), ), - select( - [t2.c.col3.label("col3"), t2.c.col4.label("col4")], + select(t2.c.col3.label("col3"), t2.c.col4.label("col4")).where( t2.c.col2.in_(["t2col2r2", "t2col2r3"]), ), ) @@ -1172,12 +1164,10 @@ class CompoundTest(fixtures.TestBase): @testing.fails_on("firebird", "doesn't like ORDER BY with UNIONs") def test_union_ordered(self, connection): (s1, s2) = ( - select( - [t1.c.col3.label("col3"), t1.c.col4.label("col4")], + select(t1.c.col3.label("col3"), t1.c.col4.label("col4")).where( t1.c.col2.in_(["t1col2r1", "t1col2r2"]), ), - select( - [t2.c.col3.label("col3"), t2.c.col4.label("col4")], + select(t2.c.col3.label("col3"), t2.c.col4.label("col4")).where( t2.c.col2.in_(["t2col2r2", "t2col2r3"]), ), ) @@ -1195,12 +1185,10 @@ class CompoundTest(fixtures.TestBase): @testing.requires.subqueries def test_union_ordered_alias(self, connection): (s1, s2) = ( - select( - [t1.c.col3.label("col3"), t1.c.col4.label("col4")], + select(t1.c.col3.label("col3"), t1.c.col4.label("col4")).where( t1.c.col2.in_(["t1col2r1", "t1col2r2"]), ), - select( - [t2.c.col3.label("col3"), t2.c.col4.label("col4")], + select(t2.c.col3.label("col3"), t2.c.col4.label("col4")).where( t2.c.col2.in_(["t2col2r2", "t2col2r3"]), ), ) @@ -1225,8 +1213,7 @@ class CompoundTest(fixtures.TestBase): @testing.fails_on("sqlite", "FIXME: unknown") def test_union_all(self, connection): e = union_all( - select([t1.c.col3]), - union(select([t1.c.col3]), select([t1.c.col3])), + select(t1.c.col3), union(select(t1.c.col3), select(t1.c.col3)), ) wanted = [("aaa",), ("aaa",), ("bbb",), ("bbb",), ("ccc",), ("ccc",)] @@ -1245,9 +1232,9 @@ class CompoundTest(fixtures.TestBase): """ - u = union(select([t1.c.col3]), select([t1.c.col3])).alias() + u = union(select(t1.c.col3), select(t1.c.col3)).alias() - e = union_all(select([t1.c.col3]), select([u.c.col3])) + e = union_all(select(t1.c.col3), select(u.c.col3)) wanted = [("aaa",), ("aaa",), ("bbb",), ("bbb",), ("ccc",), ("ccc",)] found1 = self._fetchall_sorted(connection.execute(e)) @@ -1261,8 +1248,8 @@ class CompoundTest(fixtures.TestBase): @testing.requires.intersect def test_intersect(self, connection): i = intersect( - select([t2.c.col3, t2.c.col4]), - select([t2.c.col3, t2.c.col4], t2.c.col4 == t3.c.col3), + select(t2.c.col3, t2.c.col4), + select(t2.c.col3, t2.c.col4).where(t2.c.col4 == t3.c.col3), ) wanted = [("aaa", "bbb"), ("bbb", "ccc"), ("ccc", "aaa")] @@ -1280,11 +1267,11 @@ class CompoundTest(fixtures.TestBase): def test_except_style1(self, connection): e = except_( union( - select([t1.c.col3, t1.c.col4]), - select([t2.c.col3, t2.c.col4]), - select([t3.c.col3, t3.c.col4]), + select(t1.c.col3, t1.c.col4), + select(t2.c.col3, t2.c.col4), + select(t3.c.col3, t3.c.col4), ), - select([t2.c.col3, t2.c.col4]), + select(t2.c.col3, t2.c.col4), ) wanted = [ @@ -1306,13 +1293,13 @@ class CompoundTest(fixtures.TestBase): e = except_( union( - select([t1.c.col3, t1.c.col4]), - select([t2.c.col3, t2.c.col4]), - select([t3.c.col3, t3.c.col4]), + select(t1.c.col3, t1.c.col4), + select(t2.c.col3, t2.c.col4), + select(t3.c.col3, t3.c.col4), ) .alias() .select(), - select([t2.c.col3, t2.c.col4]), + select(t2.c.col3, t2.c.col4), ) wanted = [ @@ -1338,10 +1325,10 @@ class CompoundTest(fixtures.TestBase): def test_except_style3(self, connection): # aaa, bbb, ccc - (aaa, bbb, ccc - (ccc)) = ccc e = except_( - select([t1.c.col3]), # aaa, bbb, ccc + select(t1.c.col3), # aaa, bbb, ccc except_( - select([t2.c.col3]), # aaa, bbb, ccc - select([t3.c.col3], t3.c.col3 == "ccc"), # ccc + select(t2.c.col3), # aaa, bbb, ccc + select(t3.c.col3).where(t3.c.col3 == "ccc"), # ccc ), ) eq_(connection.execute(e).fetchall(), [("ccc",)]) @@ -1351,10 +1338,10 @@ class CompoundTest(fixtures.TestBase): def test_except_style4(self, connection): # aaa, bbb, ccc - (aaa, bbb, ccc - (ccc)) = ccc e = except_( - select([t1.c.col3]), # aaa, bbb, ccc + select(t1.c.col3), # aaa, bbb, ccc except_( - select([t2.c.col3]), # aaa, bbb, ccc - select([t3.c.col3], t3.c.col3 == "ccc"), # ccc + select(t2.c.col3), # aaa, bbb, ccc + select(t3.c.col3).where(t3.c.col3 == "ccc"), # ccc ) .alias() .select(), @@ -1370,12 +1357,8 @@ class CompoundTest(fixtures.TestBase): ) def test_intersect_unions(self, connection): u = intersect( - union( - select([t1.c.col3, t1.c.col4]), select([t3.c.col3, t3.c.col4]) - ), - union( - select([t2.c.col3, t2.c.col4]), select([t3.c.col3, t3.c.col4]) - ) + union(select(t1.c.col3, t1.c.col4), select(t3.c.col3, t3.c.col4)), + union(select(t2.c.col3, t2.c.col4), select(t3.c.col3, t3.c.col4)) .alias() .select(), ) @@ -1387,14 +1370,10 @@ class CompoundTest(fixtures.TestBase): @testing.requires.intersect def test_intersect_unions_2(self, connection): u = intersect( - union( - select([t1.c.col3, t1.c.col4]), select([t3.c.col3, t3.c.col4]) - ) + union(select(t1.c.col3, t1.c.col4), select(t3.c.col3, t3.c.col4)) .alias() .select(), - union( - select([t2.c.col3, t2.c.col4]), select([t3.c.col3, t3.c.col4]) - ) + union(select(t2.c.col3, t2.c.col4), select(t3.c.col3, t3.c.col4)) .alias() .select(), ) @@ -1406,11 +1385,11 @@ class CompoundTest(fixtures.TestBase): @testing.requires.intersect def test_intersect_unions_3(self, connection): u = intersect( - select([t2.c.col3, t2.c.col4]), + select(t2.c.col3, t2.c.col4), union( - select([t1.c.col3, t1.c.col4]), - select([t2.c.col3, t2.c.col4]), - select([t3.c.col3, t3.c.col4]), + select(t1.c.col3, t1.c.col4), + select(t2.c.col3, t2.c.col4), + select(t3.c.col3, t3.c.col4), ) .alias() .select(), @@ -1423,11 +1402,11 @@ class CompoundTest(fixtures.TestBase): @testing.requires.intersect def test_composite_alias(self, connection): ua = intersect( - select([t2.c.col3, t2.c.col4]), + select(t2.c.col3, t2.c.col4), union( - select([t1.c.col3, t1.c.col4]), - select([t2.c.col3, t2.c.col4]), - select([t3.c.col3, t3.c.col4]), + select(t1.c.col3, t1.c.col4), + select(t2.c.col3, t2.c.col4), + select(t3.c.col3, t3.c.col4), ) .alias() .select(), @@ -1518,8 +1497,8 @@ class JoinTest(fixtures.TestBase): """Joins t1->t2.""" for criteria in (t1.c.t1_id == t2.c.t1_id, t2.c.t1_id == t1.c.t1_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id], from_obj=[t1.join(t2, criteria)] + expr = select(t1.c.t1_id, t2.c.t2_id).select_from( + t1.join(t2, criteria) ) self.assertRows(expr, [(10, 20), (11, 21)]) @@ -1527,8 +1506,8 @@ class JoinTest(fixtures.TestBase): """Joins t1->t2->t3.""" for criteria in (t1.c.t1_id == t2.c.t1_id, t2.c.t1_id == t1.c.t1_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id], from_obj=[t1.join(t2, criteria)] + expr = select(t1.c.t1_id, t2.c.t2_id).select_from( + t1.join(t2, criteria) ) self.assertRows(expr, [(10, 20), (11, 21)]) @@ -1536,9 +1515,8 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id], - from_obj=[t1.join(t2).join(t3, criteria)], + expr = select(t1.c.t1_id, t2.c.t2_id).select_from( + t1.join(t2).join(t3, criteria) ) self.assertRows(expr, [(10, 20)]) @@ -1546,13 +1524,10 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2,t3.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - from_obj=[ - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) - ], + expr = select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id).select_from( + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria + ) ) self.assertRows( expr, [(10, 20, 30), (11, 21, None), (12, None, None)] @@ -1562,29 +1537,29 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2,t3, where on t1.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t1.c.name == "t1 #10", - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t1.c.name == "t1 #10") + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t1.c.t1_id < 12, - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t1.c.t1_id < 12) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30), (11, 21, None)]) @@ -1592,29 +1567,29 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2,t3, where on t2.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t2.c.name == "t2 #20", - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t2.c.name == "t2 #20") + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t2.c.t2_id < 29, - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t2.c.t2_id < 29) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30), (11, 21, None)]) @@ -1622,29 +1597,29 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2,t3, where on t3.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t3.c.name == "t3 #30", - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t3.c.name == "t3 #30") + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t3.c.t3_id < 39, - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t3.c.t3_id < 39) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1652,29 +1627,28 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2,t3, where on t1 and t3.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_(t1.c.name == "t1 #10", t3.c.name == "t3 #30"), - from_obj=[ - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(and_(t1.c.name == "t1 #10", t3.c.name == "t3 #30")) + .select_from( + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) - ], + ) ) + self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_(t1.c.t1_id < 19, t3.c.t3_id < 39), - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(and_(t1.c.t1_id < 19, t3.c.t3_id < 39)) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1682,29 +1656,29 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2,t3, where on t1 and t2.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_(t1.c.name == "t1 #10", t2.c.name == "t2 #20"), - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(and_(t1.c.name == "t1 #10", t2.c.name == "t2 #20")) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_(t1.c.t1_id < 12, t2.c.t2_id < 39), - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(and_(t1.c.t1_id < 12, t2.c.t2_id < 39)) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30), (11, 21, None)]) @@ -1712,33 +1686,35 @@ class JoinTest(fixtures.TestBase): """Outer joins t1->t2,t3, where on t1, t2 and t3.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_( - t1.c.name == "t1 #10", - t2.c.name == "t2 #20", - t3.c.name == "t3 #30", - ), - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where( + and_( + t1.c.name == "t1 #10", + t2.c.name == "t2 #20", + t3.c.name == "t3 #30", + ) + ) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_(t1.c.t1_id < 19, t2.c.t2_id < 29, t3.c.t3_id < 39), - from_obj=[ + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(and_(t1.c.t1_id < 19, t2.c.t2_id < 29, t3.c.t3_id < 39)) + .select_from( ( t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( t3, criteria ) ) - ], + ) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1746,9 +1722,8 @@ class JoinTest(fixtures.TestBase): """Joins t1->t2, outer t2->t3.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - from_obj=[(t1.join(t2).outerjoin(t3, criteria))], + expr = select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id).select_from( + (t1.join(t2).outerjoin(t3, criteria)), ) print(expr) self.assertRows(expr, [(10, 20, 30), (11, 21, None)]) @@ -1757,49 +1732,51 @@ class JoinTest(fixtures.TestBase): """Joins t1->t2, outer t2->t3, plus a where on each table in turn.""" for criteria in (t2.c.t2_id == t3.c.t2_id, t3.c.t2_id == t2.c.t2_id): - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t1.c.name == "t1 #10", - from_obj=[(t1.join(t2).outerjoin(t3, criteria))], + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t1.c.name == "t1 #10",) + .select_from((t1.join(t2).outerjoin(t3, criteria))) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t2.c.name == "t2 #20", - from_obj=[(t1.join(t2).outerjoin(t3, criteria))], + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t2.c.name == "t2 #20",) + .select_from((t1.join(t2).outerjoin(t3, criteria))) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - t3.c.name == "t3 #30", - from_obj=[(t1.join(t2).outerjoin(t3, criteria))], + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(t3.c.name == "t3 #30",) + .select_from((t1.join(t2).outerjoin(t3, criteria))) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_(t1.c.name == "t1 #10", t2.c.name == "t2 #20"), - from_obj=[(t1.join(t2).outerjoin(t3, criteria))], + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(and_(t1.c.name == "t1 #10", t2.c.name == "t2 #20"),) + .select_from((t1.join(t2).outerjoin(t3, criteria))) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_(t2.c.name == "t2 #20", t3.c.name == "t3 #30"), - from_obj=[(t1.join(t2).outerjoin(t3, criteria))], + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where(and_(t2.c.name == "t2 #20", t3.c.name == "t3 #30"),) + .select_from((t1.join(t2).outerjoin(t3, criteria))) ) self.assertRows(expr, [(10, 20, 30)]) - expr = select( - [t1.c.t1_id, t2.c.t2_id, t3.c.t3_id], - and_( - t1.c.name == "t1 #10", - t2.c.name == "t2 #20", - t3.c.name == "t3 #30", - ), - from_obj=[(t1.join(t2).outerjoin(t3, criteria))], + expr = ( + select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) + .where( + and_( + t1.c.name == "t1 #10", + t2.c.name == "t2 #20", + t3.c.name == "t3 #30", + ), + ) + .select_from((t1.join(t2).outerjoin(t3, criteria))) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1842,7 +1819,7 @@ class OperatorTest(fixtures.TestBase): def test_modulo(self, connection): eq_( connection.execute( - select([flds.c.intcol % 3], order_by=flds.c.idcol) + select(flds.c.intcol % 3).order_by(flds.c.idcol) ).fetchall(), [(2,), (1,)], ) @@ -1852,10 +1829,8 @@ class OperatorTest(fixtures.TestBase): eq_( connection.execute( select( - [ - flds.c.intcol, - func.row_number().over(order_by=flds.c.strcol), - ] + flds.c.intcol, + func.row_number().over(order_by=flds.c.strcol), ) ).fetchall(), [(13, 1), (5, 2)], diff --git a/test/sql/test_quote.py b/test/sql/test_quote.py index b4d97a1b9..504ed4064 100644 --- a/test/sql/test_quote.py +++ b/test/sql/test_quote.py @@ -405,7 +405,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): ) # Note that the names are quoted b/c they are reserved words - x = select([table.c.col1, table.c["from"], table.c.order]) + x = select(table.c.col1, table.c["from"], table.c.order) self.assert_compile( x, "SELECT " @@ -429,7 +429,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): ) # Note that the names are now unquoted - x = select([table.c.col1, table.c["from"], table.c.order]) + x = select(table.c.col1, table.c["from"], table.c.order) self.assert_compile( x, "SELECT " @@ -444,7 +444,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): metadata = MetaData() t1 = Table("t1", metadata, Column("col1", Integer), schema="foo") a = t1.select().alias("anon") - b = select([1], a.c.col1 == 2, from_obj=a) + b = select(1).where(a.c.col1 == 2).select_from(a) self.assert_compile( b, "SELECT 1 " @@ -469,7 +469,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): quote_schema=True, ) a = t1.select().alias("anon") - b = select([1], a.c.col1 == 2, from_obj=a) + b = select(1).where(a.c.col1 == 2).select_from(a) self.assert_compile( b, "SELECT 1 " @@ -487,7 +487,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): metadata = MetaData() t1 = Table("T1", metadata, Column("Col1", Integer), schema="Foo") a = t1.select().alias("Anon") - b = select([1], a.c.Col1 == 2, from_obj=a) + b = select(1).where(a.c.Col1 == 2).select_from(a) self.assert_compile( b, "SELECT 1 " @@ -514,7 +514,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): quote_schema=False, ) a = t1.select().alias("Anon") - b = select([1], a.c.Col1 == 2, from_obj=a) + b = select(1).where(a.c.Col1 == 2).select_from(a) self.assert_compile( b, "SELECT 1 " @@ -533,7 +533,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): t1 = Table("t1", m, Column("col1", Integer)) cl = t1.c.col1.label("ShouldQuote") self.assert_compile( - select([cl]).order_by(cl), + select(cl).order_by(cl), 'SELECT t1.col1 AS "ShouldQuote" FROM t1 ORDER BY "ShouldQuote"', ) @@ -645,9 +645,9 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): # Lower case names, should not quote metadata = MetaData() table = Table("t1", metadata, Column("col1", Integer)) - x = select([table.c.col1.label("label1")]).alias("alias1") + x = select(table.c.col1.label("label1")).alias("alias1") self.assert_compile( - select([x.c.label1]), + select(x.c.label1), "SELECT " "alias1.label1 " "FROM (" @@ -660,9 +660,9 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): # Not lower case names, should quote metadata = MetaData() table = Table("T1", metadata, Column("Col1", Integer)) - x = select([table.c.Col1.label("Label1")]).alias("Alias1") + x = select(table.c.Col1.label("Label1")).alias("Alias1") self.assert_compile( - select([x.c.Label1]), + select(x.c.Label1), "SELECT " '"Alias1"."Label1" ' "FROM (" @@ -715,7 +715,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): col = sql.literal_column("NEEDS QUOTES").label("NEEDS QUOTES") self.assert_compile( - select([col]).alias().select(), + select(col).alias().select(), 'SELECT anon_1."NEEDS QUOTES" FROM (SELECT NEEDS QUOTES AS ' '"NEEDS QUOTES") AS anon_1', ) @@ -724,7 +724,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): col = sql.literal_column("NEEDS QUOTES").label("NEEDS QUOTES_") self.assert_compile( - select([col]).alias().select(), + select(col).alias().select(), 'SELECT anon_1."NEEDS QUOTES_" FROM (SELECT NEEDS QUOTES AS ' '"NEEDS QUOTES_") AS anon_1', ) @@ -735,7 +735,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([col]).alias().select(), + select(col).alias().select(), 'SELECT anon_1."NEEDS QUOTES" FROM ' '(SELECT NEEDS QUOTES AS "NEEDS QUOTES") AS anon_1', ) @@ -746,7 +746,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - select([col]).alias().select(), + select(col).alias().select(), 'SELECT anon_1."NEEDS QUOTES_" FROM ' '(SELECT NEEDS QUOTES AS "NEEDS QUOTES_") AS anon_1', ) @@ -760,7 +760,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): col = sql.literal_column('"NEEDS QUOTES"') self.assert_compile( - select([col]).alias().select(), + select(col).alias().select(), 'SELECT anon_1."NEEDS QUOTES" FROM ' '(SELECT "NEEDS QUOTES") AS anon_1', ) @@ -819,14 +819,13 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL): t = Table("t", m, Column("x", Integer, quote=True)) self.assert_compile( - select([t.alias()]).apply_labels(), + select(t.alias()).apply_labels(), 'SELECT t_1."x" AS "t_1_x" FROM t AS t_1', ) t2 = Table("t2", m, Column("x", Integer), quote=True) self.assert_compile( - select([t2.c.x]).apply_labels(), - 'SELECT "t2".x AS "t2_x" FROM "t2"', + select(t2.c.x).apply_labels(), 'SELECT "t2".x AS "t2_x" FROM "t2"', ) diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 578e20e44..67f347ad3 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -134,7 +134,7 @@ class CursorResultTest(fixtures.TablesTest): ) sel = ( - select([users.c.user_id]) + select(users.c.user_id) .where(users.c.user_name == "jack") .scalar_subquery() ) @@ -209,7 +209,7 @@ class CursorResultTest(fixtures.TablesTest): not_in(bar.c.content_type, row._mapping) row = connection.execute( - select([func.now().label("content_type")]) + select(func.now().label("content_type")) ).first() not_in(content.c.type, row._mapping) @@ -260,7 +260,7 @@ class CursorResultTest(fixtures.TablesTest): ) def test_column_error_printing(self, connection): - result = connection.execute(select([1])) + result = connection.execute(select(1)) row = result.first() class unprintable(object): @@ -440,7 +440,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() @@ -552,13 +552,13 @@ class CursorResultTest(fixtures.TablesTest): # unary expressions r = connection.execute( - select([users.c.user_name.distinct()]).order_by(users.c.user_name) + select(users.c.user_name.distinct()).order_by(users.c.user_name) ).first() eq_(r._mapping[users.c.user_name], "john") eq_(r.user_name, "john") def test_column_accessor_err(self, connection): - r = connection.execute(select([1])).first() + r = connection.execute(select(1)).first() assert_raises_message( AttributeError, "Could not locate column in row for column 'foo'", @@ -681,10 +681,8 @@ class CursorResultTest(fixtures.TablesTest): def test_row_case_sensitive(self, connection): row = connection.execute( select( - [ - literal_column("1").label("case_insensitive"), - literal_column("2").label("CaseSensitive"), - ] + literal_column("1").label("case_insensitive"), + literal_column("2").label("CaseSensitive"), ) ).first() @@ -704,11 +702,9 @@ class CursorResultTest(fixtures.TablesTest): with engines.testing_engine().connect() as ins_conn: row = ins_conn.execute( select( - [ - literal_column("1").label("case_insensitive"), - literal_column("2").label("CaseSensitive"), - text("3 AS screw_up_the_cols"), - ] + literal_column("1").label("case_insensitive"), + literal_column("2").label("CaseSensitive"), + text("3 AS screw_up_the_cols"), ) ).first() @@ -820,7 +816,7 @@ class CursorResultTest(fixtures.TablesTest): ua = users.alias() u2 = users.alias() result = connection.execute( - select([users.c.user_id, ua.c.user_id]).select_from( + select(users.c.user_id, ua.c.user_id).select_from( users.join(ua, true()) ) ) @@ -850,7 +846,7 @@ class CursorResultTest(fixtures.TablesTest): # but when they're fetched you'll get the ambiguous error. connection.execute(users.insert(), user_id=1, user_name="john") result = connection.execute( - select([users.c.user_id, addresses.c.user_id]).select_from( + select(users.c.user_id, addresses.c.user_id).select_from( users.outerjoin(addresses) ) ) @@ -940,10 +936,8 @@ class CursorResultTest(fixtures.TablesTest): connection.execute(users.insert(), user_id=1, user_name="john") result = connection.execute( select( - [ - users.c.user_id, - type_coerce(users.c.user_id, Integer).label("foo"), - ] + users.c.user_id, + type_coerce(users.c.user_id, Integer).label("foo"), ) ) row = result.first() @@ -1122,11 +1116,9 @@ class CursorResultTest(fixtures.TablesTest): connection.execute(users.insert(), user_id=1, user_name="foo") result = connection.execute( select( - [ - users.c.user_id, - users.c.user_name.label(None), - func.count(literal_column("1")), - ] + users.c.user_id, + users.c.user_name.label(None), + func.count(literal_column("1")), ).group_by(users.c.user_id, users.c.user_name) ) @@ -1412,7 +1404,7 @@ class CursorResultTest(fixtures.TablesTest): "Statement is not a compiled expression construct.", ), ( - select([1]), + select(1), [ lambda r: r.last_inserted_params(), lambda r: r.inserted_primary_key, @@ -1420,12 +1412,12 @@ class CursorResultTest(fixtures.TablesTest): r"Statement is not an insert\(\) expression construct.", ), ( - select([1]), + select(1), [lambda r: r.last_updated_params()], r"Statement is not an update\(\) expression construct.", ), ( - select([1]), + select(1), [lambda r: r.prefetch_cols(), lambda r: r.postfetch_cols()], r"Statement is not an insert\(\) " r"or update\(\) expression construct.", @@ -1533,7 +1525,7 @@ class KeyTargetingTest(fixtures.TablesTest): def _test_keyed_targeting_no_label_at_all(self, expression, conn): lt = literal_column("2") - stmt = select([literal_column("1"), expression, lt]).select_from( + stmt = select(literal_column("1"), expression, lt).select_from( self.tables.keyed1 ) row = conn.execute(stmt).first() @@ -1556,7 +1548,7 @@ class KeyTargetingTest(fixtures.TablesTest): return "max(a)" # assert that there is no "AS max_" or any label of any kind. - eq_(str(select([not_named_max()])), "SELECT max(a)") + eq_(str(select(not_named_max())), "SELECT max(a)") nnm = not_named_max() self._test_keyed_targeting_no_label_at_all(nnm, connection) @@ -1571,7 +1563,7 @@ class KeyTargetingTest(fixtures.TablesTest): return "max(a)" # assert that there is no "AS max_" or any label of any kind. - eq_(str(select([not_named_max()])), "SELECT max(a)") + eq_(str(select(not_named_max())), "SELECT max(a)") nnm = not_named_max() self._test_keyed_targeting_no_label_at_all(nnm, connection) @@ -1580,7 +1572,7 @@ class KeyTargetingTest(fixtures.TablesTest): t1 = text("max(a)") t2 = text("min(a)") - stmt = select([t1, t2]).select_from(self.tables.keyed1) + stmt = select(t1, t2).select_from(self.tables.keyed1) row = connection.execute(stmt).first() eq_(row._mapping[t1], "a1") @@ -1592,7 +1584,7 @@ class KeyTargetingTest(fixtures.TablesTest): keyed2 = self.tables.keyed2 row = connection.execute( - select([keyed1, keyed2]).select_from(keyed1.join(keyed2, true())) + select(keyed1, keyed2).select_from(keyed1.join(keyed2, true())) ).first() # column access is unambiguous @@ -1617,7 +1609,7 @@ class KeyTargetingTest(fixtures.TablesTest): # illustrate why row.b above is ambiguous, and not "b2"; because # if we didn't have keyed2, now it matches row.a. a new column # shouldn't be able to grab the value from a previous column. - row = connection.execute(select([keyed1])).first() + row = connection.execute(select(keyed1)).first() eq_(row.b, "a1") def test_keyed_accessor_composite_conflict_2_fix_w_uselabels( @@ -1627,7 +1619,7 @@ class KeyTargetingTest(fixtures.TablesTest): keyed2 = self.tables.keyed2 row = connection.execute( - select([keyed1, keyed2]) + select(keyed1, keyed2) .select_from(keyed1.join(keyed2, true())) .apply_labels() ).first() @@ -1643,7 +1635,7 @@ class KeyTargetingTest(fixtures.TablesTest): keyed4 = self.tables.keyed4 row = connection.execute( - select([keyed1, keyed4]).select_from(keyed1.join(keyed4, true())) + select(keyed1, keyed4).select_from(keyed1.join(keyed4, true())) ).first() eq_(row.b, "b4") eq_(row.q, "q4") @@ -1656,7 +1648,7 @@ class KeyTargetingTest(fixtures.TablesTest): keyed3 = self.tables.keyed3 row = connection.execute( - select([keyed1, keyed3]).select_from(keyed1.join(keyed3, true())) + select(keyed1, keyed3).select_from(keyed1.join(keyed3, true())) ).first() eq_(row.q, "c1") @@ -1680,7 +1672,7 @@ class KeyTargetingTest(fixtures.TablesTest): keyed2 = self.tables.keyed2 row = connection.execute( - select([keyed1, keyed2]) + select(keyed1, keyed2) .select_from(keyed1.join(keyed2, true())) .apply_labels() ).first() @@ -1711,16 +1703,14 @@ class KeyTargetingTest(fixtures.TablesTest): stmt = ( select( - [ - keyed2.c.a, - keyed3.c.a, - keyed2.c.a, - keyed2.c.a, - keyed3.c.a, - keyed3.c.a, - keyed3.c.d, - keyed3.c.d, - ] + keyed2.c.a, + keyed3.c.a, + keyed2.c.a, + keyed2.c.a, + keyed3.c.a, + keyed3.c.a, + keyed3.c.d, + keyed3.c.d, ) .select_from(keyed2.join(keyed3, true())) .apply_labels() @@ -1766,7 +1756,7 @@ class KeyTargetingTest(fixtures.TablesTest): # originally addressed by [ticket:2932], however liberalized # Column-targeting rules are deprecated 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() in_(a, row._mapping) @@ -1775,7 +1765,7 @@ class KeyTargetingTest(fixtures.TablesTest): def test_columnclause_schema_column_two(self, connection): keyed2 = self.tables.keyed2 - stmt = select([keyed2.c.a, keyed2.c.b]) + stmt = select(keyed2.c.a, keyed2.c.b) row = connection.execute(stmt).first() in_(keyed2.c.a, row._mapping) @@ -1819,12 +1809,12 @@ class KeyTargetingTest(fixtures.TablesTest): def _adapt_result_columns_fixture_one(self): keyed1 = self.tables.keyed1 stmt = ( - select([keyed1.c.b, keyed1.c.q.label("foo")]) + select(keyed1.c.b, keyed1.c.q.label("foo")) .apply_labels() .subquery() ) - return select([stmt.c.keyed1_b, stmt.c.foo]) + return select(stmt.c.keyed1_b, stmt.c.foo) def _adapt_result_columns_fixture_two(self): return text("select a AS keyed2_a, b AS keyed2_b from keyed2").columns( @@ -1833,14 +1823,14 @@ class KeyTargetingTest(fixtures.TablesTest): def _adapt_result_columns_fixture_three(self): keyed1 = self.tables.keyed1 - stmt = select([keyed1.c.b, keyed1.c.q.label("foo")]).subquery() + stmt = select(keyed1.c.b, keyed1.c.q.label("foo")).subquery() - return select([stmt.c.b, stmt.c.foo]) + return select(stmt.c.b, stmt.c.foo) def _adapt_result_columns_fixture_four(self): keyed1 = self.tables.keyed1 - stmt1 = select([keyed1]).apply_labels() + stmt1 = select(keyed1).apply_labels() a1 = keyed1.alias() stmt2 = ClauseAdapter(a1).traverse(stmt1) @@ -2232,7 +2222,7 @@ class AlternateCursorResultTest(fixtures.TablesTest): with self._proxy_fixture(cls): rows = [] with self.engine.connect() as conn: - r = conn.execute(select([self.table])) + r = conn.execute(select(self.table)) assert isinstance(r.cursor_strategy, cls) for i in range(5): rows.append(r.fetchone()) @@ -2244,17 +2234,17 @@ class AlternateCursorResultTest(fixtures.TablesTest): rows = r.fetchall() eq_(rows, [(i, "t_%d" % i) for i in range(9, 12)]) - r = conn.execute(select([self.table])) + r = conn.execute(select(self.table)) rows = r.fetchmany(None) eq_(rows[0], (1, "t_1")) # number of rows here could be one, or the whole thing assert len(rows) == 1 or len(rows) == 11 - r = conn.execute(select([self.table]).limit(1)) + r = conn.execute(select(self.table).limit(1)) r.fetchone() eq_(r.fetchone(), None) - r = conn.execute(select([self.table]).limit(5)) + r = conn.execute(select(self.table).limit(5)) rows = r.fetchmany(6) eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) @@ -2272,11 +2262,11 @@ class AlternateCursorResultTest(fixtures.TablesTest): self._assert_result_closed(r) - r = conn.execute(select([self.table]).limit(5)) + r = conn.execute(select(self.table).limit(5)) eq_(r.first(), (1, "t_1")) self._assert_result_closed(r) - r = conn.execute(select([self.table]).limit(5)) + r = conn.execute(select(self.table).limit(5)) eq_(r.scalar(), 1) self._assert_result_closed(r) @@ -2344,7 +2334,7 @@ class AlternateCursorResultTest(fixtures.TablesTest): cache = {} conn = conn.execution_options(compiled_cache=cache) - stmt = select([literal("THERE", type_=MyType())]) + stmt = select(literal("THERE", type_=MyType())) for i in range(2): r = conn.execute(stmt) eq_(r.scalar(), "HI THERE") diff --git a/test/sql/test_returning.py b/test/sql/test_returning.py index 20aa1fb3a..2fb50f37d 100644 --- a/test/sql/test_returning.py +++ b/test/sql/test_returning.py @@ -125,7 +125,7 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): eq_(result.fetchall(), [(1,)]) result2 = connection.execute( - select([table.c.id, table.c.full]).order_by(table.c.id) + select(table.c.id, table.c.full).order_by(table.c.id) ) eq_(result2.fetchall(), [(1, True), (2, False)]) @@ -215,7 +215,7 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): eq_(result.fetchall(), [(1,)]) result2 = connection.execute( - select([table.c.id, table.c.full]).order_by(table.c.id) + select(table.c.id, table.c.full).order_by(table.c.id) ) eq_(result2.fetchall(), [(2, False)]) @@ -241,7 +241,7 @@ class CompositeStatementTest(fixtures.TestBase): stmt = ( t2.insert() - .values(x=select([t1.c.x]).scalar_subquery()) + .values(x=select(t1.c.x).scalar_subquery()) .returning(t2.c.x) ) diff --git a/test/sql/test_roles.py b/test/sql/test_roles.py index c9f179ed1..4feba97ae 100644 --- a/test/sql/test_roles.py +++ b/test/sql/test_roles.py @@ -443,7 +443,7 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): table1, table2 = update_from_fixture # test against a regular constructed subquery - s = select([table2], table2.c.otherid == table1.c.myid) + s = select(table2).where(table2.c.otherid == table1.c.myid) with testing.expect_warnings( "implicitly coercing SELECT object to scalar subquery" ): diff --git a/test/sql/test_select.py b/test/sql/test_select.py index 4c00cb53c..2a2381427 100644 --- a/test/sql/test_select.py +++ b/test/sql/test_select.py @@ -57,6 +57,7 @@ class FutureSelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_legacy_calling_style_col_seq_only(self): + # keep [] here stmt = select([table1.c.myid]).where(table1.c.myid == table2.c.otherid) self.assert_compile( diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 68d79fd51..329cc39f6 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -372,8 +372,8 @@ class SelectableTest( def test_distance_on_aliases(self): a1 = table1.alias("a1") for s in ( - select([a1, table1], use_labels=True).subquery(), - select([table1, a1], use_labels=True).subquery(), + select(a1, table1).apply_labels().subquery(), + select(table1, a1).apply_labels().subquery(), ): assert s.corresponding_column(table1.c.col1) is s.c.table1_col1 assert s.corresponding_column(a1.c.col1) is s.c.a1_col1 @@ -506,7 +506,7 @@ class SelectableTest( self.assert_compile(group, "b / (y * w)") def test_subquery_on_table(self): - sel = select([table1, table2], use_labels=True).subquery() + sel = select(table1, table2).apply_labels().subquery() assert sel.corresponding_column(table1.c.col1) is sel.c.table1_col1 assert ( @@ -523,8 +523,8 @@ class SelectableTest( def test_join_against_join(self): j = outerjoin(table1, table2, table1.c.col1 == table2.c.col2) - jj = select([table1.c.col1.label("bar_col1")], from_obj=[j]).alias( - "foo" + jj = ( + select(table1.c.col1.label("bar_col1")).select_from(j).alias("foo") ) jjj = join(table1, jj, table1.c.col1 == jj.c.bar_col1) assert jjj.corresponding_column(jjj.c.table1_col1) is jjj.c.table1_col1 @@ -1044,7 +1044,7 @@ class SelectableTest( t2 = Table("t2", m, Column("id", Integer, ForeignKey("t1.id"))) t3 = Table("t3", m2, Column("id", Integer, ForeignKey("t1.id2"))) - s = select([t2, t3], use_labels=True).subquery() + s = select(t2, t3).apply_labels().subquery() assert_raises(exc.NoReferencedTableError, s.join, t1) @@ -2363,7 +2363,7 @@ class AnnotationsTest(fixtures.TestBase): """ t = table("t", column("x")) - stmt = select([t.c.x]) + stmt = select(t.c.x) whereclause = annotation._deep_annotate(t.c.x == 5, {"foo": "bar"}) @@ -2740,7 +2740,7 @@ class AnnotationsTest(fixtures.TestBase): a1 = table1.alias() 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"}), @@ -2748,7 +2748,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): @@ -3100,7 +3100,7 @@ class ResultMapTest(fixtures.TestBase): def test_unary_boolean(self): - s1 = select([not_(True)], use_labels=True) + s1 = select(not_(True)).apply_labels() eq_( [type(entry[-1]) for entry in s1.compile()._result_columns], [Boolean], diff --git a/test/sql/test_sequences.py b/test/sql/test_sequences.py index ee7c77a93..243ccfbab 100644 --- a/test/sql/test_sequences.py +++ b/test/sql/test_sequences.py @@ -150,7 +150,7 @@ class LegacySequenceExecTest(fixtures.TestBase): """test can use next_value() in select column expr""" s = Sequence("my_sequence") - self._assert_seq_result(testing.db.scalar(select([s.next_value()]))) + self._assert_seq_result(testing.db.scalar(select(s.next_value()))) class SequenceExecTest(fixtures.TestBase): @@ -201,7 +201,7 @@ class SequenceExecTest(fixtures.TestBase): """test can use next_value() in select column expr""" s = Sequence("my_sequence") - self._assert_seq_result(connection.scalar(select([s.next_value()]))) + self._assert_seq_result(connection.scalar(select(s.next_value()))) @testing.requires.sequences_in_other_clauses @testing.provide_metadata @@ -446,7 +446,7 @@ class TableBoundSequenceTest(fixtures.TablesTest): eq_( connection.scalar( - sa.select([cartitems.c.cart_id]).where( + sa.select(cartitems.c.cart_id).where( cartitems.c.description == "lala" ), ), @@ -526,7 +526,7 @@ class SequenceAsServerDefaultTest( t_seq_test = self.tables.t_seq_test connection.execute(t_seq_test.insert().values(data="some data")) - eq_(connection.scalar(select([t_seq_test.c.id])), 1) + eq_(connection.scalar(select(t_seq_test.c.id)), 1) def test_default_textual_server_only(self, connection): connection.exec_driver_sql( @@ -542,7 +542,7 @@ class SequenceAsServerDefaultTest( t_seq_test = self.tables.t_seq_test_2 connection.execute(t_seq_test.insert().values(data="some data")) - eq_(connection.scalar(select([t_seq_test.c.id])), 1) + eq_(connection.scalar(select(t_seq_test.c.id)), 1) def test_drop_ordering(self): with self.sql_execution_asserter(testing.db) as asserter: diff --git a/test/sql/test_tablesample.py b/test/sql/test_tablesample.py index 7e0600a66..785dc5da8 100644 --- a/test/sql/test_tablesample.py +++ b/test/sql/test_tablesample.py @@ -59,7 +59,7 @@ class TableSampleTest(fixtures.TablesTest, AssertsCompiledSQL): table1 = self.tables.people self.assert_compile( - select([table1.tablesample(text("1"), name="alias").c.people_id]), + select(table1.tablesample(text("1"), name="alias").c.people_id), "SELECT alias.people_id FROM " "people AS alias TABLESAMPLE system(1)", ) diff --git a/test/sql/test_text.py b/test/sql/test_text.py index 9d5ab65ed..0cd6f8cf3 100644 --- a/test/sql/test_text.py +++ b/test/sql/test_text.py @@ -54,7 +54,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_text_adds_to_result_map(self): t1, t2 = text("t1"), text("t2") - stmt = select([t1, t2]) + stmt = select(t1, t2) compiled = stmt.compile() eq_( compiled._result_columns, @@ -75,16 +75,12 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_composition_one(self): self.assert_compile( select( - [ - literal_column("foobar(a)"), - literal_column("pk_foo_bar(syslaal)"), - ], - text("a = 12"), - from_obj=[ - text( - "foobar left outer join lala on foobar.foo = lala.foo" - ) - ], + literal_column("foobar(a)"), + literal_column("pk_foo_bar(syslaal)"), + ) + .where(text("a = 12")) + .select_from( + text("foobar left outer join lala on foobar.foo = lala.foo") ), "SELECT foobar(a), pk_foo_bar(syslaal) FROM foobar " "left outer join lala on foobar.foo = lala.foo WHERE a = 12", @@ -105,7 +101,8 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_composition_three(self): self.assert_compile( - select([column("column1"), column("column2")], from_obj=table1) + select(column("column1"), column("column2")) + .select_from(table1) .alias("somealias") .select(), "SELECT somealias.column1, somealias.column2 FROM " @@ -116,15 +113,13 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): # test that use_labels doesn't interfere with literal columns self.assert_compile( select( - [ - text("column1"), - column("column2"), - column("column3").label("bar"), - table1.c.myid, - ], - from_obj=table1, - use_labels=True, - ), + text("column1"), + column("column2"), + column("column3").label("bar"), + table1.c.myid, + ) + .select_from(table1) + .apply_labels(), "SELECT column1, column2, column3 AS bar, " "mytable.myid AS mytable_myid " "FROM mytable", @@ -135,14 +130,12 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): # with literal columns that have textual labels self.assert_compile( select( - [ - text("column1 AS foobar"), - text("column2 AS hoho"), - table1.c.myid, - ], - from_obj=table1, - use_labels=True, - ), + text("column1 AS foobar"), + text("column2 AS hoho"), + table1.c.myid, + ) + .select_from(table1) + .apply_labels(), "SELECT column1 AS foobar, column2 AS hoho, " "mytable.myid AS mytable_myid FROM mytable", ) @@ -155,13 +148,11 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): # no columns is being maintained. self.assert_compile( select( - [ - literal_column("column1 AS foobar"), - literal_column("column2 AS hoho"), - table1.c.myid, - ], - from_obj=[table1], + literal_column("column1 AS foobar"), + literal_column("column2 AS hoho"), + table1.c.myid, ) + .select_from(table1) .subquery() .select(), "SELECT anon_1.column1 AS foobar, anon_1.column2 AS hoho, " @@ -172,20 +163,17 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_composition_seven(self): self.assert_compile( - select( - [literal_column("col1"), literal_column("col2")], - from_obj=table("tablename"), - ).alias("myalias"), + select(literal_column("col1"), literal_column("col2")) + .select_from(table("tablename")) + .alias("myalias"), "SELECT col1, col2 FROM tablename", ) def test_select_composition_eight(self): self.assert_compile( - select( - [table1.alias("t"), text("foo.f")], - text("foo.f = t.id"), - from_obj=[text("(select f from bar where lala=heyhey) foo")], - ), + select(table1.alias("t"), text("foo.f")) + .where(text("foo.f = t.id")) + .select_from(text("(select f from bar where lala=heyhey) foo")), "SELECT t.myid, t.name, t.description, foo.f FROM mytable AS t, " "(select f from bar where lala=heyhey) foo WHERE foo.f = t.id", ) @@ -193,12 +181,11 @@ class SelectCompositionTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_bundle_columns(self): self.assert_compile( select( - [ - table1, - table2.c.otherid, - text("sysdate()"), - text("foo, bar, lala"), - ], + table1, + table2.c.otherid, + text("sysdate()"), + text("foo, bar, lala"), + ).where( and_( text("foo.id = foofoo(lala)"), text("datetime(foo) = Today"), @@ -302,7 +289,7 @@ class BindParamTest(fixtures.TestBase, AssertsCompiledSQL): t1 = text("select :foo").bindparams(bindparam("foo", 5, unique=True)) t2 = text("select :foo").bindparams(bindparam("foo", 10, unique=True)) - stmt = select([t1, t2]) + stmt = select(t1, t2) self.assert_compile( stmt, "SELECT select :foo_1, select :foo_2", @@ -383,7 +370,7 @@ class BindParamTest(fixtures.TestBase, AssertsCompiledSQL): ).bindparams(x=None, y=None, z=None) s = select( - [(func.current_date() + literal_column("s.a")).label("dates")] + (func.current_date() + literal_column("s.a")).label("dates") ).select_from(generate_series) self.assert_compile( @@ -411,7 +398,7 @@ class BindParamTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_percent_signs_literal_binds(self): - stmt = select([literal("percent % signs %%")]) + stmt = select(literal("percent % signs %%")) self.assert_compile( stmt, "SELECT 'percent % signs %%' AS anon_1", @@ -487,7 +474,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): .subquery() ) - stmt = select([table1.c.myid]).select_from( + stmt = select(table1.c.myid).select_from( table1.join(t, table1.c.myid == t.c.id) ) compiled = stmt.compile() @@ -592,7 +579,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): .cte("t") ) - s = select([table1]).where(table1.c.myid == t.c.id) + s = select(table1).where(table1.c.myid == t.c.id) self.assert_compile( s, "WITH t AS (select id, name from user) " @@ -608,7 +595,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): ) stmt = ( - select([table1.c.myid]) + select(table1.c.myid) .select_from(table1.join(t, table1.c.myid == t.c.id)) .order_by(t.c.name) ) @@ -627,7 +614,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): .alias("t") ) - s = select([table1]).where(table1.c.myid == t.c.id) + s = select(table1).where(table1.c.myid == t.c.id) self.assert_compile( s, "SELECT mytable.myid, mytable.name, mytable.description " @@ -641,7 +628,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): assert subq.type._type_affinity is Integer()._type_affinity - s = select([table1.c.myid, subq]).where(table1.c.myid == subq) + s = select(table1.c.myid, subq).where(table1.c.myid == subq) self.assert_compile( s, "SELECT mytable.myid, (select id from user) AS anon_1 " @@ -672,16 +659,16 @@ class TextErrorsTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_where(self): - self._test(select([table1.c.myid]).where, "myid == 5", "myid == 5") + self._test(select(table1.c.myid).where, "myid == 5", "myid == 5") def test_column(self): self._test(select, ["myid"], "myid") def test_having(self): - self._test(select([table1.c.myid]).having, "myid == 5", "myid == 5") + self._test(select(table1.c.myid).having, "myid == 5", "myid == 5") def test_from(self): - self._test(select([table1.c.myid]).select_from, "mytable", "mytable") + self._test(select(table1.c.myid).select_from, "mytable", "mytable") class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): @@ -700,20 +687,20 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_order_by_label(self): - stmt = select([table1.c.myid.label("foo")]).order_by("foo") + stmt = select(table1.c.myid.label("foo")).order_by("foo") self.assert_compile( stmt, "SELECT mytable.myid AS foo FROM mytable ORDER BY foo" ) def test_order_by_colname(self): - stmt = select([table1.c.myid]).order_by("name") + stmt = select(table1.c.myid).order_by("name") self.assert_compile( stmt, "SELECT mytable.myid FROM mytable ORDER BY mytable.name" ) def test_order_by_alias_colname(self): t1 = table1.alias() - stmt = select([t1.c.myid]).apply_labels().order_by("name") + stmt = select(t1.c.myid).apply_labels().order_by("name") self.assert_compile( stmt, "SELECT mytable_1.myid AS mytable_1_myid " @@ -732,7 +719,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): for mod in modifiers: order_by = mod(order_by) - stmt = select([case]).order_by(order_by) + stmt = select(case).order_by(order_by) col_expr = str(case) self.assert_compile( @@ -740,7 +727,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_order_by_named_label_from_anon_label(self): - s1 = select([table1.c.myid.label(None).label("foo"), table1.c.name]) + s1 = select(table1.c.myid.label(None).label("foo"), table1.c.name) stmt = s1.order_by("foo") self.assert_compile( stmt, @@ -752,8 +739,8 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): # test [ticket:3335], assure that order_by("foo") # catches the label named "foo" in the columns clause only, # and not the label named "foo" in the FROM clause - s1 = select([table1.c.myid.label("foo"), table1.c.name]).alias() - stmt = select([s1.c.name, func.bar().label("foo")]).order_by("foo") + s1 = select(table1.c.myid.label("foo"), table1.c.name).alias() + stmt = select(s1.c.name, func.bar().label("foo")).order_by("foo") self.assert_compile( stmt, @@ -763,12 +750,12 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_unresolvable_warning_order_by(self): - stmt = select([table1.c.myid]).order_by("foobar") + stmt = select(table1.c.myid).order_by("foobar") self._test_exception(stmt, "foobar") def test_distinct_label(self): - stmt = select([table1.c.myid.label("foo")]).distinct("foo") + stmt = select(table1.c.myid.label("foo")).distinct("foo") self.assert_compile( stmt, "SELECT DISTINCT ON (foo) mytable.myid AS foo FROM mytable", @@ -777,7 +764,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): def test_distinct_label_keyword(self): - stmt = select([table1.c.myid.label("foo")], distinct="foo") + stmt = select(table1.c.myid.label("foo")).distinct("foo") self.assert_compile( stmt, "SELECT DISTINCT ON (foo) mytable.myid AS foo FROM mytable", @@ -787,27 +774,27 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): def test_unresolvable_distinct_label(self): from sqlalchemy.dialects import postgresql - stmt = select([table1.c.myid.label("foo")]).distinct("not a label") + stmt = select(table1.c.myid.label("foo")).distinct("not a label") self._test_exception(stmt, "not a label", dialect=postgresql.dialect()) def test_group_by_label(self): - stmt = select([table1.c.myid.label("foo")]).group_by("foo") + stmt = select(table1.c.myid.label("foo")).group_by("foo") self.assert_compile( stmt, "SELECT mytable.myid AS foo FROM mytable GROUP BY foo" ) def test_group_by_colname(self): - stmt = select([table1.c.myid]).group_by("name") + stmt = select(table1.c.myid).group_by("name") self.assert_compile( stmt, "SELECT mytable.myid FROM mytable GROUP BY mytable.name" ) def test_unresolvable_warning_group_by(self): - stmt = select([table1.c.myid]).group_by("foobar") + stmt = select(table1.c.myid).group_by("foobar") self._test_exception(stmt, "foobar") def test_asc(self): - stmt = select([table1.c.myid]).order_by(asc("name"), "description") + stmt = select(table1.c.myid).order_by(asc("name"), "description") self.assert_compile( stmt, "SELECT mytable.myid FROM mytable " @@ -815,8 +802,8 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_group_by_subquery(self): - stmt = select([table1]).alias() - stmt = select([stmt]).apply_labels().group_by("myid") + stmt = select(table1).alias() + stmt = select(stmt).apply_labels().group_by("myid") self.assert_compile( stmt, "SELECT anon_1.myid AS anon_1_myid, anon_1.name AS anon_1_name, " @@ -829,7 +816,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): def test_order_by_literal_col_quoting_one(self): col = literal_column("SUM(ABC)").label("SUM(ABC)") tbl = table("my_table") - query = select([col]).select_from(tbl).order_by(col) + query = select(col).select_from(tbl).order_by(col) self.assert_compile( query, 'SELECT SUM(ABC) AS "SUM(ABC)" FROM my_table ORDER BY "SUM(ABC)"', @@ -838,7 +825,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): def test_order_by_literal_col_quoting_two(self): col = literal_column("SUM(ABC)").label("SUM(ABC)_") tbl = table("my_table") - query = select([col]).select_from(tbl).order_by(col) + query = select(col).select_from(tbl).order_by(col) self.assert_compile( query, 'SELECT SUM(ABC) AS "SUM(ABC)_" FROM my_table ORDER BY ' @@ -848,7 +835,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): def test_order_by_literal_col_quoting_one_explict_quote(self): col = literal_column("SUM(ABC)").label(quoted_name("SUM(ABC)", True)) tbl = table("my_table") - query = select([col]).select_from(tbl).order_by(col) + query = select(col).select_from(tbl).order_by(col) self.assert_compile( query, 'SELECT SUM(ABC) AS "SUM(ABC)" FROM my_table ORDER BY "SUM(ABC)"', @@ -857,7 +844,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): def test_order_by_literal_col_quoting_two_explicit_quote(self): col = literal_column("SUM(ABC)").label(quoted_name("SUM(ABC)_", True)) tbl = table("my_table") - query = select([col]).select_from(tbl).order_by(col) + query = select(col).select_from(tbl).order_by(col) self.assert_compile( query, 'SELECT SUM(ABC) AS "SUM(ABC)_" FROM my_table ORDER BY ' @@ -865,9 +852,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_order_by_func_label_desc(self): - stmt = select([func.foo("bar").label("fb"), table1]).order_by( - desc("fb") - ) + stmt = select(func.foo("bar").label("fb"), table1).order_by(desc("fb")) self.assert_compile( stmt, @@ -876,7 +861,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_pg_distinct(self): - stmt = select([table1]).distinct("name") + stmt = select(table1).distinct("name") self.assert_compile( stmt, "SELECT DISTINCT ON (mytable.name) mytable.myid, " @@ -885,9 +870,9 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_over(self): - stmt = select([column("foo"), column("bar")]).subquery() + stmt = select(column("foo"), column("bar")).subquery() stmt = select( - [func.row_number().over(order_by="foo", partition_by="bar")] + func.row_number().over(order_by="foo", partition_by="bar") ).select_from(stmt) self.assert_compile( @@ -898,8 +883,8 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_union_column(self): - s1 = select([table1]) - s2 = select([table1]) + s1 = select(table1) + s2 = select(table1) stmt = union(s1, s2).order_by("name") self.assert_compile( stmt, @@ -909,8 +894,8 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_union_label(self): - s1 = select([func.foo("hoho").label("x")]) - s2 = select([func.foo("Bar").label("y")]) + s1 = select(func.foo("hoho").label("x")) + s2 = select(func.foo("Bar").label("y")) stmt = union(s1, s2).order_by("x") self.assert_compile( stmt, @@ -937,7 +922,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): adapter = sql_util.ColumnAdapter(ta, anonymize_labels=True) s1 = ( - select([adapter.columns[expr] for expr in exprs]) + select(*[adapter.columns[expr] for expr in exprs]) .apply_labels() .order_by("myid", "t1name", "x") ) @@ -969,7 +954,7 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL): adapter = sql_util.ColumnAdapter(ta) s1 = ( - select([adapter.columns[expr] for expr in exprs]) + select(*[adapter.columns[expr] for expr in exprs]) .apply_labels() .order_by("myid", "t1name", "x") ) diff --git a/test/sql/test_type_expressions.py b/test/sql/test_type_expressions.py index 412623c01..09ade319e 100644 --- a/test/sql/test_type_expressions.py +++ b/test/sql/test_type_expressions.py @@ -113,14 +113,14 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): table = self._fixture() self.assert_compile( - select([table]), + select(table), "SELECT test_table.x, lower(test_table.y) AS y FROM test_table", ) def test_anonymous_expr(self): table = self._fixture() self.assert_compile( - select([cast(table.c.y, String)]), + select(cast(table.c.y, String)), "SELECT CAST(test_table.y AS VARCHAR) AS y FROM test_table", ) @@ -128,7 +128,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): table = self._fixture() self.assert_compile( - select([table]).apply_labels(), + select(table).apply_labels(), "SELECT test_table.x AS test_table_x, " "lower(test_table.y) AS test_table_y FROM test_table", ) @@ -136,7 +136,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): def test_select_cols_use_labels_result_map_targeting(self): table = self._fixture() - compiled = select([table]).apply_labels().compile() + compiled = select(table).apply_labels().compile() assert table.c.y in compiled._create_result_map()["test_table_y"][1] assert table.c.x in compiled._create_result_map()["test_table_x"][1] @@ -169,7 +169,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): def test_select_binds(self): table = self._fixture() self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT test_table.x, lower(test_table.y) AS y FROM " "test_table WHERE test_table.y = lower(:y_1)", ) @@ -180,7 +180,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): # 'x' is straight String self.assert_compile( - select([table.c.x]).where(table.c.x == "hi"), + select(table.c.x).where(table.c.x == "hi"), "SELECT dialect_colexpr(test_table.x) AS x " "FROM test_table WHERE test_table.x = dialect_bind(:x_1)", dialect=dialect, @@ -190,7 +190,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): table = self._type_decorator_inside_fixture() self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT test_table.x, inside_colexpr(test_table.y) AS y " "FROM test_table WHERE test_table.y = inside_bind(:y_1)", ) @@ -204,7 +204,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): # implementation supersedes that, which is the same as with other # processor functions self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT dialect_colexpr(test_table.x) AS x, " "dialect_colexpr(test_table.y) AS y FROM test_table " "WHERE test_table.y = dialect_bind(:y_1)", @@ -215,7 +215,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): table = self._type_decorator_outside_fixture() self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT test_table.x, outside_colexpr(test_table.y) AS y " "FROM test_table WHERE test_table.y = outside_bind(:y_1)", ) @@ -227,7 +227,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): # for "outer", the MyString isn't calling the "impl" functions, # so we don't get the "impl" self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT dialect_colexpr(test_table.x) AS x, " "outside_colexpr(test_table.y) AS y " "FROM test_table WHERE test_table.y = outside_bind(:y_1)", @@ -238,7 +238,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): table = self._type_decorator_both_fixture() self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT test_table.x, " "outside_colexpr(inside_colexpr(test_table.y)) AS y " "FROM test_table WHERE " @@ -254,7 +254,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): # implementation supersedes that, which is the same as with other # processor functions self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT dialect_colexpr(test_table.x) AS x, " "outside_colexpr(dialect_colexpr(test_table.y)) AS y " "FROM test_table WHERE " @@ -266,7 +266,7 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): table = self._variant_fixture(self._type_decorator_both_fixture()) self.assert_compile( - select([table]).where(table.c.y == "hi"), + select(table).where(table.c.y == "hi"), "SELECT test_table.x, " "outside_colexpr(inside_colexpr(test_table.y)) AS y " "FROM test_table WHERE " @@ -276,8 +276,8 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): def test_compound_select(self): table = self._fixture() - s1 = select([table]).where(table.c.y == "hi") - s2 = select([table]).where(table.c.y == "there") + s1 = select(table).where(table.c.y == "hi") + s2 = select(table).where(table.c.y == "there") self.assert_compile( union(s1, s2), @@ -290,8 +290,8 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): def test_select_of_compound_select(self): table = self._fixture() - s1 = select([table]).where(table.c.y == "hi") - s2 = select([table]).where(table.c.y == "there") + s1 = select(table).where(table.c.y == "hi") + s2 = select(table).where(table.c.y == "there") self.assert_compile( union(s1, s2).alias().select(), @@ -352,7 +352,7 @@ class RoundTripTestBase(object): # conversion back to upper eq_( connection.execute( - select([self.tables.test_table]).order_by( + select(self.tables.test_table).order_by( self.tables.test_table.c.y ) ).fetchall(), @@ -363,14 +363,14 @@ class RoundTripTestBase(object): testing.db.execute( self.tables.test_table.insert(), {"x": "X1", "y": "Y1"} ) - row = testing.db.execute(select([self.tables.test_table])).first() + row = testing.db.execute(select(self.tables.test_table)).first() eq_(row._mapping[self.tables.test_table.c.y], "Y1") def test_targeting_by_string(self): testing.db.execute( self.tables.test_table.insert(), {"x": "X1", "y": "Y1"} ) - row = testing.db.execute(select([self.tables.test_table])).first() + row = testing.db.execute(select(self.tables.test_table)).first() eq_(row._mapping["y"], "Y1") def test_targeting_apply_labels(self): @@ -378,7 +378,7 @@ class RoundTripTestBase(object): self.tables.test_table.insert(), {"x": "X1", "y": "Y1"} ) row = testing.db.execute( - select([self.tables.test_table]).apply_labels() + select(self.tables.test_table).apply_labels() ).first() eq_(row._mapping[self.tables.test_table.c.y], "Y1") @@ -388,10 +388,8 @@ class RoundTripTestBase(object): ) row = testing.db.execute( select( - [ - self.tables.test_table.c.x.label("xbar"), - self.tables.test_table.c.y.label("ybar"), - ] + self.tables.test_table.c.x.label("xbar"), + self.tables.test_table.c.y.label("ybar"), ) ).first() eq_(row._mapping[self.tables.test_table.c.y], "Y1") diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 2ede1e686..5464750db 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -604,7 +604,7 @@ class UserDefinedRoundTripTest(_UserDefinedTypeFixture, fixtures.TablesTest): self._data_fixture() stmt = ( - select([users.c.user_id, users.c.goofy8]) + select(users.c.user_id, users.c.goofy8) .where(users.c.goofy8.in_([15, 9])) .order_by(users.c.user_id) ) @@ -616,7 +616,7 @@ class UserDefinedRoundTripTest(_UserDefinedTypeFixture, fixtures.TablesTest): self._data_fixture() stmt = ( - select([users.c.user_id, users.c.goofy8]) + select(users.c.user_id, users.c.goofy8) .where(users.c.goofy8.in_(bindparam("goofy", expanding=True))) .order_by(users.c.user_id) ) @@ -642,7 +642,7 @@ class UserDefinedTest( return "HI->%s<-THERE" % value self.assert_compile( - select([literal("test", MyType)]), + select(literal("test", MyType)), "SELECT 'HI->test<-THERE' AS anon_1", dialect="default", literal_binds=True, @@ -674,7 +674,7 @@ class UserDefinedTest( return "HI->%s<-THERE" % value self.assert_compile( - select([literal("test", MyType)]), + select(literal("test", MyType)), "SELECT 'HI->test<-THERE' AS anon_1", dialect="default", literal_binds=True, @@ -866,7 +866,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): conn.execute(t.insert().values(data=coerce_fn("d1", MyType))) eq_( - conn.execute(select([coerce_fn(t.c.data, MyType)])).fetchall(), + conn.execute(select(coerce_fn(t.c.data, MyType))).fetchall(), [("BIND_INd1BIND_OUT",)], ) @@ -890,7 +890,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): conn.execute(t.insert().values(data=coerce_fn(MyObj(), MyType))) eq_( - conn.execute(select([coerce_fn(t.c.data, MyType)])).fetchall(), + conn.execute(select(coerce_fn(t.c.data, MyType))).fetchall(), [("BIND_INTHISISMYOBJBIND_OUT",)], ) @@ -908,7 +908,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): eq_( conn.execute( - select([t.c.data, coerce_fn(t.c.data, MyType)]) + select(t.c.data, coerce_fn(t.c.data, MyType)) ).fetchall(), [("BIND_INd1", "BIND_INd1BIND_OUT")], ) @@ -927,7 +927,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): eq_( conn.execute( - select([t.c.data.label("x"), coerce_fn(t.c.data, MyType)]) + select(t.c.data.label("x"), coerce_fn(t.c.data, MyType)) .alias() .select() ).fetchall(), @@ -949,7 +949,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): # coerce on left side eq_( conn.execute( - select([t.c.data, coerce_fn(t.c.data, MyType)]).where( + select(t.c.data, coerce_fn(t.c.data, MyType)).where( coerce_fn(t.c.data, MyType) == "d1" ) ).fetchall(), @@ -959,7 +959,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): # coerce on right side eq_( conn.execute( - select([t.c.data, coerce_fn(t.c.data, MyType)]).where( + select(t.c.data, coerce_fn(t.c.data, MyType)).where( t.c.data == coerce_fn("d1", MyType) ) ).fetchall(), @@ -979,7 +979,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): conn.execute(t.insert().values(data=coerce_fn("d1", MyType))) eq_( conn.execute( - select([t.c.data, coerce_fn(t.c.data, MyType)]).where( + select(t.c.data, coerce_fn(t.c.data, MyType)).where( t.c.data == coerce_fn(None, MyType) ) ).fetchall(), @@ -988,7 +988,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): eq_( conn.execute( - select([t.c.data, coerce_fn(t.c.data, MyType)]).where( + select(t.c.data, coerce_fn(t.c.data, MyType)).where( coerce_fn(t.c.data, MyType) == None ) ).fetchall(), # noqa @@ -1013,7 +1013,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): eq_( conn.execute( - select([t.c.data, coerce_fn(MyFoob(), MyType)]) + select(t.c.data, coerce_fn(MyFoob(), MyType)) ).fetchall(), [("BIND_INd1", "BIND_INd1BIND_OUT")], ) @@ -1030,7 +1030,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): t = self.tables.t conn.execute(t.insert().values(data=coerce_fn("d1", MyType))) - stmt = select([t.c.data, coerce_fn(t.c.data, MyType)]) + stmt = select(t.c.data, coerce_fn(t.c.data, MyType)) def col_to_bind(col): if col is t.c.data: @@ -1071,12 +1071,8 @@ class TypeCoerceCastTest(fixtures.TablesTest): conn.execute(t.insert().values(data=coerce_fn("d1", MyType))) stmt = select( - [ - bindparam(None, "x", String(50), unique=True), - coerce_fn( - bindparam(None, "x", String(50), unique=True), MyType - ), - ] + bindparam(None, "x", String(50), unique=True), + coerce_fn(bindparam(None, "x", String(50), unique=True), MyType), ) eq_( @@ -1093,7 +1089,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): # when cast() is given an already typed value, # the type does not take effect on the value itself. eq_( - connection.scalar(select([coerce_fn(literal("d1"), MyType)])), + connection.scalar(select(coerce_fn(literal("d1"), MyType))), "d1BIND_OUT", ) @@ -1110,9 +1106,7 @@ class TypeCoerceCastTest(fixtures.TablesTest): ) eq_( - connection.execute( - select([coerce_fn(t.c.data, MyType)]) - ).fetchall(), + connection.execute(select(coerce_fn(t.c.data, MyType))).fetchall(), [("BIND_INd1BIND_OUT",)], ) @@ -1240,7 +1234,7 @@ class VariantTest(fixtures.TestBase, AssertsCompiledSQL): conn.execute(t.insert(), x="foo") - eq_(conn.scalar(select([t.c.x]).where(t.c.x == "foo")), "fooUTWO") + eq_(conn.scalar(select(t.c.x).where(t.c.x == "foo")), "fooUTWO") @testing.only_on("sqlite") @testing.provide_metadata @@ -1259,7 +1253,7 @@ class VariantTest(fixtures.TestBase, AssertsCompiledSQL): eq_( conn.scalar( - select([t.c.x]).where( + select(t.c.x).where( t.c.x == datetime.datetime(2015, 4, 18, 10, 15, 17, 1059) ) @@ -1620,9 +1614,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest): eq_( connection.execute( - select(["foo" + enum_table.c.someenum]).order_by( - enum_table.c.id - ) + select("foo" + enum_table.c.someenum).order_by(enum_table.c.id) ).fetchall(), [("footwo",), ("footwo",), ("fooone",)], ) @@ -1651,14 +1643,12 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest): non_native_enum_table = self.tables.non_native_enum_table connection.execute(enum_table.insert(), {"id": 1, "someenum": None}) - eq_(connection.scalar(select([enum_table.c.someenum])), None) + eq_(connection.scalar(select(enum_table.c.someenum)), None) connection.execute( non_native_enum_table.insert(), {"id": 1, "someenum": None} ) - eq_( - connection.scalar(select([non_native_enum_table.c.someenum])), None - ) + eq_(connection.scalar(select(non_native_enum_table.c.someenum)), None) @testing.requires.enforces_check_constraints def test_check_constraint(self, connection): @@ -1783,7 +1773,7 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest): "'four' is not among the defined enum values. " "Enum name: None. Possible values: one, two, three", conn.scalar, - select([self.tables.non_native_enum_table.c.someotherenum]), + select(self.tables.non_native_enum_table.c.someotherenum), ) def test_non_native_round_trip(self, connection): @@ -1801,10 +1791,8 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest): eq_( connection.execute( select( - [ - non_native_enum_table.c.id, - non_native_enum_table.c.someenum, - ] + non_native_enum_table.c.id, + non_native_enum_table.c.someenum, ).order_by(non_native_enum_table.c.id) ).fetchall(), [(1, "two"), (2, "two"), (3, "one")], @@ -2218,7 +2206,7 @@ class BinaryTest(fixtures.TestBase, AssertsExecutionResults): connection.execute(binary_table.insert(), data=data) eq_( connection.scalar( - select([func.count("*")]) + select(func.count("*")) .select_from(binary_table) .where(binary_table.c.data == data) ), @@ -2227,7 +2215,7 @@ class BinaryTest(fixtures.TestBase, AssertsExecutionResults): @testing.requires.binary_literals def test_literal_roundtrip(self, connection): - compiled = select([cast(literal(util.b("foo")), LargeBinary)]).compile( + compiled = select(cast(literal(util.b("foo")), LargeBinary)).compile( dialect=testing.db.dialect, compile_kwargs={"literal_binds": True} ) result = connection.execute(compiled) @@ -2532,11 +2520,9 @@ class ExpressionTest( eq_( connection.execute( select( - [ - test_table.c.id, - test_table.c.data, - test_table.c.atimestamp, - ] + test_table.c.id, + test_table.c.data, + test_table.c.atimestamp, ).where(expr), {"thedate": datetime.date(2007, 10, 15)}, ).fetchall(), @@ -2650,7 +2636,7 @@ class ExpressionTest( assert expr.right.type.__class__ is MyTypeDec eq_( - connection.execute(select([expr.label("foo")])).scalar(), + connection.execute(select(expr.label("foo"))).scalar(), "BIND_INfooBIND_INhiBIND_OUT", ) @@ -2712,7 +2698,7 @@ class ExpressionTest( is_(expr.type.__class__, MyTypeDec) eq_( - connection.execute(select([expr.label("foo")])).scalar(), + connection.execute(select(expr.label("foo"))).scalar(), "BIND_INfooBIND_IN6BIND_OUT", ) @@ -2861,10 +2847,10 @@ class ExpressionTest( eq_(expr.type, types.NULLTYPE) def test_distinct(self, connection): - s = select([distinct(test_table.c.avalue)]) + s = select(distinct(test_table.c.avalue)) eq_(connection.execute(s).scalar(), 25) - s = select([test_table.c.avalue.distinct()]) + s = select(test_table.c.avalue.distinct()) eq_(connection.execute(s).scalar(), 25) assert distinct(test_table.c.data).type == test_table.c.data.type @@ -3250,8 +3236,7 @@ class BooleanTest( ) eq_( - conn.scalar(select([boolean_table.c.unconstrained_value])), - True, + conn.scalar(select(boolean_table.c.unconstrained_value)), True, ) def test_bind_processor_coercion_native_true(self): diff --git a/test/sql/test_update.py b/test/sql/test_update.py index 964e3ee6b..a5e57a78a 100644 --- a/test/sql/test_update.py +++ b/test/sql/test_update.py @@ -216,9 +216,9 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): u = update( table1, values={ - table1.c.name: select( - [mt.c.name], mt.c.myid == table1.c.myid - ).scalar_subquery() + table1.c.name: select(mt.c.name) + .where(mt.c.myid == table1.c.myid) + .scalar_subquery() }, ) self.assert_compile( @@ -233,9 +233,11 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): table2 = self.tables.myothertable # test against a regular constructed subquery - s = select( - [table2], table2.c.otherid == table1.c.myid - ).scalar_subquery() + s = ( + select(table2) + .where(table2.c.otherid == table1.c.myid) + .scalar_subquery() + ) u = update(table1, table1.c.name == "jack", values={table1.c.name: s}) self.assert_compile( u, @@ -250,7 +252,7 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): table2 = self.tables.myothertable # test a non-correlated WHERE clause - s = select([table2.c.othername], table2.c.otherid == 7) + s = select(table2.c.othername).where(table2.c.otherid == 7) u = update(table1, table1.c.name == s.scalar_subquery()) self.assert_compile( u, @@ -265,7 +267,7 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): table2 = self.tables.myothertable # test one that is actually correlated... - s = select([table2.c.othername], table2.c.otherid == table1.c.myid) + s = select(table2.c.othername).where(table2.c.otherid == table1.c.myid) u = table1.update(table1.c.name == s.scalar_subquery()) self.assert_compile( u, @@ -395,7 +397,7 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, 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)), ) @@ -1005,7 +1007,7 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): cte = ( q.update().where(q.c.z == 1).values(x=7).returning(q.c.z).cte("c") ) - stmt = select([p.c.s, cte.c.z]).where(p.c.s == cte.c.z) + stmt = select(p.c.s, cte.c.z).where(p.c.s == cte.c.z) dialect = default.StrCompileDialect() dialect.paramstyle = "qmark" @@ -1026,7 +1028,7 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): """ table1 = self.tables.mytable table2 = self.tables.myothertable - sel = select([table2]).where(table2.c.otherid == 5).alias() + sel = select(table2).where(table2.c.otherid == 5).alias() upd = ( table1.update() .where(table1.c.name == sel.c.othername) diff --git a/test/sql/test_utils.py b/test/sql/test_utils.py index 676ad4298..a4b76f35d 100644 --- a/test/sql/test_utils.py +++ b/test/sql/test_utils.py @@ -35,7 +35,7 @@ class MiscTest(fixtures.TestBase): Column("extra", String(45)), ) - subset_select = select([common.c.id, common.c.data]).alias() + subset_select = select(common.c.id, common.c.data).alias() eq_(set(sql_util.find_tables(subset_select)), {common}) @@ -50,7 +50,7 @@ class MiscTest(fixtures.TestBase): ) calias = common.alias() - subset_select = select([common.c.id, calias.c.data]).subquery() + subset_select = select(common.c.id, calias.c.data).subquery() eq_( set(sql_util.find_tables(subset_select, include_aliases=True)), @@ -103,12 +103,12 @@ class MiscTest(fixtures.TestBase): (column("q").label(None).desc().label(None), [column("q")]), ("foo", []), # textual label reference ( - select([column("q")]).scalar_subquery().label(None), - [select([column("q")]).scalar_subquery().label(None)], + select(column("q")).scalar_subquery().label(None), + [select(column("q")).scalar_subquery().label(None)], ), ( - select([column("q")]).scalar_subquery().label(None).desc(), - [select([column("q")]).scalar_subquery().label(None)], + select(column("q")).scalar_subquery().label(None).desc(), + [select(column("q")).scalar_subquery().label(None)], ), ) def test_unwrap_order_by(self, expr, expected): diff --git a/test/sql/test_values.py b/test/sql/test_values.py index 154701ea0..3b0544278 100644 --- a/test/sql/test_values.py +++ b/test/sql/test_values.py @@ -59,7 +59,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): name="Spaces and Cases", ).data([(1, "textA", 99), (2, "textB", 88)]) self.assert_compile( - select([v1]), + select(v1), 'SELECT "Spaces and Cases"."CaseSensitive", ' '"Spaces and Cases"."has spaces" FROM ' "(VALUES (:param_1, :param_2, :param_3), " @@ -83,7 +83,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): def test_bound_parameters(self, literal_parameter_fixture): literal_parameter_fixture = literal_parameter_fixture(False) - stmt = select([literal_parameter_fixture]) + stmt = select(literal_parameter_fixture) self.assert_compile( stmt, @@ -104,7 +104,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): def test_literal_parameters(self, literal_parameter_fixture): literal_parameter_fixture = literal_parameter_fixture(True) - stmt = select([literal_parameter_fixture]) + stmt = select(literal_parameter_fixture) self.assert_compile( stmt, @@ -119,7 +119,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): values = Values( column("column1", Integer), column("column2", Integer), ).data([(1, 1), (2, 1), (3, 2), (3, 3)]) - stmt = select([people, values]).select_from( + stmt = select(people, values).select_from( people.join(values, values.c.column2 == people.c.people_id) ) self.assert_compile( @@ -148,7 +148,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): column("bookcase_owner_id", Integer), name="bookcases", ).data([(1, 1), (2, 1), (3, 2), (3, 3)]) - stmt = select([people, values]).select_from( + stmt = select(people, values).select_from( people.join( values, values.c.bookcase_owner_id == people.c.people_id ) @@ -183,7 +183,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): .data([(1, 1), (2, 1), (3, 2), (3, 3)]) .alias("bookcases") ) - stmt = select([people, values]).select_from( + stmt = select(people, values).select_from( people.join( values, values.c.bookcase_owner_id == people.c.people_id ) @@ -216,7 +216,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): ).data([(1, 1), (2, 1), (3, 2), (3, 3)]) values = alias(values, "bookcases") - stmt = select([people, values]).select_from( + stmt = select(people, values).select_from( people.join( values, values.c.bookcase_owner_id == people.c.people_id ) @@ -252,9 +252,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): .data([(1, 1), (2, 1), (3, 2), (3, 3)]) .lateral() ) - stmt = select([people, values]).select_from( - people.join(values, true()) - ) + stmt = select(people, values).select_from(people.join(values, true())) self.assert_compile( stmt, "SELECT people.people_id, people.age, people.name, " @@ -282,7 +280,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): column("bookcase_owner_id", Integer), name="bookcases", ).data([(1, 1), (2, 1), (3, 2), (3, 3)]) - stmt = select([people, values]) + stmt = select(people, values) with testing.expect_warnings( r"SELECT statement has a cartesian product between FROM " @@ -297,7 +295,7 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): column("bookcase_id", Integer), column("bookcase_owner_id", Integer), ).data([(1, 1), (2, 1), (3, 2), (3, 3)]) - stmt = select([people, values]) + stmt = select(people, values) with testing.expect_warnings( r"SELECT statement has a cartesian product between FROM " |
