Netezza nzsql Query Buffer to Edit Command Line Queries

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

Life is much easier if you use any query tools to access Netezza nzsql queries. Some people do not like to use specific tool, instead they use Netezza command line. In this article, we will check on Netezza nzsql Query Buffer to edit command line Queries.

Netezza nzsql Query Buffer

Because the nzsql command is line oriented, it is difficult to edit a complex, multiline SQL statement. Netezza sql supports query buffer that you can use to edit complex and multiline queries.

Netezza nzsql Query Buffer Options

  • \e — Edit the current query buffer or file with an external editor. The insert and save options are similar to vi editor.
    TRAINING.ADMIN(ADMIN)=>\e

    TRAINING.ADMIN(ADMIN)=>\p
    Select count(*) from DIM_DATE;

    TRAINING.ADMIN(ADMIN)=>\e
    COUNT
    --------
    40100
   (1 row)

Once you enter above option, nzsql query buffer will open up and you can enter the query that you want to execute.

When you exit the query buffer editor, the Netezza system automatically runs your query.

Note that the query buffer stores only the last SQL statement. The default editor is vi.

  • \p — Show the contents of the query buffer.
     TRAINING.ADMIN(ADMIN)=>\p 
     Select count(*) from DIM_DATE;
  • \w <file> — Write the query buffer to a file. This option allows you to save the complex query to external file.
     TRAINING.ADMIN(ADMIN)=>\w test.txt

     $cat test.txt
     Select count(*) from DIM_DATE;
  • \r — Reset (clear) the query buffer. You will not get the query if you reset unless you save that to external file.
     TRAINING.ADMIN(ADMIN)=>\r 

     Query buffer reset (cleared).

Read: