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?
-
1I 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) )teggy– teggy2009-07-27 05:24:08 +00:00Commented Jul 27, 2009 at 5:24
Add a comment
|
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));
^
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.
Comments
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