Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of varchar type in PostgreSQL?

I'm migrating my MySQL database to PostgreSQL and have a simple question:
What is the best equivalent of varchar(30) in PostgreSQL? Is it text?

like image 891
EdwardBloom Avatar asked May 07 '14 19:05

EdwardBloom


4 Answers

The best mapping to varchar(30) in MySQL is varchar(30) in PostgreSQL. varchar is part of the sql standard and can be used as is in postgresql.

TEXT is non standard, since you are in a migration situation it might be best to stick to standard elements.

like image 138
tburette Avatar answered Nov 05 '22 17:11

tburette


According to PostgreSQL documentation you can use the following data types:

enter image description here

Of the above the only type that is unlimited is text. So, if you need unlimited space then use text. However, if you know how large the field can be I would use varchar(n). There is no point in using an unlimited data type for a finite requirement. By doing so, you are just wasting space.

like image 41
Linger Avatar answered Nov 05 '22 18:11

Linger


Go ahead and make use of VARCHAR(30).

like image 23
Kuberchaun Avatar answered Nov 05 '22 19:11

Kuberchaun


here is the documentation

http://www.postgresql.org/docs/8.4/static/datatype.html

you can also use vachar(n)

like image 1
Papouche Guinslyzinho Avatar answered Nov 05 '22 18:11

Papouche Guinslyzinho