雪花 - >如何将日期(时间戳)从舞台插入桌子?
雪花 - >如何将日期(时间戳)从舞台插入桌子?
例如 : 我有以下平面文件
FILE.CSV
ID; DATE ; TEXT
6908402;16-06-2022 13:28:52;DAWEAWEADA
6908403;16-06-2022 ; asdasda
6908404;16-06-2022 13:28:53;helloTest
6908405;16-06-2022 13:28:54;hello%%$%
6908406;16-06-2022 13:28:55;
创建的格式,该格式将包含
CREATE OR REPLACE FILE FORMAT DBO.CSV_SEMICOLON
type = 'CSV'
field_delimiter = ';'
skip_header = 1
encoding=UTF8
;
我将格式分配给新阶段的
CREATE STAGE IF NOT EXISTS DBO.STG_FILE file_format = DBO.CSV_SEMICOLON;
我将信息插入阶段
REMOVE @STG_FILE;
put file://D:\TEST\FILE.CSV @STG_FILE;
文件,一旦将信息插入@stage_file,
,我想将信息插入表中。 这是我遇到问题的地方此值
的定义是目的地字段,
Table : dbo.T_FILE
ID = VARCHAR(255)
DATE = TIMESTAMPNTZ
TEXT = VARCHAR(5000)
-------------
-INSERT TABLE
-------------
INSERT INTO DBO.T_FILE(ID, "DATE", TEXT)
SELECT $1, $2, $3,
FROM @STG_FILE WHERE $3 <> ''
非常感谢您的建议
SnowFlake -> How to insert a date (timestamp) from a stage to a table?
For example :
I have the following flat file
FILE.CSV
ID; DATE ; TEXT
6908402;16-06-2022 13:28:52;DAWEAWEADA
6908403;16-06-2022 ; asdasda
6908404;16-06-2022 13:28:53;helloTest
6908405;16-06-2022 13:28:54;hello%%$%
6908406;16-06-2022 13:28:55;
I create the format that will contain the file
CREATE OR REPLACE FILE FORMAT DBO.CSV_SEMICOLON
type = 'CSV'
field_delimiter = ';'
skip_header = 1
encoding=UTF8
;
I assign the format to the new stage
CREATE STAGE IF NOT EXISTS DBO.STG_FILE file_format = DBO.CSV_SEMICOLON;
I insert the information to the stage
REMOVE @STG_FILE;
put file://D:\TEST\FILE.CSV @STG_FILE;
Once the information is inserted into the @stage_file, I want to insert the information into the table.
This is where I have problems since the $2 column of the stage that comes from the file can come either just the date or with the time , I don't know what I should do to be able to insert this value
the definition of the destination fields are these
Table : dbo.T_FILE
ID = VARCHAR(255)
DATE = TIMESTAMPNTZ
TEXT = VARCHAR(5000)
-------------
-INSERT TABLE
-------------
INSERT INTO DBO.T_FILE(ID, "DATE", TEXT)
SELECT $1, $2, $3,
FROM @STG_FILE WHERE $3 <> ''
Thank you very much for your advice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目标表 -
查询 -
将插入以下
从下面给出的源文件 -
Target table -
Below Query -
will insert following -
After reading from the source file given below -