sqlshellunixnetezzanzsql

Netezza : Fetch all database names and write to a file in unix directory


I want to create a shell script which runs a Netezza SQL and create lookup file dbnames.lkp in a unix directory

lookup file name : dbnames.lkp

Could someone help me with nzsql command. I know just to connect to Netezza server using nzsql command and then run the queries. But my requirement is that the shell script should run connect and write the result of SQL query to a lookup file

nzsql -u $user -pw $password -d $db -host $hostname

Solution

  • You can query Netezza System view _v_database to fetch all databases in the connected server, provided the user should have access.

    You can create a shell script with below command and this will take care of it.

    user=<user_name>
    password=<password>
    query="select database from _v_database;"
    file=dbnames.lkp
    dbname=<dbname_to_connect>
    hostname=<server>
    nzsql -u $user -pw $password -d $dbname -host $hostname  -o $file -A -t -c  "$query"
    

    -c : will run only a single query and exit nzsql.

    You can get more information from below link:

    https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.1.0/com.ibm.nz.adm.doc/r_sysadm_nzsql_command.html