Index postgresql_ops ignored when func.lower(column)

Issue #3970 resolved
Віталій Пономар created an issue

Here is code:

from sqlalchemy import Table, Column, Index, String, MetaData, func, create_engine

md = MetaData()
tbl = Table('t1', md, Column('col1', String()))
idx = Index('idx1', func.lower(tbl.c.col1), postgresql_ops={'col1': 'text_pattern_ops'})

e = create_engine("postgresql://postgres:postgres@localhost/test", echo=True)
with e.connect() as c:
    md.create_all(c)

Outputs

 Column |       Type        | Modifiers 
--------+-------------------+-----------
 col1   | character varying |

Indexes:
    "idx1" btree (lower(col1::text))  # NO text_pattern_ops!!!

Comments (5)

  1. Mike Bayer repo owner

    please use a label():

    idx = Index('idx1', func.lower(tbl.c.col1).label('col1_lower'), postgresql_ops={'col1_lower': 'text_pattern_ops'})
    
  2. Mike Bayer repo owner

    test / document postgresql_ops against a labeled expression

    Since postgresql_ops explicitly states that it expects string keys, to apply to a function call or expression one needs to give the SQL expression a label that can be referred to by name in the dictionary. test / document this.

    Change-Id: I4bc4ade46dac27f9c1b92e7823433292beab97b9 Fixes: #3970

    → <<cset 029d0f753852>>

  3. Mike Bayer repo owner

    test / document postgresql_ops against a labeled expression

    Since postgresql_ops explicitly states that it expects string keys, to apply to a function call or expression one needs to give the SQL expression a label that can be referred to by name in the dictionary. test / document this.

    Change-Id: I4bc4ade46dac27f9c1b92e7823433292beab97b9 Fixes: #3970 (cherry picked from commit 029d0f75385298f8056c04eba1d2f9563126a8a6)

    → <<cset ca7f83bf9b7d>>

  4. Mike Bayer repo owner

    test / document postgresql_ops against a labeled expression

    Since postgresql_ops explicitly states that it expects string keys, to apply to a function call or expression one needs to give the SQL expression a label that can be referred to by name in the dictionary. test / document this.

    Change-Id: I4bc4ade46dac27f9c1b92e7823433292beab97b9 Fixes: #3970 (cherry picked from commit 029d0f75385298f8056c04eba1d2f9563126a8a6)

    → <<cset 4120a4c79321>>

  5. Log in to comment