Skip navigation
19343 Views 9 Replies Latest reply: Sep 29, 2011 1:47 AM by Syed Mateen RSS
samirkakade New Enzee 19 posts since
Sep 3, 2009
Currently Being Moderated

Oct 23, 2009 11:42 AM

spooling data

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

  • David Birmingham Active Enzee 426 posts since
    Sep 24, 2007
    Currently Being Moderated
    1. Oct 23, 2009 12:25 PM (in response to samirkakade)
    Re: spooling data

    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

     

    !

  • ulab New Enzee 59 posts since
    Jul 1, 2011
    Currently Being Moderated
    3. Sep 25, 2011 5:54 AM (in response to samirkakade)
    Re: spooling data

    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....

  • Sergey New Enzee 3 posts since
    Sep 23, 2011
    Currently Being Moderated
    4. Sep 26, 2011 12:14 PM (in response to samirkakade)
    Re: spooling data

    To create an external table that uses column definitions from an existing table, enter:
    CREATE EXTERNAL TABLE demo_ext SAMEAS emp USING (dataobject
    ('/tmp/demo.out') DELIMITER '|');

    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.

  • bharat.tandon New Enzee 16 posts since
    May 6, 2010
    Currently Being Moderated
    5. Sep 26, 2011 12:28 PM (in response to samirkakade)
    Re: spooling data

    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

  • Syed Mateen New Enzee 19 posts since
    Oct 22, 2010
    Currently Being Moderated
    6. Sep 28, 2011 12:18 AM (in response to ulab)
    Re: spooling data

    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.

  • Syed Mateen New Enzee 19 posts since
    Oct 22, 2010
    Currently Being Moderated
    7. Sep 28, 2011 12:23 AM (in response to bharat.tandon)
    Re: spooling data

    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

  • Andrew Colby New Enzee 3 posts since
    Apr 28, 2009
    Currently Being Moderated
    8. Sep 28, 2011 10:15 AM (in response to Sergey)
    Re: spooling data

    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.

    WindowsExplorer.jpg

  • Syed Mateen New Enzee 19 posts since
    Oct 22, 2010
    Currently Being Moderated
    9. Sep 29, 2011 1:47 AM (in response to Andrew Colby)
    Re: spooling data

    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.

More Like This

  • Retrieving data ...

Bookmarked By (1)

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points