Use declare & loop in BigQuery to insert data

前端 未结 1 1152
太阳男子
太阳男子 2021-01-20 10:40

I just practice using Bigquery & try to use one of my SQL query on it

declare @id int 
select @id = 1
while @id >=1 and @id <= 1000
begin
    inser         


        
相关标签:
1条回答
  • 2021-01-20 10:52

    It is not the best practice to use cursor-based logic when dealing with sql, rather you need to tune yourself into set-based processing. Especially with BigQuery which does not support [yet] cursor processing and procedural logic, but luckily has rich support for ARRAYs which can be used here

    As your question is little abstract - below example is abstract too, but gives you an idea

    #standardSQL
    INSERT INTO `project.dataset.Quincy` (id, col)
    WITH array_to_loop_through AS (
      SELECT id 
      FROM UNNEST(GENERATE_ARRAY(1, 1000, 1)) id
    )
    SELECT id, CONCAT('Rank: ', CAST(id AS STRING))
    FROM array_to_loop_through
    
    0 讨论(0)
提交回复
热议问题