添加LIMIT修复了Amazon Redshift中的"无效数字,值N"错误.为什么?

huy*_*huy 6 amazon-web-services amazon-redshift

listings在Redshift表上有一个带有所有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
Run Code Online (Sandbox Code Playgroud)

和错误:

  -----------------------------------------------
  error:  Invalid digit, Value 'N', Pos 0, Type: Integer 
  code:      1207
  context:   NULL
  query:     2422868
  location:  :0
  process:   query0_24 [pid=0]
  -----------------------------------------------
Run Code Online (Sandbox Code Playgroud)

如果我删除where price < 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
Run Code Online (Sandbox Code Playgroud)

请注意,该表的记录远少于限制中所述的数字.

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

gre*_*les 1

我的疑问可以简单地表达为:

SELECT TOP 10 field1, field2
FROM table1
INNER JOIN table2
ON table1.field3::int = table2.field3
ORDER BY table1.field1 DESC
Run Code Online (Sandbox Code Playgroud)

删除显式强制转换::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