Yeah, this will keep coming back as long as people work with schemas,
which use fixed length character types (CHAR, NCHAR), which is
probably for another 30 years. May I propose an enhancement to String
(and as a result to CHAR, NCHAR and Unicode) to take trim=False
keyword and effect a TRIM() function on the server side if set to
True?

class sqlalchemy.types.String(length=None, convert_unicode=False,
assert_unicode=None, unicode_error=None, _warn_on_bytestring=False,
trim=False)

Maybe type constructor is not the cleanest place from the SQLAlchemy
API perspective but would be convenient for users. I am also wondering
if this can be accomplished with a @compiles trick but don't know
how :-p

On Dec 25 2011, 11:58 am, Michael Bayer <mike...@zzzcomputing.com>
wrote:
> On Dec 24, 2011, at 10:52 PM, alex bodnaru wrote:
>
>
>
> > hello friends,
>
> > i'm happily using  sqlalchemy in a tg 2.1 project. with a legacy database, 
> > thus
> > my queries are in the form of dbsession.execute(sql).
>
> sql is...... a string ?    select() construct ?
>
> > where should i hook astripof the data from achar(len) field?
>
> astripon the ....input side ?  output side ?
>
> if we're talking about textual statement and removing trailing chars 
> fromCHARin the result:
>
> class StripChar(TypeDecorator):
>     impl =CHAR
>     def process_result_value(self, value, dialect):
>         if value is not None:
>             value = value.rstrip()
>         return value
>
> sql = text(sql, typemap={'char_col_one':StripChar, 'char_col_two':StripChar})
> execute(sql)

-- 
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