Netezza / PureData – How To Quote a Single Quote in Netezza SQL

How To Quote a Single Quote in Netezza SQL?

The short answer is to use four single quotes (””), which will result in a single quote within the select statement results.

How to Assemble the SQL to Quote a Single Quote in a SQL Select Statement

Knowing how to construct a list to embed in a SQL where clause ‘in’ list or to add to an ETL job can be a serious time saver eliminating the need to manually edit large lists.  In the example below, I used the Select result set to create a rather long list of values, which needed to be included in an ELT where clause.  By:

  • Adding the comma delimiter (‘,’) and a Concatenate (||) on the front
  • Followed by adding a quoted single Quote (entered as four single quotes (””)) and a Concatenate (||)
  • The Field I which to have delaminated and Quoted (S1.ORDER_NUM)
  • And closed with a quoted single Quote (entered as four single quotes (””))

This results in a delimited and quoted list ( ,’116490856′) which needs only to have the parentheses added and the first comma removed, which is much less work than manually editing the 200 item that resulted from this select.

Example SQL:

SELECT Distinct

‘,’||””|| S1.ORDER_NUM||”” as Quoted_Order_Number

FROM Sales S1

 

How to Quote A Single Quote Example SQL

How to Quote A Single Quote Example SQL

Related Reference

Netezza / PureData – How to build a multi table drop command from a select

Database Management

Database Management

How to Quick Drop Multiple Tables

occasionally, there is a need to quickly drop a list of tables and you don’t always want to write or generate each command individually in Aginity.  So, here is a quick example of how you can use a ‘Select’ SQL statement to generate a list of drop commands for you. Now, this approach assumes there is a common naming convention, so, you may need to adapt it to your needs.

An outline of the Drop Multiple Tables Process

Here is a quick summary of the steps to generate the drop statements from _V_Table:

  1. Build required Netezza SQL select; paying particular attention to the where clause criteria to exclude any unnecessary tables.
  2. Execute the SQL statement
  3. Copy from Aginity Results Tab without headers
  4. Past into new Aginity Query window
  5. validate that only the tables are in the list — No extras
  6. Click with the SQL Drop command list and Execute as a single batch

Example generate the drop statements

select  ‘Drop table ‘||tablename||’;’

from _V_TABLE

where tablename like ‘NZCC_TT_%’;

 

Related References

IBM Knowledge Center > PureData System for Analytics 7.2.1

IBM Netezza database user documentation > Netezza SQL command reference > Drop Table

Netezza / PureData – Aginity for Netezza shortcut key list

Aginity for netezza shortcut key list

Aginity for Netezza

Recently, while working with a couple of my teammates on different projects I picked up a couple shortcut keys for Aginity for netezza, which I did not know existed. So, I thought about be nice to put a list of shortcut keys for future reference. I don’t use most of them very often, but I have flagged the ones that I have found to be frequently useful. I hope you find this useful as well.

Frequently Used By Me

Shortcut Keystrokes

Shortcut Description

Alt-C Complete Code Snippet
Alt-F4 Exit
Alt-Q Go to Query
Alt-R Go to Results
Alt-T Go to Tree
Atl-H User Query History
Ctrl-Alt-0 Goto Bookmark 0
Ctrl-Alt-1 Goto Bookmark 1
Ctrl-Alt-2 Goto Bookmark 2
Ctrl-Alt-3 Goto Bookmark 3
Ctrl-Alt-4 Goto Bookmark 4
Ctrl-Alt-5 Goto Bookmark 5
Ctrl-Alt-6 Goto Bookmark 6
Ctrl-Alt-7 Goto Bookmark 7
Ctrl-Alt-8 Goto Bookmark 8
Ctrl-Alt-9 Goto Bookmark 9
X Ctrl-Alt-C Comment Selection
Ctrl-Alt-Left Goto Previous Bookmark
Ctrl-Alt-Right Goto Next Bookmark
Ctrl-Alt-Shift-0 Set Bookmark 0
Ctrl-Alt-Shift-1 Set Bookmark 1
Ctrl-Alt-Shift-2 Set Bookmark 2
Ctrl-Alt-Shift-3 Set Bookmark 3
Ctrl-Alt-Shift-4 Set Bookmark 4
Ctrl-Alt-Shift-5 Set Bookmark 5
Ctrl-Alt-Shift-6 Set Bookmark 6
Ctrl-Alt-Shift-7 Set Bookmark 7
Ctrl-Alt-Shift-8 Set Bookmark 8
Ctrl-Alt-Shift-9 Set Bookmark 9
Ctrl-Alt-Shift-U Change select case
X Ctrl-Alt-U Uncomment Selection
Ctrl-Alt-W Word Wrap
X Ctrl-A Select All
Ctrl-B Toggle Object Browser
X Ctrl-C Copy
X Ctrl+Double click object name Find object in browser panel for current database
X Ctrl-F Find
Ctrl-F5 Execute as Single Batch
Ctrl-F6 Next Query Tab
Ctrl-G Goto Line
Ctrl-H Replace
Ctrl-N New Query Window
Ctrl-O Open SQL File
Ctrl-P Print
Ctrl-R Toggle
Ctrl-S Save Query
Ctrl-Shift-F6 Previous Query Tab
Ctrl-Shift-U Make selection UPPER case
Ctrl-T Add New Query Editor
Ctrl-U Make selection LOWER case
Ctrl-V Paste
X Ctrl-X Cut
X Ctrl-Y Redo
X Ctrl-Z Undo
F11 Toggle full screen
F12 Select Query at Cursor
 X F3 Find Again
F5 Execute
F8 Explain
F9 Toggle Bookmark
Shift-F5 Execute All

Related References

 

Aginity for Netezza – How to Display Query Results in a Single Row Grid

Aginity

Aginity

Displaying your Netezza query results in a grid can be useful.  Especially, when desiring to navigation left and right to see an entire rows data and to avoid the distraction of other rows being displayed on the screen. I use this capability in Aginity when I’m proofing code results and/or validating data in a table.

How To switch to the Single Row Grid

  • Execute your Query
  • When the results return, right click on the gray bar above your results (where you see the drag a column box
  • Choose the ‘Show a Single Row Grid’ Menu item

    Aginity Show Single Row Grid

    Aginity Show Single Row Grid

 

Grid View Change

  • Your result display will change from a horizontal row to a vertical grid as shown below
Aginity Single Row Grid Display

Aginity Single Row Grid Display

How to Navigate in the Single Row Grid

  • To navigate in the single row grid, use the buttons provided at the bottom of the results section.
Aginity Single Row Grid Navigation Buttons

Aginity Single Row Grid Navigation Buttons

Related References

 

Aginity Workbench for PureData /Netezza System for Analytics – Useful links

Aginity

Aginity

 

Here are some Aginity Workbench for Netezza references, which I have found useful.

Reference Type Link
Aginity Workbench for Netezza http://www.aginity.com/workbench/netezza/
Aginity Workbench for Netezza Documentation http://www.aginity.com/documentation/WB/NZ/

Related References

Aginity for Netezza – How to disable and/or Enable the Autocomplete Function

Aginity for Netezza an out complete feature, which auto completes brackets, quotes, and comment character, which some folks find useful and helpful.  However, if you are an old-school style coder like me, you may find these annoying, to say the least.  Usually, when I’m coding I want to write straight through without the need to think about how the application may be trying to help me, which means I usually end up cleanup all the autocomplete added characters after the fact.  Disabling this feature is quick and easy and can be easily be reinstated later, if you find you want to leverage some or all of the autocomplete features.

Aginity Tools Options

Aginity Tools Options

 

To Disable the Autocomplete Functions

  • Navigate to: Tools > Options
  • Then, Navigate to: Query Analyzer > Code autocomplete
  • Then, Uncheck the feature or features you wish to disable and press, ‘OK
Disable Aginity Code Autocomplete Options Disable

Disable Aginity Code Autocomplete Options Disable

To Enable the Autocomplete Functions

  • Navigate to: Tools > Options
  • Then, Navigate to: Query Analyzer > Code autocomplete
  • Then, Check the feature or features you wish to enable and press, ‘OK
Enable Aginity Code Autocomplete Options Disable

Enable Aginity Code Autocomplete Options Disable

Related References

How to get a previously run SQL in Aginity

Every once and a while, it happens that a SQL needs to be reused, but for whatever reason it was not saved.  If it wasn’t too far back in time, you can recover the SQL from the User Query History.  This is a fairly straight forward process, if not exactly obvious.

The basic process is:

  • Connect to the database
  • Navigate to View > User Query History
Aginity View User Query History

Aginity View User Query History

  • Select the SQL Statement you want to retrieve

note: you want to select a databases and or user to narrow you rows returned.

  • Right Click to display command menu
Copy SQL Statement from Aginity User Query History

Copy SQL Statement from Aginity User Query History

  • Select ‘Copy SQL Statement’
  • Now you can paste the SQL in any Aginity Query Tab of your choosing

PureData / Netezza – Useful links

IBM Netezza / IBM PureData for Analytics Useful links

IBM Netezza / IBM PureData for Analytics

Here are a few Netezza references, which I have found useful.

Reference Type Link
Vendor Documentation https://www.ibm.com/support/knowledgecenter/SSULQD_7.2.0/com.ibm.nz.welcome.doc/doc/welcome.html
IBM Developer Works https://www.ibm.com/developerworks/community/groups/service/html/communitystart?communityUuid=9c8f1300-9ac0-4de5-80e6-0
Aginity Workbench for Netezza http://www.aginity.com/workbench/netezza/
IBM Netezza Database User’s Guide https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.2.0/com.ibm.nz.dbu.doc/c_dbuser_ntz_sql_introduction.html
Client Software Packages https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.2.0/com.ibm.nz.adm.doc/c_sysadm_client_software_packages.html
Netezza Client Software Installation https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.2.0/com.ibm.nz.adm.doc/c_sysadm_client_software_install.html

Related References