Ensure to always surround USING expression with parenthesis in CREATE INDEX

Closes #14487
(grafted from b45a29b26853324f65adc8c49b59a62d6f591529)

--HG--
branch : 7.0
This commit is contained in:
Cédric Krier committed 2026-01-13 16:50:08 +01:00
1 parent 62184f4e90
commit f4fb494f32
1 file changed
+9 -1
+9 -1
View File
@@ -4,6 +4,7 @@ import logging
import re
from psycopg2.sql import SQL, Identifier
from sql import Column
from trytond.backend.table import (
IndexTranslatorInterface, TableHandlerInterface)
@@ -581,11 +582,18 @@ class IndexMixin:
@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'])