Oct 23, 2009 11:42 AM
spooling data
-
Like (0)
Hi,
How can i spool data from a table into a file? something similar to the 'spool' command in Oracle. Would appreciate if anyone can help me with this query. I am using WinSql for quering the NZ database.
Thanks and regards,
Samir
nzsql -d $TARGET_DB -A -q -t -c " sql statement here; " > $FILE_NAME
you can also use the -o instead:
nzsql -o $FILENAME -d $TARGET_DB -A -q -t -c "sql statement here; "
or
nzsql -o $FILENAME -d $TARGET_DB -A -q -t <<!
complex sql statement here
!
HI David,
i tried below command
nzsql -db XXX_YY -u ABC -pw XXXXX -host ***** -a -E -f /usr/abc_123.sql > /usr/abc_123.log
above script resulted in few errors.....but log file didnot capture the errors......how to capture those errors ....
Also,.if we are running script in database using \i how to spool the results?...... any way?
thanks....
Need to do 2 steps to unload data from your database into a file:
1. Create an external table that uses column definitions from an existing table:
CREATE EXTERNAL TABLE demo_ext SAMEAS emp USING (dataobject
('/tmp/demo.out') DELIMITER '|');
2.Unload data from your database into a file by using an insert statement:
INSERT INTO demo_ext SELECT * FROM emp;
For more detail see "CREATE EXTERNAL TABLE" in documentation.
Hi
I had a situation where windows server had SQL server installed and I was hitting a remote Netezza server to extract data. The approach followed was to store all the .SQL files under a single location and create a batch script which will issue a SQL CMD command to spool data into flat files. Here is the syntax of the SQL CMD comman:
sqlcmd -W -S <Server Name on which SQL Server is installed> -h -<Number of header rows to be skipped> -s "<Delimiter>" -i <Input .SQL file along with path> -o <Output .TXT file along with path - this will be over written in case it already exists>
Shared this as this thread seems to be pretty similar. Hope this helps !
Regards
BT
Errors from your nzsql command should print on the screen as you haven't re-directed the SYSERROR to a file.
example:
nzsql -a -E -f /usr/abc.sql > /usr/abc.log 2>&1
above statement will capture the errors in log itself when these processes are run in the background.
when you are running the script in db, you can spool the output using \o <file name> on the nzsql prompt.
if you are using "nzsql" well and good, because nzsql has various option to spool the data to a flat file. Please check all the option nzsql provides using:
nzsql -h
This is not quite accurate. A remote external table can be used from an ODBC- or JDBC-connected client to create an flat file local to the client system with the REMOTESOURCE option. Remote external tables cannot be used with nzsql, since the underlying connection is not ODBC.
For example, with Aginity Workbench on my Windows 7 laptop connected to to TwinFin3 I ran the following:
drop table pass;
create table pass (
username varchar(64) not null,
password char(8),
userid bigint not null,
groupid bigint not null,
fullname varchar(255),
homeDir varchar(255),
shell varchar(255) )
distribute on random;
insert into pass (select * FROM EXTERNAL '/etc/passwd' using (DELIM ':' TIMEDELIM '-')) limit 28 ;
CREATE EXTERNAL TABLE 'C:\Users\IBM_ADMIN\Documents\tmp\0928\localpass.txt' using (DELIM '|' REMOTESOURCE 'ODBC') as select * from pass;
The result is a file called localpass.txt on my laptop.
Agree with Andrew:
Its nzsql which doesn't support remote external tables. Exporting data to a system other than netezza host can be done with ODBC or JDBC connection.

