Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatype for phone numbers in postgresql

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?

like image 793
joedenly Avatar asked Jan 28 '20 06:01

joedenly


People also ask

What type of data type is phone number?

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.

Is phone number varchar or INT?

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.

Which data type is appropriate to represent a telephone number?

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).


2 Answers

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.

like image 105
Laurenz Albe Avatar answered Oct 05 '22 10:10

Laurenz Albe


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 ]

like image 21
Karamdeep Singh Avatar answered Oct 05 '22 11:10

Karamdeep Singh