diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index ecdbe0018..e9040fb43 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -3381,7 +3381,7 @@ class PGDialect(default.DefaultDialect): CHECK_SQL = """ SELECT cons.conname as name, - cons.consrc as src + pg_get_constraintdef(cons.oid) as src FROM pg_catalog.pg_constraint cons WHERE @@ -3391,8 +3391,19 @@ 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) + if not m: + util.warn("Could not parse CHECK constraint text: %r" % src) + return "" + return m.group(1) + return [ - {"name": name, "sqltext": src[1:-1]} for name, src in c.fetchall() + {"name": name, "sqltext": match_cons(src)} + for name, src in c.fetchall() ] def _load_enums(self, connection, schema=None): |