Hi Chris,

Use Unicode/UnicodeText wherever you have text (and are able to know its 
character encoding at storage time, preferably always). Text and String are 
really just byte sequences, and should be used if it's arbitrary bytes you 
want to store.

If you don't have control of the DB schema, then you must follow it; if it 
only stores bytes, then it's bytes you put in (i.e. you have to encode your 
text in some particular character encoding). But your application and your 
collaborators and successors will thank you for enforcing consistency: 
always store your text in the same character encoding. Generally: your 
application is responsible for knowing/guessing the character encoding of 
incoming textual data. Your data model should be unconcerned with it if at 
all possible.

The "significant performance overhead" quoted in the docs is if you are 
forcing sqlalchemy to do unicode conversion on a platform that already 
natively supports it. I wouldn't worry about it otherwise.

Under Python 3, Text and String still mean the same thing: they still refer 
to byte-sequences stored in the DB, and Unicode and UnicodeText still refer 
to text. The difference under Python 3 is that "str" is a unicode string 
type (unlike "str" in Python 2.x), and the byte-sequence type is called 
"bytes" (which is what "str" is for in Python 2.x).

So in Python 3 you pass an object of type "bytes" for Text/String columns 
where you would have passed an object of type "str" in Python 2.x, and you 
pass an object of type "str" for UnicodeText/Unicode columns where you would 
have passed an object of type "unicode" in Python 2.x.

Regards,

- Gulli

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to