Netezza SQL Query formatter – nz_format and Examples

  • Post author:
  • Post last modified:February 27, 2018
  • Post category:Netezza
  • Reading time:3 mins read

Sometimes you may have to get the view or any object DDL directly from the Netezza database, in that case you might have noticed that query will not be in proper format. In this article, we will check Netezza SQL query formatter – nz_format with an example.

Netezza SQL Query formatter - nz_format

Netezza SQL Query formatter – nz_format

You can use the nz_format script functionality to format the Netezza SQL query which is not in proper format.

Script will generate the formatted SQL if you pass raw query in form of file or standard input. The nz_format utility is available at /nz/support/bin path. You either add this path to the system PATH variable or use fully qualified path to execute nz_ddl_table utility.

nz_format Prerequisites

You don’t need any special privilege of permission to use this script.

Netezza SQL Query formatter – nz_format

Below is the usage of the script:

nz_format [<filename>]

inputs:

You can pass the SQL to be formatted as ‘standard in’ or You can pass the name of the file containing the SQL. The stream/file can contain multiple SQL statements. All the queries will be formatted.

Netezza SQL Query formatter – nz_format Example

Below is the sample SQL formatter example:

Raw Query:

$cat test.sql
CREATE OR REPLACE VIEW test_view AS SELECT col1,col2,col3,col4,col5 from test_table where col1 = '123';

Formatted Query:

$nz_format /data/home/test.sql
CREATE
 OR REPLACE VIEW test_view AS
SELECT
 col1,
 col2,
 col3,
 col4,
 col5
FROM
 test_table
WHERE
 col1 = '123';

Read: