3

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

1
  • 1
    I apologize for not being clear. Here is how my current table looks like: property_table = schema.Table('property', meta.metadata, schema.Column('id', types.Unicode(255), primary_key=True), schema.Column('name', types.Unicode(255), nullable=False), schema.Column('address', types.Unicode(255), nullable=False), schema.Column('city', types.Unicode(255), nullable=False), schema.Column('state', types.Unicode(255), nullable=False), schema.Column('zip', types.Unicode(255), nullable=False) ) Commented Jul 27, 2009 at 5:24

3 Answers 3

4

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));
                          ^

Maybe you meant varchar(255). In this case - let me ask: what will happen if you'll need 320 character description?

Personally I prefer to use TEXT datatype - since database generally doesn't care if the string is 100 or 1000 characters long.

Sign up to request clarification or add additional context in comments.

Comments

2

It's worth adding to depesz's answer that there are no performance penalties for using text type rather than varchar(n) or char(n) data types, so unless you need to set a hard limit for business purposes just use text. Even then, use text with a length constraint :-)

Comments

-1

There are a number of reasons to use proper datatypes in your databases. Performance (pdf) is the biggest concern, but there are other reasons too. For example:

  • Dates will not sort properly unless they are a date datatype (usually a unix timestamp)
  • You cannot use mathematical operators on numbers that are stored as strings
  • "true" as a string does not equal boolean true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.