簡體   English   中英

雪花表和生成器函數未給出預期結果

[英]Snowflake table and generator functions does not give expected result

我嘗試創建一個簡單的 SQL 來跟蹤 query_history 的使用情況,但在使用tablegenerator函數(下面名為x的 CTE)創建我的時隙時遇到了麻煩。

當使用我的時隙限制 query_history 時我沒有得到任何結果,所以過了一會兒我硬編碼了一個 SQL 以給出相同的結果(下面名為y的 CTE)並且這工作正常。

為什么x不起作用? 據我所知xy產生相同的結果?

要測試示例,首先按原樣運行代碼,這不會產生任何結果。 然后將x as timeslots並將y as timeslots ,這將給出所需的結果。

with 
x as (
    select
        dateadd('min',seq4()*10,dateadd('min',-60,current_timestamp())) f,
        dateadd('min',(seq4()+1)*10,dateadd('min',-60,current_timestamp())) t
    from table(generator(rowcount => 6))
), 
y as (
    select
        dateadd('min',n*10,dateadd('min',-60,current_timestamp())) f,
        dateadd('min',(n+1)*10,dateadd('min',-60,current_timestamp())) t
    from (select 0 n union all select 1 n union all select 2 union all select 3 
          union all select 4 union all select 5)
)

--select * from x;
--select * from y;

select distinct 
    user_name,
    timeslots.f
from snowflake.account_usage.query_history, 
   x as timeslots
   --y as timeslots
where start_time >= timeslots.f
and start_time < timeslots.t
order by timeslots.f desc;

(我知道代碼不是最優的,這只是為了說明問題)

序列號

返回一個單調遞增的整數序列,帶有回繞。 環繞發生在 integer 寬度(1、2、4 或 8 字節)的最大可表示 integer 之后。

如果需要完全有序、無間隙的序列,請考慮使用 ROW_NUMBER window function。

為了:

with x as (
    select
        dateadd('min',seq4()*10,dateadd('min',-60,current_timestamp())) f,
        dateadd('min',(seq4()+1)*10,dateadd('min',-60,current_timestamp())) t
    from table(generator(rowcount => 6))
)
SELECT * FROM x;

應該:

with x as (
    select
        (ROW_NUMBER() OVER(ORDER BY seq4())) - 1 AS n,
        dateadd('min',n*10,dateadd('min',-60,current_timestamp())) f,
        dateadd('min',(n+1)*10,dateadd('min',-60,current_timestamp())) t
    from table(generator(rowcount => 6))
)
SELECT * FROM x;

復制到<div id="text_translate"><p>我正在嘗試將數據從本地復制到雪花,我得到了</p><blockquote><p> snowflake.connector.errors.ProgrammingError: 001757 (42601): SQL 編譯錯誤:表 'RAW_DATA' 不存在</p></blockquote><p>相同的代碼在 Jupiter notebook 中有效,但在 vs code 中無效。 我的角色是 accountadmin,所以權限沒有問題。</p><p> 我要運行的代碼是這個</p><pre>COPY INTO RAW_DATA file_format=(FIELD_OPTIONALLY_ENCLOSED_BY ='"' skip_header=1)</pre></div>在雪花拋出表中不存在<table> </table>

[英]COPY INTO <table> in snowflake throws table does not exist

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM