Netezza Database Users Guide
Netezza Database Users Guide
Netezza Corporation
Corporate Headquarters
26 Forest St., Marlborough, Massachusetts 01752
tel 508.382.8200 fax 508.382.8300 www.netezza.com
The specifications and information regarding the products described in this manual are subject to change without notice. All statements, information, and
recommendations in this manual are believed to be accurate.
Netezza makes no representations or warranties of any kind, express or implied, including, without limitation, those of merchantability, fitness for a partic-
ular purpose, and non infringement, regarding this manual or the products' use or performance. In no event will Netezza be liable for indirect, incidental,
consequential, special, or economic damages (including lost business profits, business interruption, loss or damage of data, and the like) arising out of the
use or inability to use this manual or the products, regardless of the form of action, whether in contract, tort (including negligence), breach of warranty, or
otherwise, even if Netezza has been advised of the possibility of such damages.
Netezza, the Netezza logo, Netezza TwinFin, TwinFin, Snippet Blades, S-Blades, NPS, Snippet, Snippet Processing Unit, SPU, Snippet Processing Array,
SPA, Performance Server, Netezza Performance Server, Asymmetric Massively Parallel Processing, AMPP, Intelligent Query Streaming and other marks are
trademarks or registered trademarks of Netezza Corporation in the United States and/or other countries. All rights reserved.
Red Hat is a trademark or registered trademark of Red Hat, Inc. in the United States and/or other countries.
Linux is a trademark or registered trademark of Linus Torvalds in the United States and/or other countries.
D-CC, D-C++, Diab+, FastJ, pSOS+, SingleStep, Tornado, VxWorks, Wind River, and the Wind River logo are trademarks, registered trademarks, or service
marks of Wind River Systems, Inc. Tornado patent pending.
APC and the APC logo are trademarks or registered trademarks of American Power Conversion Corporation.
All document files and software of the above named third-party suppliers are provided "as is" and may contain deficiencies. Netezza and its suppliers dis-
claim all warranties of any kind, express or implied, including, without limitation, those of merchantability, fitness for a particular purpose, and non
infringement.
In no event will Netezza or its suppliers be liable for indirect, incidental, consequential, special, or economic damages (including lost business profits, busi-
ness interruption, loss or damage of data, and the like), or the use or inability to use the above-named third-party products, even if Netezza or its suppliers
have been advised of the possibility of such damages.
All other trademarks mentioned in this document are the property of their respective owners.
Document Number: 20284-12
Software Release Number: 5.0.x
Netezza Database User’s Guide
Copyright © 2001-2009 Netezza Corporation.
All rights reserved.
PostgreSQL
Portions of this publication were derived from PostgreSQL documentation. For those portions of the documentation that were derived originally from Postgr-
eSQL documentation, and only for those portions, the following applies:
PostgreSQL is copyright © 1996-2001 by the PostgreSQL global development group and is distributed under the terms of the license of the University of
California below.
Postgres95 is copyright © 1994-5 by the Regents of the University of California.
Permission to use, copy, modify, and distribute this documentation for any purpose, without fee, and without a written agreement is hereby granted, pro-
vided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.
In no event shall the University of California be liable to any party for direct, indirect, special, incidental, or consequential damages, including lost profits,
arising out of the use of this documentation, even if the University of California has been advised of the possibility of such damage.
The University of California specifically disclaims any warranties, including, but not limited to, the implied warranties of merchantability and fitness for a
particular purpose. The documentation provided hereunder is on an "as-is" basis, and the University of California has no obligations to provide maintenance,
support, updates, enhancements, or modifications.
ICU Library
The Netezza implementation of the ICU library is an adaptation of an open source library Copyright (c) 1995-2003 International Business Machines Corpo-
ration and others.
ICU License - ICU 1.8.1 and later
COPYRIGHT AND PERMISSION NOTICE
Copyright (c) 1995-2003 International Business Machines Corporation and others
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all cop-
ies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRAN-
TIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAM-
AGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization of the copyright holder.
ODBC Driver
The Netezza implementation of the ODBC driver is an adaptation of an open source driver, Copyright © 2000, 2001, Great Bridge LLC. The source code for
this driver and the object code of any Netezza software that links with it are available upon request to source-request@netezza.com
Botan License
Copyright (C) 1999-2008 Jack Lloyd
2001 Peter J Jones
2004-2007 Justin Karneges
2005 Matthew Gregan
2005-2006 Matt Johnston
2006 Luca Piccarreta
2007 Yves Jerschow
2007-2008 FlexSecure GmbH
2007-2008 Technische Universitat Darmstadt
2007-2008 Falko Strenzke
2007-2008 Martin Doering
2007 Manuel Hartl
2007 Christoph Ludwig
2007 Patrick Sona
All rights reserved.
Redistribution and use in source and binary forms, for any use, with or without modification, of Botan (http://botan.randombit.net/license.html) is permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/
or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON-
SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBIL-
ITYOF SUCH DAMAGE.
Regulatory Notices
Install the NPS system in a restricted-access location. Ensure that only those trained to operate or service the equipment have physical access to it. Install
each AC power outlet near the NPS rack that plugs into it, and keep it freely accessible.
Provide approved 30A circuit breakers on all power sources.
Product may be powered by redundant power sources. Disconnect ALL power sources before servicing.
High leakage current. Earth connection essential before connecting supply. Courant de fuite élevé. Raccordement à la terre indispensable avant le raccor-
dement au réseau.
FCC - Industry Canada Statement
This equipment has been tested and found to comply with the limits for a Class A digital device, pursuant to part 15 of the FCC rules. These limits are
designed to provide reasonable protection against harmful interference when the equipment is operated in a commercial environment. This equipment gen-
erates, uses, and can radiate radio-frequency energy and, if not installed and used in accordance with the instruction manual, may cause harmful
interference to radio communications. Operation of this equipment in a residential area is likely to cause harmful interference, in which case users will be
required to correct the interference at their own expense.
This Class A digital apparatus meets all requirements of the Canadian Interference-Causing Equipment Regulations.
Cet appareil numérique de la classe A respecte toutes les exigences du Règlement sur le matériel brouilleur du Canada.
WEEE
Netezza Corporation is committed to meeting the requirements of the European Union (EU) Waste Electrical and Electronic Equipment (WEEE) Directive.
This Directive requires producers of electrical and electronic equipment to finance the takeback, for reuse or recycling, of their products placed on the EU
market after August 13, 2005.
CE Statement (Europe)
This product complies with the European Low Voltage Directive 73/23/EEC and EMC Directive 89/336/EEC as amended by European Directive 93/68/EEC.
Warning: This is a class A product. In a domestic environment this product may cause radio interference in which case the user may be required to take
adequate measures.
VCCI Statement
Preface
v
Removing a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Truncating a Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Renaming a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Changing Table Ownership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Inserting Rows Into a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Inserting Columns Into a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Generating Table Statistics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Querying a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Updating Table Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Deleting Rows from Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Changing or Dropping a Column Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Changing the Length of a Varchar Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Changing a Column’s Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Joining Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Using Inner Join Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Using Left-Outer Join Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Using Self-Join Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Combining Tables with UNION, INTERSECT, and EXCEPT . . . . . . . . . . . . . . . . . . . 2-18
Using the UNION Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Using the INTERSECT Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Using the EXCEPT Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Understanding Precedence Ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
Handling NULLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
Understanding Data Type Promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
Managing Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Creating Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Replacing Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Dropping Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Renaming Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Changing View Ownership. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Using Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Creating Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
Viewing Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Replacing Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Dropping Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Altering Materialized Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Setting the Refresh Threshold. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
vi
Changing Materialized Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Querying Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Memory Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Mirroring and Regeneration of Materialized Views . . . . . . . . . . . . . . . . . . . . . . . 2-26
Reclamation and Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Loading and Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Backing Up and Restoring Materialized Views. . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Zone Maps and Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Assigning Privileges to Use Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Tips for Creating Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Understanding Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28
Understanding Correlated Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Using Correlated Subqueries in Netezza SQL . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Using Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Grouped Aggregates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Window Aggregates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Executing Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32
vii
Netezza SQL Extensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Character Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22
Date/Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25
Template Patterns for Date/Time Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26
Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Netezza SQL Functional Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Data Definition Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
Data Control Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31
Data Manipulation Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-34
Transaction Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-35
viii
6 Netezza SQL Analytic Functions
Overview of Analytic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1
Processing Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Using Windowing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
Window Analytic Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10
Sample Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10
Example 1 — Ranking the Detailed Data Values . . . . . . . . . . . . . . . . . . . . . . . . 6-11
Example 2 — Selecting the Top N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
Example 3 — Window Aggregation on a Grouping Select . . . . . . . . . . . . . . . . . . 6-12
Example 4 — Selecting the Top N within Each Partition . . . . . . . . . . . . . . . . . . 6-12
8 Sequences
Overview of Sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1
Creating a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Sample Creating Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Caching Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Altering a Sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
Flushing the Cache When Altering a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
ix
Altering a Sequence Increment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Altering the Sequence Sign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Dropping a Sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Sequences and Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6
Getting Values from Sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6
Getting the Next Value of a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6
Getting Batch Values for a Sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7
Backing Up and Restoring Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8
x
ALTER SESSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-17
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-17
ALTER SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-19
ALTER TABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-19
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-19
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-20
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-21
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-21
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-21
ALTER USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-22
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-22
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-23
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-24
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-24
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-25
ALTER VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-25
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-25
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-25
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-26
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-26
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
BEGIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-28
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-28
xi
COMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-28
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-28
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-29
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-29
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-29
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-30
COMMIT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-30
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-30
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-30
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-30
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-31
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-31
COPY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-32
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-32
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-32
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-33
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-33
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-35
CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-35
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-35
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-35
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-36
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-36
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-36
CREATE EXTERNAL TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-37
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-37
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-37
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-38
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-38
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-43
CREATE GROUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-43
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-43
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-44
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-44
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-45
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-45
xii
CREATE HISTORY CONFIGURATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-45
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-45
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-46
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-49
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-49
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-50
CREATE MATERIALIZED VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-50
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-50
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-50
Restrictions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-51
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-51
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-51
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-52
CREATE SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-52
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-52
Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-53
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-54
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-54
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-54
CREATE SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-55
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-55
Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-55
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-55
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-55
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-56
CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-56
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-56
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-57
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-58
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-59
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-61
CREATE TABLE AS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-62
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-62
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-62
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-62
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-62
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-64
xiii
CREATE USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-65
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-65
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-65
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-67
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-67
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-68
CREATE VIEW. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-68
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-68
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-68
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-68
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-69
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-69
DELETE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-70
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-70
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-70
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-70
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-70
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-71
DROP CONNECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-71
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-71
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-72
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-72
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-72
DROP DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-72
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-72
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-73
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-73
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-73
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
DROP GROUP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-75
DROP HISTORY CONFIGURATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-75
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-75
xiv
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-75
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-75
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-76
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-76
DROP SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-76
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-76
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-76
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-77
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-77
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-77
DROP SESSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-77
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-77
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-78
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-78
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-78
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
DROP SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
DROP TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-81
DROP USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-81
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-81
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-81
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-81
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-82
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-82
DROP VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-82
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-82
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-82
xv
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-83
EXPLAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-83
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-83
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-83
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-84
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-84
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-85
GENERATE EXPRESS STATISTICS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-87
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-87
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-87
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-87
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-87
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-88
GENERATE STATISTICS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-88
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-88
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-89
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-89
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-89
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-90
GRANT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-90
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-90
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-91
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-92
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-92
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-92
INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-93
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-93
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-93
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-93
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-94
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-94
RESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-95
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-95
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-95
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-95
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-95
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-96
xvi
REVOKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-96
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-96
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-96
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-97
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-97
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-98
ROLLBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-98
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-98
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-98
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-98
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-99
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-99
SELECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-99
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-99
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-100
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-101
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-101
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-106
SET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-108
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-108
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-108
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-108
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-109
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-110
SET AUTHENTICATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-110
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-110
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-110
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-111
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-112
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-113
SET CONNECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-113
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-113
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-114
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-114
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-115
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-115
SET HISTORY CONFIGURATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-115
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-115
xvii
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-115
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-116
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-116
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-116
SET SESSION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-116
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-116
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-117
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-117
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-117
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-117
SET SYSTEM DEFAULT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-117
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-118
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-118
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-118
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-118
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-119
SET TRANSACTION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-119
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-119
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-120
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-120
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-120
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
SHOW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-122
SHOW AUTHENTICATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-122
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-122
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-122
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-122
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-123
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-123
SHOW CONNECTION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-124
Synopsis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-124
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-124
xviii
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-124
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-124
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-125
SHOW HISTORY CONFIGURATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-125
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-125
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-125
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-126
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-126
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-126
SHOW SESSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-127
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-127
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-127
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-127
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-128
SHOW SYSTEM DEFAULT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-129
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-129
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-129
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-129
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-130
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-130
TRUNCATE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-130
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-130
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-130
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-131
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-131
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-131
UPDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-131
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-131
Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-132
Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-132
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-132
Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-133
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-133
xix
Appendix C: Join Overview
Creating Sample Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-1
Types of Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-2
Cross Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-2
Join/Inner Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-3
Left Outer Join/Left Join. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-3
Right Outer Join/Right Join. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-3
Full Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-4
Using the Conditions on, using, and natural . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-4
Cross Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-4
Inner Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-4
Left Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-5
Right Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-5
Full Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-6
Outer Joins and the Order of Evaluation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-7
Left Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-7
Samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-7
Notes for the on Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-8
Index
xx
Tables
xxi
Table 3-27: Template Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
Table 3-28: Template Patterns for Numeric Conversions . . . . . . . . . . . . . . . . . . 3-28
Table 3-29: Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Table 3-30: Data Definition Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
Table 3-31: Data Control Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
Table 3-32: Administrator Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
Table 3-33: Object Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33
Table 3-34: Data Manipulation Language. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-34
Table 3-35: Isolation Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
Table 4-1: Date and Time Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Table 4-2: Grammar Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Table 4-3: Supported Implicit and Explicit Casts . . . . . . . . . . . . . . . . . . . . . . . 4-6
Table 5-1: Create External Table Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Table 5-2: Compress Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Table 6-1: Analytic Function Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
Table 6-2: Netezza SQL Analytic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7
Table 7-1: nzconvert Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
Table 8-1: Sequence Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6
Table A-1: Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Table A-2: Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2
Table B-1: Netezza SQL Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1
Table B-2: ALTER DATABASE Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-5
Table B-3: ALTER DATABASE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-5
Table B-4: ALTER GROUP Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-7
Table B-5: ALTER GROUP Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-8
Table B-6: ALTER HISTORY CONFIGURATION Inputs. . . . . . . . . . . . . . . . . . . . B-9
Table B-7: ALTER HISTORY CONFIGURATION Output . . . . . . . . . . . . . . . . . . B-13
Table B-8: ALTER SEQUENCE Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-14
Table B-9: ALTER SEQUENCE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-15
Table B-10: ALTER SESSION Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Table B-11: ALTER SESSION Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Table B-12: ALTER SYNONYM Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Table B-13: ALTER SYNONYM Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Table B-14: ALTER TABLE Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-20
Table B-15: ALTER TABLE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-21
Table B-16: ALTER USER Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-23
Table B-17: ALTER USER Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-24
xxii
Table B-18: ALTER VIEW Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-25
Table B-19: ALTER VIEW Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-26
Table B-20: Materialized View Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-26
Table B-21: BEGIN Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
Table B-22: BEGIN Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
Table B-23: COMMENT Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-29
Table B-24: COMMENT Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-29
Table B-25: COMMIT Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-30
Table B-26: COMMIT Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-30
Table B-27: COPY Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-32
Table B-28: COPY Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-33
Table B-29: COPY FROM Backslash Sequences . . . . . . . . . . . . . . . . . . . . . . . . B-34
Table B-30: CREATE DATABASE Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-35
Table B-31: CREATE DATABASE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-36
Table B-32: CREATE EXTERNAL TABLE Input . . . . . . . . . . . . . . . . . . . . . . . . . B-37
Table B-33: CREATE EXTERNAL TABLE Output . . . . . . . . . . . . . . . . . . . . . . . . B-38
Table B-34: CREATE EXTERNAL TABLE Options . . . . . . . . . . . . . . . . . . . . . . . B-40
Table B-35: CREATE GROUP Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-44
Table B-36: CREATE GROUP Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-44
Table B-37: CREATE HISTORY CONFIGURATION Inputs . . . . . . . . . . . . . . . . . B-46
Table B-38: CREATE HISTORY CONFIGURATION Output . . . . . . . . . . . . . . . . . B-49
Table B-39: CREATE MATERIALIZED VIEW Input. . . . . . . . . . . . . . . . . . . . . . . B-50
Table B-40: CREATE MATERIALIZED VIEW Output . . . . . . . . . . . . . . . . . . . . . B-51
Table B-41: CREATE SEQUENCE Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-53
Table B-42: CREATE SEQUENCE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-54
Table B-43: CREATE SYNONYM Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-55
Table B-44: CREATE SYNONYM Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-55
Table B-45: CREATE TABLE Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-57
Table B-46: CREATE TABLE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-58
Table B-47: CREATE TABLE AS Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-62
Table B-48: CREATE USER Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-65
Table B-49: CREATE USER Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-67
Table B-50: CREATE VIEW Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-68
Table B-51: CREATE VIEW Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-68
Table B-52: DELETE Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-70
Table B-53: DELETE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-70
Table B-54: DROP CONNECTION Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-72
xxiii
Table B-55: DROP CONNECTION Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-72
Table B-56: DROP DATABASE Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-73
Table B-57: DROP DATABASE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-73
Table B-58: DROP GROUP Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
Table B-59: DROP GROUP Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-74
Table B-60: DROP HISTORY CONFIGURATION Inputs . . . . . . . . . . . . . . . . . . . B-75
Table B-61: DROP HISTORY CONFIGURATION Output . . . . . . . . . . . . . . . . . . . B-75
Table B-62: DROP SEQUENCE Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-76
Table B-63: ALTER SEQUENCE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-77
Table B-64: DROP SESSION Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-78
Table B-65: DROP SESSION Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-78
Table B-66: DROP SYNONYM Inputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
Table B-67: DROP SYNONYM Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-79
Table B-68: DROP TABLE Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
Table B-69: DROP TABLE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-80
Table B-70: DROP USER Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-81
Table B-71: DROP USER Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-81
Table B-72: DROP VIEW Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-82
Table B-73: DROP VIEW Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-83
Table B-74: EXPLAIN Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-83
Table B-75: EXPLAIN Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-84
Table B-76: GENERATE EXPRESS STATISTICS Input. . . . . . . . . . . . . . . . . . . . B-87
Table B-77: GENERATE EXPRESS STATISTICS Output. . . . . . . . . . . . . . . . . . . B-87
Table B-78: GENERATE STATISTICS Input . . . . . . . . . . . . . . . . . . . . . . . . . . . B-89
Table B-79: GENERATE STATISTICS Output . . . . . . . . . . . . . . . . . . . . . . . . . . B-89
Table B-80: GRANT Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-91
Table B-81: GRANT Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-92
Table B-82: INSERT Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-93
Table B-83: INSERT Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-93
Table B-84: RESET Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-95
Table B-85: RESET Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-95
Table B-86: REVOKE Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-96
Table B-87: REVOKE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-97
Table B-88: ROLLBACK Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-98
Table B-89: ROLLBACK Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-98
Table B-90: SELECT Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-100
Table B-91: SELECT Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-101
xxiv
Table B-92: SET Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-108
Table B-93: SET Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-108
Table B-94: SET AUTHENTICATION Input . . . . . . . . . . . . . . . . . . . . . . . . . . . B-110
Table B-95: SET AUTHENTICATION Output. . . . . . . . . . . . . . . . . . . . . . . . . . B-111
Table B-96: SET CONNECTION Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-114
Table B-97: SET CONNECTION Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-114
Table B-98: SET HISTORY CONFIGURATION Inputs. . . . . . . . . . . . . . . . . . . . B-115
Table B-99: SET HISTORY CONFIGURATION Output . . . . . . . . . . . . . . . . . . . B-116
Table B-100: SET SESSION Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-117
Table B-101: SET SESSION Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-117
Table B-102: SET SYSTEM DEFAULT Input . . . . . . . . . . . . . . . . . . . . . . . . . . . B-118
Table B-103: SET SESSION DEFAULT Output . . . . . . . . . . . . . . . . . . . . . . . . . B-118
Table B-104: SET TRANSACTION Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-120
Table B-105: SET TRANSACTION Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-120
Table B-106: SHOW Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
Table B-107: SHOW Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-121
Table B-108: SHOW AUTHENTICATION Input . . . . . . . . . . . . . . . . . . . . . . . . . B-122
Table B-109: SHOW AUTHENTICATION Output . . . . . . . . . . . . . . . . . . . . . . . . B-122
Table B-110: SHOW AUTHENTICATION Output . . . . . . . . . . . . . . . . . . . . . . . . B-124
Table B-111: SHOW HISTORY CONFIGURATION Inputs . . . . . . . . . . . . . . . . . . B-125
Table B-112: SHOW HISTORY CONFIGURATION Output . . . . . . . . . . . . . . . . . B-126
Table B-113: SHOW SESSION Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-127
Table B-114: SHOW SYSTEM DEFAULT Input . . . . . . . . . . . . . . . . . . . . . . . . . B-129
Table B-115: SHOW SYSTEM DEFAULT Output . . . . . . . . . . . . . . . . . . . . . . . . B-129
Table B-116: TRUNCATE Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-130
Table B-117: TRUNCATE Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-131
Table B-118: UPDATE Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-132
Table B-119: UPDATE Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-132
Table B-120: Netezza SQL Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-133
Table C-1: Creating Sample Tables to Illustrate Join Features . . . . . . . . . . . . . . C-1
Table D-1: nzsql Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-1
Table D-2: nzsql Internal Slash Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-2
xxv
xxvi
Preface
The Netezza data warehouse appliance includes a highly optimized SQL language called
Netezza Structured Query Language (SQL). You can use the SQL commands to create and
manage your Netezza databases, user access and permissions for the databases, as well as
to query the contents of the databases.
Topics Chapter
Using the SQL commands and the nzsql com- Chapter 1, “Netezza SQL Introduction.”
mand line interpreter.
Using Netezza SQL to create, query, and update Chapter 2, “Using the SQL Grammar.”
databases.
Using the data types, functions, expressions, Chapter 3, “Netezza SQL Basics.”
and functional categories.
Using Netezza SQL lexical structure, and Chapter 4, “SQL Statement Grammar.”
grammar.
Using the create external table command. Chapter 5, “Using External Tables.”
The nzsql command line and internal slash Appendix D, “nzsql Command Line
commands. Options.”
xxvii
Symbols and Conventions
This guide uses the following typographical conventions:
X Italics for terms, and user-defined variables such as file names
X Upper case for SQL commands; for example INSERT, DELETE
X Bold for command line input; for example, nzsystem stop
xxviii
xxix
xxx
CHAPTER 1
Netezza SQL Introduction
What’s in this chapter
X Accessing Netezza SQL Using nzsql
X Using nzsql Commands
X nzsql Exit Codes
Netezza SQL is the Netezza Structured Query Language (SQL), which runs on the Netezza
data warehouse appliance. Throughout this document, the term SQL refers to Netezza’s
SQL implementation. Several standards relate to the definition of Netezza SQL:
X SQL-92 (also called SQL/2) is the operative ANSI/ISO standard for relational databases
today. While no vendor supports the complete SQL-92 standard, Netezza SQL con-
forms to all the commonly supported components of SQL-92.
X SQL/CLI — Callable language interface (CLI), which is an addition to the SQL/92 spec-
ification in 1995 to define required functionality for CLIs to support client-server and
other network based access models. The CLI was largely driven by ODBC, but JDBC is
also a CLI-based interface.
X SQL:1999 (also called SQL-99) — Added regular expression matching, recursive que-
ries, triggers, and other object-oriented features.
If you have direct access to the Netezza appliance from a command shell, or if you have
UNIX clients with the Netezza CLI tools, you can run SQL commands using the nzsql com-
mand line interpreter. You can also run Netezza SQL commands using common SQL tools
and applications that support ODBC, JDBC, and OLE DB data connectivity APIs.
The Netezza system can support multiple concurrent connections from clients. Within a
connection, Netezza supports only one active SQL activity at a time.
This document uses the nzsql command to show query and command examples.
1-1
Netezza Database User’s Guide
Logging On
When you invoke the nzsql command, you must supply a database account user name,
password, and the name of the database to which you are connecting. You can enter this
information on the nzsql command line, or you can specify the information in environment
variables before you begin your nzsql session. For example, you can enter the following
from a command window prompt:
nzsql -d sales -u mlee -pw blue
Welcome to nzsql, the Netezza SQL interactive terminal.
The Netezza administrator creates and manages the database user accounts using SQL
commands or the Netezza NzAdmin and Web Admin administration interfaces. For a com-
plete description of how to manage user accounts, see the Netezza System Administrator’s
Guide.
The Netezza system has a default “admin” database user account who is the superuser of
the Netezza databases. The admin user can connect to any database; load data; create,
alter and drop any objects; create and manage new database users; and so on. Typically the
admin user creates new accounts so that other users can access one or more databases and
run queries. The admin user can also create accounts with administrative permissions so
that other users can be allowed to perform tasks such as manage databases and user setup,
backups, and other administrative tasks.
Session Management
Each client user who connects to the Netezza system opens a session. Users can view infor-
mation about their sessions, as well as manage them to do such tasks as alter or drop their
sessions. The admin account or any permitted user can also show, drop, and manage ses-
sions (that is, change the priority and/or rollback a transaction) for a session. For a
description of the SQL commands to manage sessions (ALTER SESSION, DROP SESSION,
and SHOW SESSION), refer to Appendix B, “Netezza SQL Command Reference.”
For details about SSL communication from the Netezza clients to the Netezza system, refer
to the Netezza ODBC, JDBC and OLE DB Configuration and Installation Guide. For a
description of how to configure the Netezza host for SSL support, refer to the Netezza Sys-
tem Administrator’s Guide.
The system feedback for inserts, updates, and deletes shows you the number of rows acted
upon. The feedback for inserts includes an extra zero before the actual number (due to a
historical artifact). Samply commands (shown in bold) and the command feedback follows:
nzsql
CREATE TABLE test1 (col1 INTEGER, col2 INTEGER, col3 CHARACTER(40));
CREATE TABLE
INSERT INTO test1 VALUES (100, 200, 'This is a test');
INSERT 0 1
INSERT INTO test1 VALUES (101, 201, 'Another test');
INSERT 0 1
UPDATE test1 SET col2 = 999 WHERE col1 < 1000;
UPDATE 2
INSERT INTO test1 SELECT * FROM test1;
INSERT 0 2
delete from test1 where col1 > 0;
DELETE 4
TRUNCATE TABLE test1;
TRUNCATE TABLE
DROP TABLE test1;
DROP TABLE
T To read input from the current source, for example a script, enter:
nzsql <<eof
SELECT * FROM test_table;
eof
T To read input (standard in), enter:
nzsql < foo.sql
T To execute queries from a file (command line argument), enter:
nzsql -f foo.sql
T To execute queries from a file (nzsql option), enter:
nzsql
\i foo.sql
X ‘literal’ — Use single quotes around literals. For example, ‘May 10, 2000’, ‘Netezza’.
‘US’. Use a pair of single quotes when you want to embed a single quote. For example,
‘Mark''s Test'.
X ”label” — Use double quotes around labels. For example, SELECT lst_name AS
"Employee Last Name" FROM emp_table;
X Identifiers — The system automatically converts identifiers, such as database, table,
and column names, to the default system case, which is Upper on new systems. If you
want to use mixed case and/or spaces, you must use double quotes around the identi-
fier. For example, CREATE TABLE "Emp Table" (emp_id integer, emp_name char(20));
SELECT emp_id FROM "Emp Table";
When you run this script, the system displays the messages “Rowcount before (or after)
the truncate count” before the two select statements.
X \h [cmd] — Display help on SQL syntax.
Use this option to display help for SQL syntax for a specific command. The help dis-
plays a description of the command and the command syntax. For a list of all the SQL
commands and their syntax, see Appendix B, “Netezza SQL Command Reference.”
X \l — List all databases.
Use this option to list all the databases and their owners.
X \![cmd] — Issue shell command.
Use this option to run a shell command without terminating your nzsql session. You
can use this option to issue shell commands between SQL statements, which is espe-
cially useful in scripts.
nzsql <<eof
\! date
SELECT COUNT(*) From customer;
\! date
eof
The example produces the following output:
Wed Jun 27 11:23:50 EDT 2007
count
-------
12399
(1 row)
Wed Jun 27 11:23:50 EDT 2007
You can use the \set command to store an often-used expression or SQL statement in a
variable. This variable is visible for the length of your connected session.
a. Set the variable:
\set my_sql 'select * from sales_tbl where amt > '
b. Use the variable in a query:
:my_sql 4000;
city | state | region | quarter | amt
------------+-------+------------+---------+------
New York | NY | Northeast | 3 | 4300
New York | NY | Northeast | 4 | 5000
You can use SQL commands to create database objects, run queries, and manage the data-
base. This chapter describes how to use the commands to perform common tasks.
Appendix B provides more detailed syntax and usage for the commands
Table 2-1 lists the SQL commands that are available. While most of the commands are
described in this guide, some commands may be documented in other feature-specific
guides. The Netezza OnStream Functions Developer’s Guide is available only to members of
the Netezza Developer Network; contact your Netezza Sales representative for more
information.
ALTER GROUP Adds or removes users from See “ALTER GROUP” on page B-6.
a group
2-1
Netezza Database User’s Guide
ALTER PROCEDURE Changes a stored procedure See the Netezza Stored Procedures
Developer’s Guide.
ALTER USER Changes a database user See “ALTER USER” on page B-22.
account
ALTER VIEW Changes the owner or name See “ALTER VIEW” on page B-25.
of a view
CREATE PROCEDURE Creates a stored procedure See the Netezza Stored Procedures
Developer’s Guide.
CREATE TABLE AS Creates a new table based See “CREATE TABLE AS” on
on query results page B-62.
DROP USER Removes a database user See “DROP USER” on page B-81.
account
SET SYSTEM DEFAULT Sets the system defaults See “SET SYSTEM DEFAULT” on
for session timeout, rowset page B-117.
limit, query timeout, and
priority
SHOW AGGREGATE Displays information about See the Netezza OnStream Func-
one or more UDAs tions Developer’s Guide.
SHOW FUNCTION Displays information about See the Netezza OnStream Func-
one or more UDAs tions Developer’s Guide.
SHOW HISTORY Display query history con- See “SHOW HISTORY CONFIGU-
CONFIGURATION figuration settings RATION” on page B-125.
SHOW PROCEDURE Displays information about See the Netezza Stored Procedures
one or more stored Developer’s Guide.
procedures
SHOW SYSTEM Shows the system defaults See “SHOW SYSTEM DEFAULT”
DEFAULT on page B-129.
Managing Databases
Using SQL commands, you can create, drop, rename, or change the owner of databases.
Creating a Database
To create a database, use the CREATE DATABASE command.
system(admin)=> CREATE DATABASE mydb;
CREATE DATABASE
If you do not have the privileges required to create a database, the system displays the fol-
lowing message:
ERROR: CREATE DATABASE: permission denied.
Database names can have a maximum length of 128 bytes, otherwise the system displays
an error message. Database names must be valid identifier names. For more information,
see “Handling SQL Identifiers” on page 2-7.
Dropping a Database
If you are logged in as the admin user or the owner of a database, you can drop the data-
base using the DROP DATABASE command. Dropping the database removes the entries for
an existing database and deletes the directory that contains the data. For example:
system(admin)=> DROP DATABASE mydb;
DROP DATABASE
Renaming a Database
If you are logged in as the admin user or the owner of a database, you can rename the data-
base using the ALTER DATABASE command. The data remains of the same type and size.
For example:
system(admin)=> ALTER DATABASE mydb RENAME TO newdb;
ALTER DATABASE
Note: After you rename a database, recompile any views that are associated with that data-
base. Any materialized views in the database will be converted to regular (non-materialized)
views. For more information, refer to “Replacing Views” on page 2-22.
Parameter Description
A regular identifier is not case sensitive; that is, if you create a database named SALES,
you can refer to it using any case combination of letters. For example, SALES, sales,
SaLeS, and SALEs all match the database named SALES. The ANSI SQL standard speci-
fies that systems should convert all regular SQL identifiers to the corresponding upper-case
characters, so the Netezza system converts any regular identifier you specify into uppercase
characters when it is saved in the database, and also when the regular identifiers are used
in query processing.
Regular identifiers can contain only letters (in any alphabet, not just the Latin alphabet),
syllables (as in the Japanese Hiragana syllabary), ideographs, decimal digits, underscores,
and dollar sign ($). Regular identifiers must begin with a letter; they cannot begin with a
digit, underscore, or dollar sign. Regular identifiers also cannot be a SQL reserved word (as
described in Appendix A, “SQL Reserved Words and Keywords”). The encoding in the
Netezza catalog is in UTF-8; the encoding for any display will depend on the client.
A delimited identifier is also a name of a database object, but it is enclosed in double-quo-
tation marks and has special considerations. A delimited identifier is case-sensitive, so a
database named “Sales” is not the same database as one named SALES, for example. The
Netezza system does not convert delimited identifiers to the default system case, nor does
it save the enclosing double-quotation marks in the database.
Within the double quotation marks, a delimited identifier can include the same letters, syl-
lables, ideographs, decimal digits, and underscores as a regular identifier, but it can also
include spaces, special characters such as hyphens and percent signs, and SQL reserved
keywords. A delimited identifier can begin with any of these letters, digits, or symbols.
For example, the following query uses delimited identifiers for both column and table
names:
SELECT "My Field" FROM "My Table" WHERE "My Field" LIKE 'A%'
Note that the string literal 'A%' is enclosed in single quotes.
You can change the system default lettercase behavior at system initialization by using the
nzinitsystem -lowercase command. For more information about the nzinitsystem command,
see the Netezza System Administrator’s Guide.
To retrieve all rows from the table EMP in connected-to database DEV, enter:
dev(admin)=>SELECT * FROM DEV..EMP;
To retrieve all rows from the table EMP in the database PROD, enter:
dev(admin)=>SELECT * FROM PROD..EMP;
To truncate the contents of DEV.EMP.
dev(admin)=>TRUNCATE TABLE EMP;
To insert the contents of PROD..EMP into DEV..EMP.
dev(admin)=>INSERT INTO EMP SELECT * FROM PROD..EMP;
To join tables from both PROD and DEV.
dev(admin)=>SELECT COUNT (*) FROM DEV..EMP DE, PROD..EMP PE WHERE
DE.ID = PE.ID;
To retrieve rows from PROD.EMP, enter:
dev(admin)=>SELECT * FROM PROD..EMP WHERE PROD..EMP.DEPTNO IN (SELECT
DE.DEPTNO FROM DEV..EMP DE WHERE DE.ID < 10);
To create a table from PROD.EMP and DEV.EMP, enter:
dev(admin)=>CREATE TABLE KEYEMPS AS SELECT * FROM PROD..EMP INTERSECT
SELECT * FROM DEV..EMP;
Using Synonyms
You can create SQL synonyms as an alternate way of referencing tables or views that reside
in the current or other databases on the Netezza system. Synonyms allow you to create eas-
ily typed names for long table or view names. They also allow you to create a level of
abstraction for the database objects and thereby enable you to swap the underlying objects
without affecting the code that references these objects.
Synonyms share the same naming restrictions as tables and views, that is, they must be
unique within a database and their names cannot be the same as global objects such as
those of databases, users, or groups.
You can use the following synonym commands:
X CREATE SYNONYM — To create a synonym
X DROP SYNONYM — To drop/delete a synonym
X ALTER SYNONYM — To rename or change the owner of a synonym
X GRANT SYNONYM — To grant permission to create, alter, or drop a synonym to a user
or group
X REVOKE SYNONYM — To revoke permission to create, alter, or drop a synonym to a
user or group
Creating Synonyms
You cannot create synonyms for temporary tables, remote databases, or other synonyms
(also called chaining). Because synonyms share the same namespace as tables and views,
you cannot create a synonym with the same name as a table or view that already exists in
the same database. Conversely, you cannot create a table or view with a name that matches
an existing synonym.
Note: A namespace is the structure underlying SQL schemas. The namespace contains all
the objects within the database plus all global objects (databases, users, groups, and sys-
tem objects). There is only one namespace for each database.
Dropping Synonyms
If you no longer need a synonym, you can drop it. Note that you can only drop a synonym in
the current database.
The syntax for the DROP SYNONYM command is:
DROP SYNONYM synonym_name;
If you drop or rename a table or view that has an associated synonym, the synonym
becomes an orphan. To re-use the synonym for another object with a different name, drop
and re-create it.
For example, to drop the synonym for EMP in database PROD, enter:
dev(admin)=>DROP SYNONYM pemp;
For more information, see “DROP SYNONYM” on page B-79.
Altering Synonyms
You can use the ALTER SYNONYM command to rename or change the owner of a synonym.
The syntax for the ALTER SYNONYM command is:
ALTER SYNONYM synonym_name RENAME TO new_synonym_name;
ALTER SYNONYM synonym_name OWNER TO new_owner;
For example, to rename the synonym for PEMP in database PROD, enter:
dev(admin)=>ALTER SYNONYM pemp RENAME TO p;
For example, to change the owner of the synonym for EMP in database PROD, enter:
dev(admin)=>ALTER SYNONYM pemp OWNER TO leslie;
For more information, see “ALTER SYNONYM” on page B-18.
Synonym Privileges
Synonyms use the same security scheme as other Netezza database objects. As the admin
user, you have all privileges on synonyms and thus do not need to explicitly grant yourself
privileges to manage them. The owner of the database has all privileges on all synonyms
within the database. The synonym owner has all privileges on the synonym.
Table 2-3 lists the privilege rules for all other users:
ALTER SYNONYM Grant the user Alter privilege for a synonym or the
Synonym object class.
DROP SYNONYM Grant the user Drop privilege for a synonym or the
Synonym object class.
LIST synonyms All users have List privilege by default and can see
all synonyms.
You grant privileges to create, alter, and drop synonyms with the GRANT SYNONYM com-
mand. For more information, see “GRANT” on page B-90.
The syntax for the GRANT SYNONYM command is:
GRANT [CREATE] SYNONYM TO user_or_group;
GRANT ALTER, DROP ON synonym_name TO user_or_group;
You revoke privileges to create, alter, and drop synonyms with the REVOKE SYNONYM
command. For more information, see “REVOKE” on page B-96.
The syntax for the REVOKE SYNONYM command is:
REVOKE [CREATE] SYNONYM FROM user_or_group;
REVOKE ALTER, DROP ON synonym_name FROM user_or_group;
Managing Tables
You can create, access, and manipulate tables using SQL commands.
Creating a Table
To create a new table, specify the table name, the column names, and their types. You can
enter a table line by line. The system recognizes that the command is not terminated until
it encounters the semicolon (;). An example follows.
system(admin)=> CREATE TABLE weather (
city varchar(80),
temp_lo int, -- low temperature
temp_hi int, -- high temperature prcp
real, -- precipitation
date date
);
The following rules apply when entering data:
X Whitespace — You can use white space (that is, spaces, tabs, and new lines) within
SQL commands.
X Comments — Two dashes ("--") introduce comments. The system ignores whatever fol-
lows a comment, up to the end of that line.
X Variable characters — The varchar(80) specifies a data type that can store arbitrary
character strings up to 80 characters in length.
X Data types — An int is the normal integer type. A real is a type for storing single preci-
sion floating-point numbers. For more information about data types, see “Netezza SQL
Basics” on page 3-1.
Note: In addition, Netezza SQL considers the following system attributes reserved words:
ctid, oid, xmin, cmin, xmax, cmax, tableoid, rowid, datasliceid, createxid, and deletexid.
Using Constraints
When you create a table you can specify column and/or table constraints. For example, a
table_constraint can be:
{ PRIMARY KEY ( column_name [, ... ] ) | FOREIGN KEY ( column_name [,
... ] ) REFERENCES reftable (refcolumn ) [ MATCH matchtype ] [ ON
DELETE action ] [ ON UPDATE action ] [ [ NOT ] DEFERRABLE ] [ INITIALLY
checktime ] } [, ...]
Note: The system permits and maintains primary key, default, foreign key, unique, and ref-
erences. Because Netezza does not support constraint checking and referential integrity,
you must ensure your own constraint checking and referential integrity.
If you have permission to create a table, you can specify a constraint. If you have permis-
sion to alter a table, you can add or drop a table constraint.
You cannot change constraint names or directly change the owner of the constraint. The
owner of the constraint is always the owner of the table. Thus, if you change the owner of
the table, the system changes the owner of all associated constraints.
For more information about constraints, see “CREATE TABLE” on page B-56.
Removing a Table
If you are the administrator, the owner of the table, or have Drop privilege, you can drop a
table. You might need to drop a table to implement a new design or to free space in your
database.
Dropping a table causes its structural definition, data, and constraints to be permanently
deleted from the database. The system makes the space that was used to store the table
available to other tables.
T To remove a table that you no longer need, use the DROP TABLE command:
system(admin)=> DROP TABLE weather;
Truncating a Table
To empty a table, use the TRUNCATE command. The TRUNCATE command frees up all the
disk space allocated to a table, making the space available for reuse.
Note: You cannot execute the TRUNCATE command inside a transaction block (begin/com-
mit pair).
Renaming a Table
You can change the name of a table without changing any of the data. The data remains the
same type and size. You must be the owner of the table or have the Alter privilege on tables
to change the table’s name.
T To rename a table, use the ALTER TABLE command:
system(admin)=> ALTER TABLE weather RENAME TO forecast;
When you use columns names, you can list them in any order and you can omit columns for
which you do not have data:
system(admin)=> INSERT INTO weather (date, city, temp_hi, temp_lo)
VALUES ('1994-11-29', 'Hayward', 54, 37);
Querying a Table
To query a table, use the SELECT command. The select command is divided into three
parts:
X The columns to return
X The tables from which to retrieve data
X Any restrictions
For example, to list all the rows of the table weather, enter:
system(admin)=> SELECT * FROM weather;
To specify expressions in the target list, enter:
system(admin)=> SELECT city, (temp_hi+temp_lo)/2 AS temp_avg, date
FROM weather;
In this example, you rename the columns temp_hi and temp_lo as temp_avg by using an
AS clause.
You can use Boolean operators (AND, OR, and NOT) in the qualification of a query. For
example, to retrieve the weather of San Francisco on rainy days, enter:
system(admin)=> SELECT * FROM weather WHERE city = 'San Francisco' AND
prcp > 0.0;
To specify that the result of a select is returned in sorted order, enter:
system(admin)=> SELECT DISTINCT city FROM weather ORDER BY city;
Joining Tables
Queries can access multiple tables at once, or access the same table in such a way that
multiple rows of the table are being processed at the same time. A query that accesses
multiple rows of the same or different tables at one time is called a join query. For more
information, see Appendix C, “Join Overview.”
For example, to list all the weather records together with the location of the associated city,
you might compare the city column of each row of the weather table with the name column
of all rows in the cities table, and select the pairs of rows where these values match:
system(admin)=> SELECT * FROM weather, cities WHERE city = name;
UNION
In a UNION [DISTINCT] operation, if a tuple t appears m (>= 0) times in the first input
table, and the same tuple t appears n (>= 0) times in the second input table, then that
tuple t appears only once in the output table if (m + n) > 0.
{0,1,2,2,2,2,3,N,N} UNION {1,2,2,3,5,5,N,N,N}
Î{0,1,2,3,5,N}
UNION ALL
In UNION ALL operation, if a tuple t appears m (>= 0) times in the first input table, and
the same tuple t appears n (>= 0) times in the second input table, then that tuple t appears
(m + n) times in the output table.
{0,1,2,2,2,2,3,N,N} UNION ALL {1,2,2,3,5,5,N,N,N}
Î{0,1,1,2,2,2,2,2,2,3,3,5,5,N,N,N,N,N}
INTERSECT
In an INTERSECT [DISTINCT] operation, if a tuple t appears m (> 0) times in the first
input table, and the same tuple t appears n (> 0) times in the second input table, then that
tuple t appears only once in the output table.
{0,1,2,2,2,2,3,N,N} INTERSECT {1,2,2,3,5,5,N,N,N}
Î{1,2,3,N}
INTERSECT ALL
In an INTERSECT ALL operation, if a tuple t appears m (> 0) times in the first input table,
and the same tuple t appears n (> 0) times in the second input table, then that tuple
appears the lesser of m and n times in the output table
{0,1,2,2,2,2,3,N,N} INTERSECT ALL {1,2,2,3,5,5,N,N,N}
Î{1,2,2,3,N,N}
EXCEPT
In an EXCEPT [DISTINCT], or a MINUS [DISTINCT] operation, if a tuple t appears m (> 0)
times in the first input table, and same tuple t appears n (>= 0) times in the second input
table, then that tuple t appears only once in the output table if (m > 0 && n == 0).
{0,1,2,2,2,2,3,N,N} EXCEPT {1,2,2,3,5,5,N,N,N}
Î{0}
EXCEPT ALL
In an EXCEPT ALL, or in a MINUS ALL operation, if a tuple t appears m (> 0) times in the
first input table, and same tuple t appears n (>= 0) times in the second input table, then
that tuple t should appear (m - n) times in the output table if (m - n) > 0.
{0,1,2,2,2,2,3,N,N} EXCEPT ALL{1,2,2,3,5,5,N,N,N}
Î{0,2,2}
Handling NULLS
SQL treats NULLS differently in set operations (UNION, INTERSECT, EXCEPT) than it does
when handing NULLS in joins and scans.
When comparing rows, SQL treats set operations NULL values as equal to each other; that
is, the evaluation expression (NULL = NULL) produces the result TRUE. Whereas in join or
scan operations, the same NULL equality expression evaluates to UNKNOWN.
Note that in Table 2-4 and Table 2-5, the table cell represents the data type of the output
table and a dash (-) means that the pair has no data type promotion logic.
INT1 INT2 INT4 INT8 NUMERIC REAL DOUBLE CHAR VARCHAR NCHAR NVARCHAR
BOOL — — — — — — — — — — —
DATE — — — — — — — — — — —
TIME — — — — — — — — — — —
TIMESTAMP — — — — — — — — — — —
TIMETZ — — — — — — — — — — —
Table 2-5 displays the data type promotion for noninteger values.
Managing Views
You can use views to focus, simplify, and customize each user’s perception of the database.
You can use views as a security mechanism by allowing users to access data through the
view, without granting the users permission to access the view’s underlying base tables
directly.
Creating Views
The CREATE VIEW command lets you define a view of a table. The view is not physically
created, but rather the Netezza RDBMS automatically generates a query rewrite to support
retrieve operations on views.
T To create a view, enter:
system(admin)=> CREATE VIEW viewname AS SELECT query;
Replacing Views
The CREATE OR REPLACE VIEW command transfers the permissions (ACL data) from one
view to another. You should also use this command to recompile your views after you
rename a database.
T To transfer view permissions, enter:
system(admin)=> CREATE OR REPLACE VIEW viewname AS SELECT query;
Dropping Views
The DROP VIEW command drops (or removes) a view. You must be the owner of the view or
have been granted the Drop privilege on views to drop an existing view from the database.
T To drop a view, enter:
system(admin)=> DROP VIEW emp;
Renaming Views
You can change the name of a view without changing any of the data. The data remains the
same type and size. You must be the owner of the view or have the Alter privilege on views
to change the view’s name.
T To rename a view, enter:
system(admin)=> ALTER VIEW emp RENAME employees;
The query planner/optimizer automatically checks for materialized views and takes advan-
tage of them when they exist and when they would be faster to use than the original table.
This means that you can add materialized views to your database and gain the performance
benefits without having to rewrite any of your applications.
Materialized views improve query performance by reducing the amount of data the system
transfers from the disk during scans, and by the fact that the data is sorted, which results
in a better zone map for the ORDER BY columns.
Materialized views also provide significant performance benefits when you use them for
single-record or few-record lookups. When you create materialized views, the system auto-
matically adds another column to each SPM view record that defines where in the base
table the SPM view record originated (that is, the base table’s block number). You can use
the SPM view as an index for the base table. A base table query targeted at a single record
or a few records can use the sorted nature of an SPM view and its corresponding automati-
cally created zone map to retrieve the block location of the records in the base table
quickly.
X Using the REFRESH option re-materializes the SPM view, which re-creates the materi-
alized table from the base table. Although normally you use the REFRESH option on
suspended materialized views, you can also use it on ordered unsuspended material-
ized views to re-sort the views for better performance. You would also use the
REFRESH option to update the materialized views after an insert to the base table.
T To change the properties of an SPM view, enter:
system(admin)=> ALTER VIEW customers_mview MATERIALIZE REFRESH;
Memory Usage
The memory utilization to support the creation of SPM views is equal to that required of
CTAS statements. Queries that rely on the sorted nature of SPM may require additional
memory to sort the unsorted records added after the materialized views were created.
X timestamp
X char — all sizes, but only the first 8 bytes are used in the zone map
X varchar — all sizes, but only the first 8 bytes are used in the zone map
X nchar — all sizes, but only the first 8 bytes are used in the zone map
X nvarchar — all sizes, but only the first 8 bytes are used in the zone map
X numeric — all sizes except 128-bit numerics
X float
X double
X bool
X time
X time w/timezone
X interval
Task Privilege
Create an SPM view Assign the Create Materialized View administration privilege.
Alter an SPM view Assign the Alter object privilege for a specific view or the View
object class.
Drop an SPM view Assign the Drop object privilege for a specific view or the View
object class.
Select from an SPM Assign the Select object privilege for a specific view or the View
view object class.
Alter Views on a table Assign the Insert object privilege for a specific view or the Table
object class.
List on SPM views Assign the List object privilege for a specific view or the View
object class.
X Most restrictive column — If there is a column that participates in a filter clause and
usually filters out most of the table (for example, temporal columns), then use this col-
umn for the ORDER BY clause in the materialized view creation.
X Materialized view index — Create very thin materialized views (with as few columns as
possible) that contain the most restrictive columns (for example, temporal columns) for
use as indexes.
X Fewer materialized views — For the best performance, create as few materialized views
per each table as possible. Each materialized view that you create for a base table
causes the system to analyze the performance of using each view over the base table,
which can add time to the query performance.
Understanding Subqueries
A subquery is a select expression that is enclosed in parentheses as a nested query block in
a query statement. These nested query blocks can appear in any of the following SQL state-
ments: SELECT, INSERT, DELETE, UPDATE, CREATE TABLE AS, INSERT INTO, and
SELECT INTO. You can nest subqueries to any arbitrary depth.
The parent query that contains the subquery is often referred to as a super query or outer
query. Subqueries in the same parent are used to derive sets of results that can be evalu-
ated in conjunction with the parent query.
Subqueries can be further divided into the following categories:
X Row subquery — Returns one row (or zero rows) and multiple columns, and can occur
in a SELECT list or in a condition expression; for example, as an argument of a compar-
ison operator.
X Table subquery — Returns multiple rows (0—n rows) and multiple columns, and can
exist in a FROM clause or as an argument of an EXISTS, IN, ANY, or ALL test.
For example, “List all stores where sales are more than one percent of all company
sales,” can be written in the SQL query-within-a-query form using a scalar subquery:
Example 1 SELECT StoreId FROM Stores
WHERE TotalSale > 0.01*
(SELECT SUM(TotalSales) FROM Stores);
The system calculates the sum of sales of the inner subquery first and then uses it
when running the outer query.
X Singleton subquery — Returns exactly one value in the format of one row (or zero
rows), one column table.
For all these subqueries the system evaluates them once and calculates and stores their
select expression. When you execute the super query, the system substitutes the computed
values in place of the subquery.
A correlated subquery, on the other hand, is a query within a query that references (or cor-
relates) with the outer query. With correlated subqueries the system evaluates the subquery
repeatedly, once for every row selected from the outer table.
Grouped Aggregates
Grouped aggregates return a single result per group or a single result for all the groups
(referred to as a grand aggregate). For example, the following query shows a grand grouped
aggregate; it returns the highest low-temperature reading in the table weather:
system(admin)=> SELECT max(temp_lo) FROM weather;
MAX
-----
55
As shown in this example, the grouped aggregates provide a summary (in this case, the
maximum value) of a set of rows, but they do not preserve any detail of the information.
They simply return the aggregate, matching value.
When aggregates are used in combination with the GROUP BY clause, the query returns a
result for each matching group. For example, the following query displays the maximum
low temperature observed in each city in the table:
system(admin)=> SELECT city, max(temp_lo) FROM weather GROUP BY city;
CITY | MAX
---------------+-----
San Francisco | 55
Boston | 40
(2 rows)
The system computes each aggregate result over the table rows that match the city. You
can filter these grouped rows using HAVING:
system(admin)=> SELECT city, max(temp_lo) FROM weather GROUP BY city
HAVING max(temp_lo) < 42;
CITY | MAX
--------+-----
Boston | 40
(1 row)
The following example uses a subquery to identify the city or cities where the max temp_lo
value occurred. The subquery is necessary because the aggregate max cannot be used in a
WHERE clause.
system(admin)=> SELECT city FROM weather WHERE temp_lo = (SELECT
max(temp_lo) FROM weather);
CITY
---------------
San Francisco
(1 row)
For more information about the available aggregate functions, see “Aggregate Functions”
on page 3-14.
Window Aggregates
Window aggregates (also called window analytic functions) allow you to compute an aggre-
gate value based on a group of rows, which are defined by a window. The window
determines the range of rows the system uses to perform the calculations. Window sizes
can be based on a physical number of rows or a logical interval such as year-to-date, quar-
terly, and so on. You can use window aggregates to compute cumulative, moving, centered,
and reporting aggregates. Unlike the grouped aggregates, window aggregates can preserve
the row information.
For example, the following is a table of monthly sales information called monthlysales:
YEAR | MONTH | SALESK
------+-------+--------
2007 | 10 | 20
2007 | 11 | 22
2007 | 12 | 25
2008 | 1 | 30
2008 | 2 | 35
2008 | 3 | 50
2008 | 4 | 70
(7 rows)
With window aggregates, you can compute various aggregations over moving time frames.
For example, the following query shows a three-month moving average of the sales total:
system(admin)=> SELECT year, month, salesk, avg(salesk) OVER
(PARTITION BY year ORDER BY month ROWS BETWEEN 1 PRECEDING AND 1
FOLLOWING) FROM monthlysales;
YEAR | MONTH | SALESK | AVG
------+-------+--------+-----------
2007 | 10 | 20 | 21.000000
2007 | 11 | 22 | 22.333333
2007 | 12 | 25 | 23.500000
2008 | 1 | 30 | 32.500000
2008 | 2 | 35 | 38.333333
2008 | 3 | 50 | 51.666667
2008 | 4 | 70 | 60.000000
(7 rows)
The output has a result for each row and the AVG value is a moving average of the previous,
current, and following month’s sales values. In the case of the first row, the average is
based only on the current and following month, as there is no previous month. Likewise,
the last row is the average of only the previous and current month.
The following example shows a running total of the sales summary:
system(admin)=> SELECT *, sum(salesk) OVER (PARTITION BY year ORDER BY
month ROWS UNBOUNDED PRECEDING) FROM monthlysales;
YEAR | MONTH | SALESK | SUM
------+-------+--------+-----
2007 | 10 | 20 | 20
2007 | 11 | 22 | 42
2007 | 12 | 25 | 67
2008 | 1 | 30 | 30
2008 | 2 | 35 | 65
2008 | 3 | 50 | 115
2008 | 4 | 70 | 185
(7 rows)
The output has a result for each row and the SUM value is the total of the sales for each
month in the table (all the previous rows plus the current row).
For more information about these functions, see “Netezza SQL Analytic Functions” on
page 6-1.
Executing Scripts
Scripts allow you to bundle all your queries into a single file, which you can then run auto-
matically and repeatedly. You can create a script by using any standard editor and typing
regular SQL commands.
There are three ways that you can execute scripts:
T You can use the redirect command on the command line to specify that the system use
a file instead of stdin:
nzsql < script_file
T You can use the nzsql command line argument -f, which allows you to specify a file:
nzsql -f script_file
T You can specify the script from within the nzsql command interpreter:
EMP(USER)=> \i script_file
This chapter contains descriptions of data types, functions and expressions, Netezza SQL
extensions, and Netezza SQL functional categories.
Data Types
A data type represents a set of values. Using data types in your databases offers the follow-
ing benefits:
X Consistent results — Having columns of a uniform type produces consistent results.
Database operations, such as displaying, sorting, aggregating, and joining, produce
consistent results. There is no conflict over how different types are compared or
displayed.
X Data validation — Having columns of a uniform type ensures that only properly format-
ted data is entered.
X Compact storage — Having columns of uniform type ensures that data is stored effi-
ciently. The system does not need to allocate more storage than necessary.
X Performance — Having columns of uniform type allows the system to process the que-
ries efficiently.
Each column in a relational database can hold only one type of data. You cannot mix data
types within a column.
This section describes the data types that Netezza SQL supports. It notes type alias where
they are available. The first type name listed is the preferred form and is the form that the
Netezza SQL saves with the table definition. Note that the type alias is not saved with the
table definition.
3-1
Netezza Database User’s Guide
Fixed-point numeric data types allow you to define the numeric rounding to a specific dec-
imal place. Table 3-2 describes the fixed-point numeric data types.
Always use the smallest integer or fixed-point numeric whenever possible. When converting
source data to the Netezza system, you may need to analyze the data to determine the
smallest data type that you can use.
T To determine the smallest data size you can use for integer and fixed point numerics,
type the following SQL command:
SELECT MIN(column_name), MAX(column_name) FROM table_name;
Netezza SQL prefers type names real and double precision, with float(p) being closer to an
alias for one or the other of the preferred forms.
Note: Not only is floating point summation approximate, but more importantly, it is non-
associative; that is, the result depends on the order in which the partial sums are com-
bined. This is very different from integer and numeric summations that are precise and
always produce the same result irrespective of any reordering.
In the massively parallel Netezza, sums and averages are partially evaluated on the SPUs
and then combined at the host to produce the final result. Because SPUs return results asyn-
chronously to the host, floating point summations produce different results from run to run.
This effect is particularly noticeable if the values span a large dynamic range and/or there
are large values of differing signs tending to cancel each other out.
Variable length, char- Variable length to a maximum N+2 or fewer bytes depend-
acter varying(n) (alias length of n. No blank padding, ing on the actual data.
varchar(n)) stored as entered. The maximum
character string size is 64,000.
Fixed length Unicode Fixed length, blank padded to For more information, see
(alias nchar(n)) length n. The maximum length of “The Data Types” on
16,000 characters. page 7-3.
Variable length, Uni- Variable length to a maximum For more information, see
code (alias length of n. The maximum length of “The Data Types” on
nvarchar(n)) 16,000 characters. page 7-3.
T To determine the optimal character data type, type the following SQL command:
system(admin)=> SELECT MAX(LENGTH(TRIM(column_
name))),AVG(LENGTH(TRIM(column_name)))FROM table_name;
When selecting a character data type, consider the following:
X If the data is exclusively numeric, use an integer data type instead of a character data
type. For example, 11212345 could be defined as a VARCHAR or a bigint. Select a
bigint, especially if you are using the column for distribution or joins.
X If, when converting source date, the MAX length is less than the CHAR size, use a
CHAR instead of VARCHAR. If the AVG length +2 is less than the CHAR size, use a
VARCHAR instead of a CHAR.
X Comparing numbers with string data types can sometimes produce unpredictable
results. As a best practice, use the to_number conversion function to convert the string
to a number, for example:
where to_number(<varchar-column>, '9999') > <integercolumn>
boolean (alias bool) With value true (t) or false (f). 1 byte
You can use the following words to specify booleans: true or false, on or off, ‘0’ or ‘1’, “true’
or ‘false’, ‘t’ or ‘f’, ‘on’ or ‘off’, ‘yes’ or ‘no’.
Note: Never use a boolean data type for distribution columns because your table would be
distributed to only two data slices in the Netezza.
Temporal Types
Temporal data types allow you to store date, time, and time-interval information. Although
you can store this data in character strings, it is better to use temporal types for consis-
tency and validation. Note that the time values provide storage accuracy in microseconds
(one millionth of a second — six decimal places).
Table 3-6 describes the temporal data types.
time with time zone (alias Hours, minutes, seconds to 6 decimal posi- 12 bytes
timetz) tions, and time zone offset from GMT.
Ranging from 00:00:00.000000+13:00 to
23:59:59.999999-12:59.
timestamp Has a date part and a time part, with seconds 8 bytes
stored to 6 decimal positions. Ranging from
January 1, 0001 00:00:00.000000 to
December 31, 9999 23:59:59.999999.
Declares intervals as having particular units; Accepts this syntax, but ignores the unit
for example, colA interval year to month, or specification.
colB interval hour. All intervals are the same, and can contain
values of any combination of units.
Does not include units in interval literals. Requires that all literal values include the
For example, an interval year to month col- units, as in “13 years 4 months,” because
umn's values might be “13-4,” meaning 13 interval units pertain to a particular value
years and 4 months. rather than to a particular column's
declaration.
Disallows declaring intervals as having both Internally normalizes all intervals to units of
units smaller than a month and units seconds. Considers a month to be thirty
greater than a day; for example, interval days for the purposes of interval
month to day, because this is ambiguous. comparisons.
To avoid inaccuracies introduced by this
approximation, use only intervals in units
smaller than months.
Note: You cannot load the interval data type from an external table.
X transaction ID — Identifies the transaction ID that created the record (createxid) and
the transaction ID that deleted the record (deletexid), which is 0 if the record has not
been deleted. When the system updates a record, it updates the deletexid on the origi-
nal row with the current transaction ID, inserts a record with the updated value and
preserves the rowid.
An xid is an 8-byte integer of which 48 bits are significant. At installation, the initial
xid value is 1024. The size of the xid allows for over 100 trillion transaction IDs.
X data slice — Identifies that portion of the database stored on each disk. At installation,
the system is divided into a logical number of data slices. When the system creates a
record, it assigns it to a logical data slice (and thus a physical disk) based on its distri-
bution key. Although the system dynamically generates datasliceid values, it does not
store them with each individual record.
You can use the datasliceid keyword in a query to identify which data slice the records
are coming from. For example:
SELECT DATASLICEID, name FROM employee_table;
For more information about data slices, see the Netezza System Administrator’s Guide.
Note: These internal data type column names are reserved words, which means that you
cannot use them in DDL statements.
Create XID Delete XID Row ID Null Vector Record Length Column_1 …Column_n
Operators
Operators differ from functions in the following ways:
X Operators are symbols not names.
X Operators usually take two arguments.
X Arguments usually appear to the left and right of the operator symbol.
The standard arithmetic operators — addition, subtraction, multiplication, division, expo-
nentiation, and modulo — use the standard precedence rules. That is, exponentiation is
performed first; multiplication, division, and modulo second; and addition and subtraction
last. You can use parentheses to alter this precedence. Netezza SQL evaluates operators of
the same precedence in a left-to-right manner unless you use parentheses.
Table 3-10 describes the Netezza SQL operators.
Operator Symbol
Addition +
Subtraction -
Multiplication *
Division /
Exponentiation ^ or **
Modulo %
Operator Symbol
Plus +
Minus -
Factorial !
Concatenate ||
Relational Operators
Equal =
Netezza follows Postgres operator precedence rules. Table 3-11 lists the precedence and
associativity of the available operators.
^ Left Exponentiation
IN Set membership
BETWEEN Containment
< <= > >= Less than, less than or equal to, greater than,
greater than or equal to
Functions
Functions allow you to access specified routines from SQL. They take one or more argu-
ments and return a result. Table 3-12 describes the functions.
Name Description
Name Description
coalesce(arg1, arg2, Returns its first non-null argument or null if all arguments are null.
…) isnull is a synonym for SQL Server compatibility.
cast (<value> as Is available to convert from one data type to another data type. For
<type>) more information, see “Cast Conversions” on page 3-11.
extract (field from Extracts a numeric datetime or time zone field from a datetime or
<datetime value>) interval value. For example, extract(year from <datetime-value>).
For a list of valid arguments, see “Extract Date-Time Value” on
page 3-12. For syntax, see Table B-120 on page B-133.
date_part ('field', Similar to extract, extracts a numeric datetime or time zone field
<datetime value>) from a datetime or interval value. For example, date_time('day',
<datetime-value>). For a list of valid arguments, see “Extract Date-
Time Value” on page 3-12. For syntax, see Table B-120 on
page B-133.
nvl(x,y) Returns the first argument if it is not null, otherwise it returns the
second argument. For example, nvl(hire_date, sysdate) returns the
sysdate if the hire_date is null.
nvl is equivalent to the SQL coalesce function, and is short hand for
the case expression “case when x is not null then x else y end.” For
more information, see “NVL Example” on page 3-13.
nvl2(x,y,z) Returns the second argument if the first argument is not null, other-
wise it returns the third argument.
nvl2 is short hand for the case expression “case when x is not null
then y else z end.” For more information, see “NVL2 Example” on
page 3-13.
decode(<expr>, Compares the expr to each search value. If the expr is equal to the
<search1>,<result1> search, decode returns the result. If there is no match, decode
, …<search N>, returns the default, or if the default is omitted, returns null.
<result N>, For more information, see “Decode Example” on page 3-14.
<default>)
Cast Conversions
You can use cast(<value> as <datatype>) to cast a data type from one type to another type.
For example, you could convert any numeric data type (byteint, smallint, int, bigint,
numeric/decimal, float, double) to any other numeric datatype. The <value> field can be a
column or an expression.
In addition to the cast function, Netezza offers additional datatype conversons as described
in Table 3-13.
You can also convert from one date, time, or timestamp to another. For example,
nzsql nzdw -a -x < x.sql
To convert a timestamp to a date, use CAST. For example,
CAST(<timestamp_value> AS DATE);
Value Description
quarter The quarter of the year (1 to 4) that the specified day is in.
month/months The number of the month within the year, from 1 to 12.
week The number of the week of the year (1-53) that the speci-
fied day is in. The value uses the ISO-8601 definition of a
week, which begins on Monday; as a result, some years
may have 53 weeks, and sometimes the first few days of
January could be included as part of the 52nd or 53rd
week of the previous year.
Value Description
For data type intervals, see “Netezza SQL Interval Support” on page 3-6.
Note: Netezza SQL does not support timezone* values.
For example:
SELECT EXTRACT(DAY FROM TIMESTAMP '2007-02-14 20:38:40');
Result: 14
NVL Example
In this example, when selecting the title and price for all books, if the price for a title is
NULL, the price displays as 0.00
SELECT title, nvl(price, 0.00) AS price
FROM titles;
Note: The nvl function is equivalent to the SQL coalesce function. The result of this expres-
sion is type compatible with both expr1 and expr2, just as in the coalesce function.
NVL2 Example
In this example, the first argument is not null, so it returns the second argument.
SELECT nvl2(1,2,3);
NVL2(1,2,3)
-----------
2
Note: The nvl function is equivalent to a case expression. The result of the expression is
type compatible with the second and third arguments, just as it is in the corresponding
case function.
Decode Example
Use the decode function to create an if-then-else statement. In this example, if the color ID
is 1000 the result is red, if 1001, blue, if 1002, yellow, otherwise it is none.
SELECT color_id,
DECODE (color_id, 1000, ‘red’, 1001, ‘blue’, 1002, ‘yellow’, ‘none’)
AS color_name
FROM colors;
Note: Netezza SQL implements the decode function as a variant of a simple case expres-
sion, and it is equivalent to the expression “case x when val1 then result 1 when val2 then
result 2 else default end.” Except If both x and val1 contain NULL values, unlike a case
expression, decode considers the NULL values to be equal.
Aggregate Functions
Aggregates compute a result value from a set of values. Table 3-15 describes the five
Netezza SQL aggregate functions.
Name Description
Table 3-16 describes data type functions and their associated aggregates.
Type Name
Function Description
Position Finds one string within another. The value 0 indicates not found. For
example, position(<character-value> in <character-value>).
Like/not like Provides pattern matching comparisons. Netezza SQL supports the
standard pattern characters: %, _ and the escape character by
default. For more information about using like, see “Pattern Match-
ing” on page 3-15.
Pattern Matching
Every pattern defines a set of strings. The LIKE expression returns true if the string is con-
tained in the set of strings represented by pattern. Consequently, the NOT LIKE expression
returns false if LIKE returns true, and vice versa. An equivalent expression is NOT (string
LIKE pattern).
If pattern does not contain percent signs or underscores, then the pattern only represents
the string itself; in that case LIKE acts like the equals operator. An underscore (_) in pat-
tern stands for (matches) any single character; a percent sign (%) matches any string of
zero or more characters.
For example:
'abc' LIKE 'abc' true
'abc' LIKE 'a%' true
'abc' LIKE '_b_' true
'abc' LIKE 'c' false
LIKE pattern matches always include the entire string. To match a pattern anywhere within
a string, the pattern must therefore start and end with a percent sign.
To match a literal underscore or percent sign without matching other characters, you must
precede the respective character in pattern with the escape character. The default escape
character is the backslash, but you can choose a different character by using the ESCAPE
clause. To match the escape character itself, enter two escape characters.
T To escape the % character, use a backslash, for example:
SELECT * FROM table WHERE col LIKE '%90\%%'
T If you cannot use the backslash character, then designate another ASCII character as
the escape character, for example:
SELECT * FROM table WHERE col LIKE '%90#%%' escape '#'
It is also possible to select no escape character by entering ESCAPE '' (empty single
quotes). In this case, there is no way to turn off the special meaning of underscore and per-
cent signs in the pattern.
Note: Netezza SQL does not support ILIKE (case insensitive search) SQL operators. How-
ever you can always use UPPER() or LOWER() to do case insensitive searches. For example:
WHERE UPPER(first_name) LIKE 'PAT%'
Because the string comparisons are case-sensitive, you can use functions such as upper()
and lower() to change the letter casing of strings prior to the comparison and ignore case-
change modifications. For example, select le_dst('Smith','SMYTH') returns a
value of 4 (three uppercase letter changes and a letter substitution). The function select
le_dst(upper('Smith'),'SMYTH') returns a value of 1 (the I/Y letter substitution).
SoundEx NYSIIS
SQL syntax:
<varchar(6) value> = nysiis(<str_expr>)
Soundex is a well-known phonetic algorithm for indexing names by sound as pronounced in
English. This function converts a string into its Soundex representation using the New York
State Identification and Intelligence System (NYSIIS) variation of Soundex. The return
value is a string of up to 6 characters that identifies the pronunciation of the input string.
For example, the function nysiis('Washington') returns the string ‘wasang’, while
the function nysiis('brown') returns the value ‘bran’.
Double Metaphone
SQL syntax:
<int4 value> = dbl_mp(<str_expr>)
Double Metaphone is another phonetic algorithm for indexing strings by their pronuncia-
tion. Similar to Soundex, it uses a different set of rules for English as well as alternate
pronunciation. The function returns two 4-character string encodings—a primary key and
secondary (or alternate) key—for pronunciation of the input string. Similar sounding words
share the same keys, though they may be of variable length and spelling. For example the
double metaphone primary and secondary keys for the name ‘washington’ are 'AXNK' and
'FXNK'.
For improved performance, the dbl_mp function maps the 4-character keys to 16-bit num-
bers and returns a composite 32-bit value (Netezza type int4) that holds both the 16-bit
primary and secondary keys. So, the function dbl_mp('washington') returns the value
781598358.
There are three helper functions (pri_mp, sec_mp, and score_mp) that you can use to
extract the primary and secondary keys as strings from the return value, as well as to per-
form key comparisons for scoring relevance.
For the four match value arguments, you can specify values such as 1, 2, 3, and 4 (for
strongest, normal, minimal, or no match). You could also use weighted values such as 100,
50, 25, and 0 to return more points for better match results.
For example, if you compare the double metaphone encodings for ‘washington’
(781598358) and ‘wachingten’ (7815963100), you could use the following score_mp
function to determine how closely they match:
score_mp(781598358,781596310,1,2,3,4)
The function returns the value 1, which indicates a strongest match.
If you compare the encodings for ‘washington’ and ‘vachingten’ (1050031766):
score_mp(781598358,1050031766,100,50,25,0)
The function returns the value 50, which indicates a normal match.
Note: Netezza SQL parses, but ignores, precisions for current_time and current_timestamp.
Math Functions
The following sections describe the trigonometric, random number, miscellaneous, and
binary math functions.
Trigonometric Functions
Table 3-19 describes the trigonometric functions.
Function Description
cos(x) cosine
cot(x) cotangent
pi() pi constant
sin(x) sine
tan(x) tangent
Function Description
intNshl(arg1, arg2 [,arg3]) Shift left, with optional mask. arg1 is ANDed with arg3 (if
present) then shifted left by arg2 bits
intNshr(arg1, arg2 [,arg3]) Shift right, with optional mask. arg1 is ANDed with arg3 (if
present) then shifted right by arg2 bits
Character Functions
Table 3-23 describes the character functions.
Name Description
ascii(s) Returns numeric ASCII value of first character in s. For the NCHAR
version, see unicode(s).
chr(n) Returns the character with ASCII value n. For NCHAR version, see
unichar(n).
Name Description
ltrim(s,t) Trims occurrences of the characters in t string from left end of string
s.
substr(s,p,l) Returns a substring of strings that begin at position p and is the size
of l characters.
translate(s,from, t) Replaces any character in s that matches a character in the from set
with the corresponding character in the to set. For example, trans-
late(‘12345’,’14’,’ax’) returns ‘a23x5’.
unichr(n) Returns the character with the ASCII value n. Equivalent to the
chr() function. The function verifies that the codepoints are in the
valid ranges, and displays an error if the codepoints are in the
invalid range of U+D800-U+DFFF or in decimal 55,296-57,343.
unicode(s) NCHAR version of ascii(). Returns the Unicode value of the first
character in the string s. A separate function is defined because six
characters have different values between Latin9 and Unicode.
Date/Time Functions
Table 3-24 describes the date/time functions. For syntax, see Table B-120 on page B-133.
For interval datatypes, see “Netezza SQL Interval Support” on page 3-6. For data/time
units, see “Extract Date-Time Value” on page 3-12.
Type Description
add_months (d, n) The function returns the date d plus the n months. You can
use any integer for n months. If d is the last day of the
month, or if the resulting month has fewer days than the day
component, then the result is the last day of the resulting
month. Otherwise, the result has the same day component as
d.
extract(units FROM col) Extracts the subfield from date/time value or the subfield
from interval value. Same as date_part().
last_day(date) Returns the last day of the month that is specified in the
date value.
months_between(d1, d2) The function returns the number of months between dates
d1 and d2.
• If d1 is later than d2, the result is positive.
• If d1 is earlier than d2, the result is negative.
• If d1 and d2 are either the same days of the month or
both the last days of months, the result is always an
integer.
• Otherwise, the function calculates the fractional portion of
the result based on a 31-day month and considers the dif-
ference in time components of d1 and d2.
Type Description
next_day(date, weekday) Returns the date of the weekday following a particular date.
The date value specifies a date, either as a date or a times-
tamp. The returned value matches the format of the date
value.
The weekday value is a day of the week (SUNDAY, MONDAY,
TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY).
It is a string literal and must be enclosed in quotes, and you
can use either uppercase or lowercase letters.
Conversion Functions
You can use the Netezza SQL formatting functions to convert data types (date/time, integer,
floating point, numeric) to formatted strings and to convert from formatted strings to spe-
cific data types. These functions all use a common calling convention: the first argument is
the value to be formatted, and the second argument is a template that defines the output
or input format.
Table 3-25 describes the conversion functions.
Pattern Description
MI Minute (00:59).
SS Second (00:59).
MS Milliseconds (00:00.999)
US Microseconds (00:00.999999)
Pattern Description
W Week of the month (1:5) where first week start on the first
day of the month.
CC Century (2 digits).
Q Quarter
You can apply the following modifiers to any template pattern to alter its behavior.
Table 3-27 describes these modifiers.
Usage notes:
X The FM prefix suppresses leading zeroes or trailing blanks that Netezza SQL would oth-
erwise add to make the output of a pattern be fixed width.
X Normally the to_timestamp and to_date types skip multiple blank spaces. If you spec-
ify the FX prefix, Netezza SQL does not skip blank spaces. Note that you must specify
the FX prefix as the first item in the template.
X To output pattern keywords as literal text, put the substring in double quotes; for exam-
ple ‘”Hello Year:”YYYY’. Netezza SQL will replace YYYY with the year data, but will not
interpret the single Y.
X To output a double quote, precede it with a backslash; for example, ‘\”YYYY Month\”’.
Table 3-28 describes the template patterns for numeric conversions.
Pattern Description
Usage notes:
X A sign formatted using the MI pattern is not an anchor in the number; for example, to_
char(-12, 'S9999') produces ' -12', but to_char(-12, 'MI9999') produces '- 12'.
X The V pattern effectively multiplies the input values by 10^n, where n is the number of
nines following V. The to_char type does not support the use of the V pattern combined
with a decimal point. For example, 99.9V99 is not allowed.
Miscellaneous Functions
Table 3-29 describes the miscellaneous functions.
Type Description
Component Description
Database
alter Sets the default character set and changes the name of the database.
Refer to “ALTER DATABASE” on page B-5.
Group
alter Changes a group’s limits, drops a user from a group, changes the
group’s owner, or name. Refer to “ALTER GROUP” on page B-6.
Component Description
User
alter Alters a user’s account. Changes the owner, password, optional expira-
tion time, rowset limits, and name. Refer to “ALTER USER” on
page B-22.
Table
create table as Creates a new table based on query results. Refer to “CREATE TABLE
AS” on page B-62.
create temp table Creates a temporary table. Refer to “CREATE TABLE” on page B-56.
View
alter Changes the owner or name of the view. Refer to “ALTER VIEW” on
page B-25.
Index
When you create new users, by default they have access only to system views. With these
views, they can retrieve lists of user database objects and select data within those objects.
Because security is also built into these system views, the list of database objects a user
can see depends on the user’s security privileges.
Table 3-31 describes the Netezza SQL DCL.
Component Description
Types of Privileges
There are two types of privileges that you can grant: administrator and object.
X Administrator privileges control creation of objects and system administration.
X Object privileges control access to specific database objects.
Some administrator privileges are global in scope, regardless of the current database. For
example, the database, user, group, system and hardware administrator privileges are glo-
bal in scope. All other administrative privileges can be either global or local depending on
the current database. Table 3-32 describes the administrative privileges.
Privilege Description
Backup Allows user to perform backups. The user can run the command
nzbackup.
[Create] Database Allows the user to create databases. Permission to operate on exist-
ing databases is controlled by object privileges.
[Create] External Allows the user to create external tables. Permission to operate on
Table existing tables is controlled by object privileges.
[Create] Group Allows the user to create groups. Permission to operate on existing
groups is controlled by object privileges.
[Create] Index For system use only. Users cannot create indexes.
[Create] Table Allows the user to create tables. Permission to operate on existing
tables is controlled by object privileges.
[Create] Temp Table Allows the user to create temporary tables. Permission to operate
on existing tables is controlled by object privileges.
Privilege Description
[Create] User Allows the user to create users. Permission to operate on existing
users is controlled by object privileges.
[Create] View Allows the user to create views. Permission to operate on existing
views is controlled by object privileges.
[Manage] Hardware Allows the user to perform the following hardware-related opera-
tions: view hardware status, manage SPUs, manage topology and
mirroring, and run diagnostics. The user can run these commands:
nzhw and nzds.
Reclaim Allows the user to reclaim disk space from user tables. The user
can run the nzreclaim command.
Restore Allows the user to restore the system. The user can run the nzre-
store command.
[Manage] System Allows the user to perform the following management operations:
start/stop/pause/resume the system, abort sessions, view the distri-
bution map, system statistics, and logs. The user can use these
commands: nzsystem, nzstate, nzstats, and nzsession.
Object privileges can also be local or global in scope. The procedure to define global object
privileges is different than that of defining local object privileges. Another difference is that
global object privileges are broader and not particular to a specific object, but instead to a
class of objects. Table 3-33 describes the object privileges.
Privilege Description
Abort Allows the user to abort sessions. Applies to groups and users.
Alter Allows the user to modify object attributes. Applies to all objects.
Delete Allows the user to delete table rows. Applies only to tables.
GenStats Allows the user to generate statistics on tables or databases. The user can run
the GENERATE STATISTICS command.
Insert Allows the user to insert rows into a table. Applies only to tables.
List Allows the user to display an object’s name, either in a list or in another man-
ner. Applies to all objects.
Select Allows the user to select (or query) rows within a table. Applies to tables and
views.
Privilege Description
Truncate Allows the user to delete all rows from a table with no rollback. Applies only to
tables.
Update Allows the user to modify table rows, such as changing field values or chang-
ing the next value of a sequence. Applies to tables only.
Component Description
Component Description
Transaction Control
Transaction control enforces database integrity by ensuring that batches of SQL operations
execute completely or not at all. The transaction control commands are BEGIN, COMMIT,
and ROLLBACK.
Netezza SQL supports auto-commit transaction mode in which there are two types of trans-
actions: single statement and multistatement.
X Single statement — If the system encounters a SQL command before a begin SQL
command, it executes the SQL command within a single statement transaction. The
system automatically commits each successful SQL command.
X Multistatement — If the system encounters a begin SQL command, it executes all suc-
cessive SQL commands within a multistatement transaction. To end a transaction, you
must issue a commit or rollback SQL command. If the system encounters a begin SQL
command when in a multistatement transaction, it generates an error. You can issue
some commands, such as truncate, within a multistatement transaction.
Isolation Level
There are four levels of transaction isolation that are defined by the ANSI/ISO SQL. Netezza
SQL supports the SQL grammar for defining all four isolation levels:
X read committed
X read uncommitted
X repeatable read
X serializable
The only isolation level that Netezza SQL implements, however, is serializable, which pro-
vides the highest possible level of consistency.
These isolation levels prevent the following occurrences between concurrent transactions:
X Dirty reads — A transaction reads data written by concurrent uncommitted
transactions.
X Nonrepeatable reads — A transaction re-reads data it previously read and finds that the
data has been modified by another transaction (that committed since the initial read).
X Phantom read — A transaction re-executes a query returning a set of rows that satisfy a
search condition and finds that the set of rows has changed due to another recently
committed transaction.
Table Locking
As a user, you cannot explicitly lock tables. The Netezza SQL, however, implicitly locks a
table when there is a DDL operation on it. For example, a drop table command is blocked if
somebody is running a select command on the same table (or vice versa).
For concurrent DML operations (select, insert, update, and delete commands), Netezza
SQL uses serialization graph checking, which is a form of optimistic concurrency control
that does not use locks. Instead, if there is a concurrency conflict, Netezza SQL rolls back
one (or sometimes several) of the affected transactions.
X A select command on a given table can proceed concurrently with an update, delete,
insert, or select command on the same table. Invisibility lists, and other mechanisms,
ensure that each transaction sees a consistent state.
X More than one concurrent insert command can proceed against the same table, pro-
vided no more than one is also selecting from the same table.
X Concurrent update or delete commands against different tables are permitted, with
some restrictions that are needed to ensure serializability. For example:
S If transaction 1 selects from table A and updates (or deletes from) table B, while
transaction 2 selects from table B and updates table A, Netezza SQL rolls back one
or the other (typically the transaction that started more recently). This is called the
cross-update case.
S If there is a cycle of three or more transactions (transaction 1 selects from A and
updates B, transaction 2 selects from B and updates C, transaction 3 selects from
C and updates A), the Netezza SQL rolls back one of the transactions in the cycle.
X The nzreclaim command (block or record) puts an exclusive lock on the table, and any
other query against that table pends until the reclaim finishes. Any users attempting to
use that table receive no errors, but automatically resume processing once the reclaim
has completed.
Read-Only Sessions
The Netezza SQL provides SQL commands that define sessions as read-only:
SET SESSION { READ ONLY | READ WRITE }
Read-only sessions are efficient and reduce the overhead in processing SQL commands. If
you define a session as read-only and the system encounters an insert, update, delete,
truncate SQL, a DDL or DCL command, it generates an error.
Keywords
Keywords are words that have a special meaning in SQL. There are two types of keywords:
reserved and non-reserved keywords. A reserved keyword cannot be used as a regular iden-
tifier. Although you can use non-reserved keywords as regular identifiers, it is typically not a
good practice to do so. Keywords are case-insensitive, so for example, the keyword select
has the same meaning as SELECT or Select. For a list of the SQL keywords, see
Appendix A, “SQL Reserved Words and Keywords.”
4-1
Netezza Database User’s Guide
Identifiers
You use identifiers to name database objects, such as users, tables, and columns. Identifi-
ers can either be unquoted (regular identifiers) or quoted (delimited identifiers). For more
information about identifiers, their naming requirements, and other restrictions, see “Han-
dling SQL Identifiers” on page 2-7.
Constants
Constants are symbols that represent specific data values. The format of a constant
depends on the data type of the value it represents. Constants are also called literals.
Constants can be either implicit or explicit. Implicitly-typed constants can be strings, inte-
gers, numeric, or floating-point numbers. Explicit constants enable more accurate
representation and more efficient system handling.
String Constants
A string constant is an arbitrary sequence of characters enclosed in single quotes (“); for
example, ’This is a string’. You can embed single quotes in strings by typing two adjacent
single quotes.
If you have two string constants that are separated only by whitespace with at least one
newline, the system concatenates them and effectively treats them as if the strings had
been written as one constant.
Integer Constants
Integer constants are sequences of decimal digits (0 though 9) with no decimal point and
no exponent. The range of legal values depends on which integer data type you use, but the
plain integer type accepts values ranging from -2147483648 to +2147483647.
Explicit Constants
You can enter a constant of an arbitrary type by using either of the following notations:
type 'string'
CAST ('string' AS type)
The system passes the string text to the input conversion routine for the type called type.
The result is a constant of the indicated type. You can omit the explicit type cast if there is
no ambiguity as to the type the constant must be (for example, when it is passed as an
argument to a non-overloaded function), in which case it is automatically coerced.
You can also specify a type coercion by using a function-like syntax:
typename ('string')
You can use CAST() and function-call syntaxes to specify runtime type conversions of arbi-
trary expressions. But, you can only use the form type 'string' to specify the type of a literal
constant.
Notation Description
YY Two-digit year
X YYYY.MM.DD
X YYYY.DDD (year and day number in year)
X DD-MON-YY
Note: For date values, Netezza assumes that the first value MM represents the number of
the month. However, if the MM value is greater than 12, Netezza treats the first value as
the day of month (DD) and treats the next value as MM. For example, 01/07/2007 is Janu-
ary 7, 2007, but 14/07/2007 is treated as July 14, 2007. As a best practice, use
consistent date formats within your queries.
You can use three-character month abbreviations or full month names, for example:
X July 4, 1776
X Jul 4, 1776
X 4 July 1776
X 4 Jul 1776
You can specify time as one or two-digit hours and minutes with optional one or two-digit
seconds (and seconds can include 0 to 6 digits after the decimal point). For example,
01:30:45 or 12:14:66.123456
You can use optional am/AM or pm/PM suffixes. If you omit the suffix, Netezza SQL
assumes a twenty-four hour notation (also called military time).
You specify time zones as signed hours with optional minutes; for example -HH or
+HH:MM, which indicate the offset of the local time zone from GMT. For example, EST is
-04 hours from GMT. The minus sign means west of Greenwich. The range of time zones is
-12:59 to +13:00.
Comments
A comment is an arbitrary sequence of characters beginning with double dashes and
extending to the end of the line, for example:
-- This is a standard SQL92 comment
Before analyzing the command syntax, the system removes the comment from the input
stream and replaces it with whitespace.
Grammar Overview
Table 4-2 describes the key to reading Netezza SQL statement grammar.
Syntax
Named… Performs this function…
element…
[, …] Square brackets enclos- Specifies that the prior item repeats, separated
ing several items by commas.
[, ()…] Square brackets enclos- Specifies that items within parenthesis repeat,
ing items in parenthesis separated by commas.
| OR Specifies an OR expression.
Varchar
Nchar
Nvarchar
Byteint
Smallint
Numeric
Timestamp
Integer
Double
Date
Boolean
Time
Interval
Real
TimeTz
To:
From:
Char X X X X X X X X X X X X X X X X
Varchar X X X X X X X X X X X X X X X X
Nchar X X X X X X X X X X X X X X X X
Nvarchar X X X X X X X X X X X X X X X X
Byteint X X X X X X X X X X
Smallint X X X X X X X X X X
Integer X X X X X X X X X X
Bigint X X X X X X X X X X
TimeTz
Boolean
Varchar
Nchar
Byteint
Integer
Bigint
Timestamp
Smallint
Char
Nvarchar
Numeric
Real
Time
Interval
Double
Date
To:
From:
Numeric X X X X X X X X X X
Real X X X X X X X X X X
Double X X X X X X X X X X
Timestamp X X X X X X X
Date X X X X X
Time X X X X X
TimeTz X X X X
Interval X X X X X
Boolean X
Note the following points about the table and implicit and explicit casting:
X To perform an explicit cast, use the CAST operator as follows:
CAST (<from-type> AS <to-type>)
For example:
CAST ( <int2-column> AS NUMERIC(12,3) )
X The Netezza system could perform an implicit cast in an expression involving functions
or operators. For example, the Netezza built-in function SQRT takes a float8 (that is,
double) argument. For example, consider the following expression:
SQRT ( <int4-column> )
The system performs an implicit cast, converting the sample expression to the follow-
ing:
SQRT ( CAST ( <int4-column> AS FLOAT8 ) )
As another example, consider the following expression:
<varchar-column> + <int4-column>
The system implicitly casts the varchar column to an int4 type, transforming the
expression to the following:
CAST ( <varchar-column> AS INT4 ) + <int4-column>
X In general, it is better to use explicit casts rather than rely on the implicit casting
behavior of the system. The implicit cast choice made by the system might not yield
the behavior you want. Also, implicit casting behavior could change from one release of
Netezza to another. In the previous example where a varchar is added to an int4, the
system chose an implicit cast from varchar to int4. But if your varchar column con-
tained strings representing numbers with decimal points, as in '25.7', the cast to
integer would generate an error.
X When executing an INSERT or UPDATE statement, the Netezza system implicitly casts
the values being inserted into table columns to the types of those columns, as needed.
This chapter describes how to create external tables, as well as best practices and restric-
tions for using them.
Note: In a Netezza system there are three types of tables: system tables, which are stored
on the host, user tables, which are stored on the data slices, and external tables, which are
stored as flat files on the host or client systems.
5-1
Netezza Database User’s Guide
Syntax
The CREATE EXTERNAL TABLE command has the following syntax.
T To create an external table based on another table:
CREATE EXTERNAL TABLE table_name
SAMEAS table_name
USING external_table_options
T To create an external table as a SELECT clause:
CREATE EXTERNAL TABLE [table_name] 'filename'
[USING external_table_options]
AS select_clause
T To create an external table by selecting columns:
CREATE EXTERNAL TABLE table_name
({ column_name type
[ column_constraint [ ... ] ]} [, ... ]
)
[USING external_table_options]
Although you can specify column_constraints, they are ignored. The column constraints
must be defined elsewhere. For a description of the column_constraints and other argu-
ments, refer to “CREATE EXTERNAL TABLE” on page B-37.
Table 5-1 describes the CREATE EXTERNAL TABLE options.
FORMAT string Specifies the data format. Valid values are text or
internal.
LOGDIR string Specifies the directory for the nzlog and nzbad files.
NULLVALUE string Specifies the string to use for the null value.
REQUIREQUOTES boolean Specifies that quotes are mandatory (except for null
values).
SOCKETBUFSIZE int Specifies the socket buffer size in bytes. Valid val-
ues range from 65536 (64KB) to 838860800
(800MB). The default value is 8388608 (8MB).
Each increment must be on a 4KB boundary, other-
wise the system truncates the increment to the next
lowest value divisible by 4096.
TIMESTYLE string Specifies the time field value expressed in the data
file.
X The USING clause in the inline external statement is optional. If you omit it, the result-
ing external table has the default settings. Note that you must specify the USING
clause in the CREATE EXTERNAL TABLE SAMEAS statement, because the SAMEAS
table might be another external table.
X When you insert data into an external table that references an existing data file, the
system truncates the file before inserting the external table’s data.
X You cannot use more than one external table in a SQL statement. The system displays
the following error if you specify multiple external tables in a SQL query, or if you refer-
ence the same external table more than once in a query:
To make use of multiple external tables, load the data into a non-external table and
specify this table in the query.
X You cannot use external tables in complex SQL statements. If the statement is not sup-
ported, the system displays an error.
You use the keyword EXTERNAL when specifying a transient external table in a INSERT-
SELECT statement.
INSERT INTO lineitem SELECT * FROM EXTERNAL
'/nzetc/tpch1/lineitem.tbl' USING(delim '|');
To unload using an transient external table, enter:
CREATE EXTERNAL TABLE '/nzetc/tpch1/lineitem.tbl' USING(delim '|') AS
SELECT * FROM lineitem;
FORMAT string yes yes 'text' — field values are text characters.
'internal' — Field values are in an internal
(compressed binary) format.
The default is ‘text’.
COMPRESS boolean yes yes True or false. The default is false. Specify
COMPRESS=true only if you are also
specifying FORMAT='internal' to use com-
pressed binary format. Compression is
ignored if you specify FORMAT='text'.
Keep in mind the following if you use the compressed binary format:
X The system ignores all the other format-related options (described in Table 5-1 on
page 5-2) for the CREATE EXTERNAL TABLE command.
X The system does not create the nzlog and nzbad files.
Examples
The following examples show how to use the CREATE EXTERNAL TABLE command to
unload and reload a user table.
T To create a compressed binary format external table definition called emp_backup for
the table emp, enter:
CREATE EXTERNAL TABLE emp_backup SAMEAS emp USING (
DATAOBJECT ('/tmp/emp.bck')
COMPRESS true
FORMAT 'internal'
);
T To back up the emp table data into emp_backup, enter:
INSERT INTO emp_backup SELECT * FROM emp;
T To restore the emp table from emp_backup, make sure that the emp table is empty and
enter:
TRUNCATE TABLE emp;
INSERT INTO emp SELECT * FROM emp_backup;
Netezza SQL supports many of the ANSI SQL:1999 standard analytic functions and some
extensions. Using analytic functions in your business intelligence queries provides the
following benefits:
X Improved query processing — Using these functions results in better performance,
because the system no longer must perform complex procedural processing and
instead can perform simple SQL queries.
X Enhanced productivity — You can perform complex analysis with clearer, more concise
code. The code is quicker to formulate and easy to maintain.
X Easy to learn — The functions utilize existing aggregate functions and thus leverage
known syntax.
X Standardized syntax — Because these functions are part of the ANSI standard, they
are supported in many software packages.
In addition, the Netezza system also supports the development and use of user-defined
functions and aggregates. This feature is described in the Netezza OnStream Functions
Developer’s Guide, which is available from Netezza for users who are participating in the
Netezza Developer Network.
6-1
Netezza Database User’s Guide
The Netezza SQL functions can be divided into the following families:
X Reporting Aggregate family — These functions enable you to compare values at differ-
ent levels of aggregation, because they can perform multiple passes over the data in a
single query block and then return the same aggregate value for every row in a
partition.
You can use reporting functions in percent-of-total and market share calculations. For
instance, you might want to know regional sales levels as a percent of national
sales.These functions provide reporting aggregate processing for all SQL aggregate
functions, which include avg, sum, min, max, count, variance, and stddev.
X Window Aggregate family — These functions answer questions such as “what is the
12-week moving average of a stock price?” or “what was the cumulative sum of sales
per each region?” They provide moving and cumulative processing for all SQL aggre-
gate functions, which include avg, sum, min, max, count, variance, and stddev.
X Lag/Lead family — These functions allow you to compare different rows of a table by
specifying an offset from the current row. You can use these functions to analyze
change and variation. The functions include lag and lead.
X First/Last family — These functions allow you to specify sorted aggregate groups and
return the first or last value of each group. For example, you could query bank state-
ments for beginning and ending monthly balances. These functions include first_value
and last_value.
X Ranking family — These functions help to answer questions such as “what are the top
10 and bottom 10 selling items?” The functions examine the entire output before dis-
playing an answer. These functions include of dense_rank and rank.
X Row count family — The row_number function assigns a number to each row, based on
its position within the window partition. It is similar to dense_rank and rank, but unlike
the rank functions, it counts ties (peer rows, that is, rows that match on the order by
column).
Processing Order
Analytic functions compute an aggregate value based on a group of rows, which are defined
by a window. The window determines the range of rows the system uses to perform the cal-
culations. Window sizes can be based on a physical number of rows or a logical interval.
The system processes queries with analytic functions in three stages:
X Processes all JOINS, WHERE, and HAVING clauses.
X Makes the result set available to the analytic functions that perform the calculations,
which include finding the partition boundaries, ordering the rows within each partition,
framing, and performing the aggregate calculations where appropriate.
X If the query has an ORDER BY clause, orders the output.
Windows
For each row in a partition, you can define a sliding window of data. The window deter-
mines the range of rows to use for calculations for the current row. You can base windows
on a physical number of rows or a logical interval such as time. Windows have a starting row
and an ending row. You can define the window to move at one or both ends.You can define
a window to be as large as all the rows in a partition or as small as a sliding window of one
row in a partition. For more information, see “Window Framing” on page 6-4.
Current Row
Each analytic calculation is based on the current row within a partition. The current row is
the reference point for the start and the end of the window. For example, you could have a
calculation based on the preceding five rows and the following four rows, which would
result in a window of ten rows.
Using Windowing
Analytic functions perform analysis on a window of data. A window is a user-specified
selection of rows (or a logical partition of a query that determines the set of rows) used to
perform certain calculations with respect to the current row.
Using windowing you can determine ranking, distribution of values, or moving averages and
sums.
A window has three components: partition, order, and frame.
X Window partitioning — Groups all rows that have partition column values that are equal
to the values in the specified row. The system returns each row of a partition that has
an equal value on the set of specific rows in a table, rather than collapsing them into a
single representative row as is the case with grouped aggregate functions.
X Window ordering — Allows you to order rows within each partition. Because all rows in
a partition have equal values in their partitioning columns, you usually order the rows
by values in other columns.
X Window framing — Defines the size of the window within a window partition. You can
express it in physical terms (the number of rows) or in logical terms (a range of values).
Window framing is also called window aggregation grouping.
Framing can be either row-based or range-based. Framing can specify anchored or
floating frame endpoints. If the frame is anchored, you can specify unbounded preced-
ing and/or unbounded following. If the frame is floating, you can specify an absolute
row offset (for row-based frames) or as a delta from the current row’s order column
value (for range-based frames).
The frames for functions in the Window Aggregation family can also specify an exclu-
sion as: exclude no others, exclude current row, exclude ties, or exclude group. For
details about which functions support the exclude clause in syntax, see Table 6-2 on
page 6-7.
Window Partitioning
You can divide a table or rowset into partitions based on the values of specific columns. For
example, you could partition sales data by the store ID. If you do not specify partitioning,
the system considers the entire table or rowset to be a single partition.
The window partition syntax allows you to name one or more columns.
<window partition clause> ::= partition by <column reference list>
<column reference list> ::= <value_expression>
The resulting window is partitioned into one or as many partitions as there are rows in the
input virtual table, based on the values of the one or more columns referenced in the
<window partition clause>.
Each partition has one or more rows, and the values of the partition columns are equal
among all rows of the partition.
Window Ordering
When you order data in a window, you are actually ordering the data in each of its parti-
tions. To order data in a window, use the ORDER BY clause to specify the columns known
as the ordering columns.
<window order clause> ::= ORDER BY <sort specification list>
<sort specification list> ::= <sort specification> [ { , <sort specification> } …]
<sort specification> ::= <sort key> [ <ordering specification> ]
<sort key> ::= <value_expression>
<ordering specification> ::= [ASC | DESC] [NULLS {FIRST | LAST}]
If your data contains nulls, Netezza SQL considers all null values to be lower than any non-
null value. This means that for an ascending sort, nulls appear first in the output, or for a
descending sort, they appear last. You can control the null sorting using NULLS {FIRST |
LAST}.
Window Framing
The window frame or window aggregation grouping defines the boundary within the window
partition for which some computation is being done.
<window frame clause> ::=
<window frame units>
<window frame extent>
[ <window frame exclusion> ]
<window frame units> ::= rows | range
<window frame extent> ::=
<window frame start> | <window frame between>
<window frame start> ::=
unbounded preceding | <unsigned value specification> preceding | current row
<window frame between> ::=
between <window frame bound 1> and <window frame bound 2>
<window frame bound 1> ::= <window frame bound>
<window frame bound 2> ::= <window frame bound>
<window frame bound> ::=
Window Aggregates
At a high level, a window aggregate is expressed as:
<aggr-type> (<arglist>) over (<window-spec>)
X aggr-type can be the functions count, sum, avg, min, max, stddev, stddev_pop, stddev_
samp, variance, var_pop, var_samp, row_number, rank, dense_rank, lead, lag, first_
value, and last_value.
X arglist specifies zero or more arguments to the aggregation. Note that only lead and lag
can take more than one argument.
X window-spec specifies the partition columns, order columns, and framing.
Syntax Description
ALL Applies the analytic function to all values. This is the default
and you do not need to specify it.
BETWEEN … AND Specifies starting and ending points for the window. The first
expression (before and) specifies the start; the second expres-
sion (after and) specifies the end.
CURRENT ROW As a starting point, specifies that the window begins at the cur-
rent row or value. As an ending point, specifies that the window
ends at the current row or value.
DISTINCT Specifies that the function should aggregate results for each
unique value. Note that DISTINCT is not supported for the
FIRST_VALUE, LAST_VALUE, LEAD, or LAG functions. It is also
not supported for STDDEV, STDDEV_POP, STDDEV_SAMP,
VARIANCE, VAR_POP, OR VAR_SAMP functions in either a
grouped or windowed aggregate.
EXCLUDE GROUP Specifies excluding the current row and all rows tied with it. Ties
occur when there is a match on the order column or columns.
EXCLUDE NO OTHERS Specifies not excluding any rows. This is the default if you spec-
ify no exclusion.
EXCLUDE TIES Specifies excluding all rows tied with the current row (peer
rows), but retaining the current row.
NULLS {FIRST | LAST} Specifies whether nulls appear before or after non-null values in
the sort ordering. By default, null values sort as if they are lower
than any non-null value; that is, NULLS FIRST is the default for
DESC order, and NULLS LAST otherwise.
ORDER BY Specifies how the data is ordered within the partition. You can
order the values on multiple keys, each defined by an ordering
sequence.
OVER Indicates that the function operates on a query result set that is
computed after the from, where, and having clauses. Use over to
define the window of rows to include in the function.
Syntax Description
PARTITION BY Partitions the query result into groups based on one or more col-
umns. If you omit this clause, the query handles the query result
as a single partition.
ROWS | RANGE Defines the window as physical rows or as a logical range. To use
range between, you must have specified the order by clause.
UNBOUNDED Specifies that the window ends at the last row of the partition. If
FOLLOWING there is no partition by clause, the end is the last row of the
dataset.
UNBOUNDED Specifies that the window starts at the first row of the partition.
PRECEDING If there is no partition by clause, the start is the first row of the
dataset.
Function Description
Syntax {sum | avg | max | min | count | stddev | stdev_pop | stdev_samp | variance
| variance_pop | variance_samp}
( [distinct] {<column reference> | *})
over ([partition by <value_expression>[,...]])
sum, avg, Reporting functions appear only in the select or order by clauses. They
max, min, enable you to make multiple passes over a single query block without
count, std- doing a self-join. Because the over clause can only contain a partition col-
dev, variance umn list, a report aggregate has the same value in each row of the
partition.
Function Description
Syntax {sum | avg | max | min | count | stddev | stdev_pop | stdev_samp | variance
| variance_pop | variance_samp}
( [distinct] {<column reference> | <value_expression>| *}) over
([partition by <column reference>[,...]]
order by { <value_expression> [asc | desc] [nulls {first | last}] } [,...]]
[ rows | range
{{current row | unbounded preceding | <literal value> preceding}
| between
{current row | unbounded preceding | <literal value> preceding}
and {current row | unbounded following | <literal value> following}}]
[exclude current row | exclude group | exclude ties | exclude no others] )
stddev Returns the standard deviation of the expression, which is the square root
of variance. When variance returns null, this function returns null.
stddev_pop Computes the population standard deviation. This function is the same as
the square root of the var_pop function. When var_pop returns null, this
function returns null.
stddev_samp Computes the sample standard deviation, which is the square root of var_
samp. When var_samp returns null, this function returns null.
Function Description
var_ samp var_samp = (sum (expr**2) - ((sum (expr) **2) / (count (*)))) / (count (*) -
1)
Returns the sample variance of a set of numbers after discarding the nulls
in this set. If you apply this function to an empty set, it returns null.
lag Provides access to more than one row of a table at the same time without
a self-join. The lag function provides access to a row at a given physical
offset prior to that position.
If you do not specify the offset, the default is one. The system returns the
value in the optional default column, if the offset is beyond the scope of
the window. If you do not specify the default, the value is null.
lead Provides access to more than one row of a table at the same time without
a self-join. The lead function provides access to a row at a given physical
offset beyond that position.
If you do not specify the offset, the default is one. The system returns the
value in the optional default column, if the offset is beyond the scope of
the window. If you do not specify the default, the value is null.
first_value Returns the first value in an ordered set of values. If the first value in the
set is null, the function returns NULL unless you specify IGNORE NULLS.
If you specify IGNORE NULLS, FIRST_VALUE returns the first non-null
value in the set, or NULL if all values are null.
last_value Returns the last value in an ordered set of values. If the last value in the
set is null, the function returns NULL unless you specify IGNORE NULLS.
If you specify IGNORE NULLS, LAST_VALUE returns the last non-null
value in the set, or NULL if all values are null.
Function Description
Ranking Family
dense_rank Returns the rank of a row in an ordered group of rows. The ranks are con-
secutive integers beginning with one. The largest rank value is the number
of unique values the query returns. If there are ties, Netezza SQL does not
skip rank values, but rather assigns rows with equal values the same rank.
For example, if three people tie for second place all three would be in sec-
ond place and the next person would be in third place.
rank Calculates the rank of a value in a group of values. Rows with equal values
for the ranking criteria receive the same rank. If there are ties, Netezza
SQL adds the number of tied rows to the tied rank to calculate the next
rank. For example if three people tie for second place, all three would be
in second place and the next person would be in fifth place.
row_number Assigns a unique number to each row to which it is applied — either each
row in the partition or each row returned by the query. In the ordered
sequence of rows specified in the order by clause, the rows begin with the
number one.
Examples
This section provides some examples describing how to use analytic functions.
X Ranking the detailed data values
X Selecting the top n
X Window aggregation on a grouping select
X Selecting the top n within each partition
Sample Table
The sample sales_tbl table contains quarterly sales totals for each of four cities in two sales
regions.
Sample Table SELECT * FROM sales_tbl;
city | state | region | quarter | amt
----------+-------+-----------+---------+------
Boston | MA | Northeast | 1 | 2000
Boston | MA | Northeast | 2 | 1500
You can use Netezza SQL to store national characters based on the syntax extensions to
SQL:1999, which use Unicode and ISO standards. Using these extensions, you can store
Latin and national characters, including Kanji.
Overview
The best known and most widely used character encoding standard is ASCII, which is
based on 7-bit byte character strings and has enough characters to encode English text,
but no other major written languages.
ISO has standardized several 8-bit extensions of ASCII for various groups of Latin-based
writing systems. The ISO standard 8859 also has sections for Cyrillic, Arabic, Greek,
Hebrew, and Thai.
X Latin-1 supports Western European languages and is widely used.
X Latin-9 has been adopted (with minor changes to Latin-1) to include the Euro sign (€).
Netezza SQL treats char and varchar as Latin-9 encoding. Latin-9 has replaced Latin-1 as
the preferred 8-bit encoding for western European character data.
Latin-9 covers most Western European written languages such as French, Spanish, Catalan,
Galician, Basque, Portuguese, Italian, Albanian, Afrikaans, Dutch, German, Danish, Swed-
ish, Norwegian, Finnish, Faroese, Icelandic, Irish, Scottish, English, but none of the
central European languages like Polish, Czech, Hungarian, Romanian, and so on. Unicode
is the problem-free way to handle written languages that are not in the Latin-9 list.
7-1
Netezza Database User’s Guide
The range of integers used to code the characters is called the codespace. A particular inte-
ger in this range is called a code point. When a character is mapped or assigned to a
particular code point in the codespace, it is referred to as a coded character.
The Unicode Standard defines three encoding forms that allow the same data to be stored
and transmitted in a byte, word, or double-word-oriented format (that is, in 8-, 16-, or
32-bits per code unit). All three encoding forms encode the same common character reper-
toire (the actual collection of characters) and can be efficiently transformed into one
another without data loss.
The three encoding forms are:
X UTF-8 stores each code point as a single 8-bit unit (the ASCII characters), or as two,
three, or four 8-bit sequences.
X UTF-16 stores each code point using either a single 16-bit unit or as a two 16-bit
units.
X UTF-32 stores each code point as a 32-bit unit.
All three encoding forms need at most 4 bytes (or 32-bits) of data for each character.
Different writing systems also vary in how they handle collation. Netezza uses binary colla-
tion to determine sorting order, which means collating char and nchar data according to the
binary character codes
Netezza Extensions
To allow the usage of national character sets, Netezza has extended its character set sup-
port in two ways. Note that the features described below for nchar are the same as those for
char.
X The char/varchar data type supports the ISO Latin-9 code set. Sort comparisons use
the 8-bit ISO code point values 0-255 for string comparisons. Netezza does not sup-
port other ISO/Latin code sets or language-specific collations.
X The ANSI SQL standard nchar/nvarchar (or national char) datatype supports Unicode
using the UTF-8 encoding. Collation is in Unicode code point order.
Syntax Shorthand
The types nchar and nvarchar are shorthand for other syntax.
X nchar(m) is equivalent to:
S national character(m)
S national char(m)
X nvarchar(m) is equivalent to:
S national character varying(m)
S national char varying(m)
X A value of ‘utf8’ indicates the whole file is in UTF-8 encoding and has only nchar/nvar-
char data and no char/varchar data. (If the file contains any char/varchar data, it will be
rejected by the load operation.)
X The value ‘internal’ indicates that the file could have either or both Latin-9 and UTF-8
data using any or all of the char, varchar, nchar, or nvarchar data types. As a best prac-
tice, Netezza recommends that you always use ‘internal’.
You can also use the CREATE EXTERNAL TABLE command to load and unload national
character set data. The source dataobject must contain char-class data in Latin-9 and
nchar-class data in correct UTF-8 encoding. The CREATE EXTERNAL TABLE command
uses the same -encoding option and values as the nzload command to identify the content
of the file.
External Table create external table xTBL sameas TBL using (dataobject
Loading ('/tmp/TBL.data') delimiter '|' encoding 'internal');
Note: If a table definition contains either or both Latin-9 and UTF-8 char/varchar and
nchar/nvarchar data, make sure that you specify the encoding as 'INTERNAL'. Also, load
and unload using external tables does not perform any codeset conversions. If your data is
in a legacy format and needs to be converted to UTF-8, use the nzconvert command. For
more information about this command, see “Converting Legacy Formats” on page 7-7.
During loading, the system verifies that the UTF-8 data is correctly encoded, which means
that a Unicode value is represented in the smallest possible number of bytes, that values
do not exceed the maximum length of four UTF-8 bytes, and that the character sequences
are well formed. The system also verifies that the data does not include any disallowed
characters.
Unloading to an external table copies unmodified column data to the external table’s
dataobject.
These actions could result in illegal character content in the database. If you unload that
data, you will not be able to reload it using nzload. Unsupported character data could also
prevent future upgrades until the characters are changed to supported values.
Examples
The following examples show how to set encoding for SJIS (Japanese).
T To set the environmental variable for SJIS, enter:
export NZ_ENCODING=SJIS
If you have set the environment to a valid ICU converter name, Netezza SQL uses it,
otherwise it displays an error message and exits.
T To set the session for Japanese, enter:
set nz_encoding=sjis
The command sets the locale variable for the current session only.
T To set the locale for EUC-JP, enter:
export LC_CTYPE=japanese.eucjp
The command sets the locale variable.
When you start a Netezza SQL session, the system checks your environment. The system
checks the locale codeset setting for the terminal window in which the nzsql command is
invoked. To display the locale codeset setting, use the Linux command locale charmap.
Of course, you can always change the nz_encoding session variable value with an explicit
SET command.
X If you set the encoding through the nzsql command, you can use mixed case; that is,
SET nz_encoding=latin9.
X If you set the encoding at the UNIX shell using the environment variable, use upper
case for the variable name; that is, export NZ_ENCODING=LATIN9. The name NZ_
ENCODING must be in upper case. The value Latin9 can be in mixed case.
To see all the data, the nz_encoding must be the same as the xterm display; that is, utf8 on
a utf-8 xterm and latin9 on a latin9 or latin1 xterm. Netezza SQL converts the output from
a char or varchar column to utf-8 when the nz_encoding to set to utf8, and nchar or nvar-
char columns to latin9 when nzencoding is set to latin9, substituting “?” if the conversion
is not valid.
Using nzconvert
The nzconvert command converts the from encoding to the to encoding. If the program
cannot map a legacy character to Unicode, it inserts a user-supplied conversion character.
You can specify the maximum substitutions allowed before the system aborts the conver-
sion. The system only logs substitution errors.
nzconvert Options
Table 7-1 describes the options you can use with the nzconvert command.
Option Description
-a[lias] name Reports whether name is supported encoding and lists all its aliases.
You can specify any number of -a options.
Option Description
-bf filename Specifies the log file for errors only. If there are no errors, the system
does not create a log file. The default is standard error.
-bom Removes the Byte Order Mark (BOM) (UTF-8, -16 or -32) from the start
of a UTF-8 output file and all other instructed transforms. The BOM is
code point FEFF in Unicode. (It is now formally known as a zero width
no-break space). It was introduced as an aid for applications to deter-
mine the endian orientation of a UTF-16 or UTF-32 stream; however,
the Netezza does not load data that begins with the BOM code point;
you can use the -bom switch to remove that code point and load the
data.
-df filename Specifies the input filename. The default is standard input.
-f[rom] Specifies the encoding that you are converting from. You cannot use it
with the -l or -a options. The default is UTF-8.
-l[ist] Lists the primary name of all supported codeset converters. You can use
it with any number of -a options.
-maxErrors n Aborts after encountering <n> characters that cannot be converted. The
default is 1. Use 0 to cause the load to never abort.
-nfc For input that is in UTF-8, -16, or -32 format, calls the International
Components for Unicode (ICU) routines to convert data to NFC format.
-of filename Specifies the output filename. The default is standard output.
-s[ubs] char Sets the substitution character to use when a conversion cannot be
done and the number of maxErrors is greater than 1.
-t[o] Specifies the encoding that you are converting to. You cannot use this
option with the -l or -a options. The default is UTF-8.
nzconvert Examples
You can use the nzconvert command with pipes to convert existing data in legacy code to
UTF-8. The following examples show sample commands for nzconvert running on a UNIX
system. The command can be used on UNIX as well as Windows Netezza clients.
T To convert and load a data file in sjis, enter:
>cat datafile | nzconvert -f sjis | nzload -t table -encoding
internal
T To convert and load data from external tables, enter:
>mkfifo namedpipe
>cat data file | convert -f sjis > namedpipe&
>nzload -df namedpipe -t jploadtest -encoding internal
Netezza supports the SQL:2003 standard that allows users to create, alter, and drop
named user sequences that exist within a containing database.
Overview of Sequences
A sequence is a named object in a database that supports the get next value method. By
using sequences, you can generate unique numbers that can be used as surrogate key val-
ues for primary key values, where the identification of rows within a table would involve a
large, compound primary key, or for other purposes.
A sequence value is an integer that you can use wherever you would use numeric values.
Netezza supports user sequences for the four integer types: byteint, smallint, integer, and
bigint.
You create a sequence with an initial value, an increment, a minimum and a maximum
value. You also specify whether the sequence cycles, which determines whether the
sequence starts over when the endpoint is reached.
Note: Sequences always provide a unique sequence number; however, you are not guaran-
teed that sequence numbers will be predictable, monotonically increasing values. Gaps and
unexpected sequence numbers occur as a result of the Netezza topology and how it pro-
cesses sequences for query performance. For more information, see “Using Sequences in a
Distributed System” on page 8-3.
Sequences do not support cross-database access; you cannot obtain a sequence value from
a sequence defined in a different database.
8-1
Netezza Database User’s Guide
Creating a Sequence
Use the CREATE SEQUENCE statement to create a sequence, which is a database object
from which users can generate unique numbers.
To create a sequence use the CREATE SEQUENCE statement and specify the options in any
order.
Create Sequence CREATE SEQUENCE <sequence name> [as <data type> <options>]
Where the options are the following:
START WITH <start value>
INCREMENT BY <increment>
no minvalue | minvalue <minimum value>
no maxvalue | maxvalue <maximum value>
cycle | no cycle
The options have the following parameters:
X The default minvalue is no minvalue, which is defined to be 1.
X The default maxvalue is no maxvalue and is the largest value by data type that the
sequence can hold.
X The default start value is the minvalue for an increasing sequence, and the maxvalue
for a decreasing sequence. The startvalue has to be within the range of the minvalue
and maxvalue.
X The default increment is 1.
X By default, sequences do not cycle.
When a user generates a sequence number, the system increments the sequence indepen-
dently of the transaction committing or rolling back. Therefore, a rollback does not return
the value to the sequence object. If two users concurrently increment the same sequence,
the sequence numbers each user acquires may have gaps because the sequence numbers
are being generated by the other user.
Sequences also can have gaps because the Netezza caches sequence values on the host
and SPUs for efficient operation. For more information, see “Using Sequences in a Distrib-
uted System” on page 8-3.
T To create a sequence that decreases by 10 and then cycles. Note that the first and sec-
ond passes return different sets of values — 93, 83,73 …100, 90, 80 … 10, 100.
CREATE SEQUENCE sequence3 as integer
START WITH 93 increment by -10
minvalue 1 maxvalue 100 cycle
Caching Sequences
Although the SQL:2003 standard does not allow you to specify a cache size, some data-
base applications encourage you to change the cache size for better performance. Netezza,
on the other hand, derives the cache size of a user sequence based the following
characteristics:
X The number of sequence values between the minvalue and the maxvalue
X The number of SPUs in the system
Sequence caching dev(admin)=> select *, next value for seq from emp;
id | name | grp | nextval
---+-------------+--------------+---------
4 | John | mkt | 49
8 | Jim K | sdev | 52
12 | Jane | adm | 54
1 | Julie | dev | 310079
5 | Jackie | hdev | 310080
9 | Mike | hdev | 310088
13 | Jill | adm | 310114
2 | Tom | adm | 198235
6 | Dan | sdev | 198312
Altering a Sequence
You can alter a user sequence by resetting any sequence option, including the name and
owner of the sequence. To change the starting value, use the RESTART WITH option.
To alter a sequence, use the ALTER SEQUENCE statement and specify the options in any
order.
Alter Sequence ALTER SEQUENCE <sequence name> <options>
Where the options are the following:
OWNER to <new owner>
RENAME TO <new sequence name>
RESTART WITH <start value>
INCREMENT BY <increment>
no minvalue | minvalue <minimum value>
no maxvalue | maxvalue <maximum value>
cycle | no cycle
If you alter a sequence while a sequence is in use by a running query, the system waits for
the running query’s transaction to complete before altering the sequence. This is similar to
the way the system handles attempts to drop a table that is in use by a running query.
Dropping a Sequence
Although you can drop a sequence, remember that system locking occurs if you attempt to
drop a sequence that is in use by a running query. In addition, if the sequence is refer-
enced by other metadata, subsequent use of that metadata results in an error, for example
if the sequence is referenced in a view definition.
To drop a sequence, use the DROP SEQUENCE statement and specify the sequence name.
Drop Sequence DROP SEQUENCE <sequence name>
Command Privileges
ALTER SEQUENCE Alter object privilege for a specific sequence or the Sequence
object class
DROP SEQUENCE Drop object privilege for a specific sequence or the Sequence
object class
NEXT VALUE FOR Update object privilege for a specific sequence or the
SEQUENCE Sequence object class
For example, “SELECT NEXT VALUE FOR <sequence
name>.”
If there is no next value without overshooting the maxvalue for ascending sequences or
undershooting the minvalue for descending sequences, the system does the following:
X For a noncycling sequence, the system displays an error.
X For a cycling sequence, the next value wraps to the minvalue for ascending sequences
and wraps to maxvalue for descending sequences.
You cannot use NEXT VALUE in the following statements:
X CASE expressions
X WHERE clauses
X ORDER BY clauses
X aggregate functions
X window functions
X grouped queries
X SELECT distinct
You can use the next value of a sequence of one precision (for example, bigint) to supply a
value for a column of a different precision (such as smallint).
Next Value Example CREATE TABLE small_int_table (col1 smallint);
CREATE SEQUENCE bing_int_seq as bigint;
INSERT INTO small_int_table SELECT NEXT VALUE FOR big_int_seq;
Note: If the actual value being inserted cannot fit into the lower-precision column, the sys-
tem displays an error.
You might want to request batch values for a sequence if you are using ETL tools that
require a large number of sequence values and want to avoid the performance impact of
requesting sequence values individually. Another advantage of requesting batch sequence
values is that when you get values in advance of adding a table row, rows of related tables
can cross-reference each other.
This appendix contains the SQL reserved words and the nonreserved keywords.
A-1
Netezza Database User’s Guide
Nonreserved Keywords
Nonreserved keywords have a special meaning only in particular contexts and can be used
as identifiers in other contexts. Most nonreserved keywords are actually the names of built-
in tables and functions. Netezza SQL uses nonreserved keywords to attach a predefined
meaning to a word in a specific context. Table A-2 contains the list of nonreserved
keywords.
Table A-2: Keywords
ABSOLUTE ACTION ADD ADMIN
AFTER AGGREGATE ALIAS ALL
ALLOCATE ALTER AND ANY
ARE ARRAY AS ASC
ASSERTION AT AUTHORIZATION BEFORE
BEGIN BINARY BIT BLOB
BOOLEAN BOTH BREADTH BY
CALL CASCADE CASCADED CASE
CAST CATALOG CHAR CHARACTER
CHECK CLASS CLOB CLOSE
COLLATE COLLATION COLUMN COMMIT
ALTER GROUP Adds or removes users from See “ALTER GROUP” on page B-6.
a group.
ALTER USER Changes a database user See “ALTER USER” on page B-22.
account.
ALTER VIEW Changes the owner or name See “ALTER VIEW” on page B-25.
of the view.
B-1
Netezza Database User’s Guide
CREATE TABLE AS Creates a new table based See “CREATE TABLE AS” on
on query results. page B-62.
DROP HISTORY Drop the configuration for See “DROP HISTORY CONFIGU-
CONFIGURATION query history logging. RATION” on page B-75.
DROP USER Removes a database user See “DROP USER” on page B-81.
account.
SET SYSTEM DEFAULT Sets the system defaults See “SET SYSTEM DEFAULT” on
for session timeout, rowset page B-117.
query timeout, and priority.
SET TRANSACTION Sets the isolation level of See “SET SYSTEM DEFAULT” on
the current transaction. page B-117.
SHOW HISTORY Display query history con- See “SHOW HISTORY CONFIGU-
CONFIGURATION figuration settings. RATION” on page B-125.
SHOW SYSTEM Shows the system defaults. See “SHOW SYSTEM DEFAULT”
DEFAULT on page B-129.
ALTER DATABASE
Use the ALTER DATABASE command to set the default character set for the database,
change its name, or change the owner of the database.
Synopsis
Syntax for specifying the default character set:
ALTER DATABASE <database_name> SET DEFAULT CHARACTER SET LATIN9
Syntax for changing the database owner:
ALTER DATABASE <database_name> OWNER TO <user_name>
Syntax for renaming the database:
ALTER DATABASE <database_name> RENAME TO <new_name>
Inputs
The ALTER DATABASE command has the following inputs:
Input Description
SET DEFAULT CHARACTER SET If you upgraded before Netezza release 2.2, the
default 8-bit character set is specified as UNDE-
CLARED. Set the character set to LATIN9 to be able
to compare, join, or cast char/nchar class data.
Outputs
The ALTER DATABASE command has the following output:
Output Description
ALTER DATABASE The message that the system returns if the command is
successful.
ERROR: ALTER DATABASE: The message that the command returns if you try to alter
database "db" is being a database which is being used by other users.
accessed by other users
Description
The ALTER DATABASE command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the Create Database
privilege, to use this command.
Common Tasks
Use the ALTER DATABASE command to change the default 8-bit character set, the name,
or the owner of the database.
Related Commands
Use the “SET SYSTEM DEFAULT” on page B-117 command to set system-wide limits. See
also, “CREATE DATABASE” on page B-35.
Usage
The following provide sample usage:
T To change the default 8-bit character set in the emp database, enter:
system(admin)=> ALTER DATABASE emp set default character set latin9
T To rename the emp database, enter:
system(admin)=> ALTER DATABASE emp RENAME TO employees
T To change the owner of the emp database, enter:
system(admin)=> ALTER DATABASE emp OWNER TO admin3
ALTER GROUP
Use the ALTER GROUP command to change properties of a group.
Synopsis
Syntax for adding a user:
ALTER GROUP <group_name> ADD USER <user_name> [, ... ]
Syntax for changing limits:
ALTER GROUP <group_name>
[WITH
[ROWSETLIMIT [integer ]
[SESSIONTIMEOUT [integer ]
[QUERYTIMEOUT [integer ]
[RESOURCELIMIT resourcepercent]
[DEFPRIORITY [critical|high|normal|low|none]]
[MAXPRIORITY [critical|high|normal|low|none]]]
Syntax for dropping a user:
ALTER GROUP <group_name> DROP USER <user_name> [, ... ]
Inputs
The ALTER GROUP command takes the following inputs:
Input Description
DEFPRIORITY Specifies the default priority for the group. The valid priorities are
critical, high, normal, and low.
QUERYTIMEOUT Specifies the amount of time a query can run before the system
sends the administrator a message. You can specify from 1 to
2,147,483,647 minutes or zero for unlimited.
ROWSETLIMIT The rowset limit specifies the maximum number of rows any query
run by this user (or group) can return. You can specify from 1 to
2,147,483,647 rows or zero for unlimited.
SESSIONTIMEOUT Specifies the amount of time a session can be idle before the sys-
tem terminates it. You can specify from 1 to 2.147,483,647
minutes or zero for unlimited.
RESOURCELIMIT When you designate non-zero for a group, the group is a resource-
sharing group. The number you enter is the percent of total system
resources reserved for that group. For general information on
resource allocation, see the work load management section in the
Netezza System Administrator’s Guide.
Outputs
The ALTER GROUP command has the following output
Output Description
ALTER GROUP The message that the system returns if the command is
successful.
Description
The ALTER GROUP command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the Alter object
privilege to use this command.
Common Tasks
Use the ALTER GROUP command to:
X Add users to a group.
X Remove users from a group.
X Alter session idle time, rowset limits, query timeout, and priority.
Note: Users you add or remove from a group must already exist. Using the ALTER GROUP
command to remove a user from a group does not drop the user from the system, but only
from the specified group.
Related Commands
Use “CREATE GROUP” on page B-43 to create a new group.
Use “DROP GROUP” on page B-74 to remove a group.
Use “SET SYSTEM DEFAULT” on page B-117 to set system-wide limits.
Usage
The following provides sample usage:
T To add the users Karl and John to the group staff, enter:
system(admin)=> ALTER GROUP staff ADD USER karl, john;
T To change the session idle time, enter:
system(admin)=> ALTER GROUP staff WITH SESSIONTIMEOUT 300;
T To remove the user Beth from the group workers, enter:
system(admin)=> ALTER GROUP workers DROP USER beth;
T To change the group’s maximum priority, enter:
system(admin)=> ALTER GROUP workers WITH MAXPRIORITY critical;
Synopsis
Syntax for altering the history configuration:
ALTER HISTORY CONFIGURATION <config-name> <hist-clause> …
<hist-clause> ::=
| HISTTYPE {QUERY | NONE}
| NPS { LOCAL }
| DATABASE <dbname>
| USER <username>
| PASSWORD <writer-password>
| COLLECT <history-item> ,...
| LOADINTERVAL {number }
| LOADMINTHRESHOLD {number}
| LOADMAXTHRESHOLD {number}
| DISKFULLTHRESHOLD {number}
| STORAGELIMIT {number}
| LOADRETRY {number}
| ENABLEHIST {boolean}
| ENABLESYSTEM {boolean}
| VERSION <version>
<history-item>
QUERY
| PLAN
| TABLE
| COLUMN
Inputs
The ALTER HISTORY CONFIGURATION command has the following inputs:
Input Description
Input Description
USER <username> Specifies the user name for accessing and inserting
data to the query history database. (This is the user
name specified in the nzhistcreatedb command.)
If you do not specify this input option, the current
configuration value is retained. This is a delimited
identifier. If not delimited, the system converts the
name to the host case.
PASSWORD <writer password> The password for the database user account. If you do
not specify this input option, the current configuration
value is retained. This is a single quoted string, and
the password is stored as an encrypted string.
If the user’s password changes, you must update the
history configuration with the new password as well, or
the loader process will fail.
Input Description
Input Description
DISKFULLTHRESHOLD This option is reserved for future use. Any value you
specify will be ignored. The default value is 0.
Input Description
VERSION <version> Specifies the query history schema version of the con-
figuration. By default, this is the query history schema
version of the current image. For Release 4.6, the ver-
sion number is 1.
Note: The version must match the version number
specified in the nzhistcreatedb command; otherwise,
the loader process will fail.
Outputs
The ALTER HISTORY CONFIGURATION command has the following outputs:
Output Description
ERROR: permission denied You must have Manage Security permission to modify
query history configuration settings.
ERROR: <config-name> not The specified configuration name could not be found.
found.
ERROR: database <dbname> The query history database was not found on the
not found. Netezza system.
Description
This command changes a query history configuration on a Netezza system. You cannot
modify the current/active configuration. Any changes you make to a configuration are saved
but they take effect only after you SET to that configuration and restart the Netezza server
using the nzstop and nzstart commands.
The ALTER command is logged to the current query history log. The target query database
does not need to be empty.
The ALTER HISTORY CONFIGURATION command has the following characteristics:
Privileges Required
You must have Manage Security permissions to alter query history configurations.
Related Commands
See the “CREATE HISTORY CONFIGURATION” on page B-45 to create a new
configuration.
See the “DROP HISTORY CONFIGURATION” on page B-75 to drop configurations.
See the “SET HISTORY CONFIGURATION” on page B-115 to specify a configuration for
query history logging.
See the “SHOW HISTORY CONFIGURATION” on page B-125 to display information about
a configuration.
Usage
The following command changes the type of history data captured to only Query data (the
other settings remain unchanged):
SYSTEM(ADMIN)=> ALTER HISTORY CONFIGURATION all_hist COLLECT QUERY;
ALTER SEQUENCE
Use the ALTER SEQUENCE command to reset a user sequence option, including the name
and owner of the sequence. This statement affects only future sequence numbers.
Synopsis
Syntax for altering a sequence
ALTER SEQUENCE <sequence name> <options>
Options
The ALTER SEQUENCE command takes the following options:
Input Description
Outputs
The ALTER SEQUENCE command produces the following output:
Output Description
ALTER SEQUENCE The message that the system returns if the command is
successful.
ERROR: ALTER on system The message that the system returns if you attempt to
sequence not allowed. alter a system sequence.
Description
The ALTER SEQUENCE command has the following characteristics:
Privileges Required
The privileges to alter sequences are as follows.
X The admin user has all privileges on all user sequences. There is no need to grant any
privileges to the admin user.
X The owner of the database has all privileges on all user sequences in that database.
There is no need to grant any privileges to the owner.
X All others must have the Alter object privilege for a specific sequence or the Sequence
object class.
Notes
If you change the increment — raise the minvalue for ascending sequences or lower the
maxvalue for descending sequences — the system clears the cache, which results in non-
sequential sequence numbers. Thus, if you want to retain the original starting value,
specify the RESTART WITH option when you use the ALTER SEQUENCE statement.
Related Commands
See “CREATE SEQUENCE” on page B-52 and “DROP SEQUENCE” on page B-76 for
related sequence commands.
Usage
The following provides sample usage:
T To change the maximum value, enter:
system(admin)=> ALTER SEQUENCE sequence1 MAXVALUE 1000;
ALTER SESSION
Use the ALTER SESSION command to abort the active transaction in a session or to set the
priority of a session.
Synopsis
Syntax for aborting a transaction in a session:
ALTER SESSION [ <session-id> ] ROLLBACK TRANSACTION
Syntax for setting the priority of a session:
ALTER SESSION [<session_id>] SET PRIORITY TO <priority>
Inputs
The ALTER SESSION command takes the following inputs:
Input Description
priority The priority level to set for the session. The priority can be one of:
CRITICAL, HIGH, NORMAL or LOW.
Outputs
The ALTER SESSION command produces the following output:
Output Description
ALTER SESSION The message that the system returns if the com-
mand is successful.
ERROR: permission denied The user does not have permission to change
the session priority of the session specified by
<session-id>.
ERROR: request exceeds maximum pri- The user attempted to raise the session priority
ority limit. beyond their maximum priority limit.
ERROR: id '<session-id>' does not cor- The specified session ID does not exist.
respond to an existing session.
ERROR: system session id '<session- The specified session id refers to a system ses-
id>' cannot be aborted sion. Users cannot rollback transactions of
system sessions.
Output Description
ERROR: access denied. You must have You do not have permission to rollback the
ABORT privileges to perform this action transaction of the session specified by <session-
id>.
ERROR: session abort failed for session The attempt to rollback the transaction in ses-
<session-id>; reason is '<reason>' sion <session-id> failed; the reason for the
failure is provided in the <reason> string.
Description
The ALTER SESSION command has two functions. You can use it to adjust the priority of a
session and to rollback the active transaction of a session.
Privileges Required
You need no special privileges to roll back your own session's active transaction or to set its
priority up to the maximum priority.
You must be the admin user or have Manage System privilege to change the priority of
someone else's session or to exceed the maximum priority of your own session.
Each session is owned by a user. You must be granted Abort privileges on the user in order
to rollback their transactions.
Common Tasks
Use the ALTER SESSION command to change the priority of a session.
Related Commands
See “ALTER SESSION” on page B-16 to change a session’s priority or to abort a transac-
tion in a session.
See “SHOW SESSION” on page B-127 to display session information.
See “DROP SESSION” on page B-77 to abort and remove a session.
Usage
The following provides sample usage:
T To change the session from normal to critical, enter:
system(admin)=> ALTER SESSION SET PRIORITY TO critical;
ALTER SYNONYM
Use the ALTER SYNONYM command to rename or change the owner of a synonym.
Synopsis
Syntax for altering a synonym:
ALTER SYNONYM <synonym_name> RENAME TO <new_synonym_name>;
ALTER SYNONYM <synonym_name> OWNER TO <new_owner>;
Inputs
The ALTER SYNONYM command takes the following inputs:
Input Description
Outputs
The ALTER SYNONYM command produces the following output:
Output Description
ALTER SYNONYM The message that the system returns if the command is successful.
Description
The ALTER SYNONYM command has the following characteristics:
Privileges Required
You can alter your own synonyms. To alter other synonyms, you must be the admin user or
have been granted the Alter privilege for synonyms.
Common Tasks
Use the ALTER SYNONYM command to rename or change the owner of a synonym.
Related Commands
See “CREATE SYNONYM” on page B-55, “DROP SYNONYM” on page B-79, and “GRANT”
on page B-90.
Usage
The following provides sample usage:
T To rename the synonym payroll to pr, enter:
system(admin)=> ALTER SYNONYM payroll RENAME TO pr;
T To change the owner of the synonym pr, enter:
system(admin)=> ALTER SYNONYM pr OWNER TO accounting;
ALTER TABLE
Use the ALTER TABLE command to change the structure of an existing table. If the table is
in use by an active query, the ALTER command will wait until that query completes.
Synopsis
Syntax for changing a column default value, or dropping a default value:
ALTER TABLE <table_name> ALTER [ COLUMN ] <column> { SET DEFAULT
<value> | DROP DEFAULT };
Syntax for modifying the column length of a VARCHAR column:
ALTER TABLE <table_name> MODIFY COLUMN (column VARCHAR(maxsize));
Syntax for renaming a column:
ALTER TABLE <table_name> RENAME [ COLUMN ] <column> TO <new_column>;
Syntax for renaming a table:
ALTER TABLE <table_name> RENAME TO <new_table>;
Syntax for changing the table owner:
ALTER TABLE <table_name> OWNER TO <name>;
Syntax for copying the privileges from one table to another:
ALTER TABLE <table_name> SET PRIVILEGES TO <table>;
Syntax for adding a constraint:
ALTER TABLE <table_name> ADD [constraint_name] <table_constraint>
[constraint_characteristics] ;
Syntax for dropping a constraint:
ALTER TABLE <table_name> DROP CONSTRAINT name {CASCADE | RESTRICT};
Constraint_name can be:
{ CONSTRAINT name }
Table_constraint can be:
{ UNIQUE ( column_name [, ... ] ) |
PRIMARY KEY ( column_name [, ... ] ) |
FOREIGN KEY ( column_name [, ... ] )
REFERENCES table [ ( column [, ... ] ) ]
[ MATCH match_type ]
[ ON UPDATE referential_action ]
[ ON DELETE referential_action ]
}
Match_type can be:
{ FULL | PARTIAL }
Referential_action can be:
{ CASCADE | RESTRICT | SET NULL | SET DEFAULT | NO ACTION }
Constraint_characteristics can be:
{ [ [ NOT ] DEFERRABLE ] { INITIALLY DEFERRED | INITIALLY IMMEDIATE }
|[ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] [ NOT ] DEFERRABLE }
Inputs
The ALTER TABLE command takes the following inputs:
Input Description
column Specifies the name of a new or existing column. You can further
specify <column> as follows:
For more information about constraint options, see “CREATE TABLE” on page B-56.
Outputs
The ALTER TABLE command produces the following output:
Output Description
ALTER The message that the system returns upon the successful renaming of a table or
column.
ERROR The message that the system returns if the table or column you specify is not
available.
Description
The ALTER TABLE command has the following characteristics:
Privileges Required
You must be an administrator, the owner of a table, or an administrator must have given you
the Alter object privilege to use this command.
Common Tasks
Use the ALTER TABLE command to:
X Change or drop a column default. Defaults you set apply to subsequent INSERT com-
mands, not to rows already in the table.
X Rename a column or a table without changing the data type or size within the column
or table.
Note: You can omit the keyword column.
X When you change the name of a table all views based on the table will cease to work,
because views use name binding.
X Add or drop a table or column constraint. Note that you cannot change the name of a
constraint. You must instead drop the constraint and create new one.
X Modify the length of a varchar column.
Related Commands
See also, “CREATE TABLE” on page B-56.
Usage
The following provides sample usage:
T To change a default, enter:
system(admin)=> ALTER TABLE distributors ALTER COLUMN address DROP
DEFAULT;
T To modify the length of a varchar column, enter:
system(admin)=> ALTER TABLE t3 MODIFY COLUMN (col1 VARCHAR(6));
ALTER USER
Use the ALTER USER command to modify a user account.
Synopsis
Syntax for modifying a user’s account, including owner, password, optional expiration time
for the password, rowset limits, and name:
ALTER USER user_name
[WITH
[PASSWORD {'string' | NULL}]
[IN GROUP 'group' [,...]]
[VALID UNTIL 'date' ]
[ROWSETLIMIT [integer ]
[SESSIONTIMEOUT [integer ]
[QUERYTIMEOUT [integer ]
[DEFPRIORITY [critical|high|normal|low|none]]
[MAXPRIORITY [critical|high|normal|low|none]]
[IN RESOURCEGROUP resourcegroupname]
]
ALTER USER user_name OWNER TO username
ALTER USER user_name RESET ACCOUNT
ALTER USER user_name RENAME TO newname
Inputs
The ALTER USER command takes the following inputs:
Input Description
date Specifies the date (and, optionally, the time) when this user's pass-
word expires.
DEFPRIORITY Specifies the default priority for the user. The valid priorities are crit-
ical, high, normal, low.
QUERYTIMEOUT Specifies the amount of time a query can run before the system
sends the administrator a message. You can specify from 1 to
2,147,483,647 minutes or zero for unlimited.
RESET ACCOUNT Unlocks the account after the maximum number of logons has been
exceeded.
ROWSETLIMIT Specifies the number of rows a query can return.You can specify
from 1 to 2,147,483,647 rows or zero for unlimited. The rowset
limit specifies the maximum number of rows any query run by this
user (or group) can return.
SESSIONTIMEOUT Specifies the amount of time a session can be idle before the system
terminates it. You can specify from 1 to 2.147,483,647 minutes or
zero for unlimited.
NULL You can specify WITH PASSWORD NULL to explicitly set a user’s
password to NULL. A user with a NULL password cannot log on when
authentication is set to LOCAL.
Note: The system stores an empty password as a null password.
user_name Specifies the name of the user whose details are to be altered.
Outputs
The ALTER USER command produces the following output:
Output Description
ALTER USER The message that the system returns upon successfully
altering the user’s account.
ERROR: ALTER USER: user The message that the system returns if the database
‘username’ does not exist does not recognize the user.
Description
The ALTER USER command has the following characteristics:
Privileges Required
You must be an administrator to alter the passwords or limits of others, or an administrator
must have given you the Alter object privilege. Ordinary users can change only their own
passwords and limits.
Common Tasks
Use the ALTER USER command to change attributes of a user’s account:
X Set or change a password.
X Set an expiration time for the password.
X Set session timeout, query timeout, and rowset limits.
X Unlock an account after the maximum number of logon attempts has been exceeded.
Note: Whatever attributes you do not mention remain unchanged. For example, if you do
not specify an expiration time, the previously set expiration time applies.
The ALTER USER command cannot change a user’s group memberships.
Related Commands
Use “CREATE USER” on page B-65 to create a new user.
Use “DROP USER” on page B-81 to drop a user.
Use “ALTER GROUP” on page B-6 to change a user’s group memberships.
Use “SET AUTHENTICATION” on page B-110 to set authentication to and from LDAP and
LOCAL.
Use “SHOW AUTHENTICATION” on page B-122 to display how the Netezza system is cur-
rently configured for authentication.
Use “SET CONNECTION” on page B-113 to specify which Netezza system connections
should use an SSL connection.
Use “SHOW CONNECTION” on page B-124 to display the Netezza connections that use
SSL.
Usage
The following provides sample usage.
T To change a user password, enter:
system(admin)=> ALTER USER davide WITH PASSWORD 'hu8jmn3';
T To set the user’s password expiration, enter:
system(admin)=> ALTER USER manuel WITH VALID UNTIL 'Jan 31 2030';
T To set the user’s rowset limits, enter:
system(admin)=> ALTER USER mark WITH ROWSETLIMIT 10000;
ALTER VIEW
Use the ALTER VIEW command to change the name or the owner of a view.
Synopsis
Syntax for altering a view:
ALTER VIEW <viewname> RENAME TO <newname>;
ALTER VIEW <viewname> OWNER TO <newowner>;
ALTER VIEW <view> SET PRIVILEGES TO <view>;
To alter materialized views:
ALTER VIEW <view> MATERIALIZE REFRESH
ALTER VIEW <view> MATERIALIZE SUSPEND
To alter all the materialized views for a base table:
ALTER VIEWS ON <table> MATERIALIZE {REFRESH|SUSPEND}
Inputs
The ALTER VIEW command takes the following inputs:
Input Description
MATERIALIZE Specifies a materialized view. You can either refresh it, that is, re-
create the materialized table from the base table, or suspend it,
that is, truncate the materialized table and redirect all queries
against the materialized view to the base table
Input Description
Outputs
The ALTER VIEW command has the following output:
Output Description
Description
The ALTER VIEW command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Task Privilege
Create an SPM view Assign the Create Materialized View administration privilege.
Alter an SPM view Assign the Alter object privilege for a specific view or the View
object class.
Drop an SPM view Assign the Drop object privilege for a specific view or the View
object class.
Select from an SPM view Assign the Select object privilege for a specific view or the
View object class.
Alter Views on a table Assign the Insert object privilege for a specific table or the
Table object class.
List on SPM views Assign the List object privilege for a specific view or the View
object class.
Common Tasks
Use the ALTER VIEW command to rename or change the owner of a view.
Note: Views are read-only. The system does not allow an insert, update, or delete on a view.
Related Commands
See “DROP VIEW” on page B-82 to drop views.
Usage
The following provides sample usage.
T To rename a view, enter:
system(admin)=> ALTER VIEW emp RENAME TO employees
T To change the owner of a view, enter:
system(admin)=> ALTER VIEW emp OWNER TO john
BEGIN
Use the BEGIN command to start a transaction block.
Synopsis
Syntax for starting a transaction block:
BEGIN [ WORK | TRANSACTION ]
Inputs
The BEGIN command takes the following inputs:
Input Description
TRANSACTION
Outputs
The BEGIN command has the following output:
Output Description
BEGIN The message that the system returns when a new trans-
action has been started.
NOTICE: BEGIN: already a The message that the system returns indicating a trans-
transaction in progress action was already in progress. The current transaction is
not affected.
Description
The BEGIN command has the following characteristics.
Privileges Required
You need no special privileges to use the BEGIN command.
Common Tasks
Use the BEGIN command to Initiate a user transaction in chained mode. The system exe-
cutes all user commands after a BEGIN command in a single transaction until an explicit
commit, rollback, or execution abort. The system executes commands in chained mode
more quickly because transaction start/commit requires significant CPU and disk activity.
Chained mode allows consistency when you are executing multiple commands inside a
transaction while changing several related tables.
Note: By default, Netezza SQL executes transactions in unchained mode (also known as
autocommit). The system executes each user statement in its own transaction, and per-
forms an implicit commit at the end of the statement (if execution was successful,
otherwise the system does a rollback).
If the transaction is committed, Netezza SQL ensures either that all updates are done or
else that none of them is done. Transactions have the standard ACID (atomic, consistent,
isolatable, and durable) property.
Related Commands
Use the “COMMIT” on page B-30 or “ROLLBACK” on page B-98 commands to terminate a
transaction.
Usage
The following provides sample usage:
T To begin a user transaction, enter:
system(admin)=> BEGIN WORK;
COMMENT
Use the COMMENT command to define or change an object’s comment.
Synopsis
Syntax for adding a comment:
COMMENT ON
[[ DATABASE | SEQUENCE | TABLE | VIEW ]
object_name | COLUMN table_name.column_name] IS 'text'];
Inputs
The COMMENT command takes the following inputs:
Input Description
Outputs
The COMMENT command has the following output:
Output Description
Comment The message that the system returns to indicate commenting was successful.
Description
The COMMENT command has the following characteristics:
Privileges Required
You can change comments for objects you own.
You must be an administrator, or an administrator must have given you the Alter object
privilege to use this command.
Common Tasks
Use the COMMENT command to:
X Store a comment about a database object. You can retrieve comments with the CLI
command \dd.
X Modify a comment by issuing a new COMMENT command for the same object.
X Remove a comment by entering null in place of the text string.
Note: Only one comment string is stored for each object.The system automatically drops
comments when you drop an object. Do not put security-critical information into com-
ments. Any user connected to a database can view all comments for objects in the
database.
Usage
The following provides sample usage.
T To add a comment to the table mytable, enter:
system(admin)=> COMMENT ON my_table IS 'This is my table.';
T To add comments to a database, sequence, view, and column, enter:
system(admin)=> COMMENT ON DATABASE my_database IS 'Development
Database';
system(admin)=> COMMENT ON SEQUENCE my_sequence IS 'Used to
generate primary keys';
system(admin)=> COMMENT ON VIEW my_view IS 'View of departmental
costs';
system(admin)=> COMMENT ON COLUMN my_table.my_field IS 'Employee ID
number';
COMMIT
Use the COMMIT command to commit the current transaction.
Synopsis
Syntax for committing a transaction:
COMMIT [ WORK | TRANSACTION ];
Inputs
The command takes the following inputs:
Input Description
TRANSACTION
Outputs
The command has the following output:
Output Description
Output Description
NOTICE: COMMIT: no transac- The system returns this message if there is no transac-
tion in progress tion in progress.
Note: Always precede a COMMIT command with a
BEGIN command.
Description
The command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the COMMIT command to commit the current transaction. All changes made by the
transaction become visible to other users.
Related Commands
Precede a COMMIT command with a BEGIN command. Use the ROLLBACK command to
abort a transaction.
Usage
The following provides sample usage.
T To make all changes permanent, enter:
COMMIT WORK;
T To use the COMMIT command within (at the end of) a transaction, enter:
system(admin)=> begin;
BEGIN
system(admin)=> insert into cities values ('Boston',
'Massachusetts');
INSERT 0 1
system(admin)=> insert into cities values ('Houston', 'Texas');
INSERT 0 1
system(admin)=> commit;
COMMIT
system(admin)=>
COPY
Use the COPY command to copy data between files and tables. Note that there is no COPY
command in SQL92.
Netezza does not recommend using the COPY command. For load/unload operations use
the nzload command or CREATE EXTERNAL TABLE commands. These commands are
faster and more stable than the COPY command. The command is documented here
because it is used for internal operations.
Synopsis
Syntax for input coming from a client application:
COPY [BINARY] table
FROM { 'file name' | stdin }
[ [USING] DELIMITERS 'delimiter' ]
[ WITH NULL AS 'null string' ];
Syntax for output going to a client application:
COPY table
TO { 'file name' | stdout }
[ [USING] DELIMITERS 'delimiter' ]
[ WITH NULL AS 'null string' ];
Inputs
The COPY command takes the following inputs:
Input Description
BINARY Changes the behavior of field formatting. Forces all data to be stored or
read in binary format rather than text.
delimiter Specifies the character that separates fields within each row of the file.
file name Specifies the absolute path name of the input or output file.
null string The string that represents a NULL value. The default is "\N" (backslash-N).
Note: On a copy in, any data item that matches this string is stored as a
NULL value. Ensure you use the same string as you used on copy out.
Outputs
The COPY command has the following output
Output Description
COPY The system returns this message if the copy completes successfully.
ERROR: If a copy fails, the system returns this message with a reason for the
reason failure.
Description
The command has the following characteristics:
Privileges Required
You must have Select privilege on any table whose values are read by the COPY command.
You must have either Insert or Update privilege to a table into which values are being
inserted by the COPY command.
The database server also needs appropriate permissions for any file read or written by the
COPY command.
Common Tasks
The COPY command moves data between Netezza tables and standard file-system files.
Use the COPY command with a file name to read directly from or write to a file.
X Use the COPY TO command to copy the entire contents of a table to a file. The COPY
TO command does not act on column defaults.
X Use the COPY FROM command to copy data from a file to a table. Note that, if there is
data in the table already, the command appends to the table.
By default, a text copy uses a tab ("\t") character as a delimiter between fields. You can
change the field delimiter to any other single character with the keyword phrase using
delimiters. The system backslash quotes characters in data fields that happen to match the
delimiter character.
Note: You can use the COPY command with plain tables, but not with views.
The COPY command stops operation at the first error. In the case of the COPY FROM com-
mand, this is not an issue. In the case of the COPY TO command, the target relation will
already have received earlier rows. These rows are not visible or accessible, but they still oc-
cupy disk space. This might amount to a considerable amount of wasted disk space if the
failure happens well into a large copy operation.
When using a file name, always specify an absolute path. The database server enforces an
absolute path in the case of the COPY TO command, but for the COPY FROM command you
have the option of reading from a file specified by a relative path. The system interprets the
path relative to the database server's working directory, not the Netezza SQL working
directory.
File Formats
The following subsections describe file formats for the COPY command.
Text Format
When you use a COPY command, the system reads or writes a text file with one line per
table row. The delimiter character separates columns (attributes) in a row. The attribute
values themselves are strings that the output function generates for each attribute’s data
type, or that are acceptable to the input function. The system uses the specified null-value
string in place of attributes that are null.
You can represent end-of-data by a single line containing just backslash-period (\.). An end-
of-data marker is not necessary when reading from a UNIX file, but you must provide an
end marker when copying data to or from a client application.
You can use backslash characters (\) in the COPY command data to quote data characters
that might otherwise be assumed to be row or column delimiters. Specifically, the following
characters must be preceded by a backslash if they appear as part of an attribute value:
backslash itself, newline, and the current delimiter character.
Table B-29 describes the COPY FROM command backslash sequences.
Sequence Represents
\b Backspace (ASCII 8)
\t Tab (ASCII 9)
\digits Backslash followed by one to three octal digits specifies the character with
that numeric code.
The COPY TO command does not output an octal-digits backslash sequence, but it does
use the other sequences listed in Table B-29 for those control characters.
Note: Do not add a backslash before a data character N or period (.). Such pairs are mis-
taken for the default null string or the end-of-data marker, respectively. Any other
backslashed character that is not mentioned in Table B-29 is taken to represent itself.
Netezza recommends that applications generating COPY command data convert data new-
lines and carriage returns to the \n and \r sequences respectively.
The end of each row is marked by a UNIX-style newline ("\n"). The COPY FROM command
does not work properly with a file containing DOS- or Mac-style newlines.
Related Commands
See “CREATE TABLE AS” on page B-62.
Usage
The following provides sample usage.
T To copy a table to standard output, using a vertical bar (|) as the field delimiter, enter:
system(admin)=> COPY country TO stdout USING DELIMITERS '|';
T To copy data from a UNIX file into the table country, enter:
system(admin)=> COPY country FROM '/usr1/proj/bray/sql/country_
data';
T This is a sample of data suitable for copying into a table from stdin (so it has the termi-
nation sequence on the last line):
AF AFGHANISTAN
AL ALBANIA
DZ ALGERIA
ZM ZAMBIA
ZW ZIMBABWE
\.
CREATE DATABASE
Use the CREATE DATABASE command to create a new database.
Synopsis
Syntax for creating a new database:
CREATE DATABASE name
CREATE DATABASE name
[ WITH
[ DEFAULT CHARACTER SET charset ]
[ DEFAULT CHARACTER SET charset COLLATION collation ]
]
Inputs
The CREATE DATABASE command takes the following inputs:
Input Description
DEFAULT CHARACTER SET Specifies the default character set and collation. The
default and only supported value is Latin9. Do not spec-
ify other values. For more information on character
encoding on the Netezza, see Chapter 7, “Using
National Character Sets.”
Outputs
The CREATE DATABASE command has the following output:
Output Description
ERROR: User 'username' is not The system returns this message if you do not have the
allowed to create/drop correct access to create a database. You must have the
databases. Create Database privilege to create databases. See
“CREATE USER” on page B-65.
ERROR: Createdb: database The system returns this message if a database with the
‘name’ already exists. name you specified already exists.
ERROR: Create database: may If you have an explicit transaction block in progress, you
not be called in a transaction cannot call create database. You must finish the transac-
block. tion first.
ERROR: Unable to create data- The system returns these messages if you have:
base directory 'path'. • Insufficient permissions on the data directory; you
must have access to the location.
ERROR: Could not initialize
database directory. • A full disk.
• Other file system problems.
Description
The CREATE DATABASE command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the CREATE DATABASE command to create and become the owner of a new database.
Related Commands
Use “DROP DATABASE” on page B-72 to remove a database.
Usage
The following provides sample usage.
T To create a new database, enter:
system(admin)=> create database customers;
Synopsis
Syntax for the CREATE EXTERNAL TABLE command based on another table:
CREATE EXTERNAL TABLE table_name
SAMEAS table_name
USING external_table_options
Syntax for the CREATE EXTERNAL TABLE command by selecting columns:
CREATE EXTERNAL TABLE table_name
({ column_name
type
[ column_constraint [ ... ] ]
} [, ... ]
)
Syntax for the CREATE EXTERNAL TABLE command as a SELECT clause:
CREATE EXTERNAL TABLE [table_name] 'filename'
[USING external_table_options]
AS select_clause
Column constraints can be:
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY |
DEFAULT value |
REFERENCES table
[ ( column ) ]
}
Inputs
The CREATE EXTERNAL TABLE command takes the following inputs:
Input Description
column constraints For more information about column constraints, see “CREATE
TABLE” on page B-56.
column_name Specifies the name of the column to create in the new table.
dataobject Allows you to specify a file. You must use the full path, not a relative
path.
external_table_ For more information about the options, see Table B-34 on
options page B-40
Input Description
delimiter Specifies the byte value that separates fields in a delimited text file.
You can specify characters in the 7-bit ASCII range using either a
quoted value (for example: delimiter '|') or by its unquoted
decimal number (delimiter 124) . To specify a byte value above
127, use the decimal number.
host_file name Specifies the full file specification (path) of a host file. You must
have single quotes around the file name. The path and file name can
use only 7-bit ASCII characters.
table_name Specifies the name of the external table. You cannot use the same
name as the system catalog tables and the external table name must
use ASCII characters.
type Specifies the data type. See Chapter 3, “Netezza SQL Basics.”
Outputs
The CREATE EXTERNAL TABLE command has the following output
Output Description
ERROR: Relative path not Message returned if you specify a relative path.
allowed in the 'dataobject'
option
Description
The CREATE EXTERNAL TABLE command has the following characteristics:
Privileges Required
The user who issues the CREATE EXTERNAL TABLE command owns the resultant table.
You must be the administrator, or an administrator must have given you the appropriate
object privileges, to use this command. You must have permission to write to that data
object’s path.
Common Tasks
Use the CREATE EXTERNAL TABLE command to create an external table. An external table
is an abstract name, or handle, to a flat file on the host. You can list external tables as you
would list regular tables.
Note: In a Netezza system there are three types of tables: system tables, which are stored
on the host, user tables, which are stored on the data slices, and external tables, which are
stored as flat files on the host or client systems. An external table cannot have the same
name as a system table.
Operations
Keep in mind the following:
X You can insert and drop an external table, using the INSERT and DROP commands.
X You cannot delete, truncate, or update an external table.
X You cannot specify more than one external table in a FROM or WHERE clause in a
query or subquery. The system displays an error if you specify multiple external tables
in a SQL query, or if you reference the same external table more than once in a query:
*ERROR: Multiple external table references in a query not
allowed*
To specify more than two external tables, load the data in into a non-external table and
specify this table in the query.
X You cannot perform a union operation involving two or more external tables.
X You cannot back up external tables using the nzbackup command. If you attempt to
back up an external table, the system displays a warning message.
X You cannot use the limit clause with compressed external tables.
X You can use the boolStyle and dateStyle to select data from the external table (load-
ing), but you cannot use all the options for inserting into an external table (unloading).
Unload supports boolStyle of ‘1_0’(default, ‘Y_N’ and ‘T_F’). It does not support
‘TRUE_FALSE’ and ‘YES_NO’. In other words, it supports single char values, but not
multi-char strings.
Inserting Options
You can specify options when you create an external table definition. The options are a sub-
set of the nzload command options. You can use these options when loading from an
external table or when using the external table directly in a SQL query.
Note: Loading from an external table is similar to using the nzload command in that the
system processes the source data and records any errors in the nzlog and nzbad files.
Check these files occasionally to verify that the processing has been successful.
Table B-34 describes those options. For more information about these options, see the
nzload command in the Netezza System Administrator’s Guide.
ctrlChars boolean yes yes The default is false. The datatype for
ctrlchar is boolean. Acceptable val-
ues are: true or false, on or off. Do
not insert quotes around the value.
dateStyle string yes yes The date style settings ‘YMD’, ‘MDY’,
‘DMY’, ‘MONDY’. The default is
YMD. It does not support the two-
digit year formats (Y2MD, MDY2,
DMY2 and MONDY2).
delimiter string yes yes The default is the pipe character. You
can specify characters in the 7-bit
ASCII range using either a quoted
value (for example: delimiter
'|') or by its unquoted decimal
number (delimiter 124) . To
specify a byte value above 127, use
the decimal number.
escapeChar string yes yes The only supported char is ‘\’. The
character immediately following the
‘\’ is escaped.
y2base integer (max 4 yes yes First year expressible using two-digit
digit) year (Y2) in dateStyle.
Related Commands
See “CREATE TABLE AS” on page B-62 and “CREATE TABLE” on page B-56.
Usage
The following provides sample usage.
T To create an external table, enter:
CREATE EXTERNAL TABLE demo_ext SAMEAS emp USING (dataobject ('/tmp/
demo.out') DELIMITER '|');
T To create an external table that uses only a few columns from an existing table, enter:
CREATE EXTERNAL TABLE ext_orders(ord_num INT, ord_dt
TIMESTAMP)USING(dataobject('/tmp/order.tbl') DELIMITER '|');
T To create an external table and specify the escape character (‘\’), enter:
CREATE EXTERNAL TABLE extemp SAMEAS emp USING( dataobject ('/tmp/
extemp.dat') DELIMITER '|' escapechar '\');
T To unload data from your database into a file by using an insert statement, enter:
INSERT INTO demo_ext SELECT * FROM weather;
T To drop an external table, enter:
DROP TABLE extemp
The system removes only the external table’s schema information from the system cat-
alog. The file defined in the dataobject option remains unaffected in the filesystem.
T To back up by creating an external table, enter:
CREATE EXTERNAL TABLE '/path/extfile' USING (FORMAT 'internal'
COMPRESS true) AS SELECT * FROM source_table;
T To restore from an external table, enter:
INSERT INTO t_desttbl SELECT * FROM EXTERNAL'/path/extfile'
USING(FORMAT 'internal' COMPRESS true);
CREATE GROUP
Use the CREATE GROUP command to create a new group.
Synopsis
Syntax for creating a group:
CREATE GROUP name
[ WITH
[ SYSID gid ]
[ROWSETLIMIT [integer ]
[SESSIONTIMEOUT [integer ]
[QUERYTIMEOUT [integer ]
[DEFPRIORITY [critical|high|normal|low|none]]
[MAXPRIORITY [critical|high|normal|low|none]]
[RESOURCELIMIT resourcepercent]
[ USER username [, ...] ]
]
Inputs
The command takes the following inputs:
Input Description
<gid> Specifies the SYSID clause to choose the group ID of the new group.
Note: If you do not specify SYSID, the system uses the highest
assigned group ID plus one, starting at 1, as the default.
ROWSETLIMIT The rowset limit specifies the maximum number of rows any query
run by this user (or group) can return. You can specify from 1 to
2,147,483,647 rows or zero for unlimited.
SESSIONTIMEOUT Specifies the amount of time a session can be idle before the system
terminates it. You can specify from 1 to 2.147,483,647 minutes or
zero for unlimited.
QUERYTIMEOUT Specifies the amount of time a query can run before the system
sends the administrator a message. You can specify from 1 to
2,147,483,647 minutes or zero for unlimited.
Note that to receive a message, you must enable the RunAwayQuery
event rule. For more information, see the Netezza System Adminis-
trator’s Guide.
DEFPRIORITY Specifies the default priority for the group. The valid priorities are
critical, high, normal, low.
RESOURCELIMIT When you designate non-zero for a group, the group is a resource-
sharing group. The number you enter is the percent of total system
resources reserved for that group. For general information on
resource allocation, see the “Work Load Management” section in the
Netezza System Administrator’s Guide.
Outputs
The command has the following output:
Output Description
CREATE GROUP The system returns this message if the command completed
successfully.
Description
The command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the CREATE GROUP command to create a new group in the database installation.
Related Commands
Use the ALTER GROUP command to change a group's membership, and DROP GROUP to
remove a group.
Usage
The following provides sample usage.
T To create an empty group, enter:
system(admin)=> CREATE GROUP staff;
T To create a group with members, enter:
system(admin)=> CREATE GROUP marketing WITH USER jonathan, david;
T To set the group’s maximum priority, enter:
system(admin)=> Create GROUP workers WITH MAXPRIORITY critical;
Synopsis
Syntax for creating the history configuration:
CREATE HISTORY CONFIGURATION <config-name> <hist-clause> …
<hist-clause> ::=
| HISTTYPE {QUERY | NONE}
| NPS { LOCAL }
| DATABASE <dbname>
| USER <username>
| PASSWORD <writer-password>
| COLLECT <history-item> ,...
| LOADINTERVAL {number }
| LOADMINTHRESHOLD {number}
| LOADMAXTHRESHOLD {number}
| DISKFULLTHRESHOLD {number}
| STORAGELIMIT {number}
| LOADRETRY {number}
| ENABLEHIST {boolean}
| ENABLESYSTEM {boolean}
| VERSION <version>
<history-item>
QUERY
| PLAN
| TABLE
| COLUMN
Inputs
The CREATE HISTORY CONFIGURATION command has the following inputs:
Input Description
USER <username> Specifies the user name for accessing and inserting
data to the query history database. This is the user
name specified in the nzhistcreatedb command.
There is no default. This is a delimited identifier. If
not delimited, the system converts the name to the
host case.
PASSWORD <writer password> The password for the database user account. There is
no default. This is a single quoted string, and the
password is stored as an encrypted string.
If the user’s password changes, you must update the
history configuration with the new password as well, or
the loader process will fail.
Input Description
Input Description
DISKFULLTHRESHOLD This option is reserved for future use. Any value you
specify will be ignored. The default value is 0.
Input Description
VERSION <version> Specifies the query history schema version of the con-
figuration. By default, this is the query history schema
version of the current image. For Release 4.6, the ver-
sion number is 1.
The version must match the version number specified
in the nzhistcreatedb command; otherwise, the loader
process will fail.
Outputs
The CREATE HISTORY CONFIGURATION command has the following outputs:
Output Description
ERROR: permission denied You must have Manage Security permission to configure
query history logging.
ERROR: database <dbname> The query history database was not found on the
not found. Netezza system.
Description
This command creates a configuration definition for query history logging on a Netezza sys-
tem. You must create at least one configuration for the current schema version to enable
query history logging. This operation itself is not logged in the query history database if it is
being set up for the first time for the current query history schema version or if the current
history configuration points to a type NONE. The CREATE HISTORY CONFIGURATION
command has the following characteristics:
Privileges Required
You must have Manage Security permissions to configure query history logging.
Related Commands
See the “ALTER HISTORY CONFIGURATION” on page B-9 to modify configurations.
See the “DROP HISTORY CONFIGURATION” on page B-75 to drop configurations.
See the “SET HISTORY CONFIGURATION” on page B-115 to specify a configuration for
query history logging.
See the “SHOW HISTORY CONFIGURATION” on page B-125 to display information about
a configuration.
Usage
Some sample usages of the CREATE HISTORY CONFIGURATION command follow.
The following command creates a history configuration named all_hist which enables the
capture of all history information:
SYSTEM(ADMIN)=> CREATE HISTORY CONFIGURATION all_hist HISTTYPE QUERY
DATABASE histdb USER histusr PASSWORD histusrpw COLLECT PLAN,COLUMN
LOADINTERVAL 5 LOADMINTHRESHOLD 4 LOADMAXTHRESHOLD 20 VERSION 1;
The following command creates a history configuration named hist_mincollect which col-
lects the basic level of history data (login failure, session creation, and termination, and the
startup of the alcapp process):
SYSTEM(ADMIN)=> CREATE HISTORY CONFIGURATION hist_mincollect HISTTYPE
QUERY DATABASE histdb USER histusr PASSWORD histusrpw COLLECT
LOADINTERVAL 5 LOADMINTHRESHOLD 4 LOADMAXTHRESHOLD 20 VERSION 1;
The following command creates a history configuration named hist_queryonly which col-
lects query and plan details and the basic level of information:
SYSTEM(ADMIN)=> CREATE HISTORY CONFIGURATION hist_mincollect HISTTYPE
QUERY DATABASE "query db" USER histusr PASSWORD histusrpw COLLECT
QUERY,PLAN LOADINTERVAL 5 LOADMINTHRESHOLD 4 LOADMAXTHRESHOLD 20
VERSION 1;
The following command creates a history configuration named hist_disabled that disables
history collection:
SYSTEM(ADMIN)=> CREATE HISTORY CONFIGURATION hist_disabled HISTTYPE
NONE;
Synopsis
Syntax for creating a materialized view:
CREATE MATERIALIZED VIEW <viewname> AS SELECT <select_column> [,...]
FROM <table> [ORDER BY <order_columns>[,...]];
CREATE OR REPLACE MATERIALIZED VIEW <viewname> AS SELECT <select_
column> [,...]
FROM <table> [ORDER BY <order_columns>[,...]];
Inputs
The CREATE MATERIALIZED VIEW command takes the following inputs:
Input Description
Input Description
CREATE OR Replaces an existing materialized view. You should use this option to
REPLACE rebuild a view after its base table changes in some way or after renaming
a database.
select_column Specifies the columns that comprise this view (up to 64).
Restrictions
The CREATE MATERIALIZED VIEW command has the following restrictions:
X You can only specify a single base table in the FROM clause.
X You cannot use the WHERE clause when creating a materialized view.
X The columns you specify in the selection list must exist in the base table.
X You must specify at least one column in the selection list.
X You can select up to 64 columns for your materialized view.
X The columns in the ORDER BY list must be specified in the selection list.
X You cannot specify an external, temporary, or system table as a base table.
Outputs
The CREATE MATERIALIZED VIEW command has the following output:
Output Description
ERROR: Relation 'view' already Message returned if the view you specified already
exists. exists in the database.
Description
The CREATE MATERIALIZED VIEW command requires the following privileges and per-
forms the following tasks:
Privileges Required
You must be an administrator or an administrator must have given you the Create Material-
ized View administration privilege to use this command.
Common Tasks
Use the CREATE MATERIALIZED VIEW command to define a sorted, projected, material-
ized view of a subset of the base tables’ columns.
Note: The system persistently stores the view and it is visible with the \dm command.
Related Commands
See “DROP VIEW” on page B-82 to drop view. See “ALTER VIEW” on page B-25 to refresh
or suspend an existing view.
Usage
The following provides sample usage.
T To create a materialized view, enter:
system(admin)=> CREATE MATERIALIZED VIEW kinds AS SELECT t1 FROM
emp ORDER BY name;
CREATE SEQUENCE
Use the CREATE SEQUENCE statement to create a sequence. A sequence is a database
object from which multiple users can generate unique integers. For more information about
creating and using sequences, see Chapter 8, “Sequences.”
After you create a sequence, you can access its value in SQL statement with the NEXT
VALUE FOR statement (which increments the sequence and returns the new value).
The system generates sequence numbers independent of whether the transaction commits
or rolls back. If two users concurrently increment the same sequence, the sequence num-
bers each user acquires can have gaps, because the other user is generating sequence
numbers. No user, however, can every acquire the sequence number generated by another
user.
Synopsis
Syntax for creating a sequence:
CREATE SEQUENCE <sequence_name>
[ AS datatype ]
[ START WITH start value ]
[ INCREMENT BY increment ]
[ NO MINVALUE | MINVALUE minimum value ]
[ NO MAXVALUE | MAXVALUE maximum value ]
[ NO CYCLE | CYCLE ];
Options
The CREATE SEQUENCE command takes the following inputs:
Input Description
datatype Specifies the data type. The value can be any exact integer
type such as byteint, smallint, integer, or bigint. If you do
not specify this option, the default datatype is bigint. For a
description of the datatypes and their ranges, see
Table 3-1 on page 3-2.
START WITH Specifies the starting value. Use this clause to start an
ascending sequence at a value greater than its minimum or
to start a descending sequence at a value less than its
maximum.
For ascending sequences, the default value is the mini-
mum value of the sequence. For descending sequences,
the default value is the maximum value of the sequence.
This integer value must be between the sequence
datatype’s minvalue and maxvalue.
NO MINVALUE | MINVALUE Specifies the minimum value of the sequence. The default
is NO MINVALUE, which results in a value of 1.
MINVALUE must be less than or equal to START WITH and
must be less than MAXVALUE.
NO MAXVALUE | MAXVALUE Specifies the maximum value that the sequence can have.
The default is NO MAXVALUE, which results in the largest
value for the specified datatype.
MAXVALUE must be equal to or greater than START WITH
and must be greater than MINVALUE. For a description of
the datatype ranges, see “Integer Types” on page 3-2.
Input Description
Outputs
The CREATE SEQUENCE command produces the following output:
Output Description
create sequence The message that the system returns if the command is
successful.
Description
The CREATE SEQUENCE command has the following characteristics:
Privileges Required
The privileges to create sequences are as follows:
X The admin user has all privileges on all user sequences. There is no need to grant any
privileges to the admin user.
X The owner of the database has all privileges on all user sequences in that database.
There is no need to grant any privileges to the owner.
X All others must have the Create Sequence administration permission.
Notes
To create specific sequences, do the following:
X To create an ascending sequence that increments to its maximum datatype value, omit
the MAXVALUE or specify NO MAXVALUE. For descending sequences that should dec-
rement to the minimum value of 1, omit the MINVALUE or specify NO MINVALUE.
X To create a sequence that stops at a predefined limit for ascending sequences, specify
a value for the MAXVALUE parameter. For descending sequences, specify a value for
the MINVALUE. Also specify NO CYCLE. Any attempt to generate a sequence number
after the sequence has reached its limit results in an error.
X To create a sequence that restarts after reaching its limit, specify CYCLE.
Related Commands
See “ALTER SEQUENCE” on page B-14 and “DROP SEQUENCE” on page B-76 for related
sequence commands.
Usage
The following provides sample usage:
CREATE SYNONYM
Use the CREATE SYNONYM statement to create a synonym. A synonym is an alternate way
of referencing tables or views. Synonyms allow you to create easy to type names for long
table or view names.
Synonyms share the same naming restrictions as tables and views, that is, they must be
unique with a database and their names cannot be the same as global objects such as
those of databases, users, or groups.
Synopsis
Syntax for creating a synonym:
CREATE SYNONYM synonym_name FOR table_reference
Options
The CREATE SYNONYM command takes the following inputs:
Input Description
Outputs
The CREATE SYNONYM command produces the following output:
Output Description
CREATE SYNONYM The message that the system returns if the command is
successful.
Description
The command has the following characteristics:
Privileges Required
The admin user and the owner of the database can create synonyms. All other users must
be granted the Create Synonym privilege.
Notes
The synonym_name is a name that follows the table and view naming conventions. You can
create a synonym for a non-existent table or view. At runtime the system expands the table_
reference to its fully qualified form. If the referenced object does not exist, the system dis-
plays an error message.
Related Commands
See ALTER SYNONYM and DROP SYNONYM.
Usage
The following provides sample usage:
T To create a synonym pr for the table payroll, enter:
CREATE SYNONYM pr FOR payroll;
CREATE TABLE
Use the CREATE TABLE command to define a new table.
Synopsis
General syntax for the create table command:
CREATE [ TEMPORARY | TEMP ] TABLE table_name
(
column_name type [ [ constraint_name ] column_constraint [ constraint_
characteristics ] ] [, ... ]
[ [ constraint_name ] table_constraint [ constraint_characteristics ]
] [, ... ]
) [ DISTRIBUTE ON ( column [, ...] ) ]
Where constraint_name can be:
{CONSTRAINT name}
Where column_constraint can be:
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY | DEFAULT value |
REFERENCES table [ ( column [, ... ] ) ]
[ MATCH match_type ]
[ ON UPDATE referential_action ]
[ ON DELETE referential_action ]
}
Where table_constraint can be:
{ UNIQUE ( column_name [, ... ] ) |
PRIMARY KEY ( column_name [, ... ] ) |
FOREIGN KEY ( column_name [, ... ] )
REFERENCES table [ ( column [, ... ] ) ]
[ MATCH match_type ]
[ ON UPDATE referential_action ]
[ ON DELETE referential_action ]
}
Inputs
The CREATE TABLE command takes the following inputs:
Input Description
constraint_name Specifies a name for a column or table constraint. The system gener-
ates a name if you do not specify one.
INITIALLY Specifies either DEFERRED (at the end of the transaction) or IMMEDI-
checktime ATE (at the end of each statement).
Match match Specifies the match type, which can be MATCH FULL, MATCH PAR-
type TIAL, and the default.
• Match Full prevents one column from a multicolumn foreign key
from being null if other parts of the foreign key are not null.
• MATCH PARTIAL is unsupported.
NOT Controls where the constraint can be deferred to the end of the transac-
DEFERRABLE tion. If DEFERRABLE SET CONSTRAINTS ALL DEFERRED causes the
foreign key to be checked only at the end of the transaction. NOT
DEFERRABLE is the default.
NOT NULL Specifies that the column is not allowed to contain null values.
NULL Specifies that the column is allowed to contain null values. This is the
default.
Input Description
ON UPDATE Specifies the action when a referenced column in the referenced table
is updated to a new value. The actions are the same as those of the ON
DELETE parameter.
primary key The primary key constraint specifies that a column or columns of a
(column_ table may contain only unique (non-duplicate), non-null values.
constraint) Note: The primary key constraint is virtually a combination of the
primary key ( unique and not null constraints, but identifying a set of columns as a
column_name [, primary key also provides metadata about the design of the schema. A
... ] ) (table_ primary key implies that other tables may rely on this set of columns as
constraint) a unique identifier for rows.
You can specify only one primary key constraint for a table, whether as
a column constraint or a table constraint.
The primary key constraint should name a set of columns that is differ-
ent from other sets of columns named by any unique constraint defined
for the same table.
references table Specifies that a group of one or more columns of the new table must
[ ( column )] only contain values that match against values in the referenced col-
foreign key( umn(s) of the referenced table. If you omit column, the primary key of
column_name [, the table is used. The referenced columns must be the columns of a
... ] ) references unique or primary key constraint in the referenced table.
table [ ( column
[, ... ] ) ] (table_
constraint)
type Specifies the data type of the column. See Chapter 3, “Netezza SQL
Basics,” for information about data types.
Outputs
The command has the following output:
Output Description
CREATE TABLE The system returns this message if the command completes
successfully.
ERROR The system returns this message if table creation fails. The error mes-
sage provides descriptive text, such as:
error: Relation 'table' already exists.
Description
The command has the following characteristics:
Privileges Required
The user who issues the CREATE TABLE command owns the resultant table. You must be
an administrator, or an administrator must have given you the appropriate object privileges,
to use this command.
Common Tasks
Use the CREATE TABLE command to create a new, initially empty table in the current data-
base. The CREATE TABLE command automatically creates a data type that represents the
tuple type (structure type) corresponding to one row of the table.
Note that a table cannot have the following:
X The same name as any existing data type.
X The same name as a system catalog table.
X More than 1600 columns. In practice, the effective limit is lower because of tuple-
length constraints.
X Table or view attributes with the following names: ctid, oid, xmin, cmin, xmax, cmax,
tableoid, rowid, datasliceid, createxid, and deletexid
The optional constraint clauses specify constraints (or tests) that new or updated rows must
satisfy for an insert or update operation to succeed. A constraint is a named rule: a SQL
object that helps define valid sets of values by putting limits on the results of insert,
update, or delete operations performed on a table.
You can define table constraints and column constraints.
X A column constraint is defined as part of a column definition.
X A table constraint definition is not tied to a particular column, and it can encompass
more than one column.
You can also write every column constraint as a table constraint. A column constraint is
only a notational convenience if the constraint only affects one column.
Note: The SQL92 standard specifies that check column constraints may refer only to the
column to which they apply. Only check table constraints may refer to multiple columns.
Netezza SQL does not enforce this restriction; it treats column and table check constraints
alike.
Distribution Specification
Each table in a Netezza RDBMS database has only one distribution key, which consists of
one to four columns. You can use the following SQL syntax to create distribution keys.
T To create an explicit distribution key, the Netezza SQL syntax is:
usage: create table <tablename> [ ( <column> [, … ] ) ] as <select_clause>
[ distribute on [hash] ( <column> [ ,… ] ) ]
The phrase distribute on specifies the distribution key, the word hash is optional.
Constraint Attributes
Constraints can have the following attributes that determine whether the constraint check
is immediate or deferred. Note that because the system does not enforce constraint check-
ing, these attributes are merely accepted rather than invoked.
X [NOT] DEFERRABLE — Determines whether the constraint is checked at the end of
the transaction.
X INITIALLY DEFERRED — Checks the constraint only at the end of the transaction.
X INITIALLY IMMEDIATE — Checks the constraint after each statement.
Related Commands
Refer to CREATE TABLE AS and ALTER TABLE.
Usage
The following provides sample usage:
T To create a table, enter:
system(admin)=>
CREATE TABLE name (
code CHARACTER(5) CONSTRAINT firstkey PRIMARY KEY,
title CHARACTER VARYING(40) NOT NULL,
did DECIMAL(3) NOT NULL,
date_prod DATE,
kind CHAR(10),
len INTERVAL HOUR TO MINUTE
);
T To define a primary key table constraint for the table films, you can define primary key
table constraints on one or more columns of the table:
system(admin)=>
CREATE TABLE name (
code CHAR(5),
title VARCHAR(40),
did DECIMAL(3),
date_prod DATE,
kind VARCHAR(10),
len INTERVAL HOUR TO MINUTE,
CONSTRAINT code_title PRIMARY KEY(code,title)
);
T To define a primary key constraint for the table distributors, enter:
system(admin)=> CREATE TABLE distributors (
did DECIMAL(3),
name CHAR VARYING(40),
PRIMARY KEY(did)
);
system(admin)=> CREATE TABLE distributors (
did DECIMAL(3) PRIMARY KEY,
name VARCHAR(40)
);
Note: The two examples are equivalent — the first uses the table constraint syntax, the
second uses the column constraint notation.
T To define two not null column constraints on the table distributors, one of which is
explicitly given a name, enter:
system(admin)=> CREATE TABLE distributors (
did DECIMAL(3) CONSTRAINT no_null NOT NULL,
name VARCHAR(40) NOT NULL
);
CREATE TABLE AS
Use the CREATE TABLE AS command to create a new table from the results of a query.
Note that this command is often referred to as CTAS in the documentation.
Synopsis
Syntax for using the CREATE TABLE AS command:
CREATE [ TEMPORARY | TEMP ] TABLE <table> [ (<column_name> [, ...] ) ]
AS <select_clause> [ DISTRIBUTE ON ( <column> [, ...] ) ]
Inputs
The CREATE TABLE AS command takes the following inputs:
Input Description
column_name Specifies the name of a column in the new table. You can specify mul-
tiple column names using a comma-delimited list of column names. If
you do not provide column names, they are taken from the output col-
umn names of the query.
DISTRIBUTE ON Specifies the distribution column. For more information, see “Handling
Distribution Keys” on page B-63.
table Specifies the name of the new table to create. This table must not
already exist. A temporary table, however, can be created that has the
same name as an existing permanent table.
Outputs
Refer to the CREATE TABLE and SELECT commands for a listing of possible output
messages.
Description
The CREATE TABLE AS command has the following characteristics:
Privileges Required
The user who issues the CREATE TABLE AS command owns the resultant table. You must
be an administrator, or an administrator must have given you the appropriate object privi-
leges, to use this command.
Common Tasks
Use the CREATE TABLE AS command to create a table and fill it with data from a select
command:
X Table columns have the names and data types associated with the output columns of
the SELECT command, unless you override the column names by giving an explicit list
of new column names.
X The CREATE TABLE AS command creates a new table and evaluates the query just
once to fill the new table initially. The new table does not track subsequent changes to
the source tables of the query. (In contrast, whenever you query a view it re-evaluates
the underlying SELECT commands.)
Table t_three inherits its distribution keys from the grouping node, which would be
(b1,b2,b3).
Example 3 CREATE TABLE t_three AS SELECT ... FROM tbl_one, tbl_two, tbl_three...
WHERE .... GROUP BY b1,b2,b3;
Be careful of the following special case when issuing a CREATE TABLE AS command on a
table that uses random distribution. For example:
1. Create a table with multiple columns and distribute randomly.
2. Using CREATE TABLE AS, create a copy of the randomly distributed table without
specifying a distribution key. The resulting table distributes on the first column.
This result may be contrary to what you would expect. Typically, the new table inherits the
distribution key. To avoid this result for tables with random distribution, override the
default distribution as follows:
X When issuing the CREATE TABLE AS command, specify “LIMIT 0” in the source
SELECT statement.
X Populate the new table by issuing an INSERT command with the SELECT option.
Related Commands
See “CREATE TABLE” on page B-56.
Usage
The following provides sample usage.
T To show an example of the CREATE TABLE AS command, consider the following table,
named cows, enter:
system(admin)=> CREATE TABLE cow2 AS SELECT * FROM cows;
cnumber | cname | cbreed | ckind
---------+--------+-------------+-------
3 | Cindy | Ayrshire | milk
8 | Muffin | Guernsey | milk
2 | Martha | Brown Swiss | milk
7 | Joe | Angus | beef
5 | Gretel | Highland | beef
1 | Betsy | Holstein | milk
6 | Bob | Angus | beef
4 | Mindy | Hereford | beef
9 | Milda | Jersey | milk
(9 rows)
T To use the CREATE TABLE AS command to create a new table from two columns of the
table cows, enter:
system(admin)=> CREATE TABLE cow2 AS SELECT cname, cbreed FROM cows;
cname | cbreed
--------+-------------
Cindy | Ayrshire
Muffin | Guernsey
Mindy | Hereford
Milda | Jersey
Betsy | Holstein
Gretel | Highland
Martha | Brown Swiss
Joe | Angus
Bob | Angus
(9 rows)
CREATE USER
Use the CREATE USER command to define a new database user account.
Synopsis
Syntax for creating a user:
CREATE USER username
[WITH
[PASSWORD {'string' | NULL }]
[SYSID uid]
[ROWSETLIMIT [integer ]
[IN GROUP groupname [, ...] ]
[VALID UNTIL 'date' ]
[SESSIONTIMEOUT [integer ]
[QUERYTIMEOUT [integer ]
[DEFPRIORITY [critical|high|normal|low|none]]
[MAXPRIORITY [critical|high|normal|low|none]]
[IN RESOURCEGROUP resourcegroupname]
]
Inputs
The command takes the following inputs:
Input Description
Input Description
uid Use the sysid clause to choose the user ID of the user you are
creating.
If you do not specify uid, the system uses the highest user ID and
adds one (with a minimum of 100) as default.
NULL You can specify WITH PASSWORD NULL to explicitly create a user
with a null password. This is the same as not including the WITH
PASSWORD option.
Note: A user who has privileges to access the “_t_user” table can find
all users with null passwords by executing the following:
select * from _t_user where passwd is null
date Specifies the date (and, optionally, the time) when this user's pass-
word expires.
ROWSETLIMIT Specifies the number of rows a query can return. You can specify
from 1 to 2,147,483,647 rows or zero for unlimited. The rowset
limit specifies the maximum number of rows any query run by this
user (or group) can return.
SESSIONTIMEOUT Specifies the amount of time a session can be idle before the system
terminates it. You can specify from 1 to 2.147,483,647 minutes or
zero for unlimited.
QUERYTIMEOUT Specifies the amount of time a query can run before the system
sends the administrator a message. You can specify from 1 to
2,147,483,647 minutes or zero for unlimited.
Note that to receive a message, you must enable the RunAwayQuery
event rule. For more information, see the Netezza System Adminis-
trator’s Guide.
DEFPRIORITY Specifies the default priority for the user. The valid priorities are crit-
ical, high, normal, low.
IN GROUP Specifies the group into which to insert the user as a new member.
Input Description
Outputs
The CREATE USER command has the following output
Output Description
Description
The CREATE USER command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the CREATE USER command to add a new user.
Related Commands
Use the following commands:
X Use “ALTER USER” on page B-22 to change a user's password and privileges.
X Use “DROP USER” on page B-81 to remove a user.
X Use “ALTER GROUP” on page B-6 to add or remove the user from other groups.
X Use “SET AUTHENTICATION” on page B-110 to set authentication to and from LDAP
and LOCAL.
X Use “SHOW AUTHENTICATION” on page B-122 to display how the Netezza system is
currently configured for authentication.
X Use“SET CONNECTION” on page B-113 to specify which Netezza system connections
should use an SSL connection.
X Use “SHOW CONNECTION” on page B-124 to display Netezza connections that use
SSL.
X Use “DROP CONNECTION” on page B-71 to drop a Netezza connection.
Usage
The following provides sample usage.
T To create a user with a password, enter:
system(admin)=> CREATE USER davide WITH PASSWORD 'jw8s0F4';
T To create a user with a password whose user account expires on January 1, 2003,
enter:
system(admin)=> CREATE USER miriam WITH PASSWORD 'jw8s0F4' VALID
UNTIL 'Jan 1 2003';
CREATE VIEW
Use the CREATE VIEW command to create a view. Use CREATE OR REPLACE VIEW to
transfer the permissions (ACL data) from one view to another.
Synopsis
Syntax for creating a view:
CREATE VIEW <viewname> AS SELECT <query>
CREATE OR REPLACE VIEW <viewname> AS SELECT <query>
Inputs
The CREATE VIEW command takes the following inputs:
Input Description
query Specifies the SQL query that provides the columns and rows of
the view. Refer to the select command for information about valid
arguments.
Outputs
The CREATE VIEW command has the following output:
Output Description
ERROR: Relation 'view' already Message returned if the view you specified already
exists exists in the database.
Description
The CREATE VIEW command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the CREATE VIEW command to define a view of a table. The view is not physically
materialized. Instead, a query rewrite retrieve rule is automatically generated to support
retrieve operations on views.
Use the CREATE OR REPLACE VIEW to redefine a view and retain the permissions from the
original view.
Note: Views are read-only. The system does not allow an insert, update, or delete on a view.
Related Commands
See “DROP VIEW” on page B-82 to drop views.
Usage
The following provides sample usage.
T To create a view consisting of all comedy films, enter:
system(admin)=> CREATE VIEW kinds AS
SELECT *
FROM films
WHERE kind = 'Comedy';
T To display the view, enter:
system(admin)=> SELECT * FROM kinds;
code | title | did | date_prod | kind | len
------+---------------------------+-----+------------+---------+--
----
C_701 | There's a Girl in my Soup | 107 | 1970-06-11 | Comedy |
01:36:00
UA502 | Bananas | 105 | 1971-07-13 | Comedy |
01:22:00
(2 rows)
T To re-create the view while retaining the permissions of the original view, enter:
system(admin)=> CREATE OR REPLACE VIEW kinds AS
SELECT *
FROM films
WHERE kind = 'Action';
DELETE
Use the DELETE command to remove rows from a table.
Synopsis
Syntax for deleting rows from a table:
DELETE FROM <table> [ WHERE <condition> ]
Inputs
The DELETE command takes the following inputs:
Input Description
condition Specifies a SQL selection query that returns the rows to be deleted.
Refer to the SELECT command for further description of the where clause.
Outputs
The DELETE command has the following output:
Output Description
DELETE COUNT Message returned if items are successfully deleted. The count is the
number of rows deleted.
If the count is zero, no rows were deleted.
Description
The DELETE command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the DELETE command to remove rows that satisfy the WHERE clause condition for a
particular table.
If you use the DELETE command without the WHERE clause, the system deletes all rows in
the table. The result is a valid, empty table.
You can use a table alias in update and delete statements. For example:
UPDATE tablename t1 set t1.c2='new value' where t1.c1=1;
DELETE from tablename t1 where t1.c1=2;
Related Commands
The TRUNCATE command provides a faster mechanism to remove all rows from a table.
Usage
The following provides sample usage.
T To remove all but musicals from the table films, enter:
system(admin)=> DELETE FROM films WHERE kind <> 'Musical';
T To display the remaining rows, enter:
system(admin)=> SELECT * FROM films;
code| title| did| date_prod| kind| len
----+------|-----|----------+-----+------
UA501| West Side Story| 105| 1961-01-03| Musical| 02:32:00
TC901| The King and I| 109| 1956-08-11| Musical| 02:13:00
WD101| Bed Knobs and Broomsticks| 111| | Musical | 01:57:00
(3 rows)
-----+---------------------------|------|----------+-----------
(3 rows)
T To clear the table films, enter:
system(admin)=> DELETE FROM films;
DROP CONNECTION
Use the DROP CONNECTION command to drop a Netezza connection record from the sys-
tem table. For more information about configuring Netezza host access for clients, refer to
the Netezza System Administrator’s Guide.
Synopsis
Syntax for dropping a connection:
DROP CONNECTION [connection_number]
Inputs
The DROP CONNECTION command takes the following inputs:
Input Description
connection_ Specifies the connection number of the connection you wish to drop. To
number obtain the connection number, use the SHOW CONNECTION command
and review the CONNID field of the output for the associated number.
Outputs
The DROP CONNECTION command has the following output:
Output Description
ERROR: permission denied You do not have the proper permission to run this
command.
Description
The DROP CONNECTION command has the following characteristics:
Privileges Required
To use this command, you must be an administrator, or an administrator must have granted
you the Manage System privilege.
Common Tasks
Use this command to drop a Netezza connection.
Related Commands
See “SET CONNECTION” on page B-113.
See “CREATE USER” on page B-65.
See “ALTER USER” on page B-22.
See “SHOW CONNECTION” on page B-124.
DROP DATABASE
Use the DROP DATABASE command to remove an existing database.
Synopsis
Syntax dropping a database:
Inputs
The DROP DATABASE command takes the following inputs:
Input Description
Outputs
The DROP DATABASE command has the following output:
Output Description
DROP DATABASE: cannot be You cannot be connected to the database that you are
executed on the currently open about to remove. Connect to any other database, and run
database the command again.
DROP DATABASE: may not be You must finish the transaction in progress before you
called in a transaction block can call the command.
ERROR: Can't delete database The database contains objects such as user-defined
- num object(s) depend on functions or aggregates, or stored procedures, which are
objects in it dependencies for num objects defined in other data-
bases. This message follows up to 5 notice messages of
the named objects. You must resolve all the dependen-
cies by either dropping or altering the objects before you
can drop the database.
Description
The DROP DATABASE command has the following characteristics:
Privileges Required
You must be the database owner, an administrator, or an administrator must have given you
the appropriate object privileges, to use this command.
Common Tasks
Use the DROP DATABASE command to remove catalog entries for an existing database,
and to delete the directory containing the data.
Note: The DROP DATABASE command cannot be undone. You cannot execute this com-
mand while you are connected to the target database.
Related Commands
See “CREATE DATABASE” on page B-35 for information on how to create a database.
Usage
The following provides sample usage:
T To delete the database emp, enter:
system(admin)=> drop database emp;
DROP GROUP
Use the DROP GROUP command to remove a group.
Synopsis
Syntax for dropping a group:
DROP GROUP <name>
Inputs
The DROP GROUP command takes the following inputs:
Input Description
Outputs
The DROP GROUP command has the following output
Output Description
Description
The DROP GROUP command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges (including the Drop privilege), to use this command.
Common Tasks
Use the DROP GROUP command to remove the specified group from the database. The
drop group command does not remove the users in the group.
Related Commands
Use “CREATE GROUP” on page B-43 to add new groups.
Use “ALTER GROUP” on page B-6 to change a group's membership.
Usage
The following provides sample usage.
T To drop the group staff, enter:
system(admin)=> DROP GROUP staff;
Synopsis
Syntax for dropping a configuration:
DROP HISTORY CONFIGURATION <config-name>
Inputs
The DROP HISTORY CONFIGURATION command has the following inputs:
Input Description
Outputs
The DROP HISTORY CONFIGURATION command has the following outputs:
Output Description
ERROR: permission denied You must have Manage Security permission to drop a
configuration.
ERROR: <config-name> not The specified configuration name could not be found.
found.
Description
This command will not allow you to drop the current query history configuration. If you
want to drop the current configuration, you must SET HISTORY CONFIGURATION to
another configuration, restart the Netezza software, and then DROP HISTORY
CONFIGURATION.
After you drop a history configuration, any existing but unloaded history files in the staging
or loading area for that configuration will not be loaded. When the loading process attempts
to load those files, if it cannot find the associated history configuration, it moves the batch
files to the error directory ($NZ_DATA/hist/error).
Privileges Required
You must have Manage Security and Drop permissions to drop history configurations.
Related Commands
See the “CREATE HISTORY CONFIGURATION” on page B-45 to create a new
configuration.
See the “ALTER HISTORY CONFIGURATION” on page B-9 to modify configurations.
See the “SET HISTORY CONFIGURATION” on page B-115 to specify a configuration for
query history logging.
See the “SHOW HISTORY CONFIGURATION” on page B-125 to display information about
a configuration.
Usage
The following sample command drops the basic_hist history configuration:
SYSTEM(ADMIN)=> DROP HISTORY CONFIGURATION basic_hist;
DROP SEQUENCE
Use the DROP SEQUENCE command to drop a sequence.
Synopsis
Syntax for dropping a sequence:
DROP SEQUENCE <sequence name>
Inputs
The DROP SEQUENCE command takes the following inputs:
Input Description
Outputs
The DROP SEQUENCE command produces the following output:
Output Description
drop sequence The message that the system returns if the command is successful.
Description
The DROP SEQUENCE command has the following characteristics:
Privileges Required
The privileges to drop sequences are as follows:
X The admin user has all privileges on all user sequences. There is no need to grant any
privileges to the admin user.
X The owner of the database has all privileges on all user sequences in that database.
There is no need to grant any privileges to the owner.
X All others must have the Drop object privilege for a specific sequence or the Sequence
object class.
Common Tasks
Use the DROP SEQUENCE command to remove a sequence.
Related Commands
See “CREATE SEQUENCE” on page B-52 and “ALTER SEQUENCE” on page B-14 for
related sequence commands.
Usage
The following provides sample usage:
T To drop sequence1, enter:
system(admin)=> DROP SEQUENCE sequence1;
DROP SESSION
Use the DROP SESSION command to abort and remove a session from the Netezza.
Synopsis
Syntax for dropping a session:
DROP SESSION <session-id>
Inputs
The DROP SESSION command takes the following inputs:
Input Description
session_id A number identifying an active session. Unlike the other session com-
mands, the <session-id> is required for this command.
Outputs
The DROP SESSION command produces the following output:
Output Description
DROP SESSION The message that the system returns if the com-
mand is successful.
ERROR: id '<session-id>' does not cor- The specified session ID does not exist.
respond to an existing session.
ERROR: system session id '<session- The specified session ID refers to a system ses-
id>' cannot be aborted sion. Users cannot rollback transactions of
system sessions.
ERROR: access denied. You must have You do not have permission to rollback the
ABORT privileges to perform this action transaction of the session specified by <session-
id>.
ERROR: session abort failed for session The attempt to rollback the transaction in ses-
<session-id>; reason is '<reason>' sion <session-id> failed; the reason for the
failure is provided in the <reason> string.
Description
The DROP SESSION command aborts a session and removes it from the Netezza.
Privileges Required
You need no special privileges to drop your own session.
Each session is owned by a user. You must be granted ABORT privileges on the user in
order to drop the user’s sessions.
Common Tasks
Use the DROP SESSION command to stop a session.
Related Commands
See “ALTER SESSION” on page B-16 to change a session’s priority or to abort a transac-
tion in a session.
Usage
The following provides sample usage:
T To change the session from normal to critical, enter:
system(admin)=> ALTER SESSION SET PRIORITY TO critical;
DROP SYNONYM
Use the DROP SYNONYM command to drop a synonym.
Synopsis
Syntax for dropping a synonym:
DROP SYNONYM <synonym_name>;
Inputs
The DROP SYNONYM command takes the following inputs:
Input Description
Outputs
The DROP SYNONYM command produces the following output:
Output Description
DROP SYNONYM The message that the system returns if the command is successful.
Description
The DROP SYNONYM command has the following characteristics:
Privileges Required
You can drop your own synonyms. To drop other synonyms, you must be the admin user or
have been granted the Drop privilege for synonyms.
Common Tasks
Dropping unneeded synonyms.
Related Commands
See “CREATE SYNONYM” on page B-55 and “ALTER SYNONYM” on page B-18.
Usage
The following provides sample usage:
T To drop synonym pr, enter:
system(admin)=> DROP SYNONYM pr;
DROP TABLE
Use the DROP TABLE command to remove an existing table from a database.
Synopsis
Syntax dropping a table:
DROP TABLE <name> [, ...]
Inputs
The DROP TABLE command takes the following inputs:
Input Description
Outputs
The DROP TABLE command has the following output:
Output Description
ERROR: Relation “name” does Message returned if the specified table does not exist in
not exist the database.
Description
The DROP TABLE command has the following characteristics:
Privileges Required
You must be the table owner, an administrator, or an administrator must have given you the
appropriate object privileges (including the Drop privilege), to use this command.
Common Tasks
Use the DROP TABLE command to remove tables from a database.
Related Commands
Refer to the “CREATE TABLE” on page B-56 and “ALTER TABLE” on page B-19 com-
mands for information on how to create or modify tables.
Use the TRUNCATE command to empty a table rather than destroy it.
Usage
The following provides sample usage.
T To drop (delete) two tables, films and distributors, enter:
system(admin)=> drop table films, distributors;
DROP USER
Use the DROP USER command to remove a user.
Synopsis
Syntax for dropping a user:
DROP USER <name>
Inputs
The DROP USER command takes the following inputs:
Input Description
Outputs
The DROP USER command has the following output:
Output Description
ERROR: Drop user: user Message returned if the user name is not found.
“name” does not exist
DROP USER: User “name” Message returned if the user you want to drop owns any
owns objects, cannot be objects. You must first change the ownership of the
removed objects or drop them before you can drop the user.
Description
The DROP USER command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges (including the Drop privilege), to use this command.
Common Tasks
Use the DROP USER command to remove a specified user from the database. The com-
mand does not remove tables, views, or other objects owned by the user.
Note: If you attempt to drop a user that owns a database, you receive an error.
Related Commands
Use “CREATE USER” on page B-65 to add new users.
Use “ALTER USER” on page B-22 to change a user's properties.
Usage
The following provides sample usage.
T To drop the user account jonathan, enter:
SYSTEM(ADMIN)=> DROP USER jonathan;
DROP USER
T If you drop a user that owns objects:
SYSTEM(ADMIN)=> DROP USER jonathan;
ERROR: DROP USER: user "jonathan" owns objects, cannot be removed
DROP VIEW
Use the DROP VIEW command to remove an existing view from a database.
Synopsis
Syntax dropping a view:
DROP VIEW <name> [, ...]
Inputs
The DROP VIEW command takes the following inputs:
Input Description
Outputs
The DROP VIEW command has the following output:
Output Description
ERROR: Name: No such view Message returned if the specified view does not exist in
the database.
Description
The DROP VIEW command has the following characteristics:
Privileges Required You must be the owner of the view, an administrator, or an administra-
tor must have given you the appropriate object privileges (including the Drop privilege), to
use this command.
Common Tasks Use the DROP VIEW command to drop an existing view from a database.
Related Commands See “CREATE VIEW” on page B-68 for information on how to create
views.
Usage
The following provides sample usage.
T To remove the view kinds, enter:
system(admin)=> DROP VIEW kinds;
EXPLAIN
Use the EXPLAIN command to show a statement execution plan.
Synopsis
Syntax using the EXPLAIN command:
EXPLAIN [ VERBOSE ] <query>
EXPLAIN DISTRIBUTION <query>
EXPLAIN [ PLANTEXT ] <query>
EXPLAIN [ PLANGRAPH ] <query>
Inputs
The EXPLAIN command takes the following inputs:
Input Description
Input Description
Outputs
The EXPLAIN command has the following output:
Output Description
NOTICE: query plan: plan Message returned with an explicit query plan.
Description
The EXPLAIN command has the following characteristics:
Privileges Required
This command requires no special privileges.
Common Tasks
Use the EXPLAIN command to display the execution plan that the planner uses for a query.
X The execution plan displays how the table(s) referenced by the query will be scanned
(for example, by plain sequential scan). You can specify a verbose, HTML, or text
version.
X If multiple tables are referenced, the execution plan specifies what join algorithms it
will use to bring together the required tuples from each input table.
X If you use the DISTRIBUTION subcommand, the EXPLAIN command prints out the
distribution that the planner used on a SELECT statement in a CTAS command that did
not specify DISTRIBUTE ON().
A portion of the execution plan estimates the query execution cost, which is the planner's
guess at how long it will take to run the query (measured in milliseconds). Two numbers are
shown:
X The start-up time before the first tuple can be returned.
Use the verbose keyword to display the full internal representation of the plan tree, rather
than just a summary. The verbose command also sends the plan to the postmaster log file.
This option is useful for debugging.
Related Commands
None
Usage
The following provides sample usage.
T To display a query plan for a simple query on a table with a single int4 column and 128
rows, enter:
system(admin)=> EXPLAIN SELECT * FROM foo;
NOTICE: QUERY PLAN:
Seq Scan on foo (cost=0.00..2.28 rows=128 width=4)
EXPLAIN
T To display a query plan for a join between the emp and grp tables, enter:
system(admin)=> EXPLAIN select emp.* from emp,grp where
emp.id=grp.grp_id;
NOTICE: QUERY PLAN:
Hash Join (cost=0.01..0.04 rows=10000 width=28)
-> Seq Scan on emp (cost=0.00..0.01 rows=1000 width=28)
-> Hash (cost=0.01..0.01 rows=1000 width=4)
-> Seq Scan on grp (cost=0.00..0.01 rows=1000 width=4)
EXPLAIN
Synopsis
Syntax for generating express statistics:
GENERATE EXPRESS STATISTICS ON <tablename> [(column_name [, ... ])];
Inputs
The GENERATE EXPRESS STATISTICS command takes the following inputs:
Input Description
Outputs
The GENERATE EXPRESS STATISTICS command has the following output:
Output Description
GENERATE EXPRESS STATISTICS Message returned when the command has been
completed.
Description
The GENERATE EXPRESS STATISTICS command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the GenStats privi-
lege, to use this command.
Common Tasks
The GENERATE EXPRESS STATISTICS command collects statistics about the min/max,
null, and estimated dispersion values. The dispersion statistics are not as accurate as the
statistics that the system maintains when you run the GENERATE STATISTICS command.
They are, however, close approximations.
The GENERATE EXPRESS STATISTICS command produces statistics for only the table or
columns you specify.
The system processes full statistics ten columns at a time, whereas it processes express
statistics 30 columns at a time.
To estimate how long generating statistics will take divide the number of columns by 10 or
30, which tells you the raw number of passes (full table scans) that the system will make
against the data table.
Because full stats attempts to calculate the number of unique values in each column, it is
affected by the cardinality in a column and the data types involved.
Because express stats uses a hash to estimate the number of unique values in each col-
umn, it is less affected by the cardinality of a column.
Related Commands
Refer to “GENERATE STATISTICS” on page B-88.
Usage
The following provides sample usage.
T To generate statistics on the table cows, enter:
system(admin)=> GENERATE EXPRESS STATISTICS ON cows;
GENERATE EXPRESS STATISTICS
GENERATE STATISTICS
Use the GENERATE STATISTICS command to generate information on a database, table, or
individual column.
Note: As of Release 4.6, the GENERATE STATISTICS and GENERATE EXPRESS STATIS-
TICS commands perform the same tasks. If you use the GENERATE EXPRESS STATISTICS
command, it follows this same usage and behavior.
Synopsis
Syntax for generating statistics:
GENERATE STATISTICS [ ON <table> [( <column_name> [, ... ])] ];
Inputs
The GENERATE STATISTICS command takes the following inputs:
Input Description
Outputs
The GENERATE STATISTICS command has the following output:
Output Description
Description
The GENERATE STATISTICS command has the following characteristics:
Privileges Required
You must have the GenStats privilege to use this command. By default, the admin user can
run this command for any database or table. The owner of a database can also run the com-
mand for the database he owns or a specific table in that database. Other users can run the
command on any table that they own or to which they have List and GenStats privilege.
An admin user can also grant a non-admin user privilege to run generate statistics for all of
the tables in a database. The admin user must grant the non-admin user List privilege on
the table object in the system database and then GenStats privilege from the target
database.
Common Tasks
The GENERATE STATISTICS command collects statistics about each column’s proportion
of duplicate values, and the maximum and minimum values. The optimizer uses this infor-
mation to determine the most efficient way to execute a query.
You should run the GENERATE STATISTICS command when you initially load the table and
any time the table’s data has changed.
Because Netezza SQL uses the statistics collected during a generate statistics process to
efficiently perform calculations involving numeric data types, if the statistics are not avail-
able, or if they are out of date (by as little as a change in a single row of the table), then the
numeric calculations from that table are less efficient.
With no parameter, the GENERATE STATISTICS command processes every table in the cur-
rent database. With a parameter, the GENERATE STATISTICS command produces statistics
for only the table you specify.
After adding or deleting a large number of records, run the GENERATE STATISTICS com-
mand for the affected table. Doing so allows the query optimizer to make better choices in
planning user queries.
Related Commands
Refer to the nzreclaim command in the Netezza System Administrator’s Guide.
Usage
The following provides sample usage.
T To generate statistics on the table cows, column cnumber, enter:
system(admin)=> GENERATE STATISTICS ON cows (cnumber);
GENERATE STATISTICS
T To generate statistics on all the tables in database mydb, enter:
mydb(admin)=> GENERATE STATISTICS;
GENERATE STATISTICS
GRANT
Use the GRANT command to grant privileges to a user, a group, or all users.
Synopsis
Syntax for granting an object privilege:
GRANT <object_privilege> [, ...] ON <object> [, ...]
TO { PUBLIC | GROUP <group> | <username> } [ WITH GRANT OPTION ]
Syntax for granting an administration privilege:
GRANT <admin_privilege> [, ...]
TO { PUBLIC | GROUP <group> | <username> } [ WITH GRANT OPTION ]
Inputs
The GRANT command takes the following inputs:
Input Description
object Specifies the target of the privilege. You can further define an object
as one or more of the following object class types or one or more
named objects of these types:
{DATABASE | GROUP | USER | TABLE | VIEW | EXTERNAL TABLE |
SEQUENCE | SYNONYM | SYSTEM TABLE | SYSTEM VIEW | MAN-
AGEMENT TABLE | MANAGEMENT VIEW | FUNCTION | AGGREGATE
| PROCEDURE }
Note: TABLE represents user tables, not all tables (user, system, and
management). To grant privileges for system tables, specify the
SYSTEM TABLE object.
PUBLIC Specifies that the privileges are to be granted to all users, including
users that may be created later.
The public group may be thought of as an implicitly defined group
that always includes all users.
Note: Each user has a sum of privileges:
• Granted directly to the user.
• Granted to any group the user is presently a member of.
• Granted to public.
WITH GRANT Allows the user to grant the privilege to other users.
Outputs
The GRANT command has the following output
Output Description
Description
The GRANT command has the following features:
Privileges Required
Administrators can access all objects regardless of object privilege settings.
Users other than the creator of an object do not have any access privileges to the object
unless the creator grants permissions. There is no need to grant privileges to the creator of
an object, as the creator automatically holds all privileges. The creator could, however,
choose to revoke some of his own privileges for safety. Note that the ability to grant and
revoke privileges is inherent in the creator and cannot be revoked. The right to drop the
object is likewise inherent in the creator, and cannot be granted or revoked. If you grant
permission to other users to manage objects, make sure that they also have the LIST per-
mission to view those objects.
Common Tasks
Use the GRANT command to give specific object or administrator permissions to one or
more users or groups of users. The system adds the permissions you grant to whatever per-
missions the user or group already has.
Note: To grant privileges to only a few columns, you must create a view having the desired
columns and then grant privileges to that view. You can use the \dp command to obtain
information about privileges on existing objects.
Related Commands
Use “REVOKE” on page B-96 to revoke access privileges.
Usage
The following provides sample usage.
T To grant the insert privilege to all users on the user table films, enter:
system(admin)=> GRANT INSERT ON films TO PUBLIC;
The table
INSERT
Use the INSERT command to add new rows to a table.
Synopsis
Syntax for using the INSERT command:
INSERT INTO <table> [ ( <column> [, ...] ) ]
{ DEFAULT VALUES | VALUES ( <expression> [, ...] ) | SELECT <query>
};
Inputs
The INSERT command takes the following inputs:
Input Description
DEFAULT VALUES Specifies that all columns be filled by nulls or by values you speci-
fied when you created the table using default clauses.
query Specifies a valid query. Refer to the SELECT command for a further
description of valid arguments.
Outputs
The INSERT command has the following output:
Output Description
insert 0 # Message returned if zero or more rows were inserted. The # stands for the
number of rows inserted.
Error: When you INSERT data to a table from an external table, the Netezza veri-
Reload fies that the null setting for each column is the same between the tables. If
allow the null settings do not match, the INSERT operaton fails and displays
NULLs mis- information about the columns which did not have matching null settings.
match
<table>
<col>
Output Description
Error: Large Message returned if the table reaches its maximum size (64 GB, unless
table size large table support is enabled).
limit on
<part>,
SPU <id>.
Description
The INSERT command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
You must have the INSERT privilege to append a table.
You must have SELECT privilege on any table specified in a where clause.
Common Tasks
Use the INSERT command to insert new rows into a table. You can insert a single row at a
time, or several rows as a result of a query. You can list the columns in the target list in any
order.
The system inserts a declared default or null value for any columns not present in the target
list. The system rejects the new column if you insert a null into a column declared not null.
If the expression for each column is not of the correct data type, the system attempts auto-
matic type coercion.
Related Commands
None
Usage
The following provides sample usage.
T To insert a single row into the table films, enter:
system(admin)=> INSERT INTO films VALUES
('UA502','Bananas',105,'1971-07-13','Comedy',INTERVAL '82
minute');
T In this sample, the last column len is omitted, and therefore the last column assumes
the default value of null:
system(admin)=> INSERT INTO films (code, title, did, date_prod,
kind)
VALUES ('T_601', 'Yojimbo', 106, DATE '1961-06-16', 'Drama');
T To insert several rows into the table films from the table tmp, enter:
system(admin)=> INSERT INTO films SELECT * FROM tmp;
RESET
Use the RESET command to restore the value of a runtime parameter to its default value.
Synopsis
Syntax resetting a parameter:
RESET variable
Inputs
The RESET command takes the following inputs:
Input Description
variable Specifies the name of a runtime parameter. Refer to the SET command for a
list.
Outputs
The RESET command has the following output:
Output Description
ERROR: ‘“Is not a valid option Message returned if the system does not recognize the
name. variable that you specify.
Description
The RESET command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the RESET command to restore runtime parameters to their default values.
Related Commands
The RESET command is an alternate form for the set variable to default command.
Usage
The following provides sample usage.
T To set DateStyle to its default value, enter:
system(admin)=> RESET DateStyle;
T To set Geqo to its default value, enter:
system(admin)=> RESET geqo;
REVOKE
Use the REVOKE command to remove access privileges for a user, a group, or all users.
Synopsis
Syntax for revoking an object privilege:
REVOKE [ GRANT OPTION FOR ] <object_privilege> [, ...]
ON <object> [, ...]
FROM { PUBLIC | GROUP <groupname> | <username> }
Syntax for granting an administration privilege:
REVOKE [ GRANT OPTION FOR ] <admin_privilege> [, ...]
FROM { PUBLIC | GROUP <groupname> | <username> }
Inputs
The REVOKE command takes the following inputs:
Input Description
object Specifies the target of the privilege. You can further define an object
as one or more of the following object class types or one or more
named objects of these types:
{DATABASE | GROUP | USER | TABLE | VIEW | EXTERNAL TABLE |
SEQUENCE | SYNONYM | SYSTEM TABLE | SYSTEM VIEW | MAN-
AGEMENT TABLE | MANAGEMENT VIEW | FUNCTION | AGGREGATE
| PROCEDURE }
Note: TABLE represents user tables, not all tables (user, system, and
management). To revoke privileges for system tables, specify the
SYSTEM TABLE object.
Input Description
PUBLIC Specifies that the privileges are to be revoked to all users, including
users that may be created later.
The public group may be thought of as an implicitly defined group
that always includes all users.
Note: Each user has a sum of privileges:
• Granted directly to the user.
• Granted to any group the user is presently a member of.
• Granted to public.
Outputs
The REVOKE command has the following output
Output Description
Description
The REVOKE command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command. If you are the creator of an object, you can revoke
previously granted permissions.
Common Tasks
Use the REVOKE command to revoke permissions from one or more users or groups of
users.
You can use the \dp internal slash command to obtain information about privileges on exist-
ing objects. For more information about slash commands, refer to the Netezza System
Administrator’s Guide.
Note: Privileges granted to a group cannot be revoked from individual members of the
group.
Related Commands
See “GRANT” on page B-90 for a description of the privilege types.
Usage
The following provides sample usage.
T To revoke the insert privilege for the group public on the table films, enter:
system(admin)=> REVOKE INSERT ON films FROM PUBLIC;
ROLLBACK
Use the ROLLBACK command to abort the current transaction.
Synopsis
Syntax for rolling back the current transaction:
ROLLBACK [ WORK | TRANSACTION ]
Inputs
The ROLLBACK command takes the following inputs:
Input Description
TRANSACTION
Outputs
The ROLLBACK command has the following output:
Output Description
Description
The ROLLBACK command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the ROLLBACK command to abort the current transaction. The system discards all
changes made by the current transaction.
Related Commands
See “COMMIT” on page B-30 to successfully terminate a transaction.
Usage
The following provides sample usage.
T To abort all changes, enter:
system(admin)=> ROLLBACK WORK;
SELECT
Use the SELECT command to retrieve rows from a table or view.
Synopsis
Syntax for using the SELECT command:
SELECT [ ALL | DISTINCT ] * | <column> [ AS <output_name> ]
<expression> [ AS <output_name> ] [, ...]
[ FROM <from_item> [, ...] ]
[ WHERE <condition> ]
[ GROUP BY <expression> [, ...] ]
[ HAVING <condition> [, ...] ]
[ { UNION | INTERSECT | EXCEPT | MINUS }[ ALL| DISTINCT ]
SELECT
[ ORDER BY expression [ ASC | DESC | USING <operator>
[NULLS {FIRST | LAST}][, ...] ]
[ LIMIT { <count> | ALL } ]
where from_item can be:
table_name
[ [ AS ] <alias> [ ( <column_alias_list> ) ] ]
|
( <select> )
[ AS ] <alias> [ ( <column_alias_list> ) ]
|
<from_item> [ NATURAL ] <join_type> <from_item>
[ ON <join_condition> | USING ( <join_column_list> ) ]
Inputs
The SELECT command takes the following inputs:
Input Description
join_type Specifies one of the following: [ inner ] join, left [ outer ] join, right [
outer ] join, full [ outer ] join, or cross join.
Note: For inner and outer join types, you must include exactly one of
natural, on join_condition, or using ( join_column_list ). For the cross
join type, none of these items may appear.
output_name Specifies another name for an output column using the AS clause.
You typically use this name to label a column for display. You can
also use it to refer to the column's value in order by and group by
clauses.
Note: You cannot use the output_name input in the where or having
clauses; write out the expression instead.
select Specifies a select command that can include all features except the
order by, for update, and limit clauses.
If you parenthesize the select, you can include the order by, for
update, and limit clauses.
When you include a sub-select in the from clause, the sub-select
acts as though its output were created as a temporary table for the
duration of this single select command.
Note: You must enclose the sub-select in parentheses, and provide an
alias for it.
Outputs
The SELECT command has the following output:
Output Description
ROWS Returns the complete set of rows resulting from the query.
Description
The command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command. You must have the Select privilege to a table to
read its values.
Note: As of Release 4.0, in order to select data from an external table, you must have the
Select privilege on the EXTERNAL TABLE class.
While connected to the “system” database, you can grant the privilege as follows:
GRANT SELECT ON EXTERNAL TABLE to user;
The example gives all users the ability to select. If you want to restrict the privilege to one
user, you would replace “user” with the specific user’s name.
To read about object privileges and object classes, refer to the Netezza Administrator’s
Guide, Chapter 8, Establishing Security and Access Control. To understand how privileges
are assigned based upon the database you are connected to, read the section, Understand-
ing Object Privileges.
Common Tasks
The SELECT command returns rows from one or more tables. Use select to choose among
rows that satisfy the where condition, and return rows based upon additional criteria you
specify within the command. If you omit the where condition, the SELECT command
chooses from all rows.
The system forms output rows by computing the select output expressions for each selected
row.
X You can include * in the output list as a shorthand way of indicating all columns of
selected rows. You can also indicate table_name.* as a shorthand for the columns com-
ing from a specific table. “Querying a Table” on page 2-15 describes functions that
you can use within a SELECT command.
X You can use the keyword distinct to eliminate duplicate rows from the result. The all
keyword (the default) returns all candidate rows, including duplicates.
Select Clauses
FROM — The FROM clause specifies one or more source tables for the SELECT command.
If you specify multiple sources, the result is the Cartesian product of all the rows in all the
sources. Usually, though, you add qualifying conditions to restrict the rows the system
returns to a small number of the Cartesian product.
You can parenthesize a subselect command within a from clause. Using a subselect com-
mand is the only way to get multiple levels of grouping, aggregation, or sorting in a single
query.
Note: You must specify an alias for the subselect command.
A FROM item can be a join clause, which combines two simpler from items. Use parenthe-
ses, if necessary, to determine the order of nesting.
WHERE — This clause has the following general form:
WHERE boolean_expr
The boolean_expr portion of the clause can consist of any expression that produces a bool-
ean value.In many cases, you use the expression as follows:
expr cond_op expr
or
log_op expr
where:
X cond_op can be one of: =, <, <=, >, >= or <>, a conditional operator like all, any, in,
like, or a locally defined operator.
X log_op can be one of: and, or, not. select ignores all rows for which the where condition
does not return true.
GROUP BY — Allows you to divide a table into groups of rows that match one or more val-
ues.Specifies a grouped table derived by applying the clause:
GROUP BY expression [, ...]
The group by clause condenses, into a single row, all selected rows that share the same val-
ues for the grouped columns. The system computes aggregate functions across all rows
making up each group, producing a separate value for each group (whereas without group
by, an aggregate produces a single value computed across all the selected rows). When you
include the group by clause, the SELECT command output expression(s) cannot refer to
ungrouped columns except within aggregate functions, because there would be more than
one possible value to return for an ungrouped column.
A group by value can be:
X An input column name.
X The name or ordinal number of an output column (select expression).
X An arbitrary expression formed from input-column values. In case of ambiguity, the sys-
tem interprets a group by name as an input-column name rather than an output
column name.
HAVING — The optional having clause has the general form:
HAVING boolean_expr
where boolean_expr is the same as specified for the where clause.
The HAVING clause specifies a grouped table derived by the elimination of rows that do not
satisfy the boolean_expr.
The having clause is different from the where clause:
X The where clause filters individual rows before application of group by.
X The having clause filters group rows created by group by.
Each column referenced in boolean_expr must unambiguously reference a grouping col-
umn, unless the reference appears within an aggregate function.
In a grouping select, the having clause can only reference expressions that are single-val-
ued within a group. That is, you can only reference group fields, aggregates, or single-
valued expressions derived from group fields or aggregates (which must include constants).
For example, to return grp and counts of grps with more than four members, enter:
SELECT grp, count(id) AS n FROM emp GROUP BY grp HAVING n > 4
In a non-grouping select where the select is conceptually grouped by zero group fields, you
can only reference aggregates or expressions that are single-valued.
For example to return no rows if there are four or fewer employees in emp, or one row with
the count if there are more than four employees in emp, enter:
SELECT count(id) AS n FROM emp HAVING n > 4
UNION — Operator causes the system to compute the collection of rows returned by the
queries. Eliminates duplicate rows unless you specify the ALL keyword.
table_query UNION [ ALL ] table_query
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
[ LIMIT { COUNT | ALL } ]
[ OFFSET start ]
where table_query specifies any select expression without an ORDER BY, FOR UPDATE, or
LIMIT clause.
Note: If you enclose a sub-expression in parentheses, you can include ORDER BY and
LIMIT clauses. If you do not include parentheses, the clauses are taken to apply to the
result of the union, not to its right-hand input expression.
The UNION operator computes the collection (set union) of the rows returned by the que-
ries involved. The two selects that represent the direct operands of the union must produce
the same number of columns, and corresponding columns must be of compatible data
types.
The result of union does not contain any duplicate rows unless you specify the ALL option.
The ALL option prevents elimination of duplicates.
Multiple union operators in the same SELECT command are evaluated left to right, unless
you indicate otherwise by using parentheses.
ORDER BY — Clause allows you to sort returned rows in the order that you specify. The first
row of each set is unpredictable unless you include the order by clause to ensure an order
to the rows.
You can add the keyword DESC (descending) or ASC (ascending) after each column name
in the order by clause. If you do not specify desc, asc is assumed by default. Alternatively,
you can specify a specific ordering operator name:
X ASC is equivalent to using <
X DESC is equivalent to using >
The null value sorts higher than any other value in a domain:
X With ascending sort order, nulls sort at the beginning.
X With descending sort order, nulls sort at the end.
You can use the NULLS FIRST | NULLS LAST keywords to specify a sorting order for null
data. If your data contains nulls, Netezza SQL considers all null values to be lower than any
non-null value. This means that for an ascending sort, nulls appear first in the output, or
for a descending sort, they appear last.
LIMIT — Clause returns a subset of the rows produced by your query.
LIMIT { COUNT | ALL }
where count specifies the maximum number of rows to return.
The LIMIT clause allows you to retrieve a portion of the rows generated by the query. If you
designate a limit, the system returns only that number of rows.
When using the LIMIT option, use an ORDER BY clause that constrains the result rows into
a unique order. Otherwise you can get an unpredictable subset of the query's rows; for
example, you may be asking for the tenth through twentieth rows, but tenth through twenti-
eth in what order? You do not know what order unless you specify the order by clause.
The query optimizer takes the LIMIT clause into account when generating a query plan, so
you are likely to get different plans (yielding different row orders) depending on what you
use for limit. Using different limit values to select different subsets of a query result gives
inconsistent results unless you enforce a predictable result ordering with the order by
clause. SQL does not promise to deliver the results of a query in any particular order unless
you use the order by clause to constrain the order.
Note: If you specify the LIMIT clause, and have also specified a rowset limit, the system
returns whichever number is lower.
INTERSECT — Combines the results of two queries into a single result that comprises all
the rows common to both queries. For more information, see “Using the INTERSECT Oper-
ation” on page 2-19.
EXCEPT or MINUS — Finds the difference between the two queries and the result com-
prises the rows that belong only to the first query. For more information, see “Using the
EXCEPT Operation” on page 2-19
CROSS JOIN and INNER JOIN — Produces a simple Cartesian product, the same as you
would get if you listed the two items at the top level of FROM.
The cross join and inner join on (true) types are equivalent; no rows are removed by
qualification.
Note: These join types are just a notational convenience. You can accomplish the same
results using the from and where clauses.
LEFT OUTER JOIN — Returns all rows in the qualified Cartesian product (that is, all com-
bined rows that pass its on condition), plus one copy of each row in the left-hand table for
which there was no right-hand row that passed the on condition.
Note: The system considers only the join's own on or using condition to determine those
rows that have matches. It applies outer on or where conditions afterwards.
RIGHT OUTER JOIN — Returns all the joined rows, plus one row for each unmatched right-
hand row (extended with nulls on the left).
Note: This is just a notational convenience. You could convert it to a left outer join by
switching the left and right inputs.
FULL OUTER JOIN — Returns all the joined rows, plus one row for each unmatched left-
hand row (extended with nulls on the right), plus one row for each unmatched right-hand
row (extended with nulls on the left).
Note: For all the join types except cross join, you must write exactly one of on join_condi-
tion, using (join_column_list), or natural:
X on is the most general case: you can write any qualification expression involving the
two tables you wish to join.
X A using column list ( a, b, ... ) is shorthand for the on condition left_table.a = right_
table.a and left_table.b = right_table.b ... using implies that only one of each pair of
equivalent columns is to be included in the join output, not both.
X natural is shorthand for a using list that mentions all similarly-named columns in the
tables.
Related Commands
None
Usage
The following provides sample usage.
T To join the table films with the table distributors, enter:
system(admin)=> SELECT f.title, f.did, d.name, f.date_prod, f.kind
FROM distributors d, films f WHERE f.did = d.did;
title |did|name|date_prod|kind
--------------------------+-----+------------------+-----------+-------
The Third Man|101|British Lion|1949-12-23|Drama
The African Queen|101|British Lion|1951-08-11|Romantic
Une Femme est une Femme|102|Jean Luc Godard|1961-03-12|Romantic
Vertigo|103|Paramount|1958-11-14|Action
Becket |103|Paramount|1964-02-03|Drama
48 Hours|103|Paramount|1982-10-22|Action
War and Peace|104|Mosfilm|1967-02-12|Drama
West Side Story|105|United Artists|1961-01-03|Musical
Bananas|105|United Artists|1971-07-13|Comedy
Yojimbo|106|Toho|1961-06-16|Drama
There’s a Girl in my Soup|107|Columbia|1970-06-11|Comedy
Taxi Driver|107|Columbia|1975-05-15|Action
Absence of Malice|107|Columbia|1981-11-15|Action
Storia di una donna|108|Westward|1970-08-15|Romantic
The King and I|109|20th Century Fox|1956-08-11|Musical
Das Boot|110|Bavaria Atelier|1981-11-11|Drama
Bed Knobs and Broomsticks|111|Walt Disney||Musical
(17 rows)
T To sum the column len of all films and group the results by kind, enter:
system(admin)=> SELECT kind, SUM(len) AS total FROM films GROUP BY
kind;
kind|total
----+-------
Action|07:34
Comedy|02:58
Drama|14:28
Musical|06:42
Romantic|04:38
(5 rows)
T To sum the column len of all films, group the results by kind, and show those group
totals that are less than 5 hours, enter:
system(admin)=> SELECT kind, SUM(len) AS total FROM films GROUP BY
kind HAVING SUM(len) < INTERVAL '5 HOUR';
kind| total
----+------
Comedy| 02:58
Romantic| 04:38
(2 rows)
T To sort the individual results according to the contents of the second column (name),
use either example:
system(admin)=> SELECT * FROM distributors ORDER BY name;
system(admin)=> SELECT * FROM distributors ORDER BY 2;
did| name
---|---------------------
109| 20th Century Fox
110| Bavaria Atelier
101| British Lion
107| Columbia
102| Jean Luc Godard
113| Luso Films
104| Mosfilm
103| Paramount
106| Toho
105| United Artists
111| Walt Disney
112| Warner Bros.
108| Westward
(13 rows)
T To show how to obtain the union of the tables distributors and actors, restricting the
results to those that begin with letter W in each table, enter:
system(admin)=> SELECT distributors.name
FROM distributors
WHERE distributors.name LIKE 'W%';
UNION
SELECT actors.name
FROM actors
WHERE actors.name LIKE 'W%';
Walt Disney
Walter Matthau
Warner Bros.
Warren Beatty
Westward
Woody Allen
Note: Because only distinct rows are wanted, the all keyword is omitted.
SET
Use the SET command to set or change a runtime parameter, the time zone, or system
limits.
Synopsis
Syntax for using the SET command:
SET <variable> { TO | = } { value | 'value' | DEFAULT }
SET TIME ZONE { 'timezone' | LOCAL | DEFAULT }
Inputs
The SET command takes the following inputs:
Input Description
Outputs
The SET command has the following output:
Output Description
ERROR: not a valid option Message returned if the parameter you try to set does
name: name not exist.
ERROR: permission denied Message returned if you do not have proper access.
Note: You must be an administrator to have access to
certain settings.
ERROR: name can only be set Message returned for certain parameters that are fixed
at start-up once the server is started.
Description
The SET command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the SET command to set or change runtime configuration parameters. The command
allows you to change parameters for the duration of the database connection.
You can alter the following parameters:
DATESTYLE — A value for set datestyle can include an output style, a substyle, or an out-
put and substyle separated by a comma.
Output Styles — Choose the date/time representation style. (Two separate settings are
made: the default date/time output and the interpretation of ambiguous input.)
The following are date/time output styles:
X ISO — Use ISO 8601-style dates and times (YYYY-MM-DD HH:MM:SS). This is the
default.
X SQL — Use Oracle-style dates and times.
X German — Use dd.mm.yyyy for numeric date representations.
Substyles — The following two options determine both a substyle of the “SQL” output for-
mats and the preferred interpretation of ambiguous date input.
X European — Use dd/mm/yyyy for numeric date representations.
X NonEuropean/US — Use mm/dd/yyyy for numeric date representations.
You can initialize the date format by setting the pgdatestyle environment variable. If pgdat-
estyle is set in the frontend environment of a client based on libpq, libpq automatically sets
datestyle to the value of pgdatestyle during connection start-up.
The datestyle option is really only intended for porting applications. To format your date/
time values to choice, use the to_char family of functions.
RANDOM_SEED — Sets the internal seed for the random number generator.
value — The random function uses this value. You can specify floating-point numbers
between 0 and 1, which are then multiplied by 2(31)-1. (This product will silently overflow
if a number outside the range is used.)
You can also set the seed by invoking the setseed function: select setseed(value);
Related Commands
Use “SHOW” on page B-121 to show the current setting of a parameter.
Usage
The following provides sample usage.
T To set the style of date to the European convention, enter:
SET DATESTYLE TO European;
T To set the threshold to 20 percent, enter:
SET SYSTEM DEFAULT MATERIALIZE THRESHOLD 20;
SET AUTHENTICATION
Use the SET AUTHENTICATION command to specify how the Netezza authenticates users
who log on to the system. Authentication verifies that the user has entered a correct and
known username-password combination when logging on to the Netezza system.
Note: To access a database, the user must also be defined by a CREATE USER statement,
and must have been granted access rights to a particular database. For more information
about configuring and using LDAP authentication, refer to the Netezza System Administra-
tor’s Guide.
Synopsis
Syntax for setting authentication.
SET AUTHENTICATION { LOCAL | LDAP [(<ldap-config>)] }
Syntax for “ldap-config” when you choose LDAP authentication.
BASE <base-string>
SERVER <server>
[ VERSION <version-number> ]
[ BINDDN { bind-string | NONE } ]
[ BINDPW { bind-password | NONE } ]
[ PORT <port> ]
[ SCOPE { SUB | ONE | BASE } ]
[ SSL { ON | OFF } ]
[ ATTRNAME <attrname-string>]
[ NAMECASE { LOWERCASE | UPPERCASE }]
Inputs
The SET AUTHENTICATION command takes the following inputs:
Input Description
attrname-string The attribute name, defined in the LDAP schema, for the field contain-
ing the user name. The default is “cn”.
Input Description
base-string The Distinguished Name (DN) within the LDAP namespace where
username searches start. An example follows.
dc=example,dc=org
bind-password The password that accompanies the <bind-string> for binding to the
LDAP server.
bind-string The Distinguished Name to use when binding to the LDAP server. A
bind string is optional. This clause is typically not defined for perform-
ing anonymous LDAP look-ups.
LOCAL The Netezza uses local authentication. When a user connects to the
Netezza system, the system uses the username and password defined
by the CREATE USER command to authenticate.
Note: This authentication mode is also compatible with releases before
Release 4.5.
LOWERCASE | Indicates whether the LDAP server stores the user name in lowercase
UPPERCASE or uppercase.
SSL Default is OFF. If ON, SSL is used when contacting the LDAP server.
port The port number to use when connecting to the LDAP server. The
default is 389.
Outputs
The SET AUTHENTICATION command has the following output:
Output Description
ERROR: permission denied Message returned if you do not have proper access.
Note: You must have the Manage System privilege to set
authentication.
Description
The SET AUTHENTICATION command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the Manage System
privilege, to use this command.
Implementation Notes
The SET AUTHENTICATION command performs as follows.
X It verifies that the user has the correct access rights to perform the operation.
X When you change the authentication from LOCAL to LDAP, the system does the
following:
S Creates a new Pluggable Authentication Module (PAM) file for the new authentica-
tion settings, /etc/pam.d/netezza_nps.
S Modifies the file /nz/data/pg_hba.conf, changing the authorization to LDAP. (The
pg_hba.conf file controls client authentication.)
S Copies the /etc/ldap.conf file to /nz/data/config/ldap.conf.orig and then updates the
/etc/ldap.conf file for the changes in the command.
X When you change the authentication from LDAP to LOCAL, the system does the
following:
S Changes the LDAP configuration files by copying ldap.conf.orig to ldap.conf.
S Deletes the PAM file /etc/pam.d/netezza_nps.
S Modifies the file /nz/data/pg_hba.conf, changing the authorization to MD5 (the
default).
X When the authentication is LDAP, you can issue additional or subsequent SET
AUTHENTICATION LDAP commands to update the LDAP configuration parameters.
The system changes the LDAP configuration file using the options that you specify in
the command. Note that the command does not retain settings from any previous SET
AUTHENTICATION commands; you must specify the command and all of the options
that you need when you issue the command.
X The system updates the catalog to record the authentication configuration you have
chosen. The system stores the parameters you enter in the _t_systemdef system table.
The _t_systemdef system table stores data using a “Tag” and “value” scheme. The sys-
tem stores each option you define with the SET AUTHENTICATION command in a
separate row in the table, using a predefined tag and the option value. Rows for LDAP
authentication follow.
Note: If you specify LOCAL authentication, the table contains only one row which
includes the tag “AUTHENTICATION METHOD” and the value “local.” The following
example shows a _t_systemdef table for an LDAP configuration.
Related Commands
See “SHOW AUTHENTICATION” on page B-122.
See “CREATE USER” on page B-65.
See “ALTER USER” on page B-22.
Usage
The following provides sample usage.
set authentication ldap base 'dc=netezza,dc=com' server
'ldapserver.netezza.com' port '389' version '3' binddn 'ldapreader'
scope 'base' ssl 'off' attrname 'cn' namecase 'lowercase';
SET CONNECTION
Use the SET CONNECTION command to define the Netezza host access records for
Netezza clients. The host access records define how Netezza clients connect to the Netezza
system, using either secured or unsecured connections. This command allows you to insert
and delete rows from the system table. For a complete description of how to configure SSL
connections for Netezza client users, refer to the Netezza System Administrator’s Guide.
Synopsis
Syntax for setting a connection.
SET CONNECTION { LOCAL | HOST | HOSTSSL | HOSTNOSSL }
DATABASE { '<database_name>' | 'ALL'}
[ IPADDR '<ip_address>' ]
[ IPMASK '<ip_address_mask>' ]
Inputs
The SET CONNECTION command takes the following inputs:
Input Description
LOCAL Specifies that you are defining a connection record for users who con-
nect to the Netezza using UNIX sockets.
HOST Specifies that you are defining a connection record for users who con-
nect to the Netezza over IP using either secured or unsecured SSL
connections.
HOSTSSL Specifies that you are defining a connection record for users who con-
nect to the Netezza over IP using only secured SSL connections.
HOSTNOSSL Specifies that you are defining a connection record for users who con-
nect to the Netezza over IP using only unsecured SSL connections.
database_name | Specifies the database_name to which the client users at the specified
ALL IP address or range have connection access. Specify ALL to match on
all databases. Note that the value ALL indicates that the user can
attempt to connect to any of the databases on the Netezza system;
however, the user account object permissions control the database
objects that the user is permitted to view.
ip_address Specifies the IP address for the client system; applies to HOST,
HOSTSSL, and HOSTNOSSL connection types.
ip_address_ Specifies the IP address mask for the client system; applies to HOST,
mask HOSTSSL, and HOSTNOSSL connection types.
Outputs
The SET CONNECTION command has the following output:
Output Description
ERROR: permission denied Message returned if you do not have proper access.
Note: You must have the Manage System privilege to set
a connection.
Description
The SET CONNECTION command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the Manage System
privilege, to use this command.
Common Tasks
Specify which Netezza system connections should use an SSL connection.
Related Commands
See “CREATE USER” on page B-65.
See “ALTER USER” on page B-22.
See “SHOW CONNECTION” on page B-124.
See “DROP CONNECTION” on page B-71.
Usage
The following provides sample usage.
SET CONNECTION HOST DATABASE 'ALL' IPADDR '192.168.0.0' IPMASK
'255.255.255.0';
Synopsis
Syntax for setting the history configuration:
SET HISTORY CONFIGURATION <config-name>
Inputs
The SET HISTORY CONFIGURATION command has the following inputs:
Input Description
Outputs
The SET HISTORY CONFIGURATION command has the following outputs:
Output Description
ERROR: permission denied You must have Manage Security permission to set the
query history configuration.
ERROR: <config-name> not The specified configuration name could not be found.
found.
Description
This command sets the history configuration to the one that will take effect after the next
Netezza software restart. After the restart, the history loader process will attempt to load
any existing history data in the staging or loading area for the previous configuration. This
load process could fail if the previous configuration was dropped.
Privileges Required
You must have Manage Security permissions to set query history configurations.
Related Commands
See the “CREATE HISTORY CONFIGURATION” on page B-45 to create a new
configuration.
See the “ALTER HISTORY CONFIGURATION” on page B-9 to modify configurations.
See the “DROP HISTORY CONFIGURATION” on page B-75 to drop configurations.
See the “SHOW HISTORY CONFIGURATION” on page B-125 to display information about
a configuration.
Usage
The following sample command sets the configuration to the all_hist configuration:
SYSTEM(ADMIN)=> SET HISTORY CONFIGURATION all_hist;
SET SESSION
Use the SET SESSION command to set the characteristics of the current SQL-transaction.
Synopsis
Syntax for setting a session:
SET SESSION { READ ONLY | READ WRITE }
Inputs
The SET SESSION command takes the following inputs:
Input Description
read only During the session, allows a user to read a database but not write to it. The
system returns an error if the user attempts to write to the database. The user
can create and write to temporary tables.
read write Allows a user to read and update a database. This is the default setting.
Outputs
The SET SESSION command has the following output:
Output Description
ERROR: Read-only session, Message returned if read only has been specified and
cannot process this request the user attempts to write to the database.
Description
The SET SESSION command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Related Commands
See “SET SYSTEM DEFAULT” on page B-117.
Usage
The following provides sample usage.
T To set a session to read-only, enter:
system(admin)=> SET SESSION READ ONLY;
Synopsis
Syntax for setting the system default:
SET SYSTEM DEFAULT
[SESSIONTIMEOUT | ROWSETLIMIT | QUERYTIMEOUT ] TO [number |
UNLIMITED ]
[DEFPRIORITY | MAXPRIORITY ] TO [critical | high | normal | low |
SET SYSTEM DEFAULT MATERIALIZE [REFRESH] THRESHOLD TO <number>;
Inputs
The SET SYSTEM DEFAULT command takes the following inputs:
Input Description
DEFPRIORITY Specifies the default priority for the system. The valid priorities are
critical, high, normal, low.
QUERYTIMEOUT Specifies the amount of time a query can run before the system
sends the administrator a message. You can specify from 1 to
2,147,483,647 minutes or zero for unlimited.
Note that to receive a message, you must enable the RunAwayQuery
event rule. For more information, see the the <Emphasis>Netezza
Performance Server System Guide.
ROWSETLIMIT Specifies the number of rows a query can return. You can specify
from 1 to 2,147,483,647 rows or zero for unlimited.
SESSIONTIMEOUT Specifies the amount of time a session can be idle before the system
terminates it. You can specify from 1 to 2.147,483,647 minutes or
zero for unlimited.
Outputs
The SET SYSTEM DEFAULT command has the following output:
Output Description
SET SYSTEM DEFAULT The message that the system returns if the command is
successful.
Description
The SET SYSTEM DEFAULT command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the SET SYSTEM DEFAULT command to change the system defaults for session idle
timeout, rowset limits, and query timeout.
The system calculates the values at session startup and them remain in effect for the dura-
tion of the session.
You can also set session timeout, rowset limits, and query timeout at the user and/or group
level. The runtime resolution for these values is:
X The value assigned to the user
X The minimum values assigned to groups of which the user is a member
X The default system value.
MATERIALIZE REFRESH THRESHOLD — Sets the threshold percentage of unsorted data
in a materialized view. When you refresh a base table, all associated materialized views that
have exceeded this threshold are refreshed.
Related Commands
Use “SHOW” on page B-121 to show the current setting of a parameters. See the Netezza
System Administrator’s Guide for more information.
Usage
The following provides sample usage.
T To set the system default timeout to five hours (300 minutes), enter:
system(admin)=> SET SYSTEM DEFAULT SESSIONTIMEOUT TO 300;
SET TRANSACTION
Use the SET TRANSACTION command to set the transaction characteristics of the current
session.
Synopsis
Syntax for setting a transaction:
SET TRANSACTION {READ ONLY | READ WRITE}
SET TRANSACTION ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED |
REPEATABLE READ | SERIALIZABLE }
Inputs
The SET TRANSACTION command takes the following inputs:
Input Description
READ ONLY During the session, allows a user to read a database but not write
to it. The system returns an error if the user attempts to write to
the database. The user can create and write to temporary tables.
READ WRITE Allows a user to read and update a database. This is the default
setting.
READ UNCOMMITTED Netezza SQL allows the syntax, but does not support these isola-
READ COMMITTED tion levels.
REPEATABLE READ
SERIALIZABLE Specifies that the current transaction can only see rows commit-
ted before the first query or data-modification statement was
executed in this transaction.
Outputs
The SET TRANSACTION command has the following output:
Output Description
Description
The SET TRANSACTION command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
The SET TRANSACTION isolation level command sets the transaction isolation level. The
isolation level of a transaction determines what data the transaction can see when other
transactions are running concurrently.
Netezza SQL supports the syntax for all isolation levels, but currently implements only the
serializable level.
Serializable means that the current transaction can only see rows committed before the
first query or data-modification statement was executed in this transaction. Intuitively, seri-
alizable means that two concurrent transactions leave the database in the same state as if
the two had been executed strictly after one another in either order.
Related Commands
None.
Usage
The following provides sample usage.
T To set the transaction isolation level command, enter:
system(admin)=> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET VARIABLE
SHOW
Use the SHOW command to display runtime parameters.
Synopsis
Syntax for using the SHOW command:
SHOW <name>
Inputs
The SHOW command takes the following inputs:
Input Description
Outputs
The SHOW command has the following output:
Output Description
Description
The SHOW command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the SHOW command to display the current setting for a runtime parameter.
Related Commands
Use “SET” on page B-108 to set runtime variables. Note that the system sets some vari-
ables at start-up.
Usage
The following provides sample usage.
T To show the current DateStyle setting, enter:
system(admin)=> SHOW DateStyle;
NOTICE: DateStyle is ISO with US (NonEuropean) conventions
SHOW AUTHENTICATION
Use the SHOW AUTHENTICATION command to display the current user authentication
configuration.
Synopsis
Syntax for showing current authentication configuration:
SHOW AUTHENTICATION [ALL]
Inputs
The SHOW AUTHENTICATION command takes the following inputs:
Input Description
ALL If you specify ALL, the results include all of the attributes of the
authentication setting, except for the password. If you do not specify
ALL, the command shows only the type of user logon authentication
(that is, LOCAL or LDAP).
Outputs
The SHOW AUTHENTICATION command has the following output:
Output Description
ERROR: permission denied You do not have the proper permission to view the
results of this command.
Description
The SHOW AUTHENTICATION command has the following characteristics:
Privileges Required
To view the results of the command SHOW AUTHENTICATION ALL, you must be an admin-
istrator, or an administrator must have granted you the following privileges:
X You must have been granted the Manage System privilege.
X You must have been granted the List and Select privileges on the view
_v_authentication_settings.
Implementation Notes
The SHOW AUTHENTICATION command performs as follows.
X It verifies that the user has the correct access rights to perform the operation.
X It transforms the request into a SELECT command.
S If you do not specify ALL, the SELECT is against the view _v_authentication
S If you do specify ALL, the SELECT is against the view _v_authentication_settings
X It records the request in the pg.log file.
Related Commands
See “SET AUTHENTICATION” on page B-110.
See “CREATE USER” on page B-65.
See “ALTER USER” on page B-22.
Usage
The following provides sample usage.
T If you have the proper access to show authentication settings, you can view all but the
password. A sample follows.
system (admin) => SHOW AUTHENTICATION ALL
AUTH_OPTION | AUTH_VALUE
--------------------------------------------------
AUTHENTICATION METHOD | LDAP
AUTHMTHD LDAP ATTRNAME | cn
AUTHMTHD LDAP BASE | dc=example, dc=org
AUTHMTHD LDAP BINDDN | ldapreader
AUTHMTHD LDAP NAMECASE | lowercase
AUTHMTHD LDAP PORT | 389
AUTHMTHD LDAP SCOPE | BASE
AUTHMTHD LDAP SERVER | myldap.netezza.com
AUTHMTHD LDAP SSL | ON
AUTHMTHD LDAP VERSION | 3
T If you do not have the Manage System privilege to show authentication settings, you
can view the type of authentication. A sample follows.
system (admin) => SHOW AUTHENTICATION
AUTH_OPTION | AUTH_VALUE
--------------------------------------------------
AUTHENTICATION METHOD | LDAP
SHOW CONNECTION
Use the SHOW CONNECTION command to display the Netezza connection records defined
for the Netezza client users.
Synopsis
Syntax for showing current authentication configuration:
SHOW CONNECTION
Inputs
There are no specific options for the SHOW CONNECTION command.
Outputs
The SHOW CONNECTION command has the following output:
Output Description
ERROR: permission denied You do not have the proper permission to view the
results of this command.
Description
The SHOW CONNECTION command has the following characteristics:
Privileges Required
To view the results of the command SHOW CONNECTION, you must be an administrator, or
an administrator must have granted you the following privileges:
X You must have been granted the Manage System privilege.
X You must have been granted the List and Select privileges on the view _v_connection.
Common Tasks
Use this command to show Netezza connections.
Related Commands
See “SET CONNECTION” on page B-113.
See “CREATE USER” on page B-65.
See “ALTER USER” on page B-22.
See “DROP CONNECTION” on page B-71.
Usage
Sample usage with output follows.
SYSTEM(ADMIN)=> SHOW CONNECTION;
CONNID | CONNTYPE | CONNDB | CONNIPADDR | CONNIPMASK | CONNAUTH
--------+-----------+--------+-------------+-----------------+--------
1 | local | all | | | trust
2 | host | all | 127.0.0.1 | 255.255.255.255 | md5
3 | host | all | 0.0.0.0 | 0.0.0.0 | md5
4 | hostnossl | ALL | 192.168.1.2 | 255.255.255.255 | md5
(4 rows)
Synopsis
Syntax for showing a configuration:
SHOW HISTORY CONFIGURATION [ <config-name> | ALL ]
Inputs
The SHOW HISTORY CONFIGURATION command has the following inputs:
Input Description
Outputs
The SHOW HISTORY CONFIGURATION command has the following outputs:
Output Description
ERROR: permission denied You must have Manage Security permission to display
the query history settings.
ERROR: <config-name> not The specified configuration name could not be found.
found.
Description
This command displays the information about a query history configuration or all
configurations.
Privileges Required
You must have Manage Security permissions to show query history configurations.
Related Commands
See the “CREATE HISTORY CONFIGURATION” on page B-45 to create a new
configuration.
See the “ALTER HISTORY CONFIGURATION” on page B-9 to modify configurations.
See the “DROP HISTORY CONFIGURATION” on page B-75 to drop configurations.
See the “SET HISTORY CONFIGURATION” on page B-115 to specify a configuration for
query history logging.
Usage
The following command shows information about the plan_hist configuration:
SYSTEM(ADMIN)=> SHOW HISTORY CONFIGURATION plan_hist;
PLAN_HIST | f | | f
| 3 | 1 | 1 | localhost |
| f | | -1 |
-1 | -1 | -1 | -
1 | -1 | f | f | f
| f | 1
(1 row)
SHOW SESSION
Use the SHOW SESSION command to display information about one or more sessions.
Synopsis
Syntax for showing sessions:
SHOW SESSION [ ALL | <session-id> ] [ VERBOSE ]
Inputs
The SHOW SESSION command takes the following inputs:
Input Description
Description
The SHOW SESSION command has the following characteristics:
Privileges Required
You must be the administrator or have the Manage System privilege to see all sessions, oth-
erwise you can see only your own sessions.
Common Tasks
Use the SHOW SESSION command to display information about the current session, a spe-
cific session, or all sessions. Information includes the user name and DB to which the user
is connected, as well as the connect time, priority, and client information.
Related Commands
See “ALTER SESSION” on page B-16 to change a session’s priority or to abort a transac-
tion in a session.
See “DROP SESSION” on page B-77 to abort and remove a session.
Usage
The following provides sample usage.
T The following command shows information about the current session:
show session;
0 | 5 | 1 | ***** | *****
| 100 | show session verbose;
(1 row)
Synopsis
Syntax for showing system defaults:
SHOW SYSTEM DEFAULT
[SESSIONTIMEOUT | ROWSETLIMIT | QUERYTIMEOUT]
[DEFPRIORITY | MAXPRIORITY ]| [MATERIALZE [REFRESH] THRESHOLD]
Inputs
The SHOW SYSTEM DEFAULT command takes the following inputs:
Input Description
DEFPRIORITY Specifies the default priority for the system. The valid priorities are
critical, high, normal, low.
QUERYTIMEOUT Specifies the amount of time a query can run before the system
sends the administrator a message. You can specify from 1 to
2,147,483,647 minutes or zero for unlimited.
ROWSETLIMIT Specifies the number of rows a query can return. You can specify
from 1 to 2,147,483,647 rows or zero for unlimited.
SESSIONTIMEOUT Specifies the amount of time a session can be idle before the system
terminates it. You can specify from 1 to 2.147,483,647 minutes or
zero for unlimited.
Outputs
The SHOW SYSTEM DEFAULT command has the following output:
Output Description
NOTICE OPTION <value> The message returned if the command completes successfully.
Description
The SHOW SYSTEM DEFAULT command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges, to use this command.
Common Tasks
Use the SHOW SYSTEM DEFAULT command to display the current setting for a session
timeout, rowset limit, and query timeout.
Related Commands
Use “SET” on page B-108 to set the session timeout, rowset limit, query timeout, and
materialized refresh threshold.
Usage
The following provides sample usage.
T To show the query timeout, enter:
system(admin)=> SHOW SYSTEM DEFAULT QUERYTIMEOUT;
NOTICE: QUERYTIMEOUT is UNLIMITED
TRUNCATE
Use the TRUNCATE command to empty a table.
Synopsis
Syntax for truncating an empty table:
TRUNCATE [ TABLE ] <name>
Inputs
The TRUNCATE command takes the following inputs:
Input Description
name Specifies the name of the table that you want to truncate.
Outputs
The TRUNCATE command has the following output:
Output Description
Description
The TRUNCATE command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges (Truncate), to use this command.
Common Tasks
Use the TRUNCATE command to remove all rows from a table. The TRUNCATE command
has the same effect as the DELETE command, but is faster than the DELETE command for
large tables. In addition, the TRUNCATE command frees up all disk space allocated to a
table, making the space available for use.
Note: You cannot execute the TRUNCATE command inside a transaction block (begin/com-
mit pair).
Related Commands
See “DELETE” on page B-70.
Usage
The following provides sample usage.
T To truncate the table bigtable, enter:
system(admin)=> TRUNCATE TABLE bigtable;
UPDATE
Use the UPDATE command to replace values of columns in a table. You cannot update col-
umns which are used as distribution keys for a table.
Synopsis
Syntax for using the UPDATE command:
UPDATE <table> SET col = expression [, ...]
[ FROM <fromlist> ]
[ WHERE <condition> ]
Inputs
The UPDATE command takes the following inputs:
Input Description
condition Specifies a where condition. Refer to the SELECT command for a full
description of the where clause.
fromlist Specifies columns from other tables for the where condition.
Outputs
The UPDATE command has the following output:
Output Description
UPDATE # Message returned if the command is successful. The symbol # represents the
number of rows updated. If the system does not update any rows, it returns
zero.
Description
The UPDATE command has the following characteristics:
Privileges Required
You must be an administrator, or an administrator must have given you the appropriate
object privileges (Update), to use this command.
You must have the List privilege for any table whose values are mentioned in the WHERE
condition.
Common Tasks
Use the UPDATE command to change values of columns you specify for all rows that satisfy
a condition.
You need only specify the column(s) you want to modify.
You can use a table alias in update and delete statements. For example:
UPDATE tablename t1 set t1.c2='new value' where t1.c1=1;
DELETE from tablename t1 where t1.c1=2;
Related Commands
None.
Usage
The following provides sample usage.
T To change the word Drama to Dramatic within the column kind, enter:
system(admin)=> UPDATE films SET kind = 'Dramatic' WHERE kind =
'Drama';
system(admin)=> SELECT * FROM films WHERE kind = 'Dramatic' OR kind
kind = 'Drama';
code| title| did| date_prod| kind| len
----+------+----+----------+------+------
BL101| The Third Man| 101| 1949-12-23| Dramatic| 01:44
P_302| Becket| 103| 1964-02-03| Dramatic| 02:28
M_401| War and Peace| 104| 1967-02-12| Dramatic| 05:57
T_601| Yojimbo| 106| 1961-06-16| Dramatic| 01:50
DA101| Das Boot| 110| 1981-11-11| Dramatic| 02:29
Functions
Table B-120 describes the Netezza SQL functions and analytic functions which appear in
the nzsql command help.
This chapter gives a brief overview of joins, and provides simple examples to explain join
concepts. For the full syntax of the select statement, see “SELECT” on page B-99.
Step Action
C-1
Netezza Database User’s Guide
Step Action
Types of Joins
This section describes the types of joins you can use to obtain specific information:
X Cross joins — Returns all possible combinations of rows from two tables.
X Joins or inner joins — Uses a comparison operator to match rows from two tables based
on the values in common columns from each table.
X Left join/left outer join — Returns all the rows from the left table specified in the left
outer join clause, not just the rows in which the columns match.
X Right join/right outer join — Returns all the rows from the right table specified in the
right outer join clause, not just the rows in which the columns match.
X Full outer join — Returns all the rows in both the left and right tables.
Cross Join
A cross join returns all possible combinations of rows of two tables (also called a cartesian
product). All of the columns from one table are followed by all of the columns from the
other table. The result usually does not make sense as a stand-alone. You must add condi-
tions to further define what you want to obtain from the cross joined information.
With a cross join, the number of rows in the resultant table is equal to the number of rows
in the first table times the number of rows in the second table (in this case, nine).
SELECT * FROM cows_one CROSS JOIN cows_two;
cnumber|cbreed |cnumber| breeds
-------+----------+-------+-------
1 | Holstein | 2 | Jersey
1 | Holstein | 3 | Brown Swiss
1 | Holstein | 4 | Ayrshire
2 | Guernsey | 2 | Jersey
2 | Guernsey | 3 | Brown Swiss
2 | Guernsey | 4 | Ayrshire
3 | Angus | 2 | Jersey
Join/Inner Join
An inner join, also known as a simple join, returns rows from joined tables that have match-
ing rows. It does not include rows from either table that have no matching rows in the other.
SELECT * FROM cows_one INNER JOIN cows_two ON cows_one.cnumber = cows_
two.cnumber;
cnumber | cbreed | cnumber | breeds
------------+------------+----------+---------
2 | Guernsey | 2 | Jersey
3 | Angus | 3 | Brown Swiss
(2 rows)
Note: The keyword inner is optional.
Cross Join
You cannot use an on, using, or natural condition with a cross join.
Inner Join
The following examples show inner joins.
X On join_condition
SELECT * FROM cows_one INNER JOIN cows_two ON cows_one.cnumber =
cows_two.cnumber;
cnumber | cbreed | cnumber | breeds
------------+------------+----------+---------
2 | Guernsey | 2 | Jersey
3 | Angus | 3 | Brown Swiss
(2 rows)
Note: Note that the following statement is equivalent:
X Natural
SELECT * FROM cows_one NATURAL INNER JOIN cows_two;
cnumber | cbreed | breeds
--------------+------------+--------------
2 | Guernsey | Jersey
3 | Angus | Brown Swiss
(2 rows)
X Using join_column_list
SELECT * FROM cows_one RIGHT JOIN cows_two USING (cnumber);
cnumber | cbreed | breeds
-----------+-------------+---------------
2 | Guernsey | Jersey
3 | Angus | Brown Swiss
4 | | Ayrshire
(3 rows)
X Natural
SELECT * FROM cows_one NATURAL RIGHT JOIN cows_two;
cnumber | cbreed | breeds
-----------+------------+---------------
2 | Guernsey | Jersey
3 | Angus | Brown Swiss
4 | | Ayrshire
(3 rows)
Samples
The following are left outer join examples.
SELECT * FROM cows_one LEFT OUTER JOIN cows_two ON cows_one.cnumber =
cows_two.cnumber AND cows_one.cnumber < 3;
cnumber | cbreed |cnumber | breeds
-----------|------------|---------+------------
1 | Holstein | |
2 | Guernsey |2 | Jersey
3 | Angus | |
(3 rows)
SELECT * FROM cows_one LEFT OUTER JOIN cows_two ON cows_one.cnumber =
cows_two.cnumber WHERE cows_one.cnumber < 3;
cnumber | cbreed |cnumber | breeds
--------|----------|---------|-------------
2 | Guernsey |2 | Jersey
1 | Holstein | |
(2 rows)
SELECT * FROM cows_one LEFT OUTER JOIN cows_two ON cows_one.cnumber =
cows_two.cnumber AND cows_two.cnumber < 3;
cnumber | cbreed | cnumber | breeds
-----------|------------|---------+------------
1 | Holstein | |
2 | Guernsey | 2 | Jersey
3 | Angus | |
(3 rows)
SELECT * FROM cows_one LEFT OUTER JOIN cows_two ON cows_one.cnumber =
cows_two.cnumber WHERE cows_two.cnumber < 3;
cnumber | cbreed | cnumber | breeds
-----------|------------|---------+------------
2 | Guernsey | 2 | Jersey
(1 row)
The nzsql command has command line options and internal slash commands that you can
use to affect input and output.
Option Description
-c query Runs only single query (or slash command) and exits
-host host Specifies the database server host (default: domain socket)
-n Disables readline
D-1
Netezza Database User’s Guide
Option Description
-T text Sets the HTML table tag options (width, border) (-P tableattr=)
Option Description
Option Description
\copy ... Performs a SQL COPY with data stream to the client
machine
\e [file] Edits the current query buffer or [file] with external editor
\g [file] Sends the query to the backend (and the results in [file] or
|pipe)
Option Description
\set var value Sets an internal variable. Note that \set specified without
any variable or argument displays a list of the current ses-
sion variables and their values.
Index
Symbols ALTER TABLE
changing ownership example 2-14
\!, shell escape 1-9 command B-19
\c option 1-4 renaming example 2-14
\d, describe table or view 1-8 ALTER USER command B-22
\dg, list groups 1-8 ALTER VIEW command 2-22
\dG, list groups of users 1-8 approximate numeric 3-3
\dST, list system tables 1-8 authentication
\dSv, list system views 1-8 local and LDAP B-23
\dt, list tables 1-8 setting B-110
\du, list users 1-8 setting connections B-113
\dU, list users’ groups 1-8 showing B-122
\dv, list views 1-8 showing connections B-124
\e, edit the query buffer 1-9 autocommit B-28
\echo, write to standard out 1-8
\h, SQL syntax help 1-9
\l, list all databases 1-9
\p, show query buffer contents 1-9
B
backslash characters B-34
\r, reset query buffer 1-10
Backup privileges 3-32
\w, write query buffer to file 1-10
BEGIN command B-27
bigint integer type 3-2
Numerics binary
arithmetic operators 3-8
16-bit values 3-2 text, operator 3-9
32-bit values 3-2 bool logical type 3-4
64-bit values 3-2 boolean
8-bit values 3-2 logical type 3-4
values B-102
boolStyle, external table B-40
A btrim function 3-22
byteint integer type 3-2
-A, command line option 1-6
Abort privilege 3-33
aborting a current transaction B-98
absolute path, and the COPY command B-33 C
ACID property B-28 -c, command line option 1-7
add_months, function 3-24 cartesian product C-2
addition, operator 3-8 case function 3-10
administrator privileges 3-32 cast
global 3-32 conversions 3-11
GRANT command B-91, B-97 explicit constant 4-3
age, function 3-24 function 3-11
aggregate functions 2-30 chained mode B-28
grouped 2-30 character
types of 2-30 fixed length 3-4, 3-6, 3-7
window 2-31 functions 3-22
alias international specifying 2-6
cross-database access 2-10 length function 3-15
data types 3-1 maximum in var/varchar 2-7
SELECT command B-100 strings 3-3
smallint 3-2 varying length 3-4, 3-6
timetz 3-5 chr function 3-22
ALTER GROUP command B-6 coalesce function 3-11
ALTER HISTORY CONFIGURATION command B-9 collecting statistics B-89
Alter privilege 3-33 column
ALTER SEQUENCE command B-14 altering B-20
ALTER SESSION command B-16 constraints B-56
ALTER SYNONYM command B-18 DISTRIBUTE ON clause B-62
INSERT command B-93
Index-1
Index
Index-2
Index
Index-3
Index
Index-4
Index
Index-5
Index
N constants 4-1
DDL grammar 3-30
name delete 3-34
CREATE DATABASE command B-35 division 3-8
CREATE GROUP command B-44 exponentiation 3-8
DROP DATABASE command B-73 factorial 3-9
DROP GROUP command B-74 functions 3-8
DROP TABLE command B-80 grammar 2-1, 4-1
DROP USER command B-81 interval 3-6, 3-24
DROP VIEW command B-82 isolation levels 3-35
SHOW command B-121 JDBC 1-1
TRUNCATE command B-130 keywords 4-1
NATURAL join condition C-4 modulo 3-8
nchar 7-3 multiplication 3-8
Netezza SQL 3-9 ODBC 1-1
about 1-1 operators 3-8
accessing using nzsql 1-1 read-only sessions 3-37
addition 3-8 reserved words A-1, C-1
APIs 1-1 REVOKE command B-96
basics 3-1 subtraction 3-8
binary text operator 3-9 system catalog 3-30
commands transaction control 3-35
ALTER GROUP command B-6 unary arithmetic operators 3-9
ALTER SEQUENCE B-14 newline characters B-34
ALTER SYNONYM B-18 next_day function 3-25
ALTER TABLE command B-19 non-ASCII characters
ALTER USER command B-22 displaying 7-6
BEGIN command B-27 non-repeatable reads, isolation level 3-35
COMMENT command B-28 non-reserved keywords 4-1
COMMIT command B-30 normalization 7-2
COPY command B-32 not equal, operator 3-9
CREATE DATABASE command B-35 not like function 3-15
CREATE EXTERNAL TABLE command B-37 NOT NULL, CREATE TABLE command B-57
CREATE GROUP command B-43 now function 3-25
CREATE MATERIALIZED VIEW B-50 null string, COPY command B-32
CREATE SEQUENCE B-52 NULL, CREATE TABLE command B-57
CREATE SYNONYM B-55 nullif, function 3-11
CREATE TABLE AS command B-62 nullValue, external table B-42
CREATE TABLE command B-56 numeric
CREATE USER command B-65 calculations, and GENERATE STATISTICS command
DELETE command B-70 B-89
DROP CONNECTION command B-71 data type 3-2
DROP DATABASE command B-72 nvl
DROP GROUP command B-74 example 3-13
DROP SEQUENCE B-76 function 3-11
DROP SYNONYM B-79 nvl2
DROP TABLE command B-80 example 3-13
DROP USER command B-81 function 3-11
DROP VIEW command B-82 nysiis function 3-17
EXPLAIN command B-83 NYSIIS Soundex algorithm 3-17
GRANT command B-90 NZ_CA_CERT_FILE 1-3
RESET command B-95 NZ_ENCODING 7-6
ROLLBACK command B-98 NZ_SECURITY_LEVEL 1-3
SELECT command B-99 nzconvert command 7-7
SET AUTHENTICATION command B-110 nzsql
SET command B-108 command 1-1
SET SESSION command B-116 options 1-6
SET TRANSACTION command B-119 prompt 1-4
SHOW AUTHENTICATION command B-122 command feedback 1-4
SHOW command B-121 identifiers 1-8
TRUNCATE command B-130 input options 1-5
UPDATE command B-131 internal slash options 1-8
comments 4-1 label 1-8
Index-6
Index
Index-7
Index
read write, SET SESSION command B-117, B-120 three-level naming 2-8
read-only sessions 3-37 schema.object-name 2-8
real, numeric type 3-3 scripts 2-32
Reclaim privilege 3-33 secure sockets layer (SSL) encryption 1-3
REFERENCES, CREATE TABLE command 2-13, B-57 seed, setting B-109
referential integrity 2-13, B-57 SELECT
refresh threshold, setting 2-25 command B-99
regular subquery 2-29 query table example 2-15
relational operators 3-9 Select
relative path, and COPY command B-33 privilege 3-33
removing select
a comment B-29 clause, CREATE TABLE AS command B-62
a view B-82 cross-database access 2-8
access privileges B-96 table rows B-99
all rows from a table B-131 self join query 2-17
renaming sequences
a database 2-6 altering 8-4, B-14
an existing column B-20 altering an increment 8-5
an existing table B-20 altering the sign 8-5
table 2-14 backing up and restoring 8-8
repeat function 3-23 caching 8-3
repeatable read creating 8-2
isolation level 3-35 dropping 8-5, B-76
SET TRANSACTION command B-119 effects of caching 8-3
synopsis B-120 examples 8-2
replacing column values B-131 flushing cache 8-4
requireQuotes, external table B-42 flushing values 8-4
reserved keyword 4-1 getting batch values 8-7
reserved words, table of A-1, C-1 getting values from 8-6
RESET command B-95 overview 8-1
resetting parameter values B-95 privileges 8-6
Restore privileges 3-33 using in a distributed system 8-3
restrictions, CREATE TABLE command B-59 serializable B-120
retrieving isolation level 3-35
comments B-29 SET TRANSACTION B-119
rows from a table or view B-99 session management 1-2
REVOKE command B-96 session variables,displaying 1-5
revoking access privileges 3-32, B-96 session_user function 3-19
right outer join B-105, C-3, C-5 sessions
rollback aborting the active transaction in B-16
or commit B-28 changing priority of B-16
transactions B-98 dropping and removing B-77
ROLLBACK command B-98 read-only 3-37
rows showing B-127
deleting 2-16 set
inserting into table 2-14 datestyle B-109
updating 2-15 field separator mode 1-7
rowset limits SET AUTHENTICATION command B-110
ALTER USER command B-22 SET command B-108
CREATE GROUP command B-43 set command 1-5, 1-9
CREATE USER command B-65 SET HISTORY CONFIGURATION command B-115
rowsize, maximum 2-7 set operation 2-18
rpad function 3-23 SET SESSION command B-116
rtrim function 3-23 SET SYSTEM DEFAULT
runtime parameters, setting B-108 command B-117
runtime parameters, showing B-121 description B-119
example B-119
SET TRANSACTION command B-119
S setting
password expiration B-24
sample join tables C-1
passwords B-22
schema
session characteristics B-116
implicit naming 2-9
SHOW AUTHENTICATION command B-122
Index-8
Index
Index-9
Index
Index-10