summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:19:47 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 18:23:11 -0500
commit1e278de4cc9a4181e0747640a960e80efcea1ca9 (patch)
tree13d0c035807613bfa07e734acad79b9c843cb8b0 /lib/sqlalchemy/dialects/postgresql/base.py
parent1e1a38e7801f410f244e4bbb44ec795ae152e04e (diff)
downloadsqlalchemy-1e278de4cc9a4181e0747640a960e80efcea1ca9.tar.gz
Post black reformatting
Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py82
1 files changed, 49 insertions, 33 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 11833da57..e77b2880f 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -290,13 +290,13 @@ use the :meth:`._UpdateBase.returning` method on a per-statement basis::
INSERT...ON CONFLICT (Upsert)
------------------------------
-Starting with version 9.5, PostgreSQL allows "upserts" (update or insert)
-of rows into a table via the ``ON CONFLICT`` clause of the ``INSERT`` statement.
-A candidate row will only be inserted if that row does not violate
-any unique constraints. In the case of a unique constraint violation,
-a secondary action can occur which can be either "DO UPDATE", indicating
-that the data in the target row should be updated, or "DO NOTHING",
-which indicates to silently skip this row.
+Starting with version 9.5, PostgreSQL allows "upserts" (update or insert) of
+rows into a table via the ``ON CONFLICT`` clause of the ``INSERT`` statement. A
+candidate row will only be inserted if that row does not violate any unique
+constraints. In the case of a unique constraint violation, a secondary action
+can occur which can be either "DO UPDATE", indicating that the data in the
+target row should be updated, or "DO NOTHING", which indicates to silently skip
+this row.
Conflicts are determined using existing unique constraints and indexes. These
constraints may be identified either using their name as stated in DDL,
@@ -331,8 +331,9 @@ Both methods supply the "target" of the conflict using either the
named constraint or by column inference:
* The :paramref:`.Insert.on_conflict_do_update.index_elements` argument
- specifies a sequence containing string column names, :class:`.Column` objects,
- and/or SQL expression elements, which would identify a unique index::
+ specifies a sequence containing string column names, :class:`.Column`
+ objects, and/or SQL expression elements, which would identify a unique
+ index::
do_update_stmt = insert_stmt.on_conflict_do_update(
index_elements=['id'],
@@ -915,34 +916,37 @@ E.g.::
"""
from collections import defaultdict
-import re
import datetime as dt
+import re
-
-from sqlalchemy.sql import elements
-from ... import sql, schema, exc, util
-from ...engine import default, reflection
-from ...sql import compiler, expression
+from ... import exc
+from ... import schema
+from ... import sql
+from ... import util
+from ...engine import default
+from ...engine import reflection
+from ...sql import compiler
+from ...sql import elements
+from ...sql import expression
from ...sql import sqltypes
+from ...types import BIGINT
+from ...types import BOOLEAN
+from ...types import CHAR
+from ...types import DATE
+from ...types import FLOAT
+from ...types import INTEGER
+from ...types import NUMERIC
+from ...types import REAL
+from ...types import SMALLINT
+from ...types import TEXT
+from ...types import VARCHAR
+
try:
- from uuid import UUID as _python_UUID
+ from uuid import UUID as _python_UUID # noqa
except ImportError:
_python_UUID = None
-from sqlalchemy.types import (
- INTEGER,
- BIGINT,
- SMALLINT,
- VARCHAR,
- CHAR,
- TEXT,
- FLOAT,
- NUMERIC,
- DATE,
- BOOLEAN,
- REAL,
-)
AUTOCOMMIT_REGEXP = re.compile(
r"\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|GRANT|REVOKE|"
@@ -2022,7 +2026,7 @@ class PGDDLCompiler(compiler.DDLCompiler):
class PGTypeCompiler(compiler.GenericTypeCompiler):
- def visit_TSVECTOR(self, type, **kw):
+ def visit_TSVECTOR(self, type_, **kw):
return "TSVECTOR"
def visit_INET(self, type_, **kw):
@@ -3087,9 +3091,21 @@ class PGDialect(default.DefaultDialect):
for conname, condef, conschema in c.fetchall():
m = re.search(FK_REGEX, condef).groups()
- constrained_columns, referred_schema, referred_table, referred_columns, _, match, _, onupdate, _, ondelete, deferrable, _, initially = (
- m
- )
+ (
+ constrained_columns,
+ referred_schema,
+ referred_table,
+ referred_columns,
+ _,
+ match,
+ _,
+ onupdate,
+ _,
+ ondelete,
+ deferrable,
+ _,
+ initially,
+ ) = m
if deferrable is not None:
deferrable = True if deferrable == "DEFERRABLE" else False