Find column names to insert into BigQuery

前端 未结 2 1348
囚心锁ツ
囚心锁ツ 2021-01-06 15:00

I am trying to do the \"insert into table\" and see that we need to explicitly specify the column names. Is there a way to get this data without having to manual type it out

2条回答
  •  佛祖请我去吃肉
    2021-01-06 15:43

    Using INFORMATION_SCHEMA, Elliott's query can be rewritten as:

    WITH ColumnNames AS (
      SELECT column_name FROM dataset.INFORMATION_SCHEMA.COLUMNS
      WHERE table_schema = 'tablename'
    )
    SELECT CONCAT(
      'INSERT dataset.tablename (',
      ARRAY_TO_STRING(ARRAY(SELECT column_name FROM ColumnNames), ', '),    
      ')');
    

提交回复
热议问题