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 /test/dialect/postgresql/test_reflection.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 'test/dialect/postgresql/test_reflection.py')
-rw-r--r-- | test/dialect/postgresql/test_reflection.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index b6cedd55f..cc231933c 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -1524,17 +1524,34 @@ class ReflectionTest(fixtures.TestBase): def test_reflect_check_constraint(self): meta = self.metadata - cc_table = Table( + udf_create = """\ + CREATE OR REPLACE FUNCTION is_positive( + x integer DEFAULT '-1'::integer) + RETURNS boolean + LANGUAGE 'plpgsql' + COST 100 + VOLATILE + AS $BODY$BEGIN + RETURN x > 0; + END;$BODY$; + """ + sa.event.listen(meta, "before_create", + sa.DDL(udf_create)) + sa.event.listen(meta, "after_drop", + sa.DDL("DROP FUNCTION is_positive(integer)")) + + Table( "pgsql_cc", meta, Column("a", Integer()), CheckConstraint("a > 1 AND a < 5", name="cc1"), CheckConstraint("a = 1 OR (a > 2 AND a < 5)", name="cc2"), + CheckConstraint("is_positive(a)", name="cc3"), ) - cc_table.create() + meta.create_all() - reflected = Table("pgsql_cc", MetaData(testing.db), autoload=True) + reflected = Table("pgsql_cc", MetaData(), autoload_with=testing.db) check_constraints = dict( (uc.name, uc.sqltext.text) @@ -1547,6 +1564,7 @@ class ReflectionTest(fixtures.TestBase): { u"cc1": u"(a > 1) AND (a < 5)", u"cc2": u"(a = 1) OR ((a > 2) AND (a < 5))", + u"cc3": u"is_positive(a)", }, ) |