1

I am creating a table called Posts in which I want to have:

id SERIAL PRIMARY KEY, title, message TEXT, created_by INTEGER.

I am having question on the title and message fields.

Type TEXT is what I want to use for message, but what about title? Shall I use varchar(255)?

Ram Mudaliar
  • 541
  • 2
  • 5
  • 12
  • See [`varchar(any_limit_you_want)`](http://www.postgresql.org/docs/9.1/static/datatype-character.html) - as such the question is an opinion. The impact of different lengths is effectively non-existent, and the slight storage differences are covered in the docs. `text` is the same as saying `varchar(without_a_limit)`. (The varies by database engine, annoyingly.) – user2864740 Sep 13 '15 at 16:08
  • 3
    It doesn't matter. From a storage or performance point of view both are identical. And if you think that 255 has some hidden magic or advantage over 200 or 300 then you are mistaken. –  Sep 13 '15 at 16:09
  • thank you Sir and Sir. one question, sorry for the beginner level, is if I want to limit the title length to something like 300 chars, what is a good way to do that? – Ram Mudaliar Sep 13 '15 at 16:15
  • If you have a business requirement that the length should not exceed 300 then do use `varchar(300)`. –  Sep 13 '15 at 17:02
  • @RamMudaliar *Read* the link provided .. please. – user2864740 Sep 13 '15 at 23:06
  • Thank you Sir I did read, but one thing I was wondering is I saw another post on this webpage which said in today there is no need to do the varchar(n) and instead to just use text. But I was wondering to use varchar(300) or use text only. Sir your link was very helpful and did answer my question. Thank you – Ram Mudaliar Sep 13 '15 at 23:10
  • Hope this helps http://stackoverflow.com/questions/4848964/postgresql-difference-between-text-and-varchar-character-varying – begemoth Sep 16 '15 at 06:31

0 Answers0