Create table SQL syntax in Google Bigquery

时间:2016-12-09 12:42:19

标签: google-bigquery

I've been reading the bigquery documentation since late last night and understand very little of it. It talks about loading data via different methods, but doesn't say how to create the table that I'm going to load data into. When I use the web UI it expects me to type out the schema. My table has over 400 columns. I will not type out hundreds of column names, types and lengths.

I've been uploading hundreds of GB of data in csv format to a google bucket. The csv files do not have column names. I have the schema in sql format which I prefer to use.

If I try creating a table through a query I get an error already on line 2 that says,

"Error: Encountered "" at line 2, column 1."

CREATE TABLE [example-mdi:myData_1.ST] (
`ADDRESS_ID` varchar(9),
`INDIVIDUAL_ID` varchar(2),
`FIRST_NAME` varchar(25),
`LAST_NAME` varchar(2),...

How can I do this or what is the right way?

4 个答案:

答案 0 :(得分:3)

您可以使用CREATE TABLE语句使用标准SQL创建表。在您的情况下,语句看起来像这样:

CREATE TABLE `example-mdi.myData_1.ST` (
  `ADDRESS_ID` STRING,
  `INDIVIDUAL_ID` STRING,
  `FIRST_NAME` STRING,
  `LAST_NAME` STRING,
  ...
);

答案 1 :(得分:2)

在Web UI中创建表格时 - 您可以按字段(Edit as Text模式 - 默认模式)输入架构,也可以输入架构作为文本(CREATE TABLE模式)
因此,如果您已经拥有sql格式的架构,则可以使用它(您可能需要稍微调整它以符合BigQuery)

查看有关不同客户的https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html的更多信息(在上面的“我们”部分中没有提供选项,因此我认为这就是您错过的原因)

P.S。截至今天,BigQuery不支持DDL - 因此db.deleteNote(position);不可用

  

更新

截至今天 - 2018年1月17日 - BigQuery creating tables支持现在位于data definition language

答案 2 :(得分:1)

自 2021 年 4 月起,可以使用标准 SQL 直接完全创建复杂表(请参阅具体的 syntax guide)。

CREATE TABLE IF NOT EXISTS `project.dataset.table_name`
(
    someName STRING
    , dateTime TIMESTAMP NOT NULL -- REQUIRED or non-null column
    , index INT64 -- INT64 for INTEGER column
    , longitude FLOAT64 -- FLOAT64 for FLOAT column
    , arr ARRAY< -- declaring Array. This ARRAY is of datatype STRUCT
        STRUCT< -- declaring STRUCT
            a FLOAT64 -- the individual STRUCT members do not need the STRUCT column name again
            , b STRING
        >
    >
);

答案 3 :(得分:0)

米哈伊尔是对的并且得到了答案。如果你和我一样慢,你会想要更多的细节,因为在他指出正确的方式之后,它还需要一段时间来弄清楚他在说什么以及如何完成它。

当您在创建表用户界面时,单击“编辑为文本”链接。

enter image description here

在弹出的文本框输入中,您将输入以下内容:

ADDRESS_ID:string,
INDIVIDUAL_ID:string,
First_name:string,
Last_name:string...

不允许使用连字符。