【问题标题】:Inserting a substring of column in Redshift在 Redshift 中插入列的子字符串
【发布时间】:2016-12-16 12:40:48
【问题描述】:

您好,我正在使用 Redshift,其中有一个临时表和一个基表。我的基表中的列(城市)之一的数据类型为 varchar,其长度为 100。当我尝试将列值从暂存表插入基表时,我希望将此值截断为第 100 个字符或最左边100 个字符。这可以在 Redshift 中实现吗?

INSERT into base_table(org_city) select substring(city,0,100) from staging_table; 

我尝试使用上述查询,但失败了。请问有什么解决办法吗?

【问题讨论】:

  • 你遇到了什么错误?
  • 为什么要添加mysqlsql-server 标签?

标签: postgresql amazon-web-services amazon-redshift


【解决方案1】:

试试这个!
您的基表列长度是 Varchar(100),因此您需要子串 0-99 个字符,即 100 个字符。您正在尝试对 101 个字符进行子串化。

INSERT into base_table(org_city) select substring(city,0,99) from staging_table; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多