如何使用 Squirrel 将 SQL 查询的结果存储在 CSV 文件中?
版本 3.0.3。这是一个相当大的结果集,大约有 300 万行。
Version 3.0.3. It's a fairly large result-set, around 3 million rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
马丁几乎有这个权利。
TL/DR 版本是您需要“SQLScripts”插件(这是“标准”插件之一),然后您可以选择以下菜单选项:
Session
>Scripts< /code> >
将 SQL 的结果存储在文件中
我正在查看 3.4 版,我不知道此功能何时引入,但如果您没有且不能,则可能需要升级。安装 SQLScripts 插件。
有关安装新插件的说明,请访问:http ://squirrel-sql.sourceforge.net/user-manual/quick_start.html#plugins
但是,如果您正在执行 Squirrel 的全新安装,则只需在安装过程中选择“SQLScripts”插件即可
。长版本:
运行查询
连接到数据库。单击
SQL
选项卡。输入您的查询。点击运行按钮(或Ctrl-Enter
)。您应该在窗格下半部分的结果区域中看到前 100 行左右(具体取决于您如何配置
限制行
选项)。导出完整结果
打开
会话
菜单。选择Scripts
项(靠近这个长菜单的底部)。选择将 SQL 结果存储在文件中
。这将打开一个对话框,您可以在其中配置导出。确保选中
导出完整结果集
以获取所有内容。我还没有尝试过使用 300 万行结果集,但我注意到 Squirrel 似乎将数据流式传输到磁盘(而不是在写入之前将其全部读入内存),所以我看不出有任何理由它不会不适用于任意大的文件。
请注意,您可以使用
Ctrl-T
调用工具弹出窗口并选择sql2file
来直接导出到文件。Martin pretty much has this right.
The TL/DR version is that you need the "SQLScripts" plugin (which is one of the "standard' plugins), and then you can select these menu options:
Session
>Scripts
>Store Result of SQL in File
I'm looking at version 3.4. I don't know when this feature was introduced but you may need to upgrade if you don't have and cannot install the SQLScripts plugin.
Instructions for installing a new plugin can be found at: http://squirrel-sql.sourceforge.net/user-manual/quick_start.html#plugins
But if you're performing a fresh install of Squirrel you can simply select the "SQLScripts" plugin during the installation.
Here's the long version:
Run the query
Connect to the database. Click on the
SQL
tab. Enter your query. Hit the run button (orCtrl-Enter
).You should see the first 100 rows or so in the results area in the bottom half of the pane (depending upon how you've configured the
Limit Rows
option).Export the full results
Open the
Session
menu. Select theScripts
item (nearly at the bottom of this long menu). SelectStore Result of SQL in File
.This opens a dialog box where you can configure your export. Make sure you check
Export the complete result set
to get everything.I haven't tried this with a 3 million row result set, but I have noticed that Squirrel seems to stream the data to disk (rather than reading it all into memory before writing), so I don't see any reason why it wouldn't work with an arbitrarily large file.
Note that you can export directly to a file by using
Ctrl-T
to invoke the tools popup and selectingsql2file
.我找到了一种方法来做到这一点,松鼠对此提供了很好的支持。运行 SQL select(导出器将忽略 100 行限制,不用担心)。然后,在主菜单中,选择“会话”、“脚本”、“将 SQL 结果存储在文件中”。默认情况下此功能可能不存在,它可能存在于某些标准插件中(但默认情况下不安装)。不过不知道是哪个插件。
I have found a way to do this, there is a nice support for this in Squirrel. Run the SQL select (the 100 row limit will be ignored by the exporter, don't worry). Then, in the main menu, choose Session, Scripts, Store Result of SQL in File. This functionality may not be present by default, it may be present in some standard plugin (but not installed by default). I don't know which plugin though.
我还想使用 SquirrelSQL 将 SQL 查询结果导出到 CSV 文件。但是根据 更改文件 似乎即使在 SquirrelSql 3.3.0 中也不支持此功能。
到目前为止,我只能通过右键单击 SQL 查询的“结果表”> 来导出显示在“结果表”中的数据。导出为 CSV。默认情况下,表大小为 100 行,CSV 导出也是如此。您可以在“会话属性”>“会话属性”中更改表大小。 SQL>限制行数。例如,将大小更改为 10000,您的导出也将包含 10000 行。问题是,SquirrelSql 将如何处理非常大的结果集(数百万行)......
I also wanted to export results of SQL query to CSV file using SquirrelSQL. However according to changes file it seems that this functionality is not supported even in SquirrelSql 3.3.0.
So far I was able to export only data shown in 'result table' of SQL query by right click on the table > Export to CSV. The table size is by default 100 rows and so is the CSV export. You may change the table size in Session Properties > SQL > Limit rows. E.g. change the size to 10000 and your export will also contain 10000 rows. The question is, how will SquirrelSql deal with really big result sets (millions of rows)...
从 GUI 运行:
使用 CSV 标头复制 (SELECT * FROM some_table) TO '/some/path/some_table.csv'
Run from your GUI:
COPY (SELECT * FROM some_table) TO '/some/path/some_table.csv' WITH CSV HEADER
使用松鼠3.5.0
如果您只有简单的选择查询,“将 SQL 结果存储为文件”非常有用。带有参数的更复杂的参数将无法工作。
即使尝试将 600,000 多行的结果导出到 CSV 文件也可能会失败。
Using Squirrel 3.5.0
The "Store SQL result as file" is great if you only have a simple Select query. A more complex one with parameters wont work.
Even trying to export a result of 600,000+ rows to a CSV file can also fail.