summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorBill Finn <bill@angaza.com>2019-08-27 12:21:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-08-27 12:54:04 -0400
commit3980a9a455d08c5073cabc3c2b77de46fa36d7b4 (patch)
tree7c4c4634dfaf9bf1de13f7315bd8424cc1b356fa /lib/sqlalchemy/dialects/postgresql/base.py
parent5bf264ca08b8bb38d50baeb48fe1729da4164711 (diff)
downloadsqlalchemy-3980a9a455d08c5073cabc3c2b77de46fa36d7b4.tar.gz
PGDialect.get_check_constraints: Handle "NOT VALID"
Added support for reflection of CHECK constraints that include the special PostgreSQL qualifier "NOT VALID", which can be present for CHECK constraints that were added to an exsiting table with the directive that they not be applied to existing data in the table. The PostgreSQL dictionary for CHECK constraints as returned by :meth:`.Inspector.get_check_constraints` may include an additional entry ``dialect_options`` which within will contain an entry ``"not_valid": True`` if this symbol is detected. Pull request courtesy Bill Finn. Fixes: #4824 Closes: #4825 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4825 Pull-request-sha: a0e1ab133c2d46521a74e55423ac2ba866682dae Change-Id: I78365f50055c95474c92124b85df66c5c80c00c8
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 8fbd97ebe..0ea6d4296 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -3447,20 +3447,24 @@ class PGDialect(default.DefaultDialect):
c = connection.execute(sql.text(CHECK_SQL), table_oid=table_oid)
- # samples:
- # "CHECK (((a > 1) AND (a < 5)))"
- # "CHECK (((a = 1) OR ((a > 2) AND (a < 5))))"
- def match_cons(src):
- m = re.match(r"^CHECK *\(\((.+)\)\)$", src)
+ ret = []
+ for name, src in c:
+ # samples:
+ # "CHECK (((a > 1) AND (a < 5)))"
+ # "CHECK (((a = 1) OR ((a > 2) AND (a < 5))))"
+ # "CHECK (((a > 1) AND (a < 5))) NOT VALID"
+ m = re.match(r"^CHECK *\(\((.+)\)\)( NOT VALID)?$", src)
if not m:
util.warn("Could not parse CHECK constraint text: %r" % src)
- return ""
- return m.group(1)
+ sqltext = ""
+ else:
+ sqltext = m.group(1)
+ entry = {"name": name, "sqltext": sqltext}
+ if m and m.group(2):
+ entry["dialect_options"] = {"not_valid": True}
- return [
- {"name": name, "sqltext": match_cons(src)}
- for name, src in c.fetchall()
- ]
+ ret.append(entry)
+ return ret
def _load_enums(self, connection, schema=None):
schema = schema or self.default_schema_name