From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | valerian <valerian2(at)hotpop(dot)com> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: type-casting and LIKE queries |
Date: | 2003-03-14 07:05:31 |
Message-ID: | 20030313230024.V76775-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, 14 Mar 2003, valerian wrote:
> I have an indexed column called home_phone, which is of type bigint.
> How can I search this column efficiently, using LIKE queries? For
I don't think you do. LIKE is defined on string types in any case, so even
if you could convert it to a bigint, it's not going to do what you seem
to want (using an index on a bigint).
You could make a function that got say the top 3 digits of a number and
use it in a functional index.
However, for what you're doing, that might not be safe anyway (nor would
like) unless you're certain that your input format is fixed or at least
requires a consistent number of digits (what happens if someone doesn't
put an area code and you expect one, or does and you don't).
> example:
>
> test=> SELECT id FROM user WHERE home_phone LIKE '407%'::bigint;
> ERROR: Bad int8 external representation "407%"
>
> Obviously, that's not correct, but I'm confused as to how the % and ?
> characters can be used along with type-casting. Or can they?
From | Date | Subject | |
---|---|---|---|
Next Message | Mohd Toha Taifor | 2003-03-14 07:20:29 | Re: Is there any procedure to start postgre database server automatically |
Previous Message | shreedhar | 2003-03-14 07:01:36 | Is there any procedure to start postgre database server automatically |