details:   https://code.tryton.org/tryton/commit/0a84460d606a
branch:    7.8
user:      Cédric Krier <[email protected]>
date:      Tue Jan 13 16:50:08 2026 +0100
description:
        Ensure to always surround USING expression with parenthesis in CREATE 
INDEX

        Closes #14487
        (grafted from b45a29b26853324f65adc8c49b59a62d6f591529)
diffstat:

 trytond/trytond/backend/postgresql/table.py |  10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diffs (31 lines):

diff -r d308e8a6210b -r 0a84460d606a trytond/trytond/backend/postgresql/table.py
--- a/trytond/trytond/backend/postgresql/table.py       Wed Jan 14 00:35:13 
2026 +0100
+++ b/trytond/trytond/backend/postgresql/table.py       Tue Jan 13 16:50:08 
2026 +0100
@@ -4,6 +4,7 @@
 import re
 
 from psycopg2.sql import SQL, Identifier
+from sql import Column
 from sql.operators import NotEqual
 
 from trytond.backend.table import (
@@ -643,11 +644,18 @@
     @classmethod
     def _get_expression_variables(cls, expression, usage):
         variables = {
-            'expression': SQL(str(expression)),
             'collate': SQL(''),
             'opclass': SQL(''),
             'order': SQL(''),
             }
+        if isinstance(expression, Column):
+            variables['expression'] = SQL(str(expression))
+        else:
+            expression_str = str(expression)
+            if expression_str.startswith('(') and expression_str.endswith(')'):
+                variables['expression'] = SQL(expression)
+            else:
+                variables['expression'] = SQL(f'({expression})')
         if usage.options.get('collation'):
             variables['collate'] = SQL('COLLATE {}').format(
                 usage.options['collation'])

Reply via email to