Export data to CSV using nzsql

冷暖自知 提交于 2019-12-05 20:20:45

Whenever you want to export data from Netezza, you will want to use its external tables functionality.

If you are exporting to a filesystem mounted locally to the Netezza host, you could use this:

CREATE external TABLE '/tmp/test_export.txt' USING (delimiter '^') AS
SELECT *
FROM test_export;

If you are connecting to Netezza via JDBC, ODBC, or OLE-DB via tool like Aginity Workbench, and want to export the data locally to your workstation, you could use this:

CREATE external TABLE 'c:\test_export.txt' USING (delimiter '^' remotesource odbc) AS
SELECT *
FROM test_export;

Unfortunately, there is is no external table option that will allow you to also wrap every column in quotation marks. You will have to do that explicitly with a concatenation in the SQL like this:

CREATE external TABLE 'c:\test_export.txt' USING (delimiter '^' remotesource odbc) AS
SELECT  '"' || col1 || '"',
        '"' || col2 || '"'
FROM test_export;

You can also use the nzsql CLI interface with the following options to achieve something similar, but it is quite a bit slower. For example, on my system, using the external table method to export about 2 million rows, which creates an export file about 3.5 GB in size, takes 20 seconds. With the CLI method it took 3about 180 seconds.

nzsql -d DB_NAME -F "^" -t -A -o export.txt  -c "select * from test_export" 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!