【问题标题】:Adding LIMIT fixes "Invalid digit, Value N" error in Amazon Redshift. Why?添加 LIMIT 可修复 Amazon Redshift 中的“无效数字,值 N”错误。为什么?
【发布时间】:2016-11-26 04:10:57
【问题描述】:

我在 Redshift 表上有一个标准的 listings 表,其中包含所有 varchars(由于加载到数据库中)

这个查询(简化)给了我错误:

with AL as (
  select
    L.price::int as price,
  from listings L
  where L.price <> 'NULL'
    and L.listing_type <> 'NULL'
)
select price from AL
where price < 800

和错误:

  -----------------------------------------------
  error:  Invalid digit, Value 'N', Pos 0, Type: Integer 
  code:      1207
  context:   NULL
  query:     2422868
  location:  :0
  process:   query0_24 [pid=0]
  -----------------------------------------------

如果我删除 where price &lt; 800 条件,查询返回就好了...但我需要 where 条件。

我还检查了price 字段的号码有效性,一切正常。

玩了之后,这实际上使它起作用了,我无法解释为什么。

with AL as (
  select
    L.price::int as price,
  from listings L
  where L.price <> 'NULL'
    and L.listing_type <> 'NULL'
  limit 10000000000
)
select price from AL
where price < 800

请注意,该表的记录数远远少于限制中规定的数量。

任何人(可能来自 Redshift 工程师团队)都可以解释为什么会这样吗?可能与查询计划的执行和并行化方式有关?

【问题讨论】:

  • 很高兴看到这个问题的答案!

标签: amazon-web-services amazon-redshift


【解决方案1】:

我的查询可以简单地表达为:

SELECT TOP 10 field1, field2
FROM table1
INNER JOIN table2
ON table1.field3::int = table2.field3
ORDER BY table1.field1 DESC

删除对::int 的显式转换为我解决了类似的错误。

同时,postgresql 在本地需要 "::int" 才能工作。

对于它的价值,我的本地 postgresql 版本是 PostgreSQL 9.6.4 on x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 8.1.0 (clang-802.0.42), 64-bit

【讨论】:

    【解决方案2】:

    Loading CSV data with NaN into AWS Redshift

    我在搜索谷歌时发现了这篇文章,但上面的链接有我需要的。我正在导入值为 NaN 的数值列,redshift numeric 不支持该列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      • 2019-06-06
      • 2018-04-07
      相关资源
      最近更新 更多