From: Paul Smith <paul@xxxxxxxxxx>
On 15/04/2021 14:47,
soumik.bhattacharjee@xxxxxxx wrote:
Phone numbers aren't numbers. They're text. Does it make sense to add two phone numbers together? No? Then they're not numbers :-) So, either store them as varchar or do something fancy. For instance, you could store them as an bigint (an integer is probably not big enough), with a smallint indicating how many preceding zeros there are - but I'd expect a varchar to be quicker, and it'd certainly be simpler. You say that 'varchar' gives a performance hit - can you explain how? Have you done some performance profiling, or have you just assumed?
create table people (name varchar, phone varchar); create index people_phone on people(cast(phone as bigint)); select * from people where cast('07000123456' as bigint)= cast(phone as bigint) and '07000123456' = phone;
select * from people where cast('000123456' as integer) = cast(substring(phone from length(phone) - 8) as integer) and '07000123456' = phone; -- Paul Paul Smith Computer Services support@xxxxxxxxxx - 01484 855800 -- Paul Smith Computer Services Tel: 01484 855800 Vat No: GB 685 6987 53 Thanks Paul for your broad example. Will test it with more scenarios and update here. |