self, index: Index, expr: str, remove_suffix: str
) -> str:
# start = expr
- expr = expr.lower()
- expr = expr.replace('"', "")
+ expr = expr.lower().replace('"', "").replace("'", "")
if index.table is not None:
# should not be needed, since include_table=False is in compile
expr = expr.replace(f"{index.table.name.lower()}.", "")
Added support for autogenerate comparison of indexes on PostgreSQL which
include SQL sort option, such as ``ASC`` or ``NULLS FIRST``.
The sort options are correctly detected only when defined using the
- sqlalchemy modifier functions, such as ``asc()`` or ``nulls_first``,
+ sqlalchemy modifier functions, such as ``asc()`` or ``nulls_first()``,
or the equivalent methods.
Passing sort options inside the ``postgresql_ops`` dict is not supported.
--- /dev/null
+.. change::
+ :tags: but, autogenerate, postgresql
+ :tickets: 1248
+
+ Improved autogenerate compare of expression based indexes on PostgreSQL
+ to produce fewer wrong detections.
from sqlalchemy import PrimaryKeyConstraint
from sqlalchemy import String
from sqlalchemy import Table
+from sqlalchemy import text
from sqlalchemy import UniqueConstraint
from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION
from sqlalchemy.sql.expression import asc
lambda t: Index("SomeIndex", t.c.ff + 42),
lambda t: Index("SomeIndex", 42 + t.c.ff),
),
+ (
+ lambda t: Index("SomeIndex", text("coalesce(z, -1)"), _table=t),
+ lambda t: Index("SomeIndex", text("coalesce(q, '-1')"), _table=t),
+ ),
]
with_sort = [