views:

33

answers:

1

Hello,

I am using Nhibernate 2 and PostgreSql

The above code generate a query with a cast on expression

res = _session.CreateCriteria(typeof(C))
                    .Add(Restrictions.Eq("Exp", Exp))
                    .AddOrder(new Order("Fr", false))
                    .SetMaxResults(MW)
                    .List<C>();

Exp is a character varying(30)

The generated query looks like: SELECT ... FROM table WHERE Exp = 'text':: text ...

I want to get rid of cast 'text":: text because the index is not used.

Nicolas

A: 

That doesn't make sense. The cast shouldn't matter. Is this a UTF-8 database?

Joshua D. Drake
It is an UTF-8 database. If i remove the cast in the query the query plan is not the same, the index is used.
Nicolas Cornu