From: Federico Caselli Date: Wed, 2 Sep 2020 21:46:06 +0000 (+0200) Subject: Update select usage to use the new 1.4 format X-Git-Tag: rel_1_4_0b1~119^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8600608669d90c4a6385b312d271aed63eb5854;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 --- diff --git a/.github/workflows/scripts/can_install.py b/.github/workflows/scripts/can_install.py index 61685d9789..ecb24b5623 100644 --- a/.github/workflows/scripts/can_install.py +++ b/.github/workflows/scripts/can_install.py @@ -1,4 +1,5 @@ import sys + from packaging import tags to_check = "--" diff --git a/doc/build/changelog/migration_14.rst b/doc/build/changelog/migration_14.rst index feb6617a8f..91b8566059 100644 --- a/doc/build/changelog/migration_14.rst +++ b/doc/build/changelog/migration_14.rst @@ -550,8 +550,8 @@ base :class:`.AliasedReturnsRows`. That is, this will now raise:: - stmt1 = select([user.c.id, user.c.name]) - stmt2 = select([addresses, stmt1]).select_from(addresses.join(stmt1)) + stmt1 = select(user.c.id, user.c.name) + stmt2 = select(addresses, stmt1).select_from(addresses.join(stmt1)) Raising:: @@ -630,7 +630,7 @@ people hope that ``.c`` does (but does not), which is to reference the columns that are in the columns clause of the SELECT statement. A common beginner mistake is code such as the following:: - stmt = select([users]) + stmt = select(users) stmt = stmt.where(stmt.c.name == 'foo') The above code appears intuitive and that it would generate @@ -642,7 +642,7 @@ The new :attr:`_expression.SelectBase.selected_columns` attribute however **does the use case above, as in a case like the above it links directly to the columns present in the ``users.c`` collection:: - stmt = select([users]) + stmt = select(users) stmt = stmt.where(stmt.selected_columns.name == 'foo') @@ -993,7 +993,7 @@ feature represents a simpler approach to building expressions in any case, it's now invoked automatically whenever a list of values is passed to an IN expression:: - stmt = select([A.id, A.data]).where(A.id.in_([1, 2, 3])) + stmt = select(A.id, A.data).where(A.id.in_([1, 2, 3])) The pre-execution string representation is:: @@ -1374,7 +1374,7 @@ the 2.0 transition:: >>> from sqlalchemy import column, select >>> c1, c2, c3, c4 = column('c1'), column('c2'), column('c3'), column('c4') - >>> stmt = select([c1, c2, c3.label('c2'), c2, c4]) + >>> stmt = select(c1, c2, c3.label('c2'), c2, c4) >>> print(stmt) SELECT c1, c2, c3 AS c2, c2, c4 @@ -1418,7 +1418,7 @@ deduplication of implicitly generated labels:: >>> from sqlalchemy import table >>> user = table('user', column('id'), column('name')) - >>> stmt = select([user.c.id, user.c.name, user.c.id]).apply_labels() + >>> stmt = select(user.c.id, user.c.name, user.c.id).apply_labels() >>> print(stmt) SELECT "user".id AS user_id, "user".name AS user_name, "user".id AS id_1 FROM "user" @@ -1428,8 +1428,8 @@ Finally, the change makes it easier to create UNION and other of columns in a SELECT statement mirrors what was given, in a use case such as:: - >>> s1 = select([user, user.c.id]) - >>> s2 = select([c1, c2, c3]) + >>> s1 = select(user, user.c.id) + >>> s2 = select(c1, c2, c3) >>> from sqlalchemy import union >>> u = union(s1, s2) >>> print(u) @@ -1476,7 +1476,7 @@ In SQLAlchemy Core expressions, we never deal with a raw generated name like the above, as SQLAlchemy applies auto-labeling to expressions like these, which are up until now always a so-called "anonymous" expression:: - >>> print(select([cast(foo.c.data, String)])) + >>> print(select(cast(foo.c.data, String))) SELECT CAST(foo.data AS VARCHAR) AS anon_1 # old behavior FROM foo @@ -1494,14 +1494,14 @@ or label names such as in :ref:`change_4753`. So we now emulate PostgreSQL's reasonable behavior for simple modifications to a single column, most prominently with CAST:: - >>> print(select([cast(foo.c.data, String)])) + >>> print(select(cast(foo.c.data, String))) SELECT CAST(foo.data AS VARCHAR) AS data FROM foo For CAST against expressions that don't have a name, the previous logic is used to generate the usual "anonymous" labels:: - >>> print(select([cast('hi there,' + foo.c.data, String)])) + >>> print(select(cast('hi there,' + foo.c.data, String))) SELECT CAST(:data_1 + foo.data AS VARCHAR) AS anon_1 FROM foo @@ -1509,14 +1509,14 @@ A :func:`.cast` against a :class:`.Label`, despite having to omit the label expression as these don't render inside of a CAST, will nonetheless make use of the given name:: - >>> print(select([cast(('hi there,' + foo.c.data).label('hello_data'), String)])) + >>> print(select(cast(('hi there,' + foo.c.data).label('hello_data'), String))) SELECT CAST(:data_1 + foo.data AS VARCHAR) AS hello_data FROM foo And of course as was always the case, :class:`.Label` can be applied to the expression on the outside to apply an "AS " label directly:: - >>> print(select([cast(('hi there,' + foo.c.data), String).label('hello_data')])) + >>> print(select(cast(('hi there,' + foo.c.data), String).label('hello_data'))) SELECT CAST(:data_1 + foo.data AS VARCHAR) AS hello_data FROM foo diff --git a/doc/build/core/custom_types.rst b/doc/build/core/custom_types.rst index c9970872da..3d65ceeb65 100644 --- a/doc/build/core/custom_types.rst +++ b/doc/build/core/custom_types.rst @@ -290,7 +290,7 @@ get at this with a type like ``JSONEncodedDict``, we need to from sqlalchemy import type_coerce, String - stmt = select([my_table]).where( + stmt = select(my_table).where( type_coerce(my_table.c.json_data, String).like('%foo%')) :class:`.TypeDecorator` provides a built-in system for working up type @@ -378,7 +378,7 @@ and use it in a :func:`_expression.select` construct:: Column('geom_data', Geometry) ) - print(select([geometry]).where( + print(select(geometry).where( geometry.c.geom_data == 'LINESTRING(189412 252431,189631 259122)')) The resulting SQL embeds both functions as appropriate. ``ST_AsText`` @@ -396,7 +396,7 @@ with the labeling of the wrapped expression. Such as, if we rendered a :func:`_expression.select` against a :func:`.label` of our expression, the string label is moved to the outside of the wrapped expression:: - print(select([geometry.c.geom_data.label('my_data')])) + print(select(geometry.c.geom_data.label('my_data'))) Output:: @@ -445,7 +445,7 @@ transparently:: message="this is my message") print(conn.scalar( - select([message.c.message]).\ + select(message.c.message).\ where(message.c.username == "some user") )) diff --git a/doc/build/core/defaults.rst b/doc/build/core/defaults.rst index b0bf3d0b99..15b002016f 100644 --- a/doc/build/core/defaults.rst +++ b/doc/build/core/defaults.rst @@ -189,7 +189,7 @@ INSERT or UPDATE statement:: Column('create_date', DateTime, default=func.now()), # define 'key' to pull its default from the 'keyvalues' table - Column('key', String(20), default=select([keyvalues.c.key]).where(keyvalues.c.type='type1')), + Column('key', String(20), default=select(keyvalues.c.key).where(keyvalues.c.type='type1')), # define 'last_modified' to use the current_timestamp SQL function on update Column('last_modified', DateTime, onupdate=func.utc_timestamp()) @@ -404,7 +404,7 @@ method, which will render at statement compilation time a SQL function that is appropriate for the target backend:: >>> my_seq = Sequence('some_sequence') - >>> stmt = select([my_seq.next_value()]) + >>> stmt = select(my_seq.next_value()) >>> print(stmt.compile(dialect=postgresql.dialect())) SELECT nextval('some_sequence') AS next_value_1 diff --git a/doc/build/core/functions.rst b/doc/build/core/functions.rst index cb53eda139..90f192eb8d 100644 --- a/doc/build/core/functions.rst +++ b/doc/build/core/functions.rst @@ -11,7 +11,7 @@ SQL functions which are known to SQLAlchemy with regards to database-specific rendering, return types and argument behavior. Generic functions are invoked like all SQL functions, using the :attr:`func` attribute:: - select([func.count()]).select_from(sometable) + select(func.count()).select_from(sometable) Note that any name not known to :attr:`func` generates the function name as is - there is no restriction on what SQL functions can be called, known or diff --git a/doc/build/core/pooling.rst b/doc/build/core/pooling.rst index 4eb462a7b0..a471501a2f 100644 --- a/doc/build/core/pooling.rst +++ b/doc/build/core/pooling.rst @@ -244,7 +244,7 @@ behaviors are needed:: # run a SELECT 1. use a core select() so that # the SELECT of a scalar value without a table is # appropriately formatted for the backend - connection.scalar(select([1])) + connection.scalar(select(1)) except exc.DBAPIError as err: # catch SQLAlchemy's DBAPIError, which is a wrapper # for the DBAPI's exception. It includes a .connection_invalidated @@ -256,7 +256,7 @@ behaviors are needed:: # itself and establish a new connection. The disconnect detection # here also causes the whole connection pool to be invalidated # so that all stale connections are discarded. - connection.scalar(select([1])) + connection.scalar(select(1)) else: raise finally: diff --git a/doc/build/errors.rst b/doc/build/errors.rst index 61f009fadb..381cf212ae 100644 --- a/doc/build/errors.rst +++ b/doc/build/errors.rst @@ -643,7 +643,7 @@ that is not associated with any :class:`_engine.Engine`:: metadata = MetaData() table = Table('t', metadata, Column('q', Integer)) - stmt = select([table]) + stmt = select(table) result = stmt.execute() # <--- raises What the logic is expecting is that the :class:`_schema.MetaData` object has @@ -681,7 +681,7 @@ This error occurs when a statement makes use of :func:`.bindparam` either implicitly or explicitly and does not provide a value when the statement is executed:: - stmt = select([table.c.column]).where(table.c.id == bindparam('my_param')) + stmt = select(table.c.column).where(table.c.id == bindparam('my_param')) result = conn.execute(stmt) @@ -762,17 +762,17 @@ Given an example as:: Column('b', Integer), Column('c', Integer) ) - stmt = select([t]) + stmt = select(t) Above, ``stmt`` represents a SELECT statement. The error is produced when we want to use ``stmt`` directly as a FROM clause in another SELECT, such as if we attempted to select from it:: - new_stmt_1 = select([stmt]) + new_stmt_1 = select(stmt) Or if we wanted to use it in a FROM clause such as in a JOIN:: - new_stmt_2 = select([some_table]).select_from(some_table.join(stmt)) + new_stmt_2 = select(some_table).select_from(some_table.join(stmt)) In previous versions of SQLAlchemy, using a SELECT inside of another SELECT would produce a parenthesized, unnamed subquery. In most cases, this form of @@ -789,9 +789,9 @@ therefore requires that :meth:`_expression.SelectBase.subquery` is used:: subq = stmt.subquery() - new_stmt_1 = select([subq]) + new_stmt_1 = select(subq) - new_stmt_2 = select([some_table]).select_from(some_table.join(subq)) + new_stmt_2 = select(some_table).select_from(some_table.join(subq)) .. seealso:: diff --git a/doc/build/faq/sqlexpressions.rst b/doc/build/faq/sqlexpressions.rst index 4d2f0774c7..ab955fcaa2 100644 --- a/doc/build/faq/sqlexpressions.rst +++ b/doc/build/faq/sqlexpressions.rst @@ -20,7 +20,7 @@ if we don't use it explicitly):: >>> from sqlalchemy import table, column, select >>> t = table('my_table', column('x')) - >>> statement = select([t]) + >>> statement = select(t) >>> print(str(statement)) SELECT my_table.x FROM my_table @@ -93,7 +93,7 @@ flag, passed to ``compile_kwargs``:: t = table('t', column('x')) - s = select([t]).where(t.c.x == 5) + s = select(t).where(t.c.x == 5) # **do not use** with untrusted input!!! print(s.compile(compile_kwargs={"literal_binds": True})) diff --git a/doc/build/glossary.rst b/doc/build/glossary.rst index bf410d2d83..3997b95249 100644 --- a/doc/build/glossary.rst +++ b/doc/build/glossary.rst @@ -453,7 +453,7 @@ Glossary as an ORDER BY clause by calling upon the :meth:`_expression.Select.where` and :meth:`_expression.Select.order_by` methods:: - stmt = select([user.c.name]).\ + stmt = select(user.c.name).\ where(user.c.id > 5).\ where(user.c.name.like('e%').\ order_by(user.c.name) diff --git a/doc/build/orm/join_conditions.rst b/doc/build/orm/join_conditions.rst index 11d7cf6d9e..80965b5a33 100644 --- a/doc/build/orm/join_conditions.rst +++ b/doc/build/orm/join_conditions.rst @@ -807,12 +807,12 @@ ten items for each collection:: id = Column(Integer, primary_key=True) a_id = Column(ForeignKey("a.id")) - partition = select([ + partition = select( B, func.row_number().over( order_by=B.id, partition_by=B.a_id ).label('index') - ]).alias() + ).alias() partitioned_b = aliased(B, partition) diff --git a/doc/build/orm/loading_relationships.rst b/doc/build/orm/loading_relationships.rst index 8909d9a6eb..5a09029454 100644 --- a/doc/build/orm/loading_relationships.rst +++ b/doc/build/orm/loading_relationships.rst @@ -1185,11 +1185,11 @@ Below it is linked to a :func:`_expression.select` which links a set of column o to a string SQL statement:: # label the columns of the addresses table - eager_columns = select([ + eager_columns = select( addresses.c.address_id.label('a1'), addresses.c.email_address.label('a2'), addresses.c.user_id.label('a3') - ]) + ) # select from a raw SQL statement which uses those label names for the # addresses table. contains_eager() matches them up. diff --git a/doc/build/orm/mapped_sql_expr.rst b/doc/build/orm/mapped_sql_expr.rst index 56c7d8f45c..360fa9ec8e 100644 --- a/doc/build/orm/mapped_sql_expr.rst +++ b/doc/build/orm/mapped_sql_expr.rst @@ -123,14 +123,14 @@ objects available for a particular ``User``:: __tablename__ = 'user' id = Column(Integer, primary_key=True) address_count = column_property( - select([func.count(Address.id)]).\ + select(func.count(Address.id)).\ where(Address.user_id==id).\ correlate_except(Address) ) In the above example, we define a :func:`_expression.select` construct like the following:: - select([func.count(Address.id)]).\ + select(func.count(Address.id)).\ where(Address.user_id==id).\ correlate_except(Address) @@ -154,7 +154,7 @@ are configured. In Declarative this has the effect of calling :meth:`_orm.Mapp to add an additional property after the fact:: User.address_count = column_property( - select([func.count(Address.id)]).\ + select(func.count(Address.id)).\ where(Address.user_id==User.id) ) @@ -168,8 +168,7 @@ association table to both tables in a relationship:: # ... book_count = column_property( - select( - [func.count(books.c.id)] + select(func.count(books.c.id) ).where( and_( book_authors.c.author_id==authors.c.id, @@ -239,7 +238,7 @@ which is then used to emit a query:: def address_count(self): return object_session(self).\ scalar( - select([func.count(Address.id)]).\ + select(func.count(Address.id)).\ where(Address.user_id==self.id) ) diff --git a/doc/build/orm/nonstandard_mappings.rst b/doc/build/orm/nonstandard_mappings.rst index 387a3bf906..94892ffbeb 100644 --- a/doc/build/orm/nonstandard_mappings.rst +++ b/doc/build/orm/nonstandard_mappings.rst @@ -125,17 +125,15 @@ subquery:: from sqlalchemy import select, func - subq = select([ + subq = select( func.count(orders.c.id).label('order_count'), func.max(orders.c.price).label('highest_order'), orders.c.customer_id - ]).group_by(orders.c.customer_id).alias() + ).group_by(orders.c.customer_id).alias() - customer_select = select([customers, subq]).\ - select_from( - join(customers, subq, - customers.c.id == subq.c.customer_id) - ).alias() + customer_select = select(customers, subq).select_from( + join(customers, subq, customers.c.id == subq.c.customer_id) + ).alias() class Customer(Base): __table__ = customer_select diff --git a/doc/build/orm/persistence_techniques.rst b/doc/build/orm/persistence_techniques.rst index ffafe92958..6e59924ccb 100644 --- a/doc/build/orm/persistence_techniques.rst +++ b/doc/build/orm/persistence_techniques.rst @@ -153,7 +153,7 @@ part of the object's primary key:: session = Session(e) - foo = Foo(pk=sql.select([sql.func.coalesce(sql.func.max(Foo.pk) + 1, 1)]) + foo = Foo(pk=sql.select(sql.func.coalesce(sql.func.max(Foo.pk) + 1, 1)) session.add(foo) session.commit() @@ -191,7 +191,7 @@ This is most easily accomplished using the result = session.execute("select * from table where id=:id", {'id':7}) # execute a SQL expression construct - result = session.execute(select([mytable]).where(mytable.c.id==7)) + result = session.execute(select(mytable).where(mytable.c.id==7)) The current :class:`~sqlalchemy.engine.Connection` held by the :class:`~sqlalchemy.orm.session.Session` is accessible using the @@ -222,7 +222,7 @@ proper context for the desired engine:: ) result = session.execute( - select([mytable], mytable.c.id==7), + select(mytable).where(mytable.c.id==7), bind_arguments={'mapper': MyMappedClass} ) diff --git a/examples/materialized_paths/materialized_paths.py b/examples/materialized_paths/materialized_paths.py index f777f131be..37e91684c1 100644 --- a/examples/materialized_paths/materialized_paths.py +++ b/examples/materialized_paths/materialized_paths.py @@ -62,17 +62,15 @@ class Node(Base): # Finding the ancestors is a little bit trickier. We need to create a fake # secondary table since this behaves like a many-to-many join. secondary = select( - [ - id.label("id"), - func.unnest( - cast( - func.string_to_array( - func.regexp_replace(path, r"\.?\d+$", ""), "." - ), - ARRAY(Integer), - ) - ).label("ancestor_id"), - ] + id.label("id"), + func.unnest( + cast( + func.string_to_array( + func.regexp_replace(path, r"\.?\d+$", ""), "." + ), + ARRAY(Integer), + ) + ).label("ancestor_id"), ).alias() ancestors = relationship( "Node", diff --git a/examples/nested_sets/nested_sets.py b/examples/nested_sets/nested_sets.py index ba45231cee..ca3e91c9ad 100644 --- a/examples/nested_sets/nested_sets.py +++ b/examples/nested_sets/nested_sets.py @@ -46,7 +46,7 @@ def before_insert(mapper, connection, instance): else: personnel = mapper.mapped_table right_most_sibling = connection.scalar( - select([personnel.c.rgt]).where( + select(personnel.c.rgt).where( personnel.c.emp == instance.parent.emp ) ) diff --git a/examples/performance/short_selects.py b/examples/performance/short_selects.py index ff9156360b..4e5c3eb000 100644 --- a/examples/performance/short_selects.py +++ b/examples/performance/short_selects.py @@ -159,7 +159,7 @@ def test_core_new_stmt_each_time(n): with engine.connect() as conn: for id_ in random.sample(ids, n): - stmt = select([Customer.__table__]).where(Customer.id == id_) + stmt = select(Customer.__table__).where(Customer.id == id_) row = conn.execute(stmt).first() tuple(row) @@ -173,7 +173,7 @@ def test_core_new_stmt_each_time_compiled_cache(n): compiled_cache=compiled_cache ) as conn: for id_ in random.sample(ids, n): - stmt = select([Customer.__table__]).where(Customer.id == id_) + stmt = select(Customer.__table__).where(Customer.id == id_) row = conn.execute(stmt).first() tuple(row) @@ -182,7 +182,7 @@ def test_core_new_stmt_each_time_compiled_cache(n): def test_core_reuse_stmt(n): """test core, reusing the same statement (but recompiling each time).""" - stmt = select([Customer.__table__]).where(Customer.id == bindparam("id")) + stmt = select(Customer.__table__).where(Customer.id == bindparam("id")) with engine.connect() as conn: for id_ in random.sample(ids, n): @@ -194,7 +194,7 @@ def test_core_reuse_stmt(n): def test_core_reuse_stmt_compiled_cache(n): """test core, reusing the same statement + compiled cache.""" - stmt = select([Customer.__table__]).where(Customer.id == bindparam("id")) + stmt = select(Customer.__table__).where(Customer.id == bindparam("id")) compiled_cache = {} with engine.connect().execution_options( compiled_cache=compiled_cache diff --git a/examples/postgis/postgis.py b/examples/postgis/postgis.py index 868d3d055d..a12b824ba1 100644 --- a/examples/postgis/postgis.py +++ b/examples/postgis/postgis.py @@ -190,13 +190,10 @@ def setup_ddl_events(): for c in gis_cols: bind.execute( select( - [ - func.DropGeometryColumn( - "public", table.name, c.name - ) - ], - autocommit=True, - ) + func.DropGeometryColumn( + "public", table.name, c.name + ) + ).execution_options(autocommit=True) ) elif event == "after-create": @@ -205,17 +202,14 @@ def setup_ddl_events(): if isinstance(c.type, Geometry): bind.execute( select( - [ - func.AddGeometryColumn( - table.name, - c.name, - c.type.srid, - c.type.name, - c.type.dimension, - ) - ], - autocommit=True, - ) + func.AddGeometryColumn( + table.name, + c.name, + c.type.srid, + c.type.name, + c.type.dimension, + ) + ).execution_options(autocommit=True) ) elif event == "after-drop": table.columns = table.info.pop("_saved_columns") @@ -319,7 +313,7 @@ if __name__ == "__main__": # core usage just fine: road_table = Road.__table__ - stmt = select([road_table]).where( + stmt = select(road_table).where( road_table.c.road_geom.intersects(r1.road_geom) ) print(session.execute(stmt).fetchall()) @@ -329,7 +323,7 @@ if __name__ == "__main__": # look up the hex binary version, using SQLAlchemy casts as_binary = session.scalar( - select([type_coerce(r.road_geom, Geometry(coerce_="binary"))]) + select(type_coerce(r.road_geom, Geometry(coerce_="binary"))) ) assert as_binary.as_hex == ( "01020000000200000000000000b832084100000000" @@ -338,7 +332,7 @@ if __name__ == "__main__": # back again, same method ! as_text = session.scalar( - select([type_coerce(as_binary, Geometry(coerce_="text"))]) + select(type_coerce(as_binary, Geometry(coerce_="text"))) ) assert as_text.desc == "LINESTRING(198231 263418,198213 268322)" diff --git a/examples/versioned_history/test_versioning.py b/examples/versioned_history/test_versioning.py index 71a6b6ad2c..6c7d05f9a0 100644 --- a/examples/versioned_history/test_versioning.py +++ b/examples/versioned_history/test_versioning.py @@ -460,10 +460,10 @@ class TestVersioning(TestCase, AssertsCompiledSQL): sess.commit() actual_changed_base = sess.scalar( - select([BaseClass.__history_mapper__.local_table.c.changed]) + select(BaseClass.__history_mapper__.local_table.c.changed) ) actual_changed_sub = sess.scalar( - select([SubClass.__history_mapper__.local_table.c.changed]) + select(SubClass.__history_mapper__.local_table.c.changed) ) h1 = sess.query(BaseClassHistory).first() eq_(h1.changed, actual_changed_base) diff --git a/examples/versioned_rows/versioned_rows_w_versionid.py b/examples/versioned_rows/versioned_rows_w_versionid.py index 4861fb3669..7a1fe54197 100644 --- a/examples/versioned_rows/versioned_rows_w_versionid.py +++ b/examples/versioned_rows/versioned_rows_w_versionid.py @@ -39,7 +39,7 @@ class Versioned(object): def __declare_last__(cls): alias = cls.__table__.alias() cls.calc_is_current_version = column_property( - select([func.max(alias.c.version_id) == cls.version_id]).where( + select(func.max(alias.c.version_id) == cls.version_id).where( alias.c.id == cls.id ) ) diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index ed17fb8631..c29fee6528 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -296,7 +296,7 @@ For statements that specify only LIMIT and no OFFSET, all versions of SQL Server support the TOP keyword. This syntax is used for all SQL Server versions when no OFFSET clause is present. A statement such as:: - select([some_table]).limit(5) + select(some_table).limit(5) will render similarly to:: @@ -306,7 +306,7 @@ For versions of SQL Server prior to SQL Server 2012, a statement that uses LIMIT and OFFSET, or just OFFSET alone, will be rendered using the ``ROW_NUMBER()`` window function. A statement such as:: - select([some_table]).order_by(some_table.c.col3).limit(5).offset(10) + select(some_table).order_by(some_table.c.col3).limit(5).offset(10) will render similarly to:: @@ -1277,9 +1277,9 @@ class TryCast(sql.elements.Cast): from sqlalchemy import Numeric from sqlalchemy.dialects.mssql import try_cast - stmt = select([ + stmt = select( try_cast(product_table.c.unit_price, Numeric(10, 4)) - ]) + ) The above would render:: @@ -1816,7 +1816,7 @@ class MSSQLCompiler(compiler.SQLCompiler): mssql_rn = sql.column("mssql_rn") limitselect = sql.select( - [c for c in select.c if c.key != "mssql_rn"] + *[c for c in select.c if c.key != "mssql_rn"] ) if offset_clause is not None: limitselect = limitselect.where(mssql_rn > offset_clause) @@ -2793,9 +2793,8 @@ class MSDialect(default.DefaultDialect): @reflection.cache def get_schema_names(self, connection, **kw): - s = sql.select( - [ischema.schemata.c.schema_name], - order_by=[ischema.schemata.c.schema_name], + s = sql.select(ischema.schemata.c.schema_name).order_by( + ischema.schemata.c.schema_name ) schema_names = [r[0] for r in connection.execute(s)] return schema_names diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 65580b4e15..3afd6fc3a7 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -1057,7 +1057,7 @@ class OracleCompiler(compiler.SQLCompiler): # Wrap the middle select and add the hint inner_subquery = select.alias() limitselect = sql.select( - [ + *[ c for c in inner_subquery.c if orig_select.selected_columns.corresponding_column(c) @@ -1140,7 +1140,7 @@ class OracleCompiler(compiler.SQLCompiler): limit_subquery = limitselect.alias() origselect_cols = orig_select.selected_columns offsetselect = sql.select( - [ + *[ c for c in limit_subquery.c if origselect_cols.corresponding_column(c) diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py index 7fd271d523..dacf1e2c2c 100644 --- a/lib/sqlalchemy/dialects/postgresql/array.py +++ b/lib/sqlalchemy/dialects/postgresql/array.py @@ -53,9 +53,7 @@ class array(expression.ClauseList, expression.ColumnElement): from sqlalchemy.dialects import postgresql from sqlalchemy import select, func - stmt = select([ - array([1,2]) + array([3,4,5]) - ]) + stmt = select(array([1,2]) + array([3,4,5])) print(stmt.compile(dialect=postgresql.dialect())) @@ -76,11 +74,11 @@ class array(expression.ClauseList, expression.ColumnElement): recursively adding the dimensions of the inner :class:`_types.ARRAY` type:: - stmt = select([ + stmt = select( array([ array([1, 2]), array([3, 4]), array([column('q'), column('x')]) ]) - ]) + ) print(stmt.compile(dialect=postgresql.dialect())) Produces:: diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 84247d0467..e40a730c50 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -572,7 +572,7 @@ SQLAlchemy makes available the PostgreSQL ``@@`` operator via the method on any textual column expression. On a PostgreSQL dialect, an expression like the following:: - select([sometable.c.text.match("search string")]) + select(sometable.c.text.match("search string")) will emit to the database:: @@ -582,9 +582,7 @@ The PostgreSQL text search functions such as ``to_tsquery()`` and ``to_tsvector()`` are available explicitly using the standard :data:`.func` construct. For example:: - select([ - func.to_tsvector('fat cats ate rats').match('cat & rat') - ]) + select(func.to_tsvector('fat cats ate rats').match('cat & rat')) Emits the equivalent of:: @@ -594,7 +592,7 @@ The :class:`_postgresql.TSVECTOR` type can provide for explicit CAST:: from sqlalchemy.dialects.postgresql import TSVECTOR from sqlalchemy import select, cast - select([cast("some text", TSVECTOR)]) + select(cast("some text", TSVECTOR)) produces a statement equivalent to:: @@ -615,7 +613,7 @@ In order to provide for this explicit query planning, or to use different search strategies, the ``match`` method accepts a ``postgresql_regconfig`` keyword argument:: - select([mytable.c.id]).where( + select(mytable.c.id).where( mytable.c.title.match('somestring', postgresql_regconfig='english') ) @@ -627,7 +625,7 @@ Emits the equivalent of:: One can also specifically pass in a `'regconfig'` value to the ``to_tsvector()`` command as the initial argument:: - select([mytable.c.id]).where( + select(mytable.c.id).where( func.to_tsvector('english', mytable.c.title )\ .match('somestring', postgresql_regconfig='english') ) @@ -927,7 +925,7 @@ is not available yet in sqlalchemy, however the :func:`_expression.literal_column` function with the name of the table may be used in its place:: - select(['*']).select_from(func.my_function(literal_column('my_table'))) + select('*').select_from(func.my_function(literal_column('my_table'))) Will generate the SQL:: diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py index e649207191..7acab0a0a7 100644 --- a/lib/sqlalchemy/dialects/postgresql/ext.py +++ b/lib/sqlalchemy/dialects/postgresql/ext.py @@ -22,7 +22,7 @@ class aggregate_order_by(expression.ColumnElement): from sqlalchemy.dialects.postgresql import aggregate_order_by expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc())) - stmt = select([expr]) + stmt = select(expr) would represent the expression:: @@ -34,7 +34,7 @@ class aggregate_order_by(expression.ColumnElement): table.c.a, aggregate_order_by(literal_column("','"), table.c.a) ) - stmt = select([expr]) + stmt = select(expr) Would represent:: diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index 4e048feb05..cb89f7c5f8 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -278,14 +278,14 @@ class hstore(sqlfunc.GenericFunction): from sqlalchemy.dialects.postgresql import array, hstore - select([hstore('key1', 'value1')]) - - select([ - hstore( - array(['key1', 'key2', 'key3']), - array(['value1', 'value2', 'value3']) - ) - ]) + select(hstore('key1', 'value1')) + + select( + hstore( + array(['key1', 'key2', 'key3']), + array(['value1', 'value2', 'value3']) + ) + ) .. seealso:: diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py index fbf61dd5f2..9ffe9cfe88 100644 --- a/lib/sqlalchemy/dialects/postgresql/json.py +++ b/lib/sqlalchemy/dialects/postgresql/json.py @@ -219,7 +219,7 @@ class JSON(sqltypes.JSON): E.g.:: - select([data_table.c.data['some key'].astext]) + select(data_table.c.data['some key'].astext) .. seealso:: diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 0bd4cd14c7..198ec41594 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -603,7 +603,7 @@ class DefaultDialect(interfaces.Dialect): @util.memoized_property def _dialect_specific_select_one(self): - return str(expression.select([1]).compile(dialect=self)) + return str(expression.select(1).compile(dialect=self)) def do_ping(self, dbapi_connection): cursor = None @@ -1586,9 +1586,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): default_arg = expression.type_coerce(default.arg, type_) else: default_arg = default.arg - compiled = expression.select([default_arg]).compile( - dialect=self.dialect - ) + compiled = expression.select(default_arg).compile(dialect=self.dialect) compiled_params = compiled.construct_params() processors = compiled._bind_processors if compiled.positional: diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py index 7736a1290a..f0447d8dfc 100644 --- a/lib/sqlalchemy/ext/compiler.py +++ b/lib/sqlalchemy/ext/compiler.py @@ -31,7 +31,7 @@ when the object is compiled to a string:: from sqlalchemy import select - s = select([MyColumn('x'), MyColumn('y')]) + s = select(MyColumn('x'), MyColumn('y')) print(str(s)) Produces:: @@ -89,7 +89,7 @@ method which can be used for compilation of embedded attributes:: compiler.process(element.select, **kw) ) - insert = InsertFromSelect(t1, select([t1]).where(t1.c.x>5)) + insert = InsertFromSelect(t1, select(t1).where(t1.c.x>5)) print(insert) Produces:: @@ -393,8 +393,8 @@ Example usage:: from sqlalchemy import select, union_all exp = union_all( - select([users.c.name, sql_false().label("enrolled")]), - select([customers.c.name, customers.c.enrolled]) + select(users.c.name, sql_false().label("enrolled")), + select(customers.c.name, customers.c.enrolled) ) """ diff --git a/lib/sqlalchemy/ext/hybrid.py b/lib/sqlalchemy/ext/hybrid.py index b031e82fd5..75bb028f0b 100644 --- a/lib/sqlalchemy/ext/hybrid.py +++ b/lib/sqlalchemy/ext/hybrid.py @@ -384,7 +384,7 @@ we can adjust our ``SavingsAccount`` example to aggregate the balances for @balance.expression def balance(cls): - return select([func.sum(SavingsAccount.balance)]).\ + return select(func.sum(SavingsAccount.balance)).\ where(SavingsAccount.user_id==cls.id).\ label('total_balance') diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 37ff489644..d941d79d2b 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -956,7 +956,7 @@ class Query( """ self._auto_correlate = False - if fromclauses and fromclauses[0] is None: + if fromclauses and fromclauses[0] in {None, False}: self._correlate = () else: self._correlate = set(self._correlate).union( @@ -2374,7 +2374,7 @@ class Query( Given a case for :func:`.aliased` such as selecting ``User`` objects from a SELECT statement:: - select_stmt = select([User]).where(User.id == 7) + select_stmt = select(User).where(User.id == 7) user_alias = aliased(User, select_stmt) q = session.query(user_alias).\ diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 271a441f00..f7673e0b7c 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -245,22 +245,18 @@ def polymorphic_union( result = [] for type_, table in table_map.items(): if typecolname is not None: - result.append( - sql.select( - [col(name, table) for name in colnames] - + [ - sql.literal_column( - sql_util._quote_ddl_expr(type_) - ).label(typecolname) - ], - from_obj=[table], - ) + cols = [col(name, table) for name in colnames] + cols.append( + sql.literal_column(sql_util._quote_ddl_expr(type_)).label( + typecolname + ), ) + result.append(sql.select(*cols).select_from(table)) else: result.append( sql.select( - [col(name, table) for name in colnames], from_obj=[table] - ) + *[col(name, table) for name in colnames] + ).select_from(table) ) return sql.union_all(*result).alias(aliasname) diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index dc28046911..67ee8c9071 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -825,7 +825,7 @@ class Executable(Generative): The :meth:`execution_options` method is generative. A new instance of this statement is returned that contains the options:: - statement = select([table.c.x, table.c.y]) + statement = select(table.c.x, table.c.y) statement = statement.execution_options(autocommit=True) Note that only a subset of possible execution options can be applied diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py index b7151ac7b0..cd4bc17aff 100644 --- a/lib/sqlalchemy/sql/dml.py +++ b/lib/sqlalchemy/sql/dml.py @@ -914,7 +914,7 @@ class Insert(ValuesBase): e.g.:: - sel = select([table1.c.a, table1.c.b]).where(table1.c.c > 5) + sel = select(table1.c.a, table1.c.b).where(table1.c.c > 5) ins = table2.insert().from_select(['a', 'b'], sel) :param names: a sequence of string column names or @@ -1116,7 +1116,7 @@ class Update(DMLWhereBase, ValuesBase): subquery:: users.update().values(name='ed').where( - users.c.name==select([addresses.c.email_address]).\ + users.c.name==select(addresses.c.email_address).\ where(addresses.c.user_id==users.c.id).\ scalar_subquery() ) @@ -1183,7 +1183,7 @@ class Update(DMLWhereBase, ValuesBase): the subquery to the outer table being updated:: users.update().values( - name=select([addresses.c.email_address]).\ + name=select(addresses.c.email_address).\ where(addresses.c.user_id==users.c.id).\ scalar_subquery() ) @@ -1334,7 +1334,7 @@ class Delete(DMLWhereBase, UpdateBase): subquery:: users.delete().where( - users.c.name==select([addresses.c.email_address]).\ + users.c.name==select(addresses.c.email_address).\ where(addresses.c.user_id==users.c.id).\ scalar_subquery() ) diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index a176120340..dc3e5f4761 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -81,7 +81,7 @@ def between(expr, lower_bound, upper_bound, symmetric=False): E.g.:: from sqlalchemy import between - stmt = select([users_table]).where(between(users_table.c.id, 5, 7)) + stmt = select(users_table).where(between(users_table.c.id, 5, 7)) Would produce SQL resembling:: @@ -91,7 +91,7 @@ def between(expr, lower_bound, upper_bound, symmetric=False): :meth:`_expression.ColumnElement.between` method available on all SQL expressions, as in:: - stmt = select([users_table]).where(users_table.c.id.between(5, 7)) + stmt = select(users_table).where(users_table.c.id.between(5, 7)) All arguments passed to :func:`.between`, including the left side column expression, are coerced from Python scalar values if a @@ -470,7 +470,7 @@ class ClauseElement( t = table('t', column('x')) - s = select([t]).where(t.c.x == 5) + s = select(t).where(t.c.x == 5) print(s.compile(compile_kwargs={"literal_binds": True})) @@ -1037,7 +1037,7 @@ class BindParameter(roles.InElementRole, ColumnElement): from sqlalchemy import bindparam - stmt = select([users_table]).\ + stmt = select(users_table).\ where(users_table.c.name == bindparam('username')) Detailed discussion of how :class:`.BindParameter` is used is @@ -1107,7 +1107,7 @@ class BindParameter(roles.InElementRole, ColumnElement): from sqlalchemy import bindparam - stmt = select([users_table]).\ + stmt = select(users_table).\ where(users_table.c.name == bindparam('username')) The above statement, when rendered, will produce SQL similar to:: @@ -1161,7 +1161,7 @@ class BindParameter(roles.InElementRole, ColumnElement): along where it is later used within statement execution. If we invoke a statement like the following:: - stmt = select([users_table]).where(users_table.c.name == 'Wendy') + stmt = select(users_table).where(users_table.c.name == 'Wendy') result = connection.execute(stmt) We would see SQL logging output as:: @@ -1625,7 +1625,7 @@ class TextClause( a literal string SQL fragment is specified as part of a larger query, such as for the WHERE clause of a SELECT statement:: - s = select([users.c.id, users.c.name]).where(text("id=:user_id")) + s = select(users.c.id, users.c.name).where(text("id=:user_id")) result = connection.execute(s, user_id=12) :func:`_expression.text` is also used for the construction @@ -1821,7 +1821,7 @@ class TextClause( stmt = text("SELECT id, name FROM some_table") stmt = stmt.columns(column('id'), column('name')).subquery('st') - stmt = select([mytable]).\ + stmt = select(mytable).\ select_from( mytable.join(stmt, mytable.c.name == stmt.c.name) ).where(stmt.c.id > 5) @@ -1901,7 +1901,7 @@ class TextClause( stmt = stmt.columns(id=Integer, name=String).cte('st') - stmt = select([sometable]).where(sometable.c.id == stmt.c.id) + stmt = select(sometable).where(sometable.c.id == stmt.c.id) :param \*cols: A series of :class:`_expression.ColumnElement` objects, typically @@ -2000,23 +2000,23 @@ class False_(SingletonConstant, roles.ConstExprRole, ColumnElement): E.g.:: >>> from sqlalchemy import false - >>> print(select([t.c.x]).where(false())) + >>> print(select(t.c.x).where(false())) SELECT x FROM t WHERE false A backend which does not support true/false constants will render as an expression against 1 or 0:: - >>> print(select([t.c.x]).where(false())) + >>> print(select(t.c.x).where(false())) SELECT x FROM t WHERE 0 = 1 The :func:`.true` and :func:`.false` constants also feature "short circuit" operation within an :func:`.and_` or :func:`.or_` conjunction:: - >>> print(select([t.c.x]).where(or_(t.c.x > 5, true()))) + >>> print(select(t.c.x).where(or_(t.c.x > 5, true()))) SELECT x FROM t WHERE true - >>> print(select([t.c.x]).where(and_(t.c.x > 5, false()))) + >>> print(select(t.c.x).where(and_(t.c.x > 5, false()))) SELECT x FROM t WHERE false .. versionchanged:: 0.9 :func:`.true` and :func:`.false` feature @@ -2068,23 +2068,23 @@ class True_(SingletonConstant, roles.ConstExprRole, ColumnElement): E.g.:: >>> from sqlalchemy import true - >>> print(select([t.c.x]).where(true())) + >>> print(select(t.c.x).where(true())) SELECT x FROM t WHERE true A backend which does not support true/false constants will render as an expression against 1 or 0:: - >>> print(select([t.c.x]).where(true())) + >>> print(select(t.c.x).where(true())) SELECT x FROM t WHERE 1 = 1 The :func:`.true` and :func:`.false` constants also feature "short circuit" operation within an :func:`.and_` or :func:`.or_` conjunction:: - >>> print(select([t.c.x]).where(or_(t.c.x > 5, true()))) + >>> print(select(t.c.x).where(or_(t.c.x > 5, true()))) SELECT x FROM t WHERE true - >>> print(select([t.c.x]).where(and_(t.c.x > 5, false()))) + >>> print(select(t.c.x).where(and_(t.c.x > 5, false()))) SELECT x FROM t WHERE false .. versionchanged:: 0.9 :func:`.true` and :func:`.false` feature @@ -2327,7 +2327,7 @@ class BooleanClauseList(ClauseList, ColumnElement): from sqlalchemy import and_ - stmt = select([users_table]).where( + stmt = select(users_table).where( and_( users_table.c.name == 'wendy', users_table.c.enrolled == True @@ -2339,7 +2339,7 @@ class BooleanClauseList(ClauseList, ColumnElement): need to be parenthesized in order to function with Python operator precedence behavior):: - stmt = select([users_table]).where( + stmt = select(users_table).where( (users_table.c.name == 'wendy') & (users_table.c.enrolled == True) ) @@ -2350,7 +2350,7 @@ class BooleanClauseList(ClauseList, ColumnElement): times against a statement, which will have the effect of each clause being combined using :func:`.and_`:: - stmt = select([users_table]).\ + stmt = select(users_table).\ where(users_table.c.name == 'wendy').\ where(users_table.c.enrolled == True) @@ -2390,7 +2390,7 @@ class BooleanClauseList(ClauseList, ColumnElement): from sqlalchemy import or_ - stmt = select([users_table]).where( + stmt = select(users_table).where( or_( users_table.c.name == 'wendy', users_table.c.name == 'jack' @@ -2402,7 +2402,7 @@ class BooleanClauseList(ClauseList, ColumnElement): need to be parenthesized in order to function with Python operator precedence behavior):: - stmt = select([users_table]).where( + stmt = select(users_table).where( (users_table.c.name == 'wendy') | (users_table.c.name == 'jack') ) @@ -2536,7 +2536,7 @@ class Case(ColumnElement): from sqlalchemy import case - stmt = select([users_table]).\ + stmt = select(users_table).\ where( case( (users_table.c.name == 'wendy', 'W'), @@ -2576,7 +2576,7 @@ class Case(ColumnElement): from sqlalchemy import case - stmt = select([users_table]).\ + stmt = select(users_table).\ where( case( (users_table.c.name == 'wendy', 'W'), @@ -2603,7 +2603,7 @@ class Case(ColumnElement): compared against keyed to result expressions. The statement below is equivalent to the preceding statement:: - stmt = select([users_table]).\ + stmt = select(users_table).\ where( case( {"wendy": "W", "jack": "J"}, @@ -2800,9 +2800,7 @@ class Cast(WrapsColumnExpression, ColumnElement): from sqlalchemy import cast, Numeric - stmt = select([ - cast(product_table.c.unit_price, Numeric(10, 4)) - ]) + stmt = select(cast(product_table.c.unit_price, Numeric(10, 4))) Details on :class:`.Cast` usage is at :func:`.cast`. @@ -2834,9 +2832,7 @@ class Cast(WrapsColumnExpression, ColumnElement): from sqlalchemy import cast, Numeric - stmt = select([ - cast(product_table.c.unit_price, Numeric(10, 4)) - ]) + stmt = select(cast(product_table.c.unit_price, Numeric(10, 4))) The above statement will produce SQL resembling:: @@ -2930,7 +2926,7 @@ class TypeCoerce(WrapsColumnExpression, ColumnElement): from sqlalchemy import type_coerce - stmt = select([type_coerce(log_table.date_string, StringDateTime())]) + stmt = select(type_coerce(log_table.date_string, StringDateTime())) The above construct will produce a :class:`.TypeCoerce` object, which does not modify the rendering in any way on the SQL side, with the @@ -2950,9 +2946,9 @@ class TypeCoerce(WrapsColumnExpression, ColumnElement): In order to provide a named label for the expression, use :meth:`_expression.ColumnElement.label`:: - stmt = select([ + stmt = select( type_coerce(log_table.date_string, StringDateTime()).label('date') - ]) + ) A type that features bound-value handling will also have that behavior @@ -2966,7 +2962,7 @@ class TypeCoerce(WrapsColumnExpression, ColumnElement): # bound-value handling of MyStringType will be applied to the # literal value "some string" - stmt = select([type_coerce("some string", MyStringType)]) + stmt = select(type_coerce("some string", MyStringType)) When using :func:`.type_coerce` with composed expressions, note that **parenthesis are not applied**. If :func:`.type_coerce` is being @@ -3145,7 +3141,7 @@ class UnaryExpression(ColumnElement): from sqlalchemy import desc, nullsfirst - stmt = select([users_table]).order_by( + stmt = select(users_table).order_by( nullsfirst(desc(users_table.c.name))) The SQL expression from the above would resemble:: @@ -3158,7 +3154,7 @@ class UnaryExpression(ColumnElement): rather than as its standalone function version, as in:: - stmt = select([users_table]).order_by( + stmt = select(users_table).order_by( users_table.c.name.desc().nullsfirst()) .. seealso:: @@ -3189,7 +3185,7 @@ class UnaryExpression(ColumnElement): from sqlalchemy import desc, nullslast - stmt = select([users_table]).order_by( + stmt = select(users_table).order_by( nullslast(desc(users_table.c.name))) The SQL expression from the above would resemble:: @@ -3202,7 +3198,7 @@ class UnaryExpression(ColumnElement): rather than as its standalone function version, as in:: - stmt = select([users_table]).order_by( + stmt = select(users_table).order_by( users_table.c.name.desc().nullslast()) .. seealso:: @@ -3230,7 +3226,7 @@ class UnaryExpression(ColumnElement): from sqlalchemy import desc - stmt = select([users_table]).order_by(desc(users_table.c.name)) + stmt = select(users_table).order_by(desc(users_table.c.name)) will produce SQL as:: @@ -3242,7 +3238,7 @@ class UnaryExpression(ColumnElement): e.g.:: - stmt = select([users_table]).order_by(users_table.c.name.desc()) + stmt = select(users_table).order_by(users_table.c.name.desc()) :param column: A :class:`_expression.ColumnElement` (e.g. scalar SQL expression) @@ -3272,7 +3268,7 @@ class UnaryExpression(ColumnElement): e.g.:: from sqlalchemy import asc - stmt = select([users_table]).order_by(asc(users_table.c.name)) + stmt = select(users_table).order_by(asc(users_table.c.name)) will produce SQL as:: @@ -3284,7 +3280,7 @@ class UnaryExpression(ColumnElement): e.g.:: - stmt = select([users_table]).order_by(users_table.c.name.asc()) + stmt = select(users_table).order_by(users_table.c.name.asc()) :param column: A :class:`_expression.ColumnElement` (e.g. scalar SQL expression) @@ -3316,7 +3312,7 @@ class UnaryExpression(ColumnElement): as in:: from sqlalchemy import distinct, func - stmt = select([func.count(distinct(users_table.c.name))]) + stmt = select(func.count(distinct(users_table.c.name))) The above would produce an expression resembling:: @@ -3325,7 +3321,7 @@ class UnaryExpression(ColumnElement): The :func:`.distinct` function is also available as a column-level method, e.g. :meth:`_expression.ColumnElement.distinct`, as in:: - stmt = select([func.count(users_table.c.name.distinct())]) + stmt = select(func.count(users_table.c.name.distinct())) The :func:`.distinct` operator is different from the :meth:`_expression.Select.distinct` method of @@ -3403,7 +3399,7 @@ class CollectionAggregate(UnaryExpression): expr = 5 == any_(mytable.c.somearray) # mysql '5 = ANY (SELECT value FROM table)' - expr = 5 == any_(select([table.c.value])) + expr = 5 == any_(select(table.c.value)) .. versionadded:: 1.1 @@ -3434,7 +3430,7 @@ class CollectionAggregate(UnaryExpression): expr = 5 == all_(mytable.c.somearray) # mysql '5 = ALL (SELECT value FROM table)' - expr = 5 == all_(select([table.c.value])) + expr = 5 == all_(select(table.c.value)) .. versionadded:: 1.1 @@ -3933,12 +3929,12 @@ class WithinGroup(ColumnElement): the :meth:`.FunctionElement.within_group` method, e.g.:: from sqlalchemy import within_group - stmt = select([ + stmt = select( department.c.id, func.percentile_cont(0.5).within_group( department.c.salary.desc() ) - ]) + ) The above statement would produce SQL similar to ``SELECT department.id, percentile_cont(0.5) @@ -4279,7 +4275,7 @@ class ColumnClause( from sqlalchemy import column id, name = column("id"), column("name") - stmt = select([id, name]).select_from("user") + stmt = select(id, name).select_from("user") The above statement would produce SQL like:: @@ -4331,7 +4327,7 @@ class ColumnClause( from sqlalchemy import column id, name = column("id"), column("name") - stmt = select([id, name]).select_from("user") + stmt = select(id, name).select_from("user") The above statement would produce SQL like:: @@ -4345,7 +4341,7 @@ class ColumnClause( from sqlalchemy.sql import column id, name = column("id"), column("name") - stmt = select([id, name]).select_from("user") + stmt = select(id, name).select_from("user") The text handled by :func:`_expression.column` is assumed to be handled @@ -4375,7 +4371,7 @@ class ColumnClause( column("description"), ) - stmt = select([user.c.description]).where(user.c.name == 'wendy') + stmt = select(user.c.description).where(user.c.name == 'wendy') A :func:`_expression.column` / :func:`.table` construct like that illustrated diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index c1b8bbd27a..c7ddcc18a5 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -137,7 +137,7 @@ class FunctionElement(Executable, ColumnElement, FromClause): from sqlalchemy.sql import column - stmt = select([column('x'), column('y')]).\ + stmt = select(column('x'), column('y')).\ select_from(func.myfunction()) @@ -317,7 +317,7 @@ class FunctionElement(Executable, ColumnElement, FromClause): from sqlalchemy.sql import column - stmt = select([column('data_view')]).\ + stmt = select(column('data_view')).\ select_from(SomeTable).\ select_from(func.unnest(SomeTable.data).alias('data_view') ) @@ -343,7 +343,7 @@ class FunctionElement(Executable, ColumnElement, FromClause): This is shorthand for:: - s = select([function_element]) + s = select(function_element) """ s = Select._create_select(self) @@ -453,7 +453,7 @@ class _FunctionGenerator(object): The returned object is an instance of :class:`.Function`, and is a column-oriented SQL element like any other, and is used in that way:: - >>> print(select([func.count(table.c.id)])) + >>> print(select(func.count(table.c.id))) SELECT count(sometable.id) FROM sometable Any name can be given to :data:`.func`. If the function name is unknown to @@ -680,7 +680,7 @@ class GenericFunction(util.with_metaclass(_GenericMeta, Function)): class as_utc(GenericFunction): type = DateTime - print(select([func.as_utc()])) + print(select(func.as_utc())) User-defined generic functions can be organized into packages by specifying the "package" attribute when defining @@ -697,7 +697,7 @@ class GenericFunction(util.with_metaclass(_GenericMeta, Function)): The above function would be available from :data:`.func` using the package name ``time``:: - print(select([func.time.as_utc()])) + print(select(func.time.as_utc())) A final option is to allow the function to be accessed from one name in :data:`.func` but to render as a different name. @@ -887,7 +887,7 @@ class count(GenericFunction): my_table = table('some_table', column('id')) - stmt = select([func.count()]).select_from(my_table) + stmt = select(func.count()).select_from(my_table) Executing ``stmt`` would emit:: @@ -958,7 +958,7 @@ class array_agg(GenericFunction): e.g.:: - stmt = select([func.array_agg(table.c.values)[2:5]]) + stmt = select(func.array_agg(table.c.values)[2:5]) .. versionadded:: 1.1 @@ -1132,8 +1132,8 @@ class cube(GenericFunction): e.g. :meth:`_expression.Select.group_by`:: stmt = select( - [func.sum(table.c.value), table.c.col_1, table.c.col_2] - ).group_by(func.cube(table.c.col_1, table.c.col_2)) + func.sum(table.c.value), table.c.col_1, table.c.col_2 + ).group_by(func.cube(table.c.col_1, table.c.col_2)) .. versionadded:: 1.2 @@ -1149,7 +1149,7 @@ class rollup(GenericFunction): e.g. :meth:`_expression.Select.group_by`:: stmt = select( - [func.sum(table.c.value), table.c.col_1, table.c.col_2] + func.sum(table.c.value), table.c.col_1, table.c.col_2 ).group_by(func.rollup(table.c.col_1, table.c.col_2)) .. versionadded:: 1.2 @@ -1166,7 +1166,7 @@ class grouping_sets(GenericFunction): e.g. :meth:`_expression.Select.group_by`:: stmt = select( - [func.sum(table.c.value), table.c.col_1, table.c.col_2] + func.sum(table.c.value), table.c.col_1, table.c.col_2 ).group_by(func.grouping_sets(table.c.col_1, table.c.col_2)) In order to group by multiple sets, use the :func:`.tuple_` construct:: @@ -1174,10 +1174,9 @@ class grouping_sets(GenericFunction): from sqlalchemy import tuple_ stmt = select( - [ - func.sum(table.c.value), - table.c.col_1, table.c.col_2, - table.c.col_3] + func.sum(table.c.value), + table.c.col_1, table.c.col_2, + table.c.col_3 ).group_by( func.grouping_sets( tuple_(table.c.col_1, table.c.col_2), diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 91a0792c3a..ba03a69347 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -462,7 +462,7 @@ class ColumnOperators(Operators): E.g.:: - stmt = select([sometable]).\ + stmt = select(sometable).\ where(sometable.c.column.like("%foobar%")) :param other: expression to be compared @@ -491,7 +491,7 @@ class ColumnOperators(Operators): E.g.:: - stmt = select([sometable]).\ + stmt = select(sometable).\ where(sometable.c.column.ilike("%foobar%")) :param other: expression to be compared @@ -579,7 +579,7 @@ class ColumnOperators(Operators): stmt.where( column.in_( - select([othertable.c.y]). + select(othertable.c.y). where(table.c.x == othertable.c.x) ) ) @@ -682,7 +682,7 @@ class ColumnOperators(Operators): E.g.:: - stmt = select([sometable]).\ + stmt = select(sometable).\ where(sometable.c.column.startswith("foobar")) Since the operator uses ``LIKE``, wildcard characters @@ -761,7 +761,7 @@ class ColumnOperators(Operators): E.g.:: - stmt = select([sometable]).\ + stmt = select(sometable).\ where(sometable.c.column.endswith("foobar")) Since the operator uses ``LIKE``, wildcard characters @@ -840,7 +840,7 @@ class ColumnOperators(Operators): E.g.:: - stmt = select([sometable]).\ + stmt = select(sometable).\ where(sometable.c.column.contains("foobar")) Since the operator uses ``LIKE``, wildcard characters @@ -1115,7 +1115,7 @@ class ColumnOperators(Operators): expr = 5 == mytable.c.somearray.any_() # mysql '5 = ANY (SELECT value FROM table)' - expr = 5 == select([table.c.value]).scalar_subquery().any_() + expr = 5 == select(table.c.value).scalar_subquery().any_() .. seealso:: @@ -1140,7 +1140,7 @@ class ColumnOperators(Operators): expr = 5 == mytable.c.somearray.all_() # mysql '5 = ALL (SELECT value FROM table)' - expr = 5 == select([table.c.value]).scalar_subquery().all_() + expr = 5 == select(table.c.value).scalar_subquery().all_() .. seealso:: diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index d67b617434..ea3bb0512b 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -263,7 +263,7 @@ class HasPrefixes(object): stmt = table.insert().prefix_with("LOW_PRIORITY", dialect="mysql") # MySQL 5.7 optimizer hints - stmt = select([table]).prefix_with( + stmt = select(table).prefix_with( "/*+ BKA(t1) */", dialect="mysql") Multiple prefixes can be specified by multiple calls @@ -315,7 +315,7 @@ class HasSuffixes(object): E.g.:: - stmt = select([col1, col2]).cte().suffix_with( + stmt = select(col1, col2).cte().suffix_with( "cycle empno set y_cycle to 1 default 0", dialect="oracle") Multiple suffixes can be specified by multiple calls @@ -396,7 +396,7 @@ class HasHints(object): the table or alias. E.g. when using Oracle, the following:: - select([mytable]).\ + select(mytable).\ with_hint(mytable, "index(%(name)s ix_mytable)") Would render SQL as:: @@ -407,7 +407,7 @@ class HasHints(object): hint to a particular backend. Such as, to add hints for both Oracle and Sybase simultaneously:: - select([mytable]).\ + select(mytable).\ with_hint(mytable, "index(%(name)s ix_mytable)", 'oracle').\ with_hint(mytable, "WITH INDEX ix_mytable", 'sybase') @@ -523,7 +523,7 @@ class FromClause(roles.AnonymizedFromClauseRole, Selectable): j = user_table.join(address_table, user_table.c.id == address_table.c.user_id) - stmt = select([user_table]).select_from(j) + stmt = select(user_table).select_from(j) would emit SQL along the lines of:: @@ -709,7 +709,7 @@ class FromClause(roles.AnonymizedFromClauseRole, Selectable): to the construction of SQL expressions using table-bound or other selectable-bound columns:: - select([mytable]).where(mytable.c.somecolumn == 5) + select(mytable).where(mytable.c.somecolumn == 5) """ @@ -923,7 +923,7 @@ class Join(roles.DMLTableRole, FromClause): j = join(user_table, address_table, user_table.c.id == address_table.c.user_id) - stmt = select([user_table]).select_from(j) + stmt = select(user_table).select_from(j) would emit SQL along the lines of:: @@ -1251,9 +1251,9 @@ class Join(roles.DMLTableRole, FromClause): from sqlalchemy import select, alias j = alias( - select([j.left, j.right]).\ + select(j.left, j.right).\ select_from(j).\ - with_labels(True).\ + apply_labels().\ correlate(False), name=name ) @@ -1635,7 +1635,7 @@ class TableSample(AliasedReturnsRows): func.bernoulli(1), name='alias', seed=func.random()) - stmt = select([selectable.c.people_id]) + stmt = select(selectable.c.people_id) Assuming ``people`` with a column ``people_id``, the above statement would render as:: @@ -1836,27 +1836,27 @@ class HasCTE(roles.HasCTERole): Column('quantity', Integer) ) - regional_sales = select([ + regional_sales = select( orders.c.region, func.sum(orders.c.amount).label('total_sales') - ]).group_by(orders.c.region).cte("regional_sales") + ).group_by(orders.c.region).cte("regional_sales") - top_regions = select([regional_sales.c.region]).\ + top_regions = select(regional_sales.c.region).\ where( regional_sales.c.total_sales > - select([ - func.sum(regional_sales.c.total_sales)/10 - ]) + select( + func.sum(regional_sales.c.total_sales) / 10 + ) ).cte("top_regions") - statement = select([ + statement = select( 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) result = conn.execute(statement).fetchall() @@ -1874,30 +1874,29 @@ class HasCTE(roles.HasCTERole): Column('quantity', Integer), ) - included_parts = select([ - parts.c.sub_part, - parts.c.part, - parts.c.quantity]).\ - where(parts.c.part=='our part').\ - cte(recursive=True) + included_parts = select(\ + parts.c.sub_part, parts.c.part, parts.c.quantity\ + ).\ + where(parts.c.part=='our part').\ + cte(recursive=True) incl_alias = included_parts.alias() parts_alias = parts.alias() included_parts = included_parts.union_all( - select([ + select( parts_alias.c.sub_part, parts_alias.c.part, parts_alias.c.quantity - ]). - where(parts_alias.c.part==incl_alias.c.sub_part) + ).\ + where(parts_alias.c.part==incl_alias.c.sub_part) ) - statement = select([ + statement = select( included_parts.c.sub_part, func.sum(included_parts.c.quantity). label('total_quantity') - ]).\ + ).\ group_by(included_parts.c.sub_part) result = conn.execute(statement).fetchall() @@ -1932,7 +1931,7 @@ class HasCTE(roles.HasCTERole): upsert = visitors.insert().from_select( [visitors.c.product_id, visitors.c.date, visitors.c.count], - select([literal(product_id), literal(day), literal(count)]) + select(literal(product_id), literal(day), literal(count)) .where(~exists(update_cte.select())) ) @@ -2585,7 +2584,7 @@ class SelectBase( Given a SELECT statement such as:: - stmt = select([table.c.id, table.c.name]) + stmt = select(table.c.id, table.c.name) The above statement might look like:: @@ -2596,7 +2595,7 @@ class SelectBase( a named sub-element:: subq = stmt.subquery() - new_stmt = select([subq]) + new_stmt = select(subq) The above renders as:: @@ -2831,7 +2830,7 @@ class GenerativeSelect(DeprecatedSelectBaseGenerations, SelectBase): E.g.:: - stmt = select([table]).with_for_update(nowait=True) + stmt = select(table).with_for_update(nowait=True) On a database like PostgreSQL or Oracle, the above would render a statement like:: @@ -3035,7 +3034,7 @@ class GenerativeSelect(DeprecatedSelectBaseGenerations, SelectBase): e.g.:: - stmt = select([table]).order_by(table.c.id, table.c.name) + stmt = select(table).order_by(table.c.id, table.c.name) :param \*clauses: a series of :class:`_expression.ColumnElement` constructs @@ -3062,7 +3061,7 @@ class GenerativeSelect(DeprecatedSelectBaseGenerations, SelectBase): e.g.:: - stmt = select([table.c.name, func.max(table.c.stat)]).\ + stmt = select(table.c.name, func.max(table.c.stat)).\ group_by(table.c.name) :param \*clauses: a series of :class:`_expression.ColumnElement` @@ -4740,7 +4739,7 @@ class Select( table1 = table('t1', column('a')) table2 = table('t2', column('b')) - s = select([table1.c.a]).\ + s = select(table1.c.a).\ select_from( table1.join(table2, table1.c.a==table2.c.b) ) @@ -4762,7 +4761,7 @@ class Select( if desired, in the case that the FROM clause cannot be fully derived from the columns clause:: - select([func.count('*')]).select_from(table1) + select(func.count('*')).select_from(table1) """ @@ -4827,7 +4826,7 @@ class Select( """ self._auto_correlate = False - if fromclauses and fromclauses[0] is None: + if fromclauses and fromclauses[0] in {None, False}: self._correlate = () else: self._correlate = self._correlate + tuple( @@ -4865,7 +4864,7 @@ class Select( """ self._auto_correlate = False - if fromclauses and fromclauses[0] is None: + if fromclauses and fromclauses[0] in {None, False}: self._correlate_except = () else: self._correlate_except = (self._correlate_except or ()) + tuple( @@ -4894,7 +4893,7 @@ class Select( col1 = column('q', Integer) col2 = column('p', Integer) - stmt = select([col1, col2]) + stmt = select(col1, col2) Above, ``stmt.selected_columns`` would be a collection that contains the ``col1`` and ``col2`` objects directly. For a statement that is diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index f1063b71ad..e2edf20b58 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -239,7 +239,7 @@ class String(Concatenable, TypeEngine): E.g.:: >>> from sqlalchemy import cast, select, String - >>> print(select([cast('some string', String(collation='utf8'))])) + >>> print(select(cast('some string', String(collation='utf8')))) SELECT CAST(:param_1 AS VARCHAR COLLATE utf8) AS anon_1 :param convert_unicode: When set to ``True``, the @@ -2394,9 +2394,9 @@ class JSON(Indexable, TypeEngine): e.g.:: - stmt = select([ + stmt = select( mytable.c.json_column['some_data'].as_boolean() - ]).where( + ).where( mytable.c.json_column['some_data'].as_boolean() == True ) @@ -2410,9 +2410,9 @@ class JSON(Indexable, TypeEngine): e.g.:: - stmt = select([ + stmt = select( mytable.c.json_column['some_data'].as_string() - ]).where( + ).where( mytable.c.json_column['some_data'].as_string() == 'some string' ) @@ -2427,9 +2427,9 @@ class JSON(Indexable, TypeEngine): e.g.:: - stmt = select([ + stmt = select( mytable.c.json_column['some_data'].as_integer() - ]).where( + ).where( mytable.c.json_column['some_data'].as_integer() == 5 ) @@ -2443,9 +2443,9 @@ class JSON(Indexable, TypeEngine): e.g.:: - stmt = select([ + stmt = select( mytable.c.json_column['some_data'].as_float() - ]).where( + ).where( mytable.c.json_column['some_data'].as_float() == 29.75 ) @@ -2460,9 +2460,7 @@ class JSON(Indexable, TypeEngine): e.g.:: - stmt = select([ - mytable.c.json_column['some_data'].as_json() - ]) + stmt = select(mytable.c.json_column['some_data'].as_json()) This is typically the default behavior of indexed elements in any case. @@ -2614,7 +2612,7 @@ class ARRAY(SchemaEventTarget, Indexable, Concatenable, TypeEngine): constructs which will produce the appropriate SQL, both for SELECT statements:: - select([mytable.c.data[5], mytable.c.data[2:7]]) + select(mytable.c.data[5], mytable.c.data[2:7]) as well as UPDATE statements when the :meth:`_expression.Update.values` method @@ -2693,7 +2691,7 @@ class ARRAY(SchemaEventTarget, Indexable, Concatenable, TypeEngine): from sqlalchemy.sql import operators conn.execute( - select([table.c.data]).where( + select(table.c.data).where( table.c.data.any(7, operator=operators.lt) ) ) @@ -2733,7 +2731,7 @@ class ARRAY(SchemaEventTarget, Indexable, Concatenable, TypeEngine): from sqlalchemy.sql import operators conn.execute( - select([table.c.data]).where( + select(table.c.data).where( table.c.data.all(7, operator=operators.lt) ) ) diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py index 5cb3cba709..27499b5f71 100644 --- a/lib/sqlalchemy/sql/visitors.py +++ b/lib/sqlalchemy/sql/visitors.py @@ -664,7 +664,7 @@ def traverse(obj, opts, visitors): from sqlalchemy.sql import visitors - stmt = select([some_table]).where(some_table.c.foo == 'bar') + stmt = select(some_table).where(some_table.c.foo == 'bar') def visit_bindparam(bind_param): print("found bound value: %s" % bind_param.value) diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 4114137d4e..302a024192 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -851,7 +851,7 @@ class SuiteRequirements(Requirements): expr = decimal.Decimal("15.7563") value = e.scalar( - select([literal(expr)]) + select(literal(expr)) ) assert value == expr diff --git a/lib/sqlalchemy/testing/suite/test_cte.py b/lib/sqlalchemy/testing/suite/test_cte.py index 1ee6cac106..4addca009b 100644 --- a/lib/sqlalchemy/testing/suite/test_cte.py +++ b/lib/sqlalchemy/testing/suite/test_cte.py @@ -53,12 +53,12 @@ class CTETest(fixtures.TablesTest): with config.db.connect() as conn: cte = ( - select([some_table]) + select(some_table) .where(some_table.c.data.in_(["d2", "d3", "d4"])) .cte("some_cte") ) result = conn.execute( - select([cte.c.data]).where(cte.c.data.in_(["d4", "d5"])) + select(cte.c.data).where(cte.c.data.in_(["d4", "d5"])) ) eq_(result.fetchall(), [("d4",)]) @@ -67,7 +67,7 @@ class CTETest(fixtures.TablesTest): with config.db.connect() as conn: cte = ( - select([some_table]) + select(some_table) .where(some_table.c.data.in_(["d2", "d3", "d4"])) .cte("some_cte", recursive=True) ) @@ -77,10 +77,10 @@ class CTETest(fixtures.TablesTest): # note that SQL Server requires this to be UNION ALL, # can't be UNION cte = cte.union_all( - select([st1]).where(st1.c.id == cte_alias.c.parent_id) + select(st1).where(st1.c.id == cte_alias.c.parent_id) ) result = conn.execute( - select([cte.c.data]) + select(cte.c.data) .where(cte.c.data != "d2") .order_by(cte.c.data.desc()) ) @@ -95,18 +95,18 @@ class CTETest(fixtures.TablesTest): with config.db.connect() as conn: cte = ( - select([some_table]) + select(some_table) .where(some_table.c.data.in_(["d2", "d3", "d4"])) .cte("some_cte") ) conn.execute( some_other_table.insert().from_select( - ["id", "data", "parent_id"], select([cte]) + ["id", "data", "parent_id"], select(cte) ) ) eq_( conn.execute( - select([some_other_table]).order_by(some_other_table.c.id) + select(some_other_table).order_by(some_other_table.c.id) ).fetchall(), [(2, "d2", 1), (3, "d3", 1), (4, "d4", 3)], ) @@ -120,12 +120,12 @@ class CTETest(fixtures.TablesTest): with config.db.connect() as conn: conn.execute( some_other_table.insert().from_select( - ["id", "data", "parent_id"], select([some_table]) + ["id", "data", "parent_id"], select(some_table) ) ) cte = ( - select([some_table]) + select(some_table) .where(some_table.c.data.in_(["d2", "d3", "d4"])) .cte("some_cte") ) @@ -136,7 +136,7 @@ class CTETest(fixtures.TablesTest): ) eq_( conn.execute( - select([some_other_table]).order_by(some_other_table.c.id) + select(some_other_table).order_by(some_other_table.c.id) ).fetchall(), [ (1, "d1", None), @@ -156,12 +156,12 @@ class CTETest(fixtures.TablesTest): with config.db.connect() as conn: conn.execute( some_other_table.insert().from_select( - ["id", "data", "parent_id"], select([some_table]) + ["id", "data", "parent_id"], select(some_table) ) ) cte = ( - select([some_table]) + select(some_table) .where(some_table.c.data.in_(["d2", "d3", "d4"])) .cte("some_cte") ) @@ -172,7 +172,7 @@ class CTETest(fixtures.TablesTest): ) eq_( conn.execute( - select([some_other_table]).order_by(some_other_table.c.id) + select(some_other_table).order_by(some_other_table.c.id) ).fetchall(), [(1, "d1", None), (5, "d5", 3)], ) @@ -186,26 +186,26 @@ class CTETest(fixtures.TablesTest): with config.db.connect() as conn: conn.execute( some_other_table.insert().from_select( - ["id", "data", "parent_id"], select([some_table]) + ["id", "data", "parent_id"], select(some_table) ) ) cte = ( - select([some_table]) + select(some_table) .where(some_table.c.data.in_(["d2", "d3", "d4"])) .cte("some_cte") ) conn.execute( some_other_table.delete().where( some_other_table.c.data - == select([cte.c.data]) + == select(cte.c.data) .where(cte.c.id == some_other_table.c.id) .scalar_subquery() ) ) eq_( conn.execute( - select([some_other_table]).order_by(some_other_table.c.id) + select(some_other_table).order_by(some_other_table.c.id) ).fetchall(), [(1, "d1", None), (5, "d5", 3)], ) diff --git a/lib/sqlalchemy/testing/suite/test_deprecations.py b/lib/sqlalchemy/testing/suite/test_deprecations.py index 8c25616a86..b36162fa59 100644 --- a/lib/sqlalchemy/testing/suite/test_deprecations.py +++ b/lib/sqlalchemy/testing/suite/test_deprecations.py @@ -38,8 +38,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest): def test_plain_union(self, connection): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2) - s2 = select([table]).where(table.c.id == 3) + s1 = select(table).where(table.c.id == 2) + s2 = select(table).where(table.c.id == 3) u1 = union(s1, s2) with testing.expect_deprecated( @@ -59,8 +59,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest): # it before. def _dont_test_select_from_plain_union(self, connection): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2) - s2 = select([table]).where(table.c.id == 3) + s1 = select(table).where(table.c.id == 2) + s2 = select(table).where(table.c.id == 3) u1 = union(s1, s2).alias().select() with testing.expect_deprecated( @@ -75,18 +75,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest): @testing.requires.parens_in_union_contained_select_w_limit_offset def test_limit_offset_selectable_in_unions(self, connection): table = self.tables.some_table - s1 = ( - select([table]) - .where(table.c.id == 2) - .limit(1) - .order_by(table.c.id) - ) - s2 = ( - select([table]) - .where(table.c.id == 3) - .limit(1) - .order_by(table.c.id) - ) + s1 = select(table).where(table.c.id == 2).limit(1).order_by(table.c.id) + s2 = select(table).where(table.c.id == 3).limit(1).order_by(table.c.id) u1 = union(s1, s2).limit(2) with testing.expect_deprecated( @@ -100,8 +90,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest): @testing.requires.parens_in_union_contained_select_wo_limit_offset def test_order_by_selectable_in_unions(self, connection): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2).order_by(table.c.id) - s2 = select([table]).where(table.c.id == 3).order_by(table.c.id) + s1 = select(table).where(table.c.id == 2).order_by(table.c.id) + s2 = select(table).where(table.c.id == 3).order_by(table.c.id) u1 = union(s1, s2).limit(2) with testing.expect_deprecated( @@ -114,8 +104,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest): def test_distinct_selectable_in_unions(self, connection): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2).distinct() - s2 = select([table]).where(table.c.id == 3).distinct() + s1 = select(table).where(table.c.id == 2).distinct() + s2 = select(table).where(table.c.id == 3).distinct() u1 = union(s1, s2).limit(2) with testing.expect_deprecated( @@ -129,7 +119,7 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest): def test_limit_offset_aliased_selectable_in_unions(self, connection): table = self.tables.some_table s1 = ( - select([table]) + select(table) .where(table.c.id == 2) .limit(1) .order_by(table.c.id) @@ -137,7 +127,7 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest): .select() ) s2 = ( - select([table]) + select(table) .where(table.c.id == 3) .limit(1) .order_by(table.c.id) diff --git a/lib/sqlalchemy/testing/suite/test_dialect.py b/lib/sqlalchemy/testing/suite/test_dialect.py index 8aa13a6225..c5ede08c69 100644 --- a/lib/sqlalchemy/testing/suite/test_dialect.py +++ b/lib/sqlalchemy/testing/suite/test_dialect.py @@ -65,7 +65,7 @@ class ExceptionTest(fixtures.TablesTest): # there's no way to make this happen with some drivers like # mysqlclient, pymysql. this at least does produce a non- # ascii error message for cx_oracle, psycopg2 - conn.execute(select([literal_column(u"méil")])) + conn.execute(select(literal_column(u"méil"))) assert False except exc.DBAPIError as err: err_str = str(err) @@ -146,7 +146,7 @@ class AutocommitTest(fixtures.TablesTest): trans.rollback() eq_( - conn.scalar(select([self.tables.some_table.c.id])), + conn.scalar(select(self.tables.some_table.c.id)), 1 if autocommit else None, ) @@ -194,7 +194,7 @@ class EscapingTest(fixtures.TestBase): eq_( conn.scalar( - select([t.c.data]).where( + select(t.c.data).where( t.c.data == literal_column("'some % value'") ) ), @@ -203,7 +203,7 @@ class EscapingTest(fixtures.TestBase): eq_( conn.scalar( - select([t.c.data]).where( + select(t.c.data).where( t.c.data == literal_column("'some %% other value'") ) ), diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py index 5b8c343c4a..74347cc774 100644 --- a/lib/sqlalchemy/testing/suite/test_insert.py +++ b/lib/sqlalchemy/testing/suite/test_insert.py @@ -55,7 +55,7 @@ class LastrowidTest(fixtures.TablesTest): r = connection.execute( self.tables.autoinc_pk.insert(), data="some data" ) - pk = connection.scalar(select([self.tables.autoinc_pk.c.id])) + pk = connection.scalar(select(self.tables.autoinc_pk.c.id)) eq_(r.inserted_primary_key, (pk,)) @requirements.dbapi_lastrowid @@ -64,7 +64,7 @@ class LastrowidTest(fixtures.TablesTest): self.tables.autoinc_pk.insert(), data="some data" ) lastrowid = r.lastrowid - pk = connection.scalar(select([self.tables.autoinc_pk.c.id])) + pk = connection.scalar(select(self.tables.autoinc_pk.c.id)) eq_(lastrowid, pk) @@ -178,7 +178,7 @@ class InsertBehaviorTest(fixtures.TablesTest): result = connection.execute( dest_table.insert().from_select( ("data",), - select([src_table.c.data]).where( + select(src_table.c.data).where( src_table.c.data.in_(["data2", "data3"]) ), ) @@ -187,7 +187,7 @@ class InsertBehaviorTest(fixtures.TablesTest): eq_(result.inserted_primary_key, (None,)) result = connection.execute( - select([dest_table.c.data]).order_by(dest_table.c.data) + select(dest_table.c.data).order_by(dest_table.c.data) ) eq_(result.fetchall(), [("data2",), ("data3",)]) @@ -199,7 +199,7 @@ class InsertBehaviorTest(fixtures.TablesTest): result = connection.execute( dest_table.insert().from_select( ("data",), - select([src_table.c.data]).where( + select(src_table.c.data).where( src_table.c.data.in_(["data2", "data3"]) ), ) @@ -207,7 +207,7 @@ class InsertBehaviorTest(fixtures.TablesTest): eq_(result.inserted_primary_key, (None,)) result = connection.execute( - select([dest_table.c.data]).order_by(dest_table.c.data) + select(dest_table.c.data).order_by(dest_table.c.data) ) eq_(result.fetchall(), []) @@ -227,7 +227,7 @@ class InsertBehaviorTest(fixtures.TablesTest): connection.execute( table.insert(inline=True).from_select( ("id", "data"), - select([table.c.id + 5, table.c.data]).where( + select(table.c.id + 5, table.c.data).where( table.c.data.in_(["data2", "data3"]) ), ) @@ -235,7 +235,7 @@ class InsertBehaviorTest(fixtures.TablesTest): eq_( connection.execute( - select([table.c.data]).order_by(table.c.data) + select(table.c.data).order_by(table.c.data) ).fetchall(), [("data1",), ("data2",), ("data2",), ("data3",), ("data3",)], ) @@ -255,7 +255,7 @@ class InsertBehaviorTest(fixtures.TablesTest): connection.execute( table.insert(inline=True).from_select( ("id", "data"), - select([table.c.id + 5, table.c.data]).where( + select(table.c.id + 5, table.c.data).where( table.c.data.in_(["data2", "data3"]) ), ) @@ -263,7 +263,7 @@ class InsertBehaviorTest(fixtures.TablesTest): eq_( connection.execute( - select([table]).order_by(table.c.data, table.c.id) + select(table).order_by(table.c.data, table.c.id) ).fetchall(), [ (1, "data1", 5, 4), @@ -306,7 +306,7 @@ class ReturningTest(fixtures.TablesTest): table.insert().returning(table.c.id), data="some data" ) pk = r.first()[0] - fetched_pk = connection.scalar(select([table.c.id])) + fetched_pk = connection.scalar(select(table.c.id)) eq_(fetched_pk, pk) def test_explicit_returning_pk_no_autocommit(self, connection): @@ -315,7 +315,7 @@ class ReturningTest(fixtures.TablesTest): table.insert().returning(table.c.id), data="some data" ) pk = r.first()[0] - fetched_pk = connection.scalar(select([table.c.id])) + fetched_pk = connection.scalar(select(table.c.id)) eq_(fetched_pk, pk) def test_autoincrement_on_insert_implicit_returning(self, connection): @@ -328,7 +328,7 @@ class ReturningTest(fixtures.TablesTest): r = connection.execute( self.tables.autoinc_pk.insert(), data="some data" ) - pk = connection.scalar(select([self.tables.autoinc_pk.c.id])) + pk = connection.scalar(select(self.tables.autoinc_pk.c.id)) eq_(r.inserted_primary_key, (pk,)) diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py index e6f6068c89..6d28a207ea 100644 --- a/lib/sqlalchemy/testing/suite/test_results.py +++ b/lib/sqlalchemy/testing/suite/test_results.py @@ -87,10 +87,8 @@ class RowFetchTest(fixtures.TablesTest): def test_row_with_dupe_names(self, connection): result = connection.execute( select( - [ - self.tables.plain_pk.c.data, - self.tables.plain_pk.c.data.label("data"), - ] + self.tables.plain_pk.c.data, + self.tables.plain_pk.c.data.label("data"), ).order_by(self.tables.plain_pk.c.id) ) row = result.first() @@ -106,8 +104,8 @@ class RowFetchTest(fixtures.TablesTest): """ datetable = self.tables.has_dates - s = select([datetable.alias("x").c.today]).scalar_subquery() - s2 = select([datetable.c.id, s.label("somelabel")]) + s = select(datetable.alias("x").c.today).scalar_subquery() + s2 = select(datetable.c.id, s.label("somelabel")) row = connection.execute(s2).first() eq_(row.somelabel, datetime.datetime(2006, 5, 12, 12, 0, 0)) @@ -256,21 +254,21 @@ class ServerSideCursorsTest( @testing.combinations( ("global_string", True, "select 1", True), ("global_text", True, text("select 1"), True), - ("global_expr", True, select([1]), True), + ("global_expr", True, select(1), True), ("global_off_explicit", False, text("select 1"), False), ( "stmt_option", False, - select([1]).execution_options(stream_results=True), + select(1).execution_options(stream_results=True), True, ), ( "stmt_option_disabled", True, - select([1]).execution_options(stream_results=False), + select(1).execution_options(stream_results=False), False, ), - ("for_update_expr", True, select([1]).with_for_update(), True), + ("for_update_expr", True, select(1).with_for_update(), True), ("for_update_string", True, "SELECT 1 FOR UPDATE", True), ("text_no_ss", False, text("select 42"), False), ( @@ -308,7 +306,7 @@ class ServerSideCursorsTest( def test_stmt_enabled_conn_option_disabled(self): engine = self._fixture(False) - s = select([1]).execution_options(stream_results=True) + s = select(1).execution_options(stream_results=True) # not this one result = ( @@ -318,7 +316,7 @@ class ServerSideCursorsTest( def test_aliases_and_ss(self): engine = self._fixture(False) - s1 = select([1]).execution_options(stream_results=True).alias() + s1 = select(1).execution_options(stream_results=True).alias() with engine.begin() as conn: result = conn.execute(s1) assert self._is_server_side(result.cursor) @@ -326,7 +324,7 @@ class ServerSideCursorsTest( # s1's options shouldn't affect s2 when s2 is used as a # from_obj. - s2 = select([1], from_obj=s1) + s2 = select(1).select_from(s1) with engine.begin() as conn: result = conn.execute(s2) assert not self._is_server_side(result.cursor) @@ -368,7 +366,7 @@ class ServerSideCursorsTest( connection.execute(test_table.delete()) eq_( connection.scalar( - select([func.count("*")]).select_from(test_table) + select(func.count("*")).select_from(test_table) ), 0, ) diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index 7e03371465..adcd7d8b90 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -67,7 +67,7 @@ class CollateTest(fixtures.TablesTest): collation = testing.requires.get_order_by_collation(testing.config) self._assert_result( - select([self.tables.some_table]).order_by( + select(self.tables.some_table).order_by( self.tables.some_table.c.data.collate(collation).asc() ), [(1, "collate data1"), (2, "collate data2")], @@ -115,44 +115,38 @@ class OrderByLabelTest(fixtures.TablesTest): def test_plain(self): table = self.tables.some_table lx = table.c.x.label("lx") - self._assert_result(select([lx]).order_by(lx), [(1,), (2,), (3,)]) + self._assert_result(select(lx).order_by(lx), [(1,), (2,), (3,)]) def test_composed_int(self): table = self.tables.some_table lx = (table.c.x + table.c.y).label("lx") - self._assert_result(select([lx]).order_by(lx), [(3,), (5,), (7,)]) + self._assert_result(select(lx).order_by(lx), [(3,), (5,), (7,)]) def test_composed_multiple(self): table = self.tables.some_table lx = (table.c.x + table.c.y).label("lx") ly = (func.lower(table.c.q) + table.c.p).label("ly") self._assert_result( - select([lx, ly]).order_by(lx, ly.desc()), + select(lx, ly).order_by(lx, ly.desc()), [(3, util.u("q1p3")), (5, util.u("q2p2")), (7, util.u("q3p1"))], ) def test_plain_desc(self): table = self.tables.some_table lx = table.c.x.label("lx") - self._assert_result( - select([lx]).order_by(lx.desc()), [(3,), (2,), (1,)] - ) + self._assert_result(select(lx).order_by(lx.desc()), [(3,), (2,), (1,)]) def test_composed_int_desc(self): table = self.tables.some_table lx = (table.c.x + table.c.y).label("lx") - self._assert_result( - select([lx]).order_by(lx.desc()), [(7,), (5,), (3,)] - ) + self._assert_result(select(lx).order_by(lx.desc()), [(7,), (5,), (3,)]) @testing.requires.group_by_complex_expression def test_group_by_composed(self): table = self.tables.some_table expr = (table.c.x + table.c.y).label("lx") stmt = ( - select([func.count(table.c.id), expr]) - .group_by(expr) - .order_by(expr) + select(func.count(table.c.id), expr).group_by(expr).order_by(expr) ) self._assert_result(stmt, [(1, 3), (1, 5), (1, 7)]) @@ -193,7 +187,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_simple_limit(self): table = self.tables.some_table self._assert_result( - select([table]).order_by(table.c.id).limit(2), + select(table).order_by(table.c.id).limit(2), [(1, 1, 2), (2, 2, 3)], ) @@ -201,7 +195,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_simple_offset(self): table = self.tables.some_table self._assert_result( - select([table]).order_by(table.c.id).offset(2), + select(table).order_by(table.c.id).offset(2), [(3, 3, 4), (4, 4, 5)], ) @@ -209,7 +203,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_simple_limit_offset(self): table = self.tables.some_table self._assert_result( - select([table]).order_by(table.c.id).limit(2).offset(1), + select(table).order_by(table.c.id).limit(2).offset(1), [(2, 2, 3), (3, 3, 4)], ) @@ -218,7 +212,7 @@ class LimitOffsetTest(fixtures.TablesTest): """test that 'literal binds' mode works - no bound params.""" table = self.tables.some_table - stmt = select([table]).order_by(table.c.id).limit(2).offset(1) + stmt = select(table).order_by(table.c.id).limit(2).offset(1) sql = stmt.compile( dialect=config.db.dialect, compile_kwargs={"literal_binds": True} ) @@ -230,7 +224,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_bound_limit(self): table = self.tables.some_table self._assert_result( - select([table]).order_by(table.c.id).limit(bindparam("l")), + select(table).order_by(table.c.id).limit(bindparam("l")), [(1, 1, 2), (2, 2, 3)], params={"l": 2}, ) @@ -239,7 +233,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_bound_offset(self): table = self.tables.some_table self._assert_result( - select([table]).order_by(table.c.id).offset(bindparam("o")), + select(table).order_by(table.c.id).offset(bindparam("o")), [(3, 3, 4), (4, 4, 5)], params={"o": 2}, ) @@ -248,7 +242,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_bound_limit_offset(self): table = self.tables.some_table self._assert_result( - select([table]) + select(table) .order_by(table.c.id) .limit(bindparam("l")) .offset(bindparam("o")), @@ -260,7 +254,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_expr_offset(self): table = self.tables.some_table self._assert_result( - select([table]) + select(table) .order_by(table.c.id) .offset(literal_column("1") + literal_column("2")), [(4, 4, 5)], @@ -270,7 +264,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_expr_limit(self): table = self.tables.some_table self._assert_result( - select([table]) + select(table) .order_by(table.c.id) .limit(literal_column("1") + literal_column("2")), [(1, 1, 2), (2, 2, 3), (3, 3, 4)], @@ -280,7 +274,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_expr_limit_offset(self): table = self.tables.some_table self._assert_result( - select([table]) + select(table) .order_by(table.c.id) .limit(literal_column("1") + literal_column("1")) .offset(literal_column("1") + literal_column("1")), @@ -291,7 +285,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_simple_limit_expr_offset(self): table = self.tables.some_table self._assert_result( - select([table]) + select(table) .order_by(table.c.id) .limit(2) .offset(literal_column("1") + literal_column("1")), @@ -302,7 +296,7 @@ class LimitOffsetTest(fixtures.TablesTest): def test_expr_limit_simple_offset(self): table = self.tables.some_table self._assert_result( - select([table]) + select(table) .order_by(table.c.id) .limit(literal_column("1") + literal_column("1")) .offset(2), @@ -347,7 +341,7 @@ class JoinTest(fixtures.TablesTest): def test_inner_join_fk(self): a, b = self.tables("a", "b") - stmt = select([a, b]).select_from(a.join(b)).order_by(a.c.id, b.c.id) + stmt = select(a, b).select_from(a.join(b)).order_by(a.c.id, b.c.id) self._assert_result(stmt, [(1, 1, 1), (1, 2, 1), (2, 4, 2), (3, 5, 3)]) @@ -355,7 +349,7 @@ class JoinTest(fixtures.TablesTest): a, b = self.tables("a", "b") stmt = ( - select([a, b]) + select(a, b) .select_from(a.join(b, true())) .order_by(a.c.id, b.c.id) ) @@ -375,7 +369,7 @@ class JoinTest(fixtures.TablesTest): a, b = self.tables("a", "b") stmt = ( - select([a, b]) + select(a, b) .select_from(a.join(b, false())) .order_by(a.c.id, b.c.id) ) @@ -386,7 +380,7 @@ class JoinTest(fixtures.TablesTest): a, b = self.tables("a", "b") stmt = ( - select([a, b]) + select(a, b) .select_from(a.outerjoin(b, false())) .order_by(a.c.id, b.c.id) ) @@ -405,7 +399,7 @@ class JoinTest(fixtures.TablesTest): def test_outer_join_fk(self): a, b = self.tables("a", "b") - stmt = select([a, b]).select_from(a.join(b)).order_by(a.c.id, b.c.id) + stmt = select(a, b).select_from(a.join(b)).order_by(a.c.id, b.c.id) self._assert_result(stmt, [(1, 1, 1), (1, 2, 1), (2, 4, 2), (3, 5, 3)]) @@ -441,8 +435,8 @@ class CompoundSelectTest(fixtures.TablesTest): def test_plain_union(self): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2) - s2 = select([table]).where(table.c.id == 3) + s1 = select(table).where(table.c.id == 2) + s2 = select(table).where(table.c.id == 3) u1 = union(s1, s2) self._assert_result( @@ -451,8 +445,8 @@ class CompoundSelectTest(fixtures.TablesTest): def test_select_from_plain_union(self): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2) - s2 = select([table]).where(table.c.id == 3) + s1 = select(table).where(table.c.id == 2) + s2 = select(table).where(table.c.id == 3) u1 = union(s1, s2).alias().select() self._assert_result( @@ -463,18 +457,8 @@ class CompoundSelectTest(fixtures.TablesTest): @testing.requires.parens_in_union_contained_select_w_limit_offset def test_limit_offset_selectable_in_unions(self): table = self.tables.some_table - s1 = ( - select([table]) - .where(table.c.id == 2) - .limit(1) - .order_by(table.c.id) - ) - s2 = ( - select([table]) - .where(table.c.id == 3) - .limit(1) - .order_by(table.c.id) - ) + s1 = select(table).where(table.c.id == 2).limit(1).order_by(table.c.id) + s2 = select(table).where(table.c.id == 3).limit(1).order_by(table.c.id) u1 = union(s1, s2).limit(2) self._assert_result( @@ -484,8 +468,8 @@ class CompoundSelectTest(fixtures.TablesTest): @testing.requires.parens_in_union_contained_select_wo_limit_offset def test_order_by_selectable_in_unions(self): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2).order_by(table.c.id) - s2 = select([table]).where(table.c.id == 3).order_by(table.c.id) + s1 = select(table).where(table.c.id == 2).order_by(table.c.id) + s2 = select(table).where(table.c.id == 3).order_by(table.c.id) u1 = union(s1, s2).limit(2) self._assert_result( @@ -494,8 +478,8 @@ class CompoundSelectTest(fixtures.TablesTest): def test_distinct_selectable_in_unions(self): table = self.tables.some_table - s1 = select([table]).where(table.c.id == 2).distinct() - s2 = select([table]).where(table.c.id == 3).distinct() + s1 = select(table).where(table.c.id == 2).distinct() + s2 = select(table).where(table.c.id == 3).distinct() u1 = union(s1, s2).limit(2) self._assert_result( @@ -505,18 +489,8 @@ class CompoundSelectTest(fixtures.TablesTest): @testing.requires.parens_in_union_contained_select_w_limit_offset def test_limit_offset_in_unions_from_alias(self): table = self.tables.some_table - s1 = ( - select([table]) - .where(table.c.id == 2) - .limit(1) - .order_by(table.c.id) - ) - s2 = ( - select([table]) - .where(table.c.id == 3) - .limit(1) - .order_by(table.c.id) - ) + s1 = select(table).where(table.c.id == 2).limit(1).order_by(table.c.id) + s2 = select(table).where(table.c.id == 3).limit(1).order_by(table.c.id) # this necessarily has double parens u1 = union(s1, s2).alias() @@ -527,7 +501,7 @@ class CompoundSelectTest(fixtures.TablesTest): def test_limit_offset_aliased_selectable_in_unions(self): table = self.tables.some_table s1 = ( - select([table]) + select(table) .where(table.c.id == 2) .limit(1) .order_by(table.c.id) @@ -535,7 +509,7 @@ class CompoundSelectTest(fixtures.TablesTest): .select() ) s2 = ( - select([table]) + select(table) .where(table.c.id == 3) .limit(1) .order_by(table.c.id) @@ -582,7 +556,7 @@ class PostCompileParamsTest( def test_compile(self): table = self.tables.some_table - stmt = select([table.c.id]).where( + stmt = select(table.c.id).where( table.c.x == bindparam("q", literal_execute=True) ) @@ -596,7 +570,7 @@ class PostCompileParamsTest( def test_compile_literal_binds(self): table = self.tables.some_table - stmt = select([table.c.id]).where( + stmt = select(table.c.id).where( table.c.x == bindparam("q", 10, literal_execute=True) ) @@ -610,7 +584,7 @@ class PostCompileParamsTest( def test_execute(self): table = self.tables.some_table - stmt = select([table.c.id]).where( + stmt = select(table.c.id).where( table.c.x == bindparam("q", literal_execute=True) ) @@ -629,7 +603,7 @@ class PostCompileParamsTest( def test_execute_expanding_plus_literal_execute(self): table = self.tables.some_table - stmt = select([table.c.id]).where( + stmt = select(table.c.id).where( table.c.x.in_(bindparam("q", expanding=True, literal_execute=True)) ) @@ -649,7 +623,7 @@ class PostCompileParamsTest( def test_execute_tuple_expanding_plus_literal_execute(self): table = self.tables.some_table - stmt = select([table.c.id]).where( + stmt = select(table.c.id).where( tuple_(table.c.x, table.c.y).in_( bindparam("q", expanding=True, literal_execute=True) ) @@ -673,7 +647,7 @@ class PostCompileParamsTest( def test_execute_tuple_expanding_plus_literal_heterogeneous_execute(self): table = self.tables.some_table - stmt = select([table.c.id]).where( + stmt = select(table.c.id).where( tuple_(table.c.x, table.c.z).in_( bindparam("q", expanding=True, literal_execute=True) ) @@ -730,7 +704,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where(table.c.x.in_(bindparam("q", expanding=True))) .where(table.c.y.in_(bindparam("p", expanding=True))) .order_by(table.c.id) @@ -743,7 +717,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where( tuple_(table.c.x, table.c.z).in_( bindparam("q", expanding=True) @@ -759,7 +733,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where( tuple_(table.c.x, table.c.y).in_( bindparam("q", expanding=True) @@ -774,7 +748,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where(table.c.x.in_(bindparam("q", expanding=True))) .order_by(table.c.id) ) @@ -786,7 +760,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where( tuple_(table.c.x, table.c.y).in_( bindparam("q", expanding=True) @@ -804,7 +778,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where( tuple_(table.c.x, table.c.z).in_( bindparam("q", expanding=True) @@ -835,7 +809,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where(table.c.x.in_(bindparam("q", expanding=True))) .order_by(table.c.id) ) @@ -846,7 +820,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where(table.c.x.notin_(bindparam("q", expanding=True))) .order_by(table.c.id) ) @@ -857,7 +831,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where(table.c.z.in_(bindparam("q", expanding=True))) .order_by(table.c.id) ) @@ -868,7 +842,7 @@ class ExpandingBoundInTest(fixtures.TablesTest): table = self.tables.some_table stmt = ( - select([table.c.id]) + select(table.c.id) .where(table.c.z.notin_(bindparam("q", expanding=True))) .order_by(table.c.id) ) @@ -877,19 +851,15 @@ class ExpandingBoundInTest(fixtures.TablesTest): def test_null_in_empty_set_is_false(self, connection): stmt = select( - [ - case( - [ - ( - null().in_( - bindparam("foo", value=(), expanding=True) - ), - true(), - ) - ], - else_=false(), - ) - ] + case( + [ + ( + null().in_(bindparam("foo", value=(), expanding=True)), + true(), + ) + ], + else_=false(), + ) ) in_(connection.execute(stmt).fetchone()[0], (False, 0)) @@ -933,9 +903,7 @@ class LikeFunctionsTest(fixtures.TablesTest): with config.db.connect() as conn: rows = { value - for value, in conn.execute( - select([some_table.c.id]).where(expr) - ) + for value, in conn.execute(select(some_table.c.id).where(expr)) } eq_(rows, expected) @@ -1047,7 +1015,7 @@ class ComputedColumnTest(fixtures.TablesTest): def test_select_all(self): with config.db.connect() as conn: res = conn.execute( - select([text("*")]) + select(text("*")) .select_from(self.tables.square) .order_by(self.tables.square.c.id) ).fetchall() @@ -1057,7 +1025,7 @@ class ComputedColumnTest(fixtures.TablesTest): with config.db.connect() as conn: res = conn.execute( select( - [self.tables.square.c.area, self.tables.square.c.perimeter] + self.tables.square.c.area, self.tables.square.c.perimeter ) .select_from(self.tables.square) .order_by(self.tables.square.c.id) @@ -1110,14 +1078,14 @@ class IdentityColumnTest(fixtures.TablesTest): def test_select_all(self, connection): res = connection.execute( - select([text("*")]) + select(text("*")) .select_from(self.tables.tbl_a) .order_by(self.tables.tbl_a.c.id) ).fetchall() eq_(res, [(42, "a"), (43, "b")]) res = connection.execute( - select([text("*")]) + select(text("*")) .select_from(self.tables.tbl_b) .order_by(self.tables.tbl_b.c.id) ).fetchall() @@ -1126,7 +1094,7 @@ class IdentityColumnTest(fixtures.TablesTest): def test_select_columns(self, connection): res = connection.execute( - select([self.tables.tbl_a.c.id]).order_by(self.tables.tbl_a.c.id) + select(self.tables.tbl_a.c.id).order_by(self.tables.tbl_a.c.id) ).fetchall() eq_(res, [(42,), (43,)]) @@ -1192,7 +1160,7 @@ class DistinctOnTest(AssertsCompiledSQL, fixtures.TablesTest): @testing.fails_if(testing.requires.supports_distinct_on) def test_distinct_on(self): - stm = select(["*"]).distinct(column("q")).select_from(table("foo")) + stm = select("*").distinct(column("q")).select_from(table("foo")) with testing.expect_deprecated( "DISTINCT ON is currently supported only by the PostgreSQL " ): diff --git a/test/aaa_profiling/test_compiler.py b/test/aaa_profiling/test_compiler.py index 4204eac452..0202768ae4 100644 --- a/test/aaa_profiling/test_compiler.py +++ b/test/aaa_profiling/test_compiler.py @@ -74,12 +74,12 @@ class CompileTest(fixtures.TestBase, AssertsExecutionResults): def test_select(self): # give some of the cached type values # a chance to warm up - s = select([t1], t1.c.c2 == t2.c.c1) + s = select(t1).where(t1.c.c2 == t2.c.c1) s.compile(dialect=self.dialect) @profiling.function_call_count(variance=0.15, warmup=1) def go(): - s = select([t1], t1.c.c2 == t2.c.c1) + s = select(t1).where(t1.c.c2 == t2.c.c1) s.compile(dialect=self.dialect) go() @@ -87,12 +87,12 @@ class CompileTest(fixtures.TestBase, AssertsExecutionResults): def test_select_labels(self): # give some of the cached type values # a chance to warm up - s = select([t1], t1.c.c2 == t2.c.c1).apply_labels() + s = select(t1).where(t1.c.c2 == t2.c.c1).apply_labels() s.compile(dialect=self.dialect) @profiling.function_call_count(variance=0.15, warmup=1) def go(): - s = select([t1], t1.c.c2 == t2.c.c1).apply_labels() + s = select(t1).where(t1.c.c2 == t2.c.c1).apply_labels() s.compile(dialect=self.dialect) go() diff --git a/test/aaa_profiling/test_misc.py b/test/aaa_profiling/test_misc.py index 585d6d5b1b..db6fd4b718 100644 --- a/test/aaa_profiling/test_misc.py +++ b/test/aaa_profiling/test_misc.py @@ -99,7 +99,7 @@ class CacheKeyTest(fixtures.TestBase): return [ ( - select([Parent.id, Child.id]) + select(Parent.id, Child.id) .select_from(ormjoin(Parent, Child, Parent.children)) .where(Child.id == 5) ) diff --git a/test/dialect/mssql/test_compiler.py b/test/dialect/mssql/test_compiler.py index 67120e8fe0..04580b8fbc 100644 --- a/test/dialect/mssql/test_compiler.py +++ b/test/dialect/mssql/test_compiler.py @@ -396,10 +396,10 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): column("description", String), ) - q = select([table1.c.myid], order_by=[table1.c.myid]).alias("foo") + q = select(table1.c.myid).order_by(table1.c.myid).alias("foo") crit = q.c.myid == table1.c.myid self.assert_compile( - select(["*"], crit), + select("*").where(crit), "SELECT * FROM (SELECT mytable.myid AS " "myid FROM mytable) AS foo, mytable WHERE " "foo.myid = mytable.myid", @@ -417,13 +417,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) q = ( - select([table1.c.myid], order_by=[table1.c.myid]) + select(table1.c.myid) + .order_by(table1.c.myid) .limit(10) .alias("foo") ) crit = q.c.myid == table1.c.myid self.assert_compile( - select(["*"], crit), + select("*").where(crit), "SELECT * FROM (SELECT TOP [POSTCOMPILE_param_1] mytable.myid AS " "myid FROM mytable ORDER BY mytable.myid) AS foo, mytable WHERE " "foo.myid = mytable.myid", @@ -441,13 +442,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) q = ( - select([table1.c.myid], order_by=[table1.c.myid]) + select(table1.c.myid) + .order_by(table1.c.myid) .offset(10) .alias("foo") ) crit = q.c.myid == table1.c.myid self.assert_compile( - select(["*"], crit), + select("*").where(crit), "SELECT * FROM (SELECT anon_1.myid AS myid FROM " "(SELECT mytable.myid AS myid, ROW_NUMBER() OVER (ORDER BY " "mytable.myid) AS mssql_rn FROM mytable) AS anon_1 " @@ -467,7 +469,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) q = ( - select([table1.c.myid], order_by=[table1.c.myid]) + select(table1.c.myid) + .order_by(table1.c.myid) .offset(10) .alias("foo") ) @@ -475,7 +478,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): dialect = mssql.dialect() dialect._supports_offset_fetch = True self.assert_compile( - select(["*"], crit), + select("*").where(crit), "SELECT * FROM (SELECT mytable.myid AS myid FROM mytable " "ORDER BY mytable.myid OFFSET :param_1 ROWS) AS foo, " "mytable WHERE foo.myid = mytable.myid", @@ -494,7 +497,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ) q = ( - select([table1.c.myid], order_by=[table1.c.myid]) + select(table1.c.myid) + .order_by(table1.c.myid) .limit(10) .offset(10) .alias("foo") @@ -503,7 +507,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): dialect = mssql.dialect() dialect._supports_offset_fetch = True self.assert_compile( - select(["*"], crit), + select("*").where(crit), "SELECT * FROM (SELECT mytable.myid AS myid FROM mytable " "ORDER BY mytable.myid OFFSET :param_1 ROWS " "FETCH NEXT :param_2 ROWS ONLY ) AS foo, " @@ -522,16 +526,17 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): column("description", String), ) - q = select( - [table1.c.myid, sql.literal("bar").label("c1")], - order_by=[table1.c.name + "-"], - ).alias("foo") + q = ( + select(table1.c.myid, sql.literal("bar").label("c1")) + .order_by(table1.c.name + "-") + .alias("foo") + ) crit = q.c.myid == table1.c.myid dialect = mssql.dialect() dialect.paramstyle = "qmark" dialect.positional = True self.assert_compile( - select(["*"], crit), + select("*").where(crit), "SELECT * FROM (SELECT mytable.myid AS " "myid, ? AS c1 FROM mytable) AS foo, mytable WHERE " "foo.myid = mytable.myid", @@ -753,12 +758,10 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): column("col4"), ) 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"]), ), ) diff --git a/test/dialect/mssql/test_deprecations.py b/test/dialect/mssql/test_deprecations.py index c0df266b1d..8c2b80a56b 100644 --- a/test/dialect/mssql/test_deprecations.py +++ b/test/dialect/mssql/test_deprecations.py @@ -144,7 +144,7 @@ class LegacySchemaAliasingTest(fixtures.TestBase, AssertsCompiledSQL): def test_column_subquery_to_alias(self): a1 = self.t2.alias("a1") - s = select([self.t2, select(a1.c.a).scalar_subquery()]) + s = select(self.t2, select(a1.c.a).scalar_subquery()) self._assert_sql( s, "SELECT t2_1.a, t2_1.b, t2_1.c, " diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py index cca6a27ded..80fc65a0b3 100644 --- a/test/dialect/mysql/test_compiler.py +++ b/test/dialect/mysql/test_compiler.py @@ -425,12 +425,13 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL): dialect = self.__dialect__ def gen(distinct=None, prefixes=None): - kw = {} - if distinct is not None: - kw["distinct"] = distinct + stmt = select(column("q")) + if distinct: + stmt = stmt.distinct() if prefixes is not None: - kw["prefixes"] = prefixes - return str(select([column("q")], **kw).compile(dialect=dialect)) + stmt = stmt.prefix_with(*prefixes) + + return str(stmt.compile(dialect=dialect)) eq_(gen(None), "SELECT q") eq_(gen(True), "SELECT DISTINCT q") diff --git a/test/dialect/mysql/test_query.py b/test/dialect/mysql/test_query.py index a8b80d91cd..15875dd542 100644 --- a/test/dialect/mysql/test_query.py +++ b/test/dialect/mysql/test_query.py @@ -262,6 +262,6 @@ class AnyAllTest(fixtures.TablesTest): def test_any_literal(self, connection): stuff = self.tables.stuff - stmt = select([4 == any_(select(stuff.c.value).scalar_subquery())]) + stmt = select(4 == any_(select(stuff.c.value).scalar_subquery())) is_(connection.execute(stmt).scalar(), True) diff --git a/test/dialect/oracle/test_compiler.py b/test/dialect/oracle/test_compiler.py index 8bfaded8fe..cea2b51419 100644 --- a/test/dialect/oracle/test_compiler.py +++ b/test/dialect/oracle/test_compiler.py @@ -745,17 +745,19 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def test_outer_join_one(self): table1, table2, table3 = self._test_outer_join_fixture() - query = select( - [table1, table2], - or_( - table1.c.name == "fred", - table1.c.myid == 10, - table2.c.othername != "jack", - text("EXISTS (select yay from foo where boo = lar)"), - ), - from_obj=[ + query = ( + select(table1, table2) + .where( + or_( + table1.c.name == "fred", + table1.c.myid == 10, + table2.c.othername != "jack", + text("EXISTS (select yay from foo where boo = lar)"), + ) + ) + .select_from( outerjoin(table1, table2, table1.c.myid == table2.c.otherid) - ], + ) ) self.assert_compile( query, diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 556601fc62..ddf03daf12 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1646,7 +1646,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): series = func.generate_series(1, 100).alias("series") series_col = column("series") query = select( - [func.array_agg(series_col).filter(series_col % 2 == 0)[3]] + func.array_agg(series_col).filter(series_col % 2 == 0)[3] ).select_from(series) self.assert_compile( query, @@ -2143,22 +2143,22 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL): def test_plain_inline(self): self.assert_compile( - select([self.table], distinct=True), + select(self.table).distinct(), "SELECT DISTINCT t.id, t.a, t.b FROM t", ) def test_on_columns_inline_list(self): self.assert_compile( - select( - [self.table], distinct=[self.table.c.a, self.table.c.b] - ).order_by(self.table.c.a, self.table.c.b), + select(self.table) + .distinct(self.table.c.a, self.table.c.b) + .order_by(self.table.c.a, self.table.c.b), "SELECT DISTINCT ON (t.a, t.b) t.id, " "t.a, t.b FROM t ORDER BY t.a, t.b", ) def test_on_columns_inline_scalar(self): self.assert_compile( - select([self.table], distinct=self.table.c.a), + select(self.table).distinct(self.table.c.a), "SELECT DISTINCT ON (t.a) t.id, t.a, t.b FROM t", ) diff --git a/test/dialect/postgresql/test_query.py b/test/dialect/postgresql/test_query.py index eb96eaabb1..eec6eed4a9 100644 --- a/test/dialect/postgresql/test_query.py +++ b/test/dialect/postgresql/test_query.py @@ -863,21 +863,19 @@ class TupleTest(fixtures.TestBase): eq_( connection.execute( select( - [ - tuple_( - literal_column("'a'"), literal_column("'b'") - ).in_( - [ - tuple_( - *[ - literal_column("'%s'" % letter) - for letter in elem - ] - ) - for elem in test - ] - ) - ] + tuple_( + literal_column("'a'"), literal_column("'b'") + ).in_( + [ + tuple_( + *[ + literal_column("'%s'" % letter) + for letter in elem + ] + ) + for elem in test + ] + ) ) ).scalar(), exp, diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 8ec848bb53..2d1fd4ee89 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -991,7 +991,7 @@ class TimezoneTest(fixtures.TestBase): assert somedate.tzinfo connection.execute(tztable.insert(), id=1, name="row1", date=somedate) row = connection.execute( - select([tztable.c.date], tztable.c.id == 1) + select(tztable.c.date).where(tztable.c.id == 1) ).first() eq_(row[0], somedate) eq_( @@ -1015,7 +1015,7 @@ class TimezoneTest(fixtures.TestBase): notztable.insert(), id=1, name="row1", date=somedate ) row = connection.execute( - select([notztable.c.date], notztable.c.id == 1) + select(notztable.c.date).where(notztable.c.id == 1) ).first() eq_(row[0], somedate) eq_(row[0].tzinfo, None) @@ -1171,7 +1171,7 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): def test_array_int_index(self): col = column("x", postgresql.ARRAY(Integer)) self.assert_compile( - select([col[3]]), + select(col[3]), "SELECT x[%(x_1)s] AS anon_1", checkparams={"x_1": 3}, ) @@ -1195,7 +1195,7 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): def test_array_contains(self): col = column("x", postgresql.ARRAY(Integer)) self.assert_compile( - select([col.contains(array([4, 5, 6]))]), + select(col.contains(array([4, 5, 6]))), "SELECT x @> ARRAY[%(param_1)s, %(param_2)s, %(param_3)s] " "AS anon_1", checkparams={"param_1": 4, "param_3": 6, "param_2": 5}, @@ -1213,7 +1213,7 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): def test_array_contained_by(self): col = column("x", postgresql.ARRAY(Integer)) self.assert_compile( - select([col.contained_by(array([4, 5, 6]))]), + select(col.contained_by(array([4, 5, 6]))), "SELECT x <@ ARRAY[%(param_1)s, %(param_2)s, %(param_3)s] " "AS anon_1", checkparams={"param_1": 4, "param_3": 6, "param_2": 5}, @@ -1222,7 +1222,7 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): def test_array_overlap(self): col = column("x", postgresql.ARRAY(Integer)) self.assert_compile( - select([col.overlap(array([4, 5, 6]))]), + select(col.overlap(array([4, 5, 6]))), "SELECT x && ARRAY[%(param_1)s, %(param_2)s, %(param_3)s] " "AS anon_1", checkparams={"param_1": 4, "param_3": 6, "param_2": 5}, @@ -1231,7 +1231,7 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): def test_array_slice_index(self): col = column("x", postgresql.ARRAY(Integer)) self.assert_compile( - select([col[5:10]]), + select(col[5:10]), "SELECT x[%(x_1)s:%(x_2)s] AS anon_1", checkparams={"x_2": 10, "x_1": 5}, ) @@ -1239,7 +1239,7 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): def test_array_dim_index(self): col = column("x", postgresql.ARRAY(Integer, dimensions=2)) self.assert_compile( - select([col[3][5]]), + select(col[3][5]), "SELECT x[%(x_1)s][%(param_1)s] AS anon_1", checkparams={"x_1": 3, "param_1": 5}, ) @@ -1298,13 +1298,11 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): """ stmt = select( - [ - func.array_cat( - array([1, 2, 3]), - array([4, 5, 6]), - type_=postgresql.ARRAY(Integer), - )[2:5] - ] + func.array_cat( + array([1, 2, 3]), + array([4, 5, 6]), + type_=postgresql.ARRAY(Integer), + )[2:5] ) self.assert_compile( stmt, @@ -1412,53 +1410,47 @@ class ArrayRoundTripTest(object): stmt = select(func.array_agg(values_table.c.value)) eq_(connection.execute(stmt).scalar(), list(range(1, 10))) - stmt = select([func.array_agg(values_table.c.value)[3]]) + stmt = select(func.array_agg(values_table.c.value)[3]) eq_(connection.execute(stmt).scalar(), 3) - stmt = select([func.array_agg(values_table.c.value)[2:4]]) + stmt = select(func.array_agg(values_table.c.value)[2:4]) eq_(connection.execute(stmt).scalar(), [2, 3, 4]) def test_array_index_slice_exprs(self, connection): """test a variety of expressions that sometimes need parenthesizing""" - stmt = select([array([1, 2, 3, 4])[2:3]]) + stmt = select(array([1, 2, 3, 4])[2:3]) eq_(connection.execute(stmt).scalar(), [2, 3]) - stmt = select([array([1, 2, 3, 4])[2]]) + stmt = select(array([1, 2, 3, 4])[2]) eq_(connection.execute(stmt).scalar(), 2) - stmt = select([(array([1, 2]) + array([3, 4]))[2:3]]) + stmt = select((array([1, 2]) + array([3, 4]))[2:3]) eq_(connection.execute(stmt).scalar(), [2, 3]) - stmt = select([array([1, 2]) + array([3, 4])[2:3]]) + stmt = select(array([1, 2]) + array([3, 4])[2:3]) eq_(connection.execute(stmt).scalar(), [1, 2, 4]) - stmt = select([array([1, 2])[2:3] + array([3, 4])]) + stmt = select(array([1, 2])[2:3] + array([3, 4])) eq_(connection.execute(stmt).scalar(), [2, 3, 4]) stmt = select( - [ - func.array_cat( - array([1, 2, 3]), - array([4, 5, 6]), - type_=self.ARRAY(Integer), - )[2:5] - ] + func.array_cat( + array([1, 2, 3]), array([4, 5, 6]), type_=self.ARRAY(Integer), + )[2:5] ) eq_(connection.execute(stmt).scalar(), [2, 3, 4, 5]) def test_any_all_exprs_array(self, connection): stmt = select( - [ - 3 - == any_( - func.array_cat( - array([1, 2, 3]), - array([4, 5, 6]), - type_=self.ARRAY(Integer), - ) + 3 + == any_( + func.array_cat( + array([1, 2, 3]), + array([4, 5, 6]), + type_=self.ARRAY(Integer), ) - ] + ) ) eq_(connection.execute(stmt).scalar(), True) @@ -1510,7 +1502,7 @@ class ArrayRoundTripTest(object): strarr=[util.u("abc"), util.u("def")], ) results = connection.execute( - select([arrtable.c.intarr + [4, 5, 6]]) + select(arrtable.c.intarr + [4, 5, 6]) ).fetchall() eq_(len(results), 1) eq_(results[0][0], [1, 2, 3, 4, 5, 6]) @@ -1554,9 +1546,7 @@ class ArrayRoundTripTest(object): def test_array_literal_roundtrip(self, connection): eq_( connection.scalar( - select( - [postgresql.array([1, 2]) + postgresql.array([3, 4, 5])] - ) + select(postgresql.array([1, 2]) + postgresql.array([3, 4, 5])) ), [1, 2, 3, 4, 5], ) @@ -1564,12 +1554,7 @@ class ArrayRoundTripTest(object): eq_( connection.scalar( select( - [ - ( - postgresql.array([1, 2]) - + postgresql.array([3, 4, 5]) - )[3] - ] + (postgresql.array([1, 2]) + postgresql.array([3, 4, 5]))[3] ) ), 3, @@ -1578,11 +1563,8 @@ class ArrayRoundTripTest(object): eq_( connection.scalar( select( - [ - ( - postgresql.array([1, 2]) - + postgresql.array([3, 4, 5]) - )[2:4] + (postgresql.array([1, 2]) + postgresql.array([3, 4, 5]))[ + 2:4 ] ) ), @@ -1593,14 +1575,9 @@ class ArrayRoundTripTest(object): eq_( connection.scalar( select( - [ - postgresql.array( - [ - postgresql.array([1, 2]), - postgresql.array([3, 4]), - ] - ) - ] + postgresql.array( + [postgresql.array([1, 2]), postgresql.array([3, 4])] + ) ) ), [[1, 2], [3, 4]], @@ -1609,14 +1586,9 @@ class ArrayRoundTripTest(object): eq_( connection.scalar( select( - [ - postgresql.array( - [ - postgresql.array([1, 2]), - postgresql.array([3, 4]), - ] - )[2][1] - ] + postgresql.array( + [postgresql.array([1, 2]), postgresql.array([3, 4])] + )[2][1] ) ), 3, @@ -1624,16 +1596,16 @@ class ArrayRoundTripTest(object): def test_array_literal_compare(self, connection): eq_( - connection.scalar(select([postgresql.array([1, 2]) < [3, 4, 5]])), + connection.scalar(select(postgresql.array([1, 2]) < [3, 4, 5])), True, ) def test_array_getitem_single_exec(self, connection): arrtable = self.tables.arrtable self._fixture_456(arrtable) - eq_(connection.scalar(select([arrtable.c.intarr[2]])), 5) + eq_(connection.scalar(select(arrtable.c.intarr[2])), 5) connection.execute(arrtable.update().values({arrtable.c.intarr[2]: 7})) - eq_(connection.scalar(select([arrtable.c.intarr[2]])), 7) + eq_(connection.scalar(select(arrtable.c.intarr[2])), 7) def test_array_getitem_slice_exec(self, connection): arrtable = self.tables.arrtable @@ -1642,11 +1614,11 @@ class ArrayRoundTripTest(object): intarr=[4, 5, 6], strarr=[util.u("abc"), util.u("def")], ) - eq_(connection.scalar(select([arrtable.c.intarr[2:3]])), [5, 6]) + eq_(connection.scalar(select(arrtable.c.intarr[2:3])), [5, 6]) connection.execute( arrtable.update().values({arrtable.c.intarr[2:3]: [7, 8]}) ) - eq_(connection.scalar(select([arrtable.c.intarr[2:3]])), [7, 8]) + eq_(connection.scalar(select(arrtable.c.intarr[2:3])), [7, 8]) def test_multi_dim_roundtrip(self, connection): arrtable = self.tables.arrtable @@ -1791,7 +1763,7 @@ class PGArrayRoundTripTest( connection.execute(arrtable.insert(), intarr=[6, 5, 4]) eq_( connection.scalar( - select([arrtable.c.intarr.contained_by([4, 5, 6, 7])]) + select(arrtable.c.intarr.contained_by([4, 5, 6, 7])) ), True, ) @@ -2591,12 +2563,10 @@ class HStoreRoundTripTest(fixtures.TablesTest): def _test_fixed_round_trip(self, engine): with engine.begin() as conn: s = select( - [ - hstore( - array(["key1", "key2", "key3"]), - array(["value1", "value2", "value3"]), - ) - ] + hstore( + array(["key1", "key2", "key3"]), + array(["value1", "value2", "value3"]), + ) ) eq_( conn.scalar(s), @@ -2615,24 +2585,14 @@ class HStoreRoundTripTest(fixtures.TablesTest): def _test_unicode_round_trip(self, engine): with engine.begin() as conn: s = select( - [ - hstore( - array( - [ - util.u("réveillé"), - util.u("drôle"), - util.u("S’il"), - ] - ), - array( - [ - util.u("réveillé"), - util.u("drôle"), - util.u("S’il"), - ] - ), - ) - ] + hstore( + array( + [util.u("réveillé"), util.u("drôle"), util.u("S’il")] + ), + array( + [util.u("réveillé"), util.u("drôle"), util.u("S’il")] + ), + ) ) eq_( conn.scalar(s), @@ -3303,7 +3263,7 @@ class JSONRoundTripTest(fixtures.TablesTest): self._fixture_data(engine) data_table = self.tables.data_table result = connection.execute( - select([data_table.c.data["k1"].astext]) + select(data_table.c.data["k1"].astext) ).first() if engine.dialect.returns_unicode_strings: assert isinstance(result[0], util.text_type) @@ -3315,7 +3275,7 @@ class JSONRoundTripTest(fixtures.TablesTest): self._fixture_data(engine) data_table = self.tables.data_table result = connection.execute( - select([data_table.c.data["k3"].astext.cast(Integer)]).where( + select(data_table.c.data["k3"].astext.cast(Integer)).where( data_table.c.name == "r5" ) ).first() diff --git a/test/dialect/test_firebird.py b/test/dialect/test_firebird.py index 18bf998750..be5cc1856b 100644 --- a/test/dialect/test_firebird.py +++ b/test/dialect/test_firebird.py @@ -515,8 +515,8 @@ class MiscTest(fixtures.TestBase): metadata.create_all() t.insert(values=dict(name="dante")).execute() t.insert(values=dict(name="alighieri")).execute() - select( - [func.count(t.c.id)], func.length(t.c.name) == 5 + select(func.count(t.c.id)).where( + func.length(t.c.name) == 5 ).execute().first()[0] == 1 def test_version_parsing(self): diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index cb418e99d6..339a7c479e 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -332,9 +332,7 @@ class JSONTest(fixtures.TestBase): with testing.db.connect() as conn: conn.execute(sqlite_json.insert(), foo=value) - eq_( - conn.scalar(select([sqlite_json.c.foo["json"]])), value["json"] - ) + eq_(conn.scalar(select(sqlite_json.c.foo["json"])), value["json"]) @testing.provide_metadata def test_deprecated_serializer_args(self): diff --git a/test/engine/test_deprecations.py b/test/engine/test_deprecations.py index d733bd6a79..c2a98726f1 100644 --- a/test/engine/test_deprecations.py +++ b/test/engine/test_deprecations.py @@ -112,7 +112,7 @@ class ConnectionlessDeprecationTest(fixtures.TestBase): ): testing.db.execute(stmt) - stmt = select([table]) + stmt = select(table) with testing.expect_deprecated_20( r"The Engine.execute\(\) function/method is considered legacy", ): @@ -129,7 +129,7 @@ class ConnectionlessDeprecationTest(fixtures.TestBase): ): stmt.execute() - stmt = select([table]) + stmt = select(table) with testing.expect_deprecated_20( r"The Executable.execute\(\) function/method is considered legacy", ): @@ -342,7 +342,7 @@ class PoolTestBase(fixtures.TestBase): def select1(db): - return str(select([1]).compile(dialect=db.dialect)) + return str(select(1).compile(dialect=db.dialect)) class DeprecatedEngineFeatureTest(fixtures.TablesTest): @@ -947,7 +947,7 @@ class EngineEventsTest(fixtures.TestBase): r"The argument signature for the " r"\"ConnectionEvents.before_execute\" event listener", ): - engine.execute(select([1])) + engine.execute(select(1)) eq_(canary, ["execute", "cursor_execute"]) def test_argument_format_execute(self): @@ -969,4 +969,4 @@ class EngineEventsTest(fixtures.TestBase): r"The argument signature for the " r"\"ConnectionEvents.after_execute\" event listener", ): - e1.execute(select([1])) + e1.execute(select(1)) diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index aec05130f4..fdab1e8da6 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1425,7 +1425,7 @@ class EngineEventsTest(fixtures.TestBase): m1 = Mock() def select1(db): - return str(select([1]).compile(dialect=db.dialect)) + return str(select(1).compile(dialect=db.dialect)) with testing.db.connect() as conn: event.listen(conn, "before_execute", m1.before_execute) diff --git a/test/engine/test_logging.py b/test/engine/test_logging.py index 624fa90053..0f0c08df4e 100644 --- a/test/engine/test_logging.py +++ b/test/engine/test_logging.py @@ -308,7 +308,7 @@ class LogParamsTest(fixtures.TestBase): r"foo.data = \? OR foo.data = \?\]\n" r"\[SQL parameters hidden due to hide_parameters=True\]", conn.execute, - select([foo]).where( + select(foo).where( or_( foo.c.data == bindparam("the_data_1"), foo.c.data == bindparam("the_data_2"), @@ -492,7 +492,7 @@ class LoggingNameTest(fixtures.TestBase): __requires__ = ("ad_hoc_engines",) def _assert_names_in_execute(self, eng, eng_name, pool_name): - eng.execute(select([1])) + eng.execute(select(1)) assert self.buf.buffer for name in [b.name for b in self.buf.buffer]: assert name in ( @@ -502,7 +502,7 @@ class LoggingNameTest(fixtures.TestBase): ) def _assert_no_name_in_execute(self, eng): - eng.execute(select([1])) + eng.execute(select(1)) assert self.buf.buffer for name in [b.name for b in self.buf.buffer]: assert name in ( @@ -545,7 +545,7 @@ class LoggingNameTest(fixtures.TestBase): def test_named_logger_names_after_dispose(self): eng = self._named_engine() - eng.execute(select([1])) + eng.execute(select(1)) eng.dispose() eq_(eng.logging_name, "myenginename") eq_(eng.pool.logging_name, "mypoolname") @@ -565,7 +565,7 @@ class LoggingNameTest(fixtures.TestBase): def test_named_logger_execute_after_dispose(self): eng = self._named_engine() - eng.execute(select([1])) + eng.execute(select(1)) eng.dispose() self._assert_names_in_execute(eng, "myenginename", "mypoolname") @@ -596,7 +596,7 @@ class EchoTest(fixtures.TestBase): # do an initial execute to clear out 'first connect' # messages - e.execute(select([10])).close() + e.execute(select(10)).close() self.buf.flush() return e @@ -634,16 +634,16 @@ class EchoTest(fixtures.TestBase): e2 = self._testing_engine() e1.echo = True - e1.execute(select([1])).close() - e2.execute(select([2])).close() + e1.execute(select(1)).close() + e2.execute(select(2)).close() e1.echo = False - e1.execute(select([3])).close() - e2.execute(select([4])).close() + e1.execute(select(3)).close() + e2.execute(select(4)).close() e2.echo = True - e1.execute(select([5])).close() - e2.execute(select([6])).close() + e1.execute(select(5)).close() + e2.execute(select(6)).close() assert self.buf.buffer[0].getMessage().startswith("SELECT 1") assert self.buf.buffer[2].getMessage().startswith("SELECT 6") diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index 92d1d1d33e..6f5093b06a 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -598,7 +598,7 @@ class PoolEventsTest(PoolTestBase): event.listen(engine, "connect", listen_three) event.listen(engine.__class__, "connect", listen_four) - engine.execute(select([1])).close() + engine.execute(select(1)).close() eq_( canary, ["listen_one", "listen_four", "listen_two", "listen_three"] ) diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 77f70b0242..cf984c6580 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -913,7 +913,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): autoload_with=testing.db, ) u2 = Table("users", meta2, autoload_with=testing.db) - s = sa.select([a2]).subquery() + s = sa.select(a2).subquery() assert s.c.user_id is not None assert len(a2.foreign_keys) == 1 @@ -938,7 +938,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): Column("user_id", sa.Integer, sa.ForeignKey("users.id")), autoload_with=testing.db, ) - s = sa.select([a2]).subquery() + s = sa.select(a2).subquery() assert s.c.user_id is not None assert len(a2.foreign_keys) == 1 diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 26ccfdfd31..4b6cb6e0c2 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -590,7 +590,7 @@ class TransactionTest(fixtures.TestBase): transaction.commit() eq_( connection.execute( - select([users.c.user_id]).order_by(users.c.user_id) + select(users.c.user_id).order_by(users.c.user_id) ).fetchall(), [(1,), (3,)], ) @@ -607,7 +607,7 @@ class TransactionTest(fixtures.TestBase): transaction.commit() eq_( connection.execute( - select([users.c.user_id]).order_by(users.c.user_id) + select(users.c.user_id).order_by(users.c.user_id) ).fetchall(), [(1,), (2,), (3,)], ) @@ -637,7 +637,7 @@ class TransactionTest(fixtures.TestBase): transaction.commit() eq_( connection.execute( - select([users.c.user_id]).order_by(users.c.user_id) + select(users.c.user_id).order_by(users.c.user_id) ).fetchall(), [(1,), (4,)], ) @@ -663,7 +663,7 @@ class TransactionTest(fixtures.TestBase): transaction.close() eq_( connection.execute( - select([users.c.user_id]).order_by(users.c.user_id) + select(users.c.user_id).order_by(users.c.user_id) ).fetchall(), [(1,), (2,)], ) @@ -695,7 +695,7 @@ class TransactionTest(fixtures.TestBase): transaction.commit() eq_( connection.execute( - select([users.c.user_id]).order_by(users.c.user_id) + select(users.c.user_id).order_by(users.c.user_id) ).fetchall(), [(1,), (2,), (5,)], ) @@ -722,7 +722,7 @@ class TransactionTest(fixtures.TestBase): with testing.db.connect() as connection2: eq_( connection2.execution_options(autocommit=True) - .execute(select([users.c.user_id]).order_by(users.c.user_id)) + .execute(select(users.c.user_id).order_by(users.c.user_id)) .fetchall(), [], ) @@ -731,7 +731,7 @@ class TransactionTest(fixtures.TestBase): connection2.commit_prepared(transaction.xid, recover=True) eq_( connection2.execute( - select([users.c.user_id]).order_by(users.c.user_id) + select(users.c.user_id).order_by(users.c.user_id) ).fetchall(), [(1,)], ) @@ -755,7 +755,7 @@ class TransactionTest(fixtures.TestBase): xa.prepare() xa.commit() result = conn.execute( - select([users.c.user_name]).order_by(users.c.user_id) + select(users.c.user_name).order_by(users.c.user_id) ) eq_(result.fetchall(), [("user1",), ("user4",)]) @@ -786,7 +786,7 @@ class TransactionTest(fixtures.TestBase): with eng.connect() as conn: result = conn.execute( - select([users.c.user_name]).order_by(users.c.user_id) + select(users.c.user_name).order_by(users.c.user_id) ) eq_(result.fetchall(), []) @@ -1060,13 +1060,13 @@ class ExplicitAutoCommitTest(fixtures.TestBase): conn1 = testing.db.connect() conn2 = testing.db.connect() - conn1.execute(select([func.insert_foo("data1")])) - assert conn2.execute(select([foo.c.data])).fetchall() == [] + conn1.execute(select(func.insert_foo("data1"))) + assert conn2.execute(select(foo.c.data)).fetchall() == [] conn1.execute(text("select insert_foo('moredata')")) - assert conn2.execute(select([foo.c.data])).fetchall() == [] + assert conn2.execute(select(foo.c.data)).fetchall() == [] trans = conn1.begin() trans.commit() - assert conn2.execute(select([foo.c.data])).fetchall() == [ + assert conn2.execute(select(foo.c.data)).fetchall() == [ ("data1",), ("moredata",), ] @@ -1077,11 +1077,9 @@ class ExplicitAutoCommitTest(fixtures.TestBase): conn1 = testing.db.connect() conn2 = testing.db.connect() conn1.execute( - select([func.insert_foo("data1")]).execution_options( - autocommit=True - ) + select(func.insert_foo("data1")).execution_options(autocommit=True) ) - assert conn2.execute(select([foo.c.data])).fetchall() == [("data1",)] + assert conn2.execute(select(foo.c.data)).fetchall() == [("data1",)] conn1.close() conn2.close() @@ -1089,28 +1087,26 @@ class ExplicitAutoCommitTest(fixtures.TestBase): conn1 = testing.db.connect() conn2 = testing.db.connect() conn1.execution_options(autocommit=True).execute( - select([func.insert_foo("data1")]) + select(func.insert_foo("data1")) ) - eq_(conn2.execute(select([foo.c.data])).fetchall(), [("data1",)]) + eq_(conn2.execute(select(foo.c.data)).fetchall(), [("data1",)]) # connection supersedes statement conn1.execution_options(autocommit=False).execute( - select([func.insert_foo("data2")]).execution_options( - autocommit=True - ) + select(func.insert_foo("data2")).execution_options(autocommit=True) ) - eq_(conn2.execute(select([foo.c.data])).fetchall(), [("data1",)]) + eq_(conn2.execute(select(foo.c.data)).fetchall(), [("data1",)]) # ditto conn1.execution_options(autocommit=True).execute( - select([func.insert_foo("data3")]).execution_options( + select(func.insert_foo("data3")).execution_options( autocommit=False ) ) eq_( - conn2.execute(select([foo.c.data])).fetchall(), + conn2.execute(select(foo.c.data)).fetchall(), [("data1",), ("data2",), ("data3",)], ) conn1.close() @@ -1124,9 +1120,7 @@ class ExplicitAutoCommitTest(fixtures.TestBase): autocommit=True ) ) - assert conn2.execute(select([foo.c.data])).fetchall() == [ - ("moredata",) - ] + assert conn2.execute(select(foo.c.data)).fetchall() == [("moredata",)] conn1.close() conn2.close() @@ -1134,7 +1128,7 @@ class ExplicitAutoCommitTest(fixtures.TestBase): conn1 = testing.db.connect() conn2 = testing.db.connect() conn1.execute(text("insert into foo (data) values ('implicitdata')")) - assert conn2.execute(select([foo.c.data])).fetchall() == [ + assert conn2.execute(select(foo.c.data)).fetchall() == [ ("implicitdata",) ] conn1.close() @@ -1330,7 +1324,7 @@ class IsolationLevelTest(fixtures.TestBase): r"on Connection.execution_options\(\), or " r"per-engine using the isolation_level " r"argument to create_engine\(\).", - select([1]).execution_options, + select(1).execution_options, isolation_level=self._non_default_isolation_level(), ) @@ -1793,7 +1787,7 @@ class FutureTransactionTest(fixtures.FutureEngineMixin, fixtures.TablesTest): canary = mock.Mock() with testing.db.connect() as conn: event.listen(conn, "rollback", canary) - conn.execute(select([1])) + conn.execute(select(1)) assert conn.in_transaction() eq_(canary.mock_calls, [mock.call(conn)]) @@ -1802,7 +1796,7 @@ class FutureTransactionTest(fixtures.FutureEngineMixin, fixtures.TablesTest): canary = mock.Mock() with testing.db.connect() as conn: event.listen(conn, "rollback", canary) - conn.execute(select([1])) + conn.execute(select(1)) conn.rollback() assert not conn.in_transaction() @@ -1813,7 +1807,7 @@ class FutureTransactionTest(fixtures.FutureEngineMixin, fixtures.TablesTest): try: with testing.db.connect() as conn: event.listen(conn, "rollback", canary) - conn.execute(select([1])) + conn.execute(select(1)) assert conn.in_transaction() raise Exception("some error") assert False @@ -1866,7 +1860,7 @@ class FutureTransactionTest(fixtures.FutureEngineMixin, fixtures.TablesTest): exc.PendingRollbackError, "Can't reconnect", conn.execute, - select([1]), + select(1), ) conn.rollback() diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 7713f3d77c..b7b5ec61aa 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -1481,7 +1481,7 @@ class DeclarativeTest(DeclarativeTestBase): user_id = Column("user_id", Integer, ForeignKey("users.id")) User.address_count = sa.orm.column_property( - sa.select([sa.func.count(Address.id)]) + sa.select(sa.func.count(Address.id)) .where(Address.user_id == User.id) .scalar_subquery() ) @@ -1528,7 +1528,7 @@ class DeclarativeTest(DeclarativeTestBase): # this doesn't really gain us anything. but if # one is used, lets have it function as expected... return sa.orm.column_property( - sa.select([sa.func.count(Address.id)]) + sa.select(sa.func.count(Address.id)) .where(Address.user_id == cls.id) .scalar_subquery() ) @@ -1628,9 +1628,9 @@ class DeclarativeTest(DeclarativeTestBase): name = Column("name", String(50)) adr_count = sa.orm.column_property( - sa.select( - [sa.func.count(Address.id)], Address.user_id == id - ).scalar_subquery() + sa.select(sa.func.count(Address.id)) + .where(Address.user_id == id) + .scalar_subquery() ) addresses = relationship(Address) @@ -1932,7 +1932,7 @@ class DeclarativeTest(DeclarativeTestBase): ) User.address_count = sa.orm.column_property( - sa.select([sa.func.count(Address.id)]) + sa.select(sa.func.count(Address.id)) .where(Address.user_id == User.id) .scalar_subquery() ) diff --git a/test/ext/declarative/test_mixin.py b/test/ext/declarative/test_mixin.py index bda08e02f3..75e5912a7f 100644 --- a/test/ext/declarative/test_mixin.py +++ b/test/ext/declarative/test_mixin.py @@ -1849,7 +1849,7 @@ class DeclaredAttrTest(DeclarativeTestBase, testing.AssertsCompiledSQL): def address_count(cls): counter(cls.id) return column_property( - select([func.count(Address.id)]) + select(func.count(Address.id)) .where(Address.user_id == cls.id) .scalar_subquery() ) diff --git a/test/ext/test_compiler.py b/test/ext/test_compiler.py index f1817b94e7..058c1dfd77 100644 --- a/test/ext/test_compiler.py +++ b/test/ext/test_compiler.py @@ -41,11 +41,11 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): return ">>%s<<" % thingy.name self.assert_compile( - select([column("foo"), MyThingy()]), "SELECT foo, >>MYTHINGY!<<" + select(column("foo"), MyThingy()), "SELECT foo, >>MYTHINGY!<<" ) self.assert_compile( - select([MyThingy("x"), MyThingy("y")]).where(MyThingy() == 5), + select(MyThingy("x"), MyThingy("y")).where(MyThingy() == 5), "SELECT >>x<<, >>y<< WHERE >>MYTHINGY!<< = :MYTHINGY!_1", ) @@ -103,12 +103,12 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): return str(compiler.counter) self.assert_compile( - select([column("foo"), MyThingy()]).order_by(desc(MyThingy())), + select(column("foo"), MyThingy()).order_by(desc(MyThingy())), "SELECT foo, 1 ORDER BY 2 DESC", ) self.assert_compile( - select([MyThingy(), MyThingy()]).where(MyThingy() == 5), + select(MyThingy(), MyThingy()).where(MyThingy() == 5), "SELECT 1, 2 WHERE 3 = :MYTHINGY!_1", ) @@ -127,7 +127,7 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): t1 = table("mytable", column("x"), column("y"), column("z")) self.assert_compile( - InsertFromSelect(t1, select([t1]).where(t1.c.x > 5)), + InsertFromSelect(t1, select(t1).where(t1.c.x > 5)), "INSERT INTO mytable (SELECT mytable.x, mytable.y, mytable.z " "FROM mytable WHERE mytable.x > :x_1)", ) @@ -203,7 +203,7 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): def compile_(element, compiler, **kw): return "OVERRIDE" - s1 = select([t1]) + s1 = select(t1) self.assert_compile(s1, "OVERRIDE") self.assert_compile(s1._annotate({}), "OVERRIDE") finally: @@ -341,7 +341,7 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): return "FOO" + element.name self.assert_compile( - select([Sub1(), Sub2()]), + select(Sub1(), Sub2()), "SELECT FOOsub1 AS sub1_1, sub2 AS sub2_1", use_default_dialect=True, ) @@ -364,7 +364,7 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): name = "subsub1" self.assert_compile( - select([Sub1(), Sub2(), SubSub1()]), + select(Sub1(), Sub2(), SubSub1()), "SELECT sub1 AS sub1_1, sub2 AS sub2_1, subsub1 AS subsub1_1", use_default_dialect=True, ) @@ -374,7 +374,7 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): return "FOO" + element.name self.assert_compile( - select([Sub1(), Sub2(), SubSub1()]), + select(Sub1(), Sub2(), SubSub1()), "SELECT FOOsub1 AS sub1_1, sub2 AS sub2_1, " "FOOsubsub1 AS subsub1_1", use_default_dialect=True, @@ -383,7 +383,7 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL): def _test_result_map_population(self, expression): lc1 = literal_column("1") lc2 = literal_column("2") - stmt = select([lc1, expression, lc2]) + stmt = select(lc1, expression, lc2) compiled = stmt.compile() eq_( @@ -437,7 +437,7 @@ class DefaultOnExistingTest(fixtures.TestBase, AssertsCompiledSQL): def compile_(element, compiler, **kw): return "OVERRIDE" - s1 = select([t1]) + s1 = select(t1) self.assert_compile(s1, "SELECT t1.c1, t1.c2 FROM t1") from sqlalchemy.dialects.sqlite import base as sqlite diff --git a/test/ext/test_serializer.py b/test/ext/test_serializer.py index e252a7f554..6d7b8da33c 100644 --- a/test/ext/test_serializer.py +++ b/test/ext/test_serializer.py @@ -136,7 +136,7 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest): ) def test_expression(self): - expr = select([users]).select_from(users.join(addresses)).limit(5) + expr = select(users).select_from(users.join(addresses)).limit(5) re_expr = serializer.loads( serializer.dumps(expr, -1), users.metadata, None ) @@ -228,7 +228,7 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest): def test_annotated_one(self): j = join(users, addresses)._annotate({"foo": "bar"}) - query = select([addresses]).select_from(j) + query = select(addresses).select_from(j) str(query) for prot in pickle_protocols(): @@ -279,7 +279,7 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest): ue("\u6e2c\u8a66"), m, Column(ue("\u6e2c\u8a66_id"), Integer) ) - expr = select([t]).where(t.c[ue("\u6e2c\u8a66_id")] == 5) + expr = select(t).where(t.c[ue("\u6e2c\u8a66_id")] == 5) expr2 = serializer.loads(serializer.dumps(expr, -1), m) diff --git a/test/orm/inheritance/test_assorted_poly.py b/test/orm/inheritance/test_assorted_poly.py index e6e23008cf..fe68805913 100644 --- a/test/orm/inheritance/test_assorted_poly.py +++ b/test/orm/inheritance/test_assorted_poly.py @@ -1420,11 +1420,10 @@ class MultiLevelTest(fixtures.MappedTest): "Manager": table_Employee.join(table_Engineer).join( table_Manager ), - "Engineer": select( - [table_Employee, table_Engineer.c.machine], - table_Employee.c.atype == "Engineer", - from_obj=[table_Employee.join(table_Engineer)], - ).subquery(), + "Engineer": select(table_Employee, table_Engineer.c.machine) + .where(table_Employee.c.atype == "Engineer") + .select_from(table_Employee.join(table_Engineer)) + .subquery(), "Employee": table_Employee.select( table_Employee.c.atype == "Employee" ).subquery(), @@ -1446,11 +1445,10 @@ class MultiLevelTest(fixtures.MappedTest): "Manager": table_Employee.join(table_Engineer).join( table_Manager ), - "Engineer": select( - [table_Employee, table_Engineer.c.machine], - table_Employee.c.atype == "Engineer", - from_obj=[table_Employee.join(table_Engineer)], - ).subquery(), + "Engineer": select(table_Employee, table_Engineer.c.machine) + .where(table_Employee.c.atype == "Engineer") + .select_from(table_Employee.join(table_Engineer)) + .subquery(), }, None, "pu_engineer", @@ -1839,10 +1837,11 @@ class MissingPolymorphicOnTest(fixtures.MappedTest): self.classes.C, self.classes.D, ) - poly_select = select( - [tablea, tableb.c.data.label("discriminator")], - from_obj=tablea.join(tableb), - ).alias("poly") + poly_select = ( + select(tablea, tableb.c.data.label("discriminator")) + .select_from(tablea.join(tableb)) + .alias("poly") + ) mapper(B, tableb) mapper( diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index 43d6363673..6372812d28 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -395,10 +395,10 @@ class PolymorphicOnNotLocalTest(fixtures.MappedTest): def test_polymorphic_on_not_present_col(self): t2, t1 = self.tables.t2, self.tables.t1 Parent = self.classes.Parent - t1t2_join = select([t1.c.x], from_obj=[t1.join(t2)]).alias() + t1t2_join = select(t1.c.x).select_from(t1.join(t2)).alias() def go(): - t1t2_join_2 = select([t1.c.q], from_obj=[t1.join(t2)]).alias() + t1t2_join_2 = select(t1.c.q).select_from(t1.join(t2)).alias() mapper( Parent, t2, @@ -417,7 +417,7 @@ class PolymorphicOnNotLocalTest(fixtures.MappedTest): def test_polymorphic_on_only_in_with_poly(self): t2, t1 = self.tables.t2, self.tables.t1 Parent = self.classes.Parent - t1t2_join = select([t1.c.x], from_obj=[t1.join(t2)]).alias() + t1t2_join = select(t1.c.x).select_from(t1.join(t2)).alias() # if its in the with_polymorphic, then its OK mapper( Parent, @@ -431,11 +431,11 @@ class PolymorphicOnNotLocalTest(fixtures.MappedTest): t2, t1 = self.tables.t2, self.tables.t1 Parent = self.classes.Parent - t1t2_join = select([t1.c.x], from_obj=[t1.join(t2)]).alias() + t1t2_join = select(t1.c.x).select_from(t1.join(t2)).alias() # if with_polymorphic, but its not present, not OK def go(): - t1t2_join_2 = select([t1.c.q], from_obj=[t1.join(t2)]).alias() + t1t2_join_2 = select(t1.c.q).select_from(t1.join(t2)).alias() mapper( Parent, t2, diff --git a/test/orm/test_assorted_eager.py b/test/orm/test_assorted_eager.py index dea7b60ec1..310e50eb2b 100644 --- a/test/orm/test_assorted_eager.py +++ b/test/orm/test_assorted_eager.py @@ -188,25 +188,25 @@ class EagerTest(fixtures.MappedTest): # not orm style correct query print("Obtaining correct results without orm") result = ( - sa.select( - [tests.c.id, categories.c.name], + sa.select(tests.c.id, categories.c.name) + .where( sa.and_( tests.c.owner_id == 1, sa.or_( options.c.someoption == None, # noqa options.c.someoption == False, ), - ), - order_by=[tests.c.id], - from_obj=[ - tests.join(categories).outerjoin( - options, - sa.and_( - tests.c.id == options.c.test_id, - tests.c.owner_id == options.c.owner_id, - ), - ) - ], + ) + ) + .order_by(tests.c.id) + .select_from( + tests.join(categories).outerjoin( + options, + sa.and_( + tests.c.id == options.c.test_id, + tests.c.owner_id == options.c.owner_id, + ), + ) ) .execute() .fetchall() @@ -530,10 +530,12 @@ class EagerTest3(fixtures.MappedTest): ) session.flush() - arb_data = sa.select( - [stats.c.data_id, sa.func.max(stats.c.somedata).label("max")], - stats.c.data_id <= 5, - group_by=[stats.c.data_id], + arb_data = ( + sa.select( + stats.c.data_id, sa.func.max(stats.c.somedata).label("max") + ) + .where(stats.c.data_id <= 5) + .group_by(stats.c.data_id) ) arb_result = arb_data.execute().fetchall() @@ -1150,14 +1152,15 @@ class EagerTest8(fixtures.MappedTest): mapper(Task_Type, task_type) j = sa.outerjoin(task, msg, task.c.id == msg.c.task_id) - jj = sa.select( - [ + jj = ( + sa.select( task.c.id.label("task_id"), sa.func.count(msg.c.id).label("props_cnt"), - ], - from_obj=[j], - group_by=[task.c.id], - ).alias("prop_c_s") + ) + .select_from(j) + .group_by(task.c.id) + .alias("prop_c_s") + ) jjj = sa.join(task, jj, task.c.id == jj.c.task_id) mapper( diff --git a/test/orm/test_composites.py b/test/orm/test_composites.py index 046a6acb9e..e084d90d9d 100644 --- a/test/orm/test_composites.py +++ b/test/orm/test_composites.py @@ -745,10 +745,11 @@ class MappedSelectTest(fixtures.MappedTest): def __composite_values__(self): return self - desc_values = select( - [values, descriptions.c.d1, descriptions.c.d2], - descriptions.c.id == values.c.description_id, - ).alias("descriptions_values") + desc_values = ( + select(values, descriptions.c.d1, descriptions.c.d2) + .where(descriptions.c.id == values.c.description_id,) + .alias("descriptions_values") + ) mapper( Descriptions, diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py index 643897b2d3..36c9a18691 100644 --- a/test/orm/test_eager_relations.py +++ b/test/orm/test_eager_relations.py @@ -1294,10 +1294,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): # tests the LIMIT/OFFSET aliasing on a mapper # against a select. original issue from ticket #904 - sel = sa.select( - [users, addresses.c.email_address], - users.c.id == addresses.c.user_id, - ).alias("useralias") + sel = ( + sa.select(users, addresses.c.email_address) + .where(users.c.id == addresses.c.user_id,) + .alias("useralias") + ) mapper( User, sel, @@ -1810,10 +1811,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): self.classes.Order, ) - max_orders_by_user = sa.select( - [sa.func.max(orders.c.id).label("order_id")], - group_by=[orders.c.user_id], - ).alias("max_orders_by_user") + max_orders_by_user = ( + sa.select(sa.func.max(orders.c.id).label("order_id")) + .group_by(orders.c.user_id) + .alias("max_orders_by_user") + ) max_orders = orders.select( orders.c.id == max_orders_by_user.c.order_id @@ -1946,7 +1948,7 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): self.classes.Order, ) - s = sa.select([orders], orders.c.isopen == 1).alias("openorders") + s = sa.select(orders).where(orders.c.isopen == 1).alias("openorders") mapper( Order, s, properties={"user": relationship(User, lazy="joined")} @@ -4762,9 +4764,8 @@ class SubqueryTest(fixtures.MappedTest): tag_score = tags_table.c.score1 * tags_table.c.score2 user_score = sa.select( - [sa.func.sum(tags_table.c.score1 * tags_table.c.score2)], - tags_table.c.user_id == users_table.c.id, - ) + sa.func.sum(tags_table.c.score1 * tags_table.c.score2) + ).where(tags_table.c.user_id == users_table.c.id,) if labeled: tag_score = tag_score.label(labelname) diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py index e5a53df4be..d29ed65e88 100644 --- a/test/orm/test_froms.py +++ b/test/orm/test_froms.py @@ -161,9 +161,11 @@ class QueryCorrelatesLikeSelect(QueryTest, AssertsCompiledSQL): def test_scalar_subquery_select_auto_correlate(self): addresses, users = self.tables.addresses, self.tables.users - query = select( - [func.count(addresses.c.id)], addresses.c.user_id == users.c.id - ).scalar_subquery() + query = ( + select(func.count(addresses.c.id)) + .where(addresses.c.user_id == users.c.id) + .scalar_subquery() + ) query = select(users.c.name.label("users_name"), query) self.assert_compile( query, self.query_correlated, dialect=default.DefaultDialect() @@ -172,9 +174,8 @@ class QueryCorrelatesLikeSelect(QueryTest, AssertsCompiledSQL): def test_scalar_subquery_select_explicit_correlate(self): addresses, users = self.tables.addresses, self.tables.users query = ( - select( - [func.count(addresses.c.id)], addresses.c.user_id == users.c.id - ) + select(func.count(addresses.c.id)) + .where(addresses.c.user_id == users.c.id) .correlate(users) .scalar_subquery() ) @@ -186,9 +187,8 @@ class QueryCorrelatesLikeSelect(QueryTest, AssertsCompiledSQL): def test_scalar_subquery_select_correlate_off(self): addresses, users = self.tables.addresses, self.tables.users query = ( - select( - [func.count(addresses.c.id)], addresses.c.user_id == users.c.id - ) + select(func.count(addresses.c.id)) + .where(addresses.c.user_id == users.c.id) .correlate(None) .scalar_subquery() ) @@ -224,13 +224,14 @@ class QueryCorrelatesLikeSelect(QueryTest, AssertsCompiledSQL): query, self.query_correlated, dialect=default.DefaultDialect() ) - def test_scalar_subquery_query_correlate_off(self): + @testing.combinations(False, None) + def test_scalar_subquery_query_correlate_off(self, value): sess = create_session() Address, User = self.classes.Address, self.classes.User query = ( sess.query(func.count(Address.id)) .filter(Address.user_id == User.id) - .correlate(None) + .correlate(value) .scalar_subquery() ) query = sess.query(User.name, query) @@ -2381,15 +2382,15 @@ class MixedEntitiesTest(QueryTest, AssertsCompiledSQL): assert q.all() == expected # test with a straight statement - s = select( - [ + s = ( + select( users, func.count(addresses.c.id).label("count"), ("Name:" + users.c.name).label("concat"), - ], - from_obj=[users.outerjoin(addresses)], - group_by=[c for c in users.c], - order_by=[users.c.id], + ) + .select_from(users.outerjoin(addresses)) + .group_by(*[c for c in users.c]) + .order_by(users.c.id) ) q = create_session().query(User) result = ( @@ -3422,10 +3423,8 @@ class ExternalColumnsTest(QueryTest): properties={ "concat": column_property((users.c.id * 2)), "count": column_property( - select( - [func.count(addresses.c.id)], - users.c.id == addresses.c.user_id, - ) + select(func.count(addresses.c.id)) + .where(users.c.id == addresses.c.user_id,) .correlate(users) .scalar_subquery() ), @@ -3585,10 +3584,8 @@ class ExternalColumnsTest(QueryTest): ), "concat": column_property((users.c.id * 2)), "count": column_property( - select( - [func.count(addresses.c.id)], - users.c.id == addresses.c.user_id, - ) + select(func.count(addresses.c.id)) + .where(users.c.id == addresses.c.user_id,) .correlate(users) .scalar_subquery() ), diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index f8133c6f05..c94fe0833d 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -1316,15 +1316,16 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): self.classes.User, ) - s = sa.select( - [ + s = ( + sa.select( users, (users.c.id * 2).label("concat"), sa.func.count(addresses.c.id).label("count"), - ], - users.c.id == addresses.c.user_id, - group_by=[c for c in users.c], - ).alias("myselect") + ) + .where(users.c.id == addresses.c.user_id) + .group_by(*[c for c in users.c]) + .alias("myselect") + ) mapper(User, s) sess = create_session() diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index 75d047b72f..1a27fd98d1 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -1894,10 +1894,11 @@ class RelationshipToSelectableTest(fixtures.MappedTest): class LineItem(fixtures.BasicEntity): pass - container_select = sa.select( - [items.c.policyNum, items.c.policyEffDate, items.c.type], - distinct=True, - ).alias("container_select") + container_select = ( + sa.select(items.c.policyNum, items.c.policyEffDate, items.c.type) + .distinct() + .alias("container_select") + ) mapper(LineItem, items) diff --git a/test/orm/test_selectin_relations.py b/test/orm/test_selectin_relations.py index e94ec03c1e..e704e16240 100644 --- a/test/orm/test_selectin_relations.py +++ b/test/orm/test_selectin_relations.py @@ -1269,10 +1269,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): self.classes.Order, ) - max_orders_by_user = sa.select( - [sa.func.max(orders.c.id).label("order_id")], - group_by=[orders.c.user_id], - ).alias("max_orders_by_user") + max_orders_by_user = ( + sa.select(sa.func.max(orders.c.id).label("order_id")) + .group_by(orders.c.user_id) + .alias("max_orders_by_user") + ) max_orders = orders.select( orders.c.id == max_orders_by_user.c.order_id diff --git a/test/orm/test_subquery_relations.py b/test/orm/test_subquery_relations.py index 5158c20467..4530921646 100644 --- a/test/orm/test_subquery_relations.py +++ b/test/orm/test_subquery_relations.py @@ -1250,10 +1250,11 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL): self.classes.Order, ) - max_orders_by_user = sa.select( - [sa.func.max(orders.c.id).label("order_id")], - group_by=[orders.c.user_id], - ).alias("max_orders_by_user") + max_orders_by_user = ( + sa.select(sa.func.max(orders.c.id).label("order_id")) + .group_by(orders.c.user_id) + .alias("max_orders_by_user") + ) max_orders = orders.select( orders.c.id == max_orders_by_user.c.order_id diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index e22f7beb3f..3ca75cdb2d 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -2253,10 +2253,15 @@ class ManyToOneTest(_fixtures.FixtureTest): ), ) - result = sa.select( - [users, addresses], - sa.and_(users.c.id == addresses.c.user_id, addresses.c.id == a.id), - ).execute() + result = ( + sa.select(users, addresses) + .where( + sa.and_( + users.c.id == addresses.c.user_id, addresses.c.id == a.id + ), + ) + .execute() + ) eq_( list(result.first()), [a.user.id, "asdf8d", a.id, a.user_id, "theater@foo.com"], diff --git a/test/requirements.py b/test/requirements.py index 145d87d753..e0e9ce60cf 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -1234,7 +1234,7 @@ class DefaultRequirements(SuiteRequirements): expr = decimal.Decimal("15.7563") value = e.scalar( - select([literal(expr)]) + select(literal(expr)) ) assert value == expr diff --git a/test/sql/test_case_statement.py b/test/sql/test_case_statement.py index f2a88bd73f..74fe8876d1 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 b5b6a4a529..098606a91d 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 b43d09045d..a6118c03fb 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 c9178d5801..410f49f2a5 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 aa1c0d48d7..3733d70c77 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 5dcc0d112b..2e3ba42459 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 04fed9b6e6..2bac963e49 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 3307f0f1ed..c67b452035 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 416f89de39..6afe41aaca 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 e0a0dd8a53..717fc47afa 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 e5f2fbe6d5..3cdf291ec1 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 e458958175..731f8fcb5c 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 a91242de5e..c283e804e5 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 b18dde57bc..c5700fff27 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 dc4e342fda..c1db9d2964 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 8521b95559..c011b961c8 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 3662a6e72d..9b3ededcd7 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 b4d97a1b90..504ed40646 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 578e20e445..67f347ad3b 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 20aa1fb3aa..2fb50f37d0 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 c9f179ed1f..4feba97aec 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 4c00cb53c7..2a2381427c 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 68d79fd512..329cc39f6d 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 ee7c77a93d..243ccfbab4 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 7e0600a667..785dc5da88 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 9d5ab65ed9..0cd6f8cf37 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 412623c013..09ade319e2 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 2ede1e6861..5464750dbf 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 964e3ee6be..a5e57a78af 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 676ad42982..a4b76f35d0 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 154701ea01..3b0544278a 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 "