summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-09-02 23:46:06 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2020-09-08 17:13:48 -0400
commite8600608669d90c4a6385b312d271aed63eb5854 (patch)
treeef984a01c536b2c81d2283b3ca5d9f4395f41dd0 /lib
parent0d56a62f721ee6c91d8a8b6a407b959c9215b3b6 (diff)
downloadsqlalchemy-e8600608669d90c4a6385b312d271aed63eb5854.tar.gz
Update select usage to use the new 1.4 format
This change includes mainly that the bracketed use within select() is moved to positional, and keyword arguments are removed from calls to the select() function. it does not yet fully address other issues such as keyword arguments passed to the table.select(). Additionally, allows False / None to both be considered as "disable" for all of select.correlate(), select.correlate_except(), query.correlate(), which establishes consistency with passing of ``False`` for the legact select(correlate=False) argument. Change-Id: Ie6c6e6abfbd3d75d4c8de504c0cf0159e6999108
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py15
-rw-r--r--lib/sqlalchemy/dialects/oracle/base.py4
-rw-r--r--lib/sqlalchemy/dialects/postgresql/array.py8
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py14
-rw-r--r--lib/sqlalchemy/dialects/postgresql/ext.py4
-rw-r--r--lib/sqlalchemy/dialects/postgresql/hstore.py16
-rw-r--r--lib/sqlalchemy/dialects/postgresql/json.py2
-rw-r--r--lib/sqlalchemy/engine/default.py6
-rw-r--r--lib/sqlalchemy/ext/compiler.py8
-rw-r--r--lib/sqlalchemy/ext/hybrid.py2
-rw-r--r--lib/sqlalchemy/orm/query.py4
-rw-r--r--lib/sqlalchemy/orm/util.py20
-rw-r--r--lib/sqlalchemy/sql/base.py2
-rw-r--r--lib/sqlalchemy/sql/dml.py8
-rw-r--r--lib/sqlalchemy/sql/elements.py102
-rw-r--r--lib/sqlalchemy/sql/functions.py31
-rw-r--r--lib/sqlalchemy/sql/operators.py16
-rw-r--r--lib/sqlalchemy/sql/selectable.py81
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py28
-rw-r--r--lib/sqlalchemy/sql/visitors.py2
-rw-r--r--lib/sqlalchemy/testing/requirements.py2
-rw-r--r--lib/sqlalchemy/testing/suite/test_cte.py36
-rw-r--r--lib/sqlalchemy/testing/suite/test_deprecations.py34
-rw-r--r--lib/sqlalchemy/testing/suite/test_dialect.py8
-rw-r--r--lib/sqlalchemy/testing/suite/test_insert.py26
-rw-r--r--lib/sqlalchemy/testing/suite/test_results.py26
-rw-r--r--lib/sqlalchemy/testing/suite/test_select.py172
27 files changed, 307 insertions, 370 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index ed17fb863..c29fee652 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 65580b4e1..3afd6fc3a 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 7fd271d52..dacf1e2c2 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 84247d046..e40a730c5 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 e64920719..7acab0a0a 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 4e048feb0..cb89f7c5f 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 fbf61dd5f..9ffe9cfe8 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 0bd4cd14c..198ec4159 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 7736a1290..f0447d8df 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 b031e82fd..75bb028f0 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 37ff48964..d941d79d2 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 271a441f0..f7673e0b7 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 dc2804691..67ee8c907 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 b7151ac7b..cd4bc17af 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 a17612034..dc3e5f476 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 c1b8bbd27..c7ddcc18a 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 91a0792c3..ba03a6934 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 d67b61743..ea3bb0512 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 f1063b71a..e2edf20b5 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 5cb3cba70..27499b5f7 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 4114137d4..302a02419 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 1ee6cac10..4addca009 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 8c25616a8..b36162fa5 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 8aa13a622..c5ede08c6 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 5b8c343c4..74347cc77 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 e6f6068c8..6d28a207e 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 7e0337146..adcd7d8b9 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 "
):