2016-07-22 75 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

相關問題