EdwardBloom
EdwardBloom

Reputation: 109

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?

Upvotes: 8

Views: 17753

Answers (4)

tburette
tburette

Reputation: 181

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.

Upvotes: 8

Linger
Linger

Reputation: 15058

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.

Upvotes: 8

Papouche Guinslyzinho
Papouche Guinslyzinho

Reputation: 5458

here is the documentation

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

you can also use vachar(n)

Upvotes: 1

Kuberchaun
Kuberchaun

Reputation: 30324

Go ahead and make use of VARCHAR(30).

Upvotes: 1

Related Questions