I am new to postgresql so can anyone tell me that is there any specific datatype to store phone numbers in postgresql while creating table in pgadmin or is it just string?
Phone number is a standard XDM data type that describes the details of a phone number. The internal dialing number used to call from a private exchange, operator, or switchboard.
A phone number should always be stored as a string or text and never an integer. Some phone numbers generally use hyphens and possibly parentheses. Also, you might need to indicate the country code before the phone number such as +46 5555-555555.
String (str or text) A phone number is usually stored as a string (+1-999-666-3333) but can also be stored as an integer (9996663333).
I recommend to use text
and add a check constraint that tests the phone number for validity.
This is a good use case for domains. Particularly if you need such a column in several places, it is convenient to have a domain that includes the check constraint.
You can store contact number in BIGINT and VARCHAR.
But with a trade off between security and performance. If you bother about performance (using a big dataset) then you should choose bigint but do read this first Google says never store phone numbers as numeric data If you do not bother about performance as data set is not soo large then go with varchar.
src - [ https://www.mayerdan.com/programming/2017/06/26/db_phone_types ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With