我有这样的查询和这样的错误:
dbadmin=> update platforms set description = E'ЮлÑ\217 - Ð\237еÑ\200Ñ\203, Ð\221оливиÑ\217, ÐквадоÑ\200 where id = 189;
ERROR 4800: String of 92 octets is too long for type Varchar(80)
当我尝试检查刺痛的长度时,我得到另一个值:
dbadmin=> select octet_length(E'ЮлÑ\217 - Ð\237еÑ\200Ñ\203, Ð\221оливиÑ\217, ÐквадоÑ\200');
octet_length
--------------
84
(1 row)
为什么价值不同?
如何自动将字符串剪切为特定的八位字节数?
目前我正在使用python函数,它返回长度为80的字符串(上面的字符串),有一些sqlalchemy
类:
from sqlalchemy.sql.sqltypes import String
from project import SessionVertica
def process(max_length, value):
literal_processor = String.literal_processor(SessionVertica.bind.dialect)
if literal_processor:
result = unicode(literal_processor(value))
else:
result = unicode(value)
if len(result) >= max_length:
result = result[:max_length - 2] + '\''
return 'E' + result
答案 0 :(得分:0)
简单:)
def process(max_length, value):
literal_processor = String.literal_processor(SessionVertica.bind.dialect)
if literal_processor:
result = unicode(literal_processor(value))
else:
result = unicode(value)
return result + '::varchar({length})'.format(length=max_length)