From c6d869f814d2e8ffe03e519c59cf35f7a4927e1c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 8 Nov 2020 11:14:22 -0500 Subject: Allow dialect-specific stringification Dialect-specific constructs such as :meth:`_postgresql.Insert.on_conflict_do_update` can now stringify in-place without the need to specify an explicit dialect object. The constructs, when called upon for ``str()``, ``print()``, etc. now have internal direction to call upon their appropriate dialect rather than the "default"dialect which doesn't know how to stringify these. The approach is also adapted to generic schema-level create/drop such as :class:`_schema.AddConstraint`, which will adapt its stringify dialect to one indicated by the element within it, such as the :class:`_postgresql.ExcludeConstraint` object. mostly towards being able to provide doctest-style examples for "on conflict" constructs using print statements. Change-Id: I4b855516fe6dee2df77744c1bb21a373d7fbab93 --- lib/sqlalchemy/dialects/postgresql/ext.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/sqlalchemy/dialects/postgresql/ext.py') diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py index c139fe94f..78d9a96b6 100644 --- a/lib/sqlalchemy/dialects/postgresql/ext.py +++ b/lib/sqlalchemy/dialects/postgresql/ext.py @@ -52,6 +52,8 @@ class aggregate_order_by(expression.ColumnElement): __visit_name__ = "aggregate_order_by" + stringify_dialect = "postgresql" + def __init__(self, target, *order_by): self.target = coercions.expect(roles.ExpressionElementRole, target) @@ -96,6 +98,8 @@ class ExcludeConstraint(ColumnCollectionConstraint): where = None + create_drop_stringify_dialect = "postgresql" + @elements._document_text_coercion( "where", ":class:`.ExcludeConstraint`", -- cgit v1.2.1