Wednesday, October 1, 2014

How to upload Netezza NZSQL and NZLOAD output to a file.


Can I export the SQL query results from Netezza? 




Lets see how to do this


nzsql -u USER001 -pw pass1 -db PGBDB201  -host myhost.com -c "SELECT * FROM COMPLE.PROD_DIM" > /infa001/Src/PROD.txt

the out put of the query "SELECT * FROM COMPLE.PROD_DIM" will be loaded to the file PROD.txt

Is the above query fails with any error, then that error will be captured in the file PROD.txt

For Auditing or for error capturing the above method is very use full (when you don't have access to bad file or log file).

In the above example instead of using Query we can pass a script file which will have a set of query's.

EX:-  open unix env

$ touch my_script

$ select * from product_dim; >> my_script

$ Select * from customer_dim; >> my_script

$ more my_script

select * from product_dim;
Select * from customer_dim;

and call my_script in NZSQL as follows 

nzsql -u USER001 -pw pass1 -db PGBDB201  -host myhost.com -f $QUER_PATH/my_script  > /infa001/Src/PROD.txt

No comments :