首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >postgresql(aws红移)错误1204字符串长度超过DDL长度

postgresql(aws红移)错误1204字符串长度超过DDL长度
EN

Stack Overflow用户
提问于 2019-01-09 01:43:11
回答 1查看 16.8K关注 0票数 8

我正在尝试将csv导入aws redshift( postgresql 8.x)。

数据流是: mysql、->、parquet文件、s3、->、csv文件、s3 ->红移文件。

表结构

mysql表sql:

代码语言:javascript
复制
create table orderitems
(
  id                         char(36) collate utf8_bin not null
    primary key,
  store_id                   char(36) collate utf8_bin not null,
  ref_type                   int                       not null,
  ref_id                     char(36) collate utf8_bin not null,
  store_product_id           char(36) collate utf8_bin not null,
  product_id                 char(36) collate utf8_bin not null,
  product_name               varchar(50)               null,
  main_image                 varchar(200)              null,
  price                      int                       not null,
  count                      int                       not null,
  logistics_type             int                       not null,
  time_create                bigint                    not null,
  time_update                bigint                    not null,
  ...
);

我使用相同的sql在redshift中创建表,但它在导入csv时出错。

我的代码将csv导入redshift (python)

代码语言:javascript
复制
# parquet is dumpy by sqoop
p2 = 'xxx'
df = pd.read_parquet(path)    

with smart_open.smart_open(p2, 'w') as f:
    df.to_csv(f, index=False)  # python3 default encoding is utf-8

conn = psycopg2.connect(CONN_STRING)

sql="""COPY %s FROM '%s' credentials 'aws_iam_role=%s' region 'cn-north-1' 
delimiter ',' FORMAT AS CSV IGNOREHEADER 1 ; commit ;""" %  (to_table, p2, AWS_IAM_ROLE)
print(sql)
cur = conn.cursor()
cur.execute(sql)
conn.close()

得到误差

通过检查STL_LOAD_ERRORSproduct_name列上找到的错误

  • .............................................215g/...:row_field_value
  • err_code: 1204
  • err_reason:字符串长度超过DDL长度

real_value是伊利畅轻蔓越莓奇亚籽风味发酵乳215g/瓶(中文)。

所以看起来像是编码问题。因为mysql是utf-8,csv也是utf-8,所以我不知道出了什么问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-09 08:21:34

您的列是varchar数据类型,长度为50。那是50个字节,不是50个字符。您给出的字符串示例看起来大约是16个汉字,每个字符大概是3个字节(UTF-8)和4个ASCII字符(每个字符是一个字节),因此大约是52个字节。这比列的字节长度长,因此导入失败。

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54102184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档