Use unicode (255) for all column types in postgres?

I do not understand when to use different lengths to call unicode. I use types.Unicode (255) for all my columns in my postgres database, such as address, name, description, etc. Is it foolish to do this?

+3
source share
3 answers

Not sure what you mean by "unicode (255)" - there is no such data type in PostgreSQL:

# create table q (x unicode(255));
ERROR:  type "unicode" does not exist
LINE 1: create table q (x unicode(255));
                          ^

Perhaps you meant varchar (255). In this case, let me ask: what happens if you need 320 characters?

Personally, I prefer to use the TEXT data type - since the database as a whole does not care if the string length is 100 or 1000 characters.

+4

depesz , , varchar (n) char (n) , , , , : -)

+2

. Performance (pdf) - , . :

  • , ( unix).
  • ,
  • "true",
0

Source: https://habr.com/ru/post/1713310/


All Articles