From 333414fe94941a6a58e7d8e45042548eb2d58119 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 30 Sep 2016 10:09:56 -0400 Subject: Add "eager_parenthesis" late-compilation rule, use w/ PG JSON/HSTORE Added compiler-level flags used by Postgresql to place additional parenthesis than would normally be generated by precedence rules around operations involving JSON, HSTORE indexing operators as well as within their operands since it has been observed that Postgresql's precedence rules for at least the HSTORE indexing operator is not consistent between 9.4 and 9.5. Fixes: #3806 Change-Id: I5899677b330595264543b055abd54f3c76bfabf2 --- lib/sqlalchemy/dialects/postgresql/json.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/json.py') diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py index 05c4d014d..821018471 100644 --- a/lib/sqlalchemy/dialects/postgresql/json.py +++ b/lib/sqlalchemy/dialects/postgresql/json.py @@ -17,33 +17,42 @@ from ... import util __all__ = ('JSON', 'JSONB') +idx_precedence = operators._PRECEDENCE[operators.json_getitem_op] + ASTEXT = operators.custom_op( - "->>", precedence=15, natural_self_precedent=True, + "->>", precedence=idx_precedence, natural_self_precedent=True, + eager_grouping=True ) JSONPATH_ASTEXT = operators.custom_op( - "#>>", precedence=15, natural_self_precedent=True, + "#>>", precedence=idx_precedence, natural_self_precedent=True, + eager_grouping=True ) HAS_KEY = operators.custom_op( - "?", precedence=15, natural_self_precedent=True + "?", precedence=idx_precedence, natural_self_precedent=True, + eager_grouping=True ) HAS_ALL = operators.custom_op( - "?&", precedence=15, natural_self_precedent=True + "?&", precedence=idx_precedence, natural_self_precedent=True, + eager_grouping=True ) HAS_ANY = operators.custom_op( - "?|", precedence=15, natural_self_precedent=True + "?|", precedence=idx_precedence, natural_self_precedent=True, + eager_grouping=True ) CONTAINS = operators.custom_op( - "@>", precedence=15, natural_self_precedent=True + "@>", precedence=idx_precedence, natural_self_precedent=True, + eager_grouping=True ) CONTAINED_BY = operators.custom_op( - "<@", precedence=15, natural_self_precedent=True + "<@", precedence=idx_precedence, natural_self_precedent=True, + eager_grouping=True ) -- cgit v1.2.1