diff options
author | Gord Thompson <gord@gordthompson.com> | 2019-12-19 12:20:39 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-01-18 09:31:31 -0500 |
commit | d8ac1e9e6bfc931d2f14f9846d6924106f56b7e6 (patch) | |
tree | 63c2f3ba202a100fcaca6e8982ff189ac0756b29 /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | a54527fb0ef71aca0be9614617f143da27e03f22 (diff) | |
download | sqlalchemy-d8ac1e9e6bfc931d2f14f9846d6924106f56b7e6.tar.gz |
Improve regex parsing of CHECK constraints for PostgreSQL.
Fixed issue where the PostgreSQL dialect would fail to parse a reflected
CHECK constraint that was a boolean-valued function (as opposed to a
boolean-valued expression).
Fixes: #5039
Closes: #5044
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5044
Pull-request-sha: b6903c656422abf658c4cc88b8cd03291d3a50f8
Change-Id: I7d39b104a8ce346cb593d541c1b4e5eab88867f9
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index cbc750066..e8e79b230 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -3485,12 +3485,13 @@ class PGDialect(default.DefaultDialect): # "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) + # "CHECK (some_boolean_function(a))" + m = re.match(r"^CHECK *\((.+)\)( NOT VALID)?$", src) if not m: util.warn("Could not parse CHECK constraint text: %r" % src) sqltext = "" else: - sqltext = m.group(1) + sqltext = re.sub(r'^\((.+)\)$', r'\1', m.group(1)) entry = {"name": name, "sqltext": sqltext} if m and m.group(2): entry["dialect_options"] = {"not_valid": True} |