2016-07-22 71 views
5

我有红移表所有VARCHAR处理标准listings表(由于加载到数据库)在Amazon Redshift中添加LIMIT修复“无效数字,值N”错误。为什么?

这个查询(简体)给我的错误:

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 < 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工程师团队)解释为什么这是它的方式?可能与查询计划如何执行和并行化有关?

+0

将是非常高兴看到这个问题的答案! – ingrid

回答

0

我有可能被简单地表示查询:

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

相关问题