summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authorEric Borczuk <eric@trialspark.com>2020-02-28 11:05:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-02-29 17:45:05 -0500
commit0fe528483afeb53300ff7a9770f7fb9c81a3a874 (patch)
tree762727472158896a8e6680e7d8abe95b586002ab /lib/sqlalchemy/dialects
parent132006ba8a714199d4f761b0e66fc2e516e46ba3 (diff)
downloadsqlalchemy-0fe528483afeb53300ff7a9770f7fb9c81a3a874.tar.gz
While parsing for check constraints, ignore newline characters in the check condition
Fixed bug where PostgreSQL reflection of CHECK constraints would fail to parse the constraint if the SQL text contained newline characters. The regular expression has been adjusted to accommodate for this case. Pull request courtesy Eric Borczuk. Fixes: #5170 Closes: #5172 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5172 Pull-request-sha: 5701b7f09f723b727bbee95d19d107d6cc1d7717 Change-Id: If727e9140b645e8b685c3476fb0fa4417c1e6526
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 0a442f256..bfe3812be 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -3488,12 +3488,18 @@ class PGDialect(default.DefaultDialect):
# "CHECK (((a = 1) OR ((a > 2) AND (a < 5))))"
# "CHECK (((a > 1) AND (a < 5))) NOT VALID"
# "CHECK (some_boolean_function(a))"
- m = re.match(r"^CHECK *\((.+)\)( NOT VALID)?$", src)
+ # "CHECK (((a\n < 1)\n OR\n (a\n >= 5))\n)"
+
+ m = re.match(
+ r"^CHECK *\((.+)\)( NOT VALID)?$", src, flags=re.DOTALL
+ )
if not m:
util.warn("Could not parse CHECK constraint text: %r" % src)
sqltext = ""
else:
- sqltext = re.sub(r"^\((.+)\)$", r"\1", m.group(1))
+ sqltext = re.compile(
+ r"^[\s\n]*\((.+)\)[\s\n]*$", flags=re.DOTALL
+ ).sub(r"\1", m.group(1))
entry = {"name": name, "sqltext": sqltext}
if m and m.group(2):
entry["dialect_options"] = {"not_valid": True}