Hi.
I want to create a function or operator, that will convert column or
string from utf-8 encoding to ascii.
I'm not sure, how function / operators work in SA. So let's start from
the beginnig:
1) using postgresql 8.3, sqlalchemy 0.5.3
2) had created function in pgsql:
CREATE FUNCTION to_ascii(bytea, name)
RETURNS text AS 'to_ascii_encname' LANGUAGE internal RETURNS NULL ON
NULL INPUT;
3) converting from utf-8 to ascii:
to_ascii(convert_to('čačašaša','latin2'), 'latin2')
result: cacasasa
4) using it like this:
... WHERE to_ascii(convert_to(<column_name>,'latin2'), 'latin2') ILIKE
to_ascii(convert_to(<non_ascii_str>,'latin2'), 'latin2')
5) my vision is to use it like this:
session.query(Client).filter( ascii(Client.name).ilike(ascii(name)).all
()
or
session.query(Client).filter( ascii(Client.name).ascii_ilike(name).all
()
or something other :)
I have tried this, but had no luck:
def ascii_op(val, enc='latin2'):
return "to_ascii(convert_to(%(val)s,'%(enc)s'), '%(enc)s')" % dict
(val=val, enc=enc)
def ascii(column):
return _UnaryExpression(column, modifier=ascii_op)
returning:
WHERE client.name <function ascii_op at 0xb7901ed4> ILIKE mario
<function ascii_op at 0xb7901ed4>
thx 4 help guys.. :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---