[Sqlalchemy-tickets] Issue #3432: Can't use postgresql_ops for expressions (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Wichert A. <iss...@bi...> - 2015-05-24 19:29:11
|
New issue 3432: Can't use postgresql_ops for expressions https://bitbucket.org/zzzeek/sqlalchemy/issue/3432/cant-use-postgresql_ops-for-expressions Wichert Akkerman: I need to build a trigram index for a set of columns in PostgreSQL. The SQL statement looks like this: ```sql CREATE INDEX trgm_idx ON my_table USING gist (language, (coalesce(col1, '') || ' ' || coalesce(col2, '')) gist_trgm_ops); ``` My attempt to do this using SQLAlchemy looks like this: ```python schema.Index('trgm_idx', Mytable.language, (func.coalesce(Mytable.col1, '') + ' ' + func.coalesce(MyTable.col2, '')).label('foo'), postgresql_ops={ 'foo': 'pg_trgm', }, postgresql_using='gist') ``` I use `label()` just to get a key I can pass to `postgresql_ops`. Unfortunately this does not work. This is the generated SQL: ``` CREATE INDEX trgm_idx ON my_table USING gist (language, (coalesce(col1, '') || ' ' || coalesce(col2, ''))) ``` |