summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
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/sqlalchemy/dialects/postgresql
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/sqlalchemy/dialects/postgresql')
-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
5 files changed, 20 insertions, 24 deletions
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::