使用默认值填充雪花 table,而不从文件数据中选择默认列值
Populate snowflake table with default values without selecting default column values from the file data
我正在尝试动态加载 table(删除 table 并加载数据 - 类似于截断和加载)。让我们假设 table 需要有 4 个字段,ID、Name、SeqNo 和 DtTimeStamp。
正在从只有两个字段(ID 和名称)的外部暂存 csv\text 文件中选择数据。以下查询给出了多个列不匹配的错误。如何解决该问题?
CREATE OR REPLACE TABLE SOMETABLENAME(ID NUMBER(38,0), Name
VARCHAR(255), SeqNo NUMBER(38,0) NOT NULL AUTOINCREMENT, DtTimeStamp
TIMESTAMP_NTZ(9) NOT NULL DEFAULT CURRENT_TIMESTAMP()) AS SELECT A.
AS ID, A. AS Name FROM @EXTERNALSTAGE/SOME_FILE.CSV A;
如果您仔细查看上面的 SQL 语句,我的 table 有两个额外的字段需要为它加载的每一行自动填充。但是我无法让它工作?
非常感谢任何建议。
提前致谢!
沙迪亚
CREATE TABLE … AS SELECT (CTAS)
CREATE TABLE <table_name> ( <col1_name> , <col2_name> , ... ) AS SELECT ...
The number of column names specified must match the number of SELECT list items in the query; the types of the columns are inferred from the types produced by the query.
要解决它,CTAS 和 INSERT INTO 可以是两个独立的步骤:
CREATE OR REPLACE TABLE SOMETABLENAME(
ID NUMBER(38,0),
Name VARCHAR(255),
SeqNo NUMBER(38,0) NOT NULL AUTOINCREMENT,
DtTimeStamp TIMESTAMP_NTZ(9) NOT NULL DEFAULT CURRENT_TIMESTAMP()
);
-- here INSERT/SELECT have matching column list
INSERT INTO SOMETABLENAME(ID, Name)
SELECT A. AS ID, A. AS Name FROM @EXTERNALSTAGE/SOME_FILE.CSV A;
我正在尝试动态加载 table(删除 table 并加载数据 - 类似于截断和加载)。让我们假设 table 需要有 4 个字段,ID、Name、SeqNo 和 DtTimeStamp。
正在从只有两个字段(ID 和名称)的外部暂存 csv\text 文件中选择数据。以下查询给出了多个列不匹配的错误。如何解决该问题?
CREATE OR REPLACE TABLE SOMETABLENAME(ID NUMBER(38,0), Name VARCHAR(255), SeqNo NUMBER(38,0) NOT NULL AUTOINCREMENT, DtTimeStamp TIMESTAMP_NTZ(9) NOT NULL DEFAULT CURRENT_TIMESTAMP()) AS SELECT A. AS ID, A. AS Name FROM @EXTERNALSTAGE/SOME_FILE.CSV A;
如果您仔细查看上面的 SQL 语句,我的 table 有两个额外的字段需要为它加载的每一行自动填充。但是我无法让它工作?
非常感谢任何建议。
提前致谢! 沙迪亚
CREATE TABLE … AS SELECT (CTAS)
CREATE TABLE <table_name> ( <col1_name> , <col2_name> , ... ) AS SELECT ...
The number of column names specified must match the number of SELECT list items in the query; the types of the columns are inferred from the types produced by the query.
要解决它,CTAS 和 INSERT INTO 可以是两个独立的步骤:
CREATE OR REPLACE TABLE SOMETABLENAME(
ID NUMBER(38,0),
Name VARCHAR(255),
SeqNo NUMBER(38,0) NOT NULL AUTOINCREMENT,
DtTimeStamp TIMESTAMP_NTZ(9) NOT NULL DEFAULT CURRENT_TIMESTAMP()
);
-- here INSERT/SELECT have matching column list
INSERT INTO SOMETABLENAME(ID, Name)
SELECT A. AS ID, A. AS Name FROM @EXTERNALSTAGE/SOME_FILE.CSV A;