Search Postgresql Archives

Re: Problem with ALTER TYPE, Indexes and cast

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marc Mamin <M.Mamin@xxxxxxxxxxxx> writes:
> Now I have generated queries that include cast information in order to ensure that the indexes get used.

> e.g.:  WHERE month1.foo = cast('XY' as character(2))

> with mixed type, this should become something like:

>  SELECT ... FROM month1
>  WHERE month1.foo = cast('XY' as character(2))
>  UNION ALL
>  SELECT... FROM month2
>  WHERE month2.foo = cast('XY' as varchar)
 
>  which is quite complicated to resolve in our "query builder framework"
 
 >  There seems to be no way to have dynamic casting, something like:
 
>   WHERE month2.foo = cast('XY' as 'month2.foo'::regtype)
  
>  Is there a way for it ?

If the comparison values are always string literals, then you should just
drop the casts altogether, ie

  WHERE month2.foo = 'XY'

In this sort of situation the literal's type is preferentially resolved as
being the same as whatever it's being compared to.

			regards, tom lane


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux