From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Marc Mamin <M(dot)Mamin(at)intershop(dot)de> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Problem with ALTER TYPE, Indexes and cast |
Date: | 2015-07-08 13:43:53 |
Message-ID: | 20647.1436363033@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Marc Mamin <M(dot)Mamin(at)intershop(dot)de> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Marc Mamin | 2015-07-08 14:56:31 | Re: Problem with ALTER TYPE, Indexes and cast |
Previous Message | Tom Lane | 2015-07-08 13:34:21 | Re: 9.4 on Ubuntu 15.04: ENETUNREACH error? |