How to execute unix commands within nzsql

netezzascriptingteradataunix

I'm converting a script from Teradata to Netezza, and I'm stuck at the portion where BTEQ uses the functionality of the OS to check if a file contains any data. If it does, it is deleted. I want to perform the same function in nzsql.

Can anyone please help?

Best Answer

The documentation for nzsql states that to shell-out you just have to use blackslash pling, followed by the command:

\! command

If you need to know how to test for file size in a shell script, you can use something similar to:

if [[ -f $file ]] && [[ -s $file ]]; then 
  echo "File exists and is greater than 0 bytes" ; 
  rm -f $file
fi

-f checks that it exists, -s checks if it's greater than 0 bytes.