2016-12-14 10 views
0

私は、このようなクエリとこのようなエラーがあります値が異なるのはなぜのVertica - 文字列のオクテット長

dbadmin=> select octet_length(E'ЮлÑ\217 - Ð\237еÑ\200Ñ\203, Ð\221оливиÑ\217, ЭквадоÑ\200'); 
octet_length 
-------------- 
      84 
(1 row) 

:私はおとり捜査の長さをチェックしようとすると、私は別の値を得た

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) 

文字列を自動的に特定のオクテット番号にカットできますか?

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

簡単:)

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) 
:一部 sqlalchemyクラスがあり、 は現在、私はPythonの関数を使用しています、そして、それは長さ80(上記の文字列)で文字列を返します。