从VSCODE编程将输出作为CSV文件保存为CSV文件

发布于 2025-02-03 01:49:18 字数 315 浏览 2 评论 0原文

我的要求:以CSV文件格式将SQL查询输出(接收到数据)保存到本地驱动器中。

我的操作系统:Windows 10 64位 VS代码1.67.1: 我已经安装了以下扩展名来与雪花数据仓库连接:

  1. SQL工具
  2. Snowflake drougr的SQL工具,

我已经成功连接了我的雪花(云)数据仓库,并在 VS代码。

我想要的是保存(导出)输出(接收到数据)到本地文件(例如d:\ result \ result.csv)。

我该如何实现?

图像附加供您参考。

谢谢大家。 PMK

My Requirement: Save the SQL query output (received the data) in to the local drives in csv file format.

My OS: Windows 10 64 bit
VS Code 1.67.1:
I have installed the following extensions to connect with snowflake data warehouse:

  1. SQL Tools
  2. Snowflake driver for SQL Tools

I have successfully connected my snowflake (cloud) data warehouse and received the data at
the VS code.

What I want is to save (export) the output (received the data) to the local file (for example to D:\result\result.csv).

How can I achieve that?

image attached for your reference.

thank you all.
pmk

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2025-02-10 01:49:18

如果您可以运行一点python,这几乎可以做您需要的

import snowflake.connector
import csv

conn = snowflake.connector.connect(
    user='',
    password='',
    account='',
    warehouse='',
    database='',
    schema='',
    role=''
 )


results = conn.cursor().execute("""MY QUERY""").fetchall()


csvfile = open(r"PATH TO FILE",'a', newline='')
output = csv.writer(csvfile)
output.writerows(results)
csvfile.close

If you can run a bit of python, this does pretty much what you need

import snowflake.connector
import csv

conn = snowflake.connector.connect(
    user='',
    password='',
    account='',
    warehouse='',
    database='',
    schema='',
    role=''
 )


results = conn.cursor().execute("""MY QUERY""").fetchall()


csvfile = open(r"PATH TO FILE",'a', newline='')
output = csv.writer(csvfile)
output.writerows(results)
csvfile.close
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文