简体   繁体   English

雪花数据仓库的 SELECT INTO 语法

[英]SELECT INTO syntax for Snowflake Datawarehouse

I believe there's an SELECT INTO -like syntax in Snowflake, but I am unable to find documentation or examples to use it.我相信 Snowflake 中有一个SELECT INTO的语法,但我找不到使用它的文档或示例。

CREATE TABLE raw_data (
    Timestamp TIMESTAMP NOT NULL, 
    Date DATE NOT NULL, 
    UserID STRING,
    Address STRING,
    Phone STRING,
    Value INTEGER
);

COPY INTO raw_data from 's3://my_bucket'
CREDENTIALS=(AWS_KEY_ID='XXXXX' AWS_SECRET_KEY='XXXX')
ON_ERROR=CONTINUE;

CREATE TABLE summary (
    Date DATE NOT NULL,
    UserID STRING,
    Value INTEGER
);

INSERT INTO summary 
SELECT Date, UserID, Value FROM raw_data

The above works, but rather than defining the table summary I want to SELECT INTO and have the SQL parser create the table for me.以上工作,但不是定义表summary我想SELECT INTO并让 SQL 解析器为我创建表。

You can use Create Table AS (CTAS) to accomplish this.您可以使用 Create Table AS (CTAS) 来完成此操作。 In your case it would be:在您的情况下,它将是:

CREATE TABLE SUMMARY AS
SELECT
  Date
, UserID
, Value
FROM
  raw_data;

Here is an example using no data that I have tested:这是一个没有使用我测试过的数据的例子:

create table foo as select $1, $2
from

    values ( 1, 'two' ), ( 3, 'four' ), ( 5, 'six' );

    select * from foo;

Hope this helps!希望这可以帮助!

CREATE TABLE summary AS SELECT Date, UserID, Value FROM raw_data

You can also use the standard "WITH AS" nomenclature:您还可以使用标准的“WITH AS”命名法:

    with a as (
        SELECT
        Date
        ,UserID
        ,Value
        FROM
        raw_data)
    SELECT * FROM a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM