3

I would like to export data as CSV from netezza. The data consists of millions of lines of records. The data should be within inverted commas and should have ^ as delimiter. Eg: "a"^"b"^"c"

1 Answer 1

7

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" 
Sign up to request clarification or add additional context in comments.

2 Comments

Can I use nzsql with -o flag. Is there any issue if I go with that method
You can, but it's quite a bit slower. I'll add that to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.