Professional Documents
Culture Documents
HP Vertica 7.1.x ConnectingToHPVertica
HP Vertica 7.1.x ConnectingToHPVertica
Legal Notices
Warranty
The only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be
construed as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein.
The information contained herein is subject to change without notice.
Copyright Notice
Copyright 2006 - 2014 Hewlett-Packard Development Company, L.P.
Trademark Notices
Adobe is a trademark of Adobe Systems Incorporated.
Microsoft and Windows are U.S. registered trademarks of Microsoft Corporation.
UNIX is a registered trademark of The Open Group.
Page 2 of 429
Contents
Contents
Using vsql
21
General Notes
21
24
24
24
24
25
27
Command-Line Options
28
General Options
28
Connection Options
31
Output Formatting
32
33
34
35
36
37
Notes:
-v Assignment --set Assignment --variable Assignment
Connecting From a Non-Cluster Host
Meta-Commands
37
37
37
39
\! [ COMMAND ]
39
\?
39
\a
41
Page 3 of 429
Connecting to HP Vertica
Contents
\b
41
41
\C [ STRING ]
41
\cd [ DIR ]
41
42
\d [ PATTERN ]
42
\df [ PATTERN ]
47
\dj [ PATTERN ]
47
\dn [ PATTERN ]
48
\dp [ PATTERN ]
48
\ds [ PATTERN ]
49
\dS [ PATTERN ]
49
\dt [ PATTERN ]
50
\dT [ PATTERN ]
50
\dtv [ PATTERN ]
51
\du [ PATTERN ]
52
\dv [ PATTERN ]
52
\e \edit [ FILE ]
53
\echo [ STRING ]
53
\f [ String ]
53
\g
53
\H
54
\h \help
54
\i FILE
55
\l
55
Locale
55
56
Page 4 of 429
Connecting to HP Vertica
Contents
56
\o
57
\p
57
\password [ USER ]
57
58
\q
60
\qecho [ STRING ]
60
\r
60
\s [ FILE ]
60
60
61
\t
62
\T [ STRING ]
62
\timing
62
\unset [ NAME ]
62
\w [ FILE ]
63
\x
63
\z
63
Variables
64
SQL Interpolation
64
AUTOCOMMIT
65
Notes
65
DBNAME
66
ECHO
66
ECHO_HIDDEN
66
ENCODING
66
HISTCONTROL
67
Page 5 of 429
Connecting to HP Vertica
Contents
HISTSIZE
67
HOST
67
IGNOREEOF
67
ON_ERROR_STOP
67
PORT
68
68
QUIET
68
SINGLELINE
68
SINGLESTEP
68
USER
68
VERBOSITY
68
VSQL_HOME
68
VSQL_SSLMODE
69
Prompting
69
70
Notes
71
72
Locales
72
72
73
Notes
73
Files
73
74
76
Client Libraries
77
77
81
Page 6 of 429
Connecting to HP Vertica
Contents
81
82
82
82
82
83
84
84
Driver Prerequisites
84
ODBC Prerequisites
84
Operating System
84
84
85
ADO.NET Prerequisites
85
Operating System
85
Memory
85
.NET Framework
85
Python Prerequisites
86
Python Driver
86
86
Perl Prerequisites
86
Perl Drivers
86
87
PHP Prerequisites
87
PHP Modules
87
87
87
Page 7 of 429
Connecting to HP Vertica
Contents
88
89
Installation Procedure
89
90
90
91
92
93
93
93
94
94
94
Windows
95
95
96
96
96
96
97
97
98
98
99
99
100
100
Page 8 of 429
Connecting to HP Vertica
Contents
100
101
103
104
104
105
105
To set up a DSN
105
110
111
118
Setting Up a DSN
118
120
121
121
Optional Parameters
122
Advanced Settings
123
Identification
126
Encryption
127
Third-Party Compatibility
128
128
129
130
131
131
131
Required Settings
132
Page 9 of 429
Connecting to HP Vertica
Contents
132
133
133
Logging Settings
133
ODBC-specific Settings
134
ADO.NET-specific Settings
136
137
ODBC Architecture
137
138
138
139
139
139
139
140
Function Changes
140
Removed Functions
141
141
142
142
Connecting to
144
Notes
146
146
149
149
150
150
Page 10 of 429
Connecting to HP Vertica
Contents
153
154
156
157
160
164
167
167
167
171
171
176
176
176
181
182
182
185
Using LONG VARCHAR and LONG VARBINARY Data Types with ODBC
188
189
189
189
190
190
190
191
191
Page 11 of 429
Connecting to HP Vertica
Contents
191
Removed Classes
191
192
192
Deprecated Methods
193
Savepoint Support
194
194
195
Deprecated Methods
195
195
195
196
196
197
Renamed Properties
197
198
199
199
199
200
200
200
200
201
202
202
202
Page 12 of 429
Connecting to HP Vertica
Contents
205
Connection Properties
205
General Properties
207
Logging Properties
209
211
211
212
213
214
215
Notes:
216
216
218
218
220
220
221
221
223
223
226
226
227
229
230
230
231
Page 13 of 429
Connecting to HP Vertica
Contents
232
232
Using LONG VARCHAR and LONG VARBINARY Data Types with JDBC
232
235
237
Notes
238
238
239
240
242
245
246
Using VerticaCopyStream
246
247
251
Handling Errors
253
253
256
258
Creating Tables and Projections for use with the Routable Query API
260
262
264
Defining the Query for Routable Queries Using the VGet Class
269
272
275
275
Page 14 of 429
Connecting to HP Vertica
Contents
275
Performance Improvements
275
Namespace Change
275
Connection Properties
276
Result Buffering
276
Logging Changes
276
276
277
277
278
278
Import the Server and Client Certificates into the Windows Key store:
278
279
279
279
280
280
281
Example Usage:
281
282
288
290
291
291
291
293
Page 15 of 429
Connecting to HP Vertica
Contents
VerticaLogProperties
293
293
SetLogPath
293
SetLogNamespace
294
SetLogLevel
295
295
296
297
298
298
Example Usage:
299
Using Parameters
299
Using Parameters
299
300
Creating Transactions
300
301
301
302
303
305
306
307
308
Batching Updates
308
308
Reading Data From HP Vertica into a Data set and Changing data:
310
312
Page 16 of 429
Connecting to HP Vertica
Contents
312
314
315
315
318
320
320
322
324
327
Python on Linux
327
Python on Windows
327
328
328
328
329
331
331
332
Perl on Linux
332
Perl on Windows
332
332
334
335
336
336
338
Page 17 of 429
Connecting to HP Vertica
Contents
339
340
342
344
345
346
347
349
352
PHP on Linux
352
PHP on Windows
352
352
Setup
352
Example odbc.ini
353
Example odbcinst.ini
353
353
353
354
354
Management API
357
cURL
360
VerticaAPIKey
362
GET /
363
GET api
365
GET backups
373
POST backups/:config_script_base
375
GET backups/:config_script_base/:archive_id
376
Page 18 of 429
Connecting to HP Vertica
Contents
POST restore/:archive_id
377
GETdatabases
378
POST databases
380
GET databases/:database_name
382
PUT databases/:database_name
384
DELETE databases/:database_name
386
GET databases/:database_name/configuration
387
PUT databases/:database_name/configuration
390
GET databases/:database_name/hosts
392
POST databases/:database_name/hosts
394
DELETE databases/:database_name/hosts/:host_id
395
POST databases/:database_name/hosts/:host_id/process
396
DELETE databases/:database_name/hosts/:host_id/process
397
POST databases/:database_name/hosts/:host_id/replace_with/:host_id_new
398
GET databases/:database_name/license
400
GET databases/:database_name/licenses
402
GET databases/:database_name/nodes
404
GET databases/:database_name/nodes/:node_id
405
POST databases/:database_name/process
406
GET databases/:database_name/process
407
DELETE databases/:database_name/process
408
POST databases/:database_name/rebalance/process
409
POST databases/:database_name/wla/process
410
GET hosts
411
GET hosts/:hostid
414
GET jobs
416
GET jobs/:id
418
Page 19 of 429
Connecting to HP Vertica
Contents
POST licenses
419
GET licenses
420
GET nodes
421
GET nodes/:nodeid
422
GET webhooks
424
POST webhooks/subscribe
426
DELETE webhooks/:subscriber_id
427
429
Page 20 of 429
Connecting to HP Vertica
Using vsql
Using vsql
vsql is a character-based, interactive, front-end utility that lets you type SQL statements and see
the results. It also provides a number of meta-commands and various shell-like features that
facilitate writing scripts and automating a variety of tasks.
If you are using the vsql client installed on the server, then you can connect from the:
l
Administration Tools
You can also install the vsql client for other supported platforms.
A man page is available for vsql. If you are running as the dbadmin user, simply type: man vsql. If
you are running as a different user, type: man -M /opt/vertica/man vsql.
General Notes
l
vsql can handles input and output in UTF-8 encoding. Note that the terminal emulator running
vsql must be set up to display the UTF-8 characters correctly. Follow the documentation of your
terminal emulator. The following example shows the settings in PuTTy from the Change
Settings > Window > Translation option:
Page 21 of 429
Connecting to HP Vertica
Using vsql
When you disconnect a user session, any transactions in progress are automatically rolled
back.
To view wide result sets, use the Linux less utility to truncate long lines.
a. Before connecting to the database, specify that you want to use less for query output:
$ export PAGER=less
Page 22 of 429
Connecting to HP Vertica
Using vsql
If a shell running vsql fails (crashes or freezes), the vsql processes continue to run even if you
stop the database. In that case, log in as root on the machine on which the shell was running
and manually kill the vsql process. For example:
Page 23 of 429
Connecting to HP Vertica
Using vsql
Console Encoding
vsql is built as a "console application." The Windows console windows use a different encoding
than the rest of the system, so take care when you use 8-bit characters within vsql. If vsql detects a
Page 24 of 429
Connecting to HP Vertica
Using vsql
problematic console code page, it warns you at startup. To change the console code page, two
things are necessary:
l
Tab Completion
Tab completion is a function of the shell, not vsql. Because of this, tab completion does not work
the same way in Windows vsql as it does on Linux versions of vsql.
On Windows, instead of using tab-completion. Press F7 to pop-up a history window of commands,
or press F8 after typing a few letters of a command to cycle through commands in the history buffer
starting with the same letters.
Note: HP Vertica does not allow users with root privileges to connect to a database for
security reasons.
Page 25 of 429
Connecting to HP Vertica
Using vsql
When you create a new user with the CREATE USER command, you can configure the
password or leave it empty. You cannot bypass the password if the user was created with a
password configured. You can change a user's password using the ALTER USER command.
5. The Administration Tools connect to the database and transfer control to vsql.
Welcome to vsql, the Vertica Analytic Database interactive terminal.
Type: \h or \? for help with vsql commands
\g or terminate with semicolon to execute query
\q to quit
=>
Note: See Meta-Commands for the various commands you can run while connected to the
database through the Administration Tools.
Page 26 of 429
Connecting to HP Vertica
Using vsql
Syntax
/opt/vertica/bin/vsql [-h host] [ option...] [ dbname [ username ] ]
Parameters
host
Not required if you are connecting to a local server. You can provide an IPv4 or IPv6
IP address or a host name.
option
dbname
Usage Considerations
l
If the database is password protected, you must specify the -w or --password command line
option.
For HP Vertica servers that have both IPv4 and IPv6 addressed and you have provided a host
name instead of an IP address, you can prefer to use an IPv4 address with the -4 option and to
use the IPv6 adddress with the -6 option if the DNS is configured to provide both IPv4 and IPv6
addresses.
The default values for both dbname and username is your Linux user name.
If the connection cannot be made for any reason,vsql returns an error and terminates. This
situation can occur if, for example, you have insufficient privileges, server is not running on the
targeted host, etc.),
Page 27 of 429
Connecting to HP Vertica
Using vsql
2If the connection to the server went bad and the session was not interactive
3If an error occurred in a script and the variable ON_ERROR_STOP was set
Unrecognized words in the command line might be interpreted as database or user names.
Examples
The following example shows how you can capture any error messages by edirecting vsql output
into an output file called retail_queries.out:
$ vsql --echo-all < retail_queries.sql > retail_queries.out 2>&1
Command-Line Options
This section contains the command-line options for vsql.
General Options
Option
Description
Runs one
command
and exits.
This
command is
useful in
shell scripts.
Page 28 of 429
Connecting to HP Vertica
Using vsql
Specifies
the name of
the database
to which you
want to
connect.
Using this
command is
equivalent to
specifying
dbname as
the first nonoption
argument on
the
command
line.
Page 29 of 429
Connecting to HP Vertica
Using vsql
--help
Displays
help about
vsql
command
line
arguments
and exits.
-l --list
Returns all
available
databases,
then exits.
Other nonconnection
options are
ignored. This
command is
similar to the
internal
command
\list.
Performs a
variable
assignment,
like the
\set
internal
command.
-V --version
Prints the
vsql version
and exits.
Page 30 of 429
Connecting to HP Vertica
Using vsql
-X --no-vsqlrc
Prevents the
start-up file
from being
read (the
system-wide
vsqlrc file or
the user's
~/.vsqlrc
file).
Connection Options
Option
Description
-4
-6
-B SERVER:PORT,SERVER:PORT,...
Sets connection backup server/port. Use commaseparate multiple hosts (default: not set). If using an IPv6
address, enclose the address in brackets ([, ]) and place
the port outside of the brackets. For example \B
[2620:0:a13:8a4:9d9f:e0e3:1181:7f51]:5433
-C --enable-connection-load-balance
-k KRB SERVICE
Page 31 of 429
Connecting to HP Vertica
Using vsql
-K KRB HOST
-m --sslmode
-U username
--username username
-w password
-W --password
Output Formatting
Option
Description
-A --no-align
-b
Page 32 of 429
Connecting to HP Vertica
Using vsql
-H --html
-t --tuples-only
-x --extended
Description
-a --echo-call
Prints all input lines to standard output as they are read. This
approach is more useful for script processing than interactive
mode. It is the same as setting the variable ECHO to all.
-e --echo-queries
-E
Page 33 of 429
Connecting to HP Vertica
Using vsql
-n
Writes all query output into file filename. Using this command is
equivalent to using the command \o.
-q --quiet
-s --single-step
-S --single-line
A command string that can be completely parsed by the server that does not contain features
specific to vsql
A single meta-command
You cannot mix SQL and vsql meta-commands. You can, however, pipe the string into vsql as
shown:
echo "\\timing\\\\select * from t" | ../Linux64/bin/vsql
Timing is on.
i | c | v
---+---+--(0 rows)
Page 34 of 429
Connecting to HP Vertica
Using vsql
Note: If you use double quotes (") with echo, you must double the backslashes (\).
Example data_file:
110|EXPRESS|SEA|FEDEX111|EXPRESS|HAND CARRY|MSC
Page 35 of 429
Connecting to HP Vertica
Using vsql
112|OVERNIGHT|COURIER|USPS
Page 36 of 429
Connecting to HP Vertica
Using vsql
Notes:
l
If you are using client authentication with a Kerberos connection method of either gss or krb5,
you are required to specify -h hostname.
If you are using client authentication with a "local" connection type specified, and you want to
match the client authentication entry, do not use -h hostname.
On Red Hat 5.0 64-bit and SUSE 10/11 64-bit, you can install the client driver RPM, which
includes the vsql executable. See Installing the Client RPM on Red Hat and SUSE for details.
If the non-cluster host is running the same version of Linux as the cluster, copy the image file to
the remote system. For example:
$ scp host01:/opt/vertica/bin/vsql .$ ./vsql
If the non-cluster host is running a different version of Linux than your cluster hosts, and that
Page 37 of 429
Connecting to HP Vertica
Using vsql
operating system is not Red Hat version 5 64-bit or SUSE 10/11 64-bit, you must install the HP
Vertica server RPM in order to get vsql. Download the appropriate rpm package from the
Download tab of the myVertica portal then log into the non-cluster host as root and install the
rpm package using the command:
# rpm -Uvh filename
In the above command, filename is the package you downloaded. Note that you do not have to
run the install_HP Vertica script on the non-cluster host in order to use vsql.
Notes
l
Use the same Command-Line Options that you would on a cluster host.
You cannot run vsql on a Cygwin bash shell (Windows). Use ssh to connect to a cluster host,
then run vsql.
Page 38 of 429
Connecting to HP Vertica
Using vsql
Meta-Commands
Anything you enter in vsql that begins with an unquoted backslash is a vsql meta-command that is
processed by vsql itself. These commands help make vsql more useful for administration or
scripting. Meta-commands are more commonly called slash or backslash commands.
The format of a vsql command is the backslash, followed immediately by a command verb, then
any arguments. The arguments are separated from the command verb and each other by any
number of whitespace characters.
To include whitespace into an argument you can quote it with a single quote. To include a single
quote into such an argument, precede it by a backslash. Anything contained in single quotes is
furthermore subject to C-like substitutions for \n (new line), \t (tab), \digits, \0digits, and \0xdigits
(the character with the given decimal, octal, or hexadecimal code).
If an unquoted argument begins with a colon (:), it is taken as a vsql variable and the value of the
variable is used as the argument instead.
Arguments that are enclosed in backquotes (`) are taken as a command line that is passed to the
shell. The output of the command (with any trailing newline removed) is taken as the argument
value. The above escape sequences also apply in backquotes.
Some commands take a SQL identifier (such as a table name) as argument. These arguments
follow the syntax rules of SQL: Unquoted letters are forced to lowercase, while double quotes (")
protect letters from case conversion and allow incorporation of whitespace into the identifier. Within
double quotes, paired double quotes reduce to a single double quote in the resulting name. For
example, FOO"BAR"BAZ is interpreted as fooBARbaz, and "A weird"" name" becomes A weird"
name.
Parsing for arguments stops when another unquoted backslash occurs. This is taken as the
beginning of a new meta-command. The special sequence \\ (two backslashes) marks the end of
arguments and continues parsing SQL commands, if any. That way SQL and vsql commands can
be freely mixed on a line. But in any case, the arguments of a meta-command cannot continue
beyond the end of the line.
\! [ COMMAND ]
\! [ COMMAND ] executes a command in a Linux shell (passing arguments as entered) or starts an
interactive shell.
\?
\? displays help information about the meta-commands. Works the same as \h .
Page 39 of 429
Connecting to HP Vertica
Using vsql
=> \?
General
\c[onnect] [DBNAME|- [USER]]
connect to new database (currently "VMart")
\cd [DIR]
change the current working directory
\q
quit vsql
\set [NAME [VALUE]]
set internal variable, or list all if no parameters
\timing
toggle timing of commands (currently off)
\unset NAME
unset (delete) internal variable
\! [COMMAND]
execute command in shell or start interactive shell
\password [USER]
change user's password
Query Buffer
\e [FILE]
edit the query buffer (or file) with external editor
\g
send query buffer to server
\g FILE
send query buffer to server and results to file
\g | COMMAND
send query buffer to server and pipe results to command
\p
show the contents of the query buffer
\r
reset (clear) the query buffer
\s [FILE]
display history or save it to file
\w FILE
write query buffer to file
Input/Output
\echo [STRING] write string to standard output
\i FILE
execute commands from file
\o FILE
send all query results to file
\o | COMMAND
pipe all query results to command
\o
close query-results file or pipe
\qecho [STRING]
write string to query output stream (see \o)
Informational
\d [PATTERN]
describe tables (list tables if no argument is supplied)
\df [PATTERN] list functions
\dj [PATTERN] list projections
\dn [PATTERN] list schemas
\dp [PATTERN] list table access privileges
\ds [PATTERN] list sequences
\dS [PATTERN] list system tables
\dt [PATTERN] list tables
\dtv [PATTERN] list tables and views
\dT [PATTERN] list data types
\du [PATTERN] list users
\dv [PATTERN] list views
\l
list all databases
\z [PATTERN]
list table access privileges (same as \dp)
Formatting
\a
toggle between unaligned and aligned output mode
\b
toggle beep on command completion
\C [STRING]
set table title, or unset if none
\f [STRING]
show or set field separator for unaligned query output
\H
toggle HTML output mode (currently off)
\pset NAME [VALUE]
set table output option
(NAME := {format|border|expanded|fieldsep|footer|null|
recordsep|tuples_only|title|tableattr|pager})
\t
show only rows (currently off)
\T [STRING]
set HTML <table> tag attributes, or unset if none
\x
toggle expanded output (currently off)
Page 40 of 429
Connecting to HP Vertica
Using vsql
\a
\a toggles output format alignment. This command is kept for backwards compatibility. See \pset
for a more general solution.
\a is similar to the command line option -A --no-align, which only disables alignment.
\b
\b toggles beep on command completion.
\C [ STRING ]
\C [ STRING ] sets the title of any tables being printed as the result of a query or unsets any such
title. This command is equivalent to \pset title title. (The name of this command derives from
"caption," as it was previously only used to set the caption in an HTML table.)
\cd [ DIR ]
\cd [ DIR ] changes the current working directory to directory. Without argument, changes to the
current user's home directory.
To print your current working directory, use \! pwd. For example:
=> \!pwd
/home/dbadmin
Page 41 of 429
Connecting to HP Vertica
Using vsql
The output from the \d metacommands places double quotes around non-alphanumeric table
names and table names that are keywords, such as in the following example.
=> CREATE TABLE my_keywords.precision(x numeric (4,2));
CREATE TABLE
=> \d
List of tables
Schema
|
Name
| Kind | Owner
--------------+-----------------------+-------+--------my_keywords | "precision"
| table | dbadmin
Double quotes are optional when you use a \d command with pattern matching.
\d [ PATTERN ]
The \d meta-command lists all tables in the database and returns their schema, table name, kind
(e.g., table), and owner.
If you use \d [ PATTERN ] and provide the schema name or table name (or wildcard or ?
characters) as the pattern argument, the result shows more detailed information about the tables:
l
Schema name
Table name
Column name
Page 42 of 429
Connecting to HP Vertica
Using vsql
Whether the column accepts null values or has a NOT NULL constraint
To view information about system tables, you must include the V_MONITOR or V_CATALOG as the
pattern argument; for example:
\d v_catalog.types
\d v_catalog.*
The following output is the result of all tables in the vmart schema, which is in the PUBLIC schema.
VMart=> \d
List of tables
Schema
|
Name
| Kind | Owner
--------------+-----------------------+-------+--------online_sales | call_center_dimension | table | dbadmin
online_sales | online_page_dimension | table | dbadmin
online_sales | online_sales_fact
| table | dbadmin
public
| customer_dimension
| table | dbadmin
public
| date_dimension
| table | dbadmin
public
| employee_dimension
| table | dbadmin
public
| inventory_fact
| table | dbadmin
public
| product_dimension
| table | dbadmin
public
| promotion_dimension
| table | dbadmin
public
| shipping_dimension
| table | dbadmin
public
| vendor_dimension
| table | dbadmin
public
| warehouse_dimension
| table | dbadmin
store
| store_dimension
| table | dbadmin
store
| store_orders_fact
| table | dbadmin
store
| store_sales_fact
| table | dbadmin
(15 rows)
This example returns information on the inventory_fact table in the VMart database:
VMart=> \x
Expanded display is on.
VMart=> \d inventory_fact
List of Fields by Tables
-[ RECORD 1 ]-----------------------------------------Schema
| public
Table
| inventory_fact
Column
| date_key
Type
| int
Size
| 8
Default
|
Not Null
| t
Primary Key | f
Foreign Key | public.date_dimension(date_key)
Page 43 of 429
Connecting to HP Vertica
Using vsql
-[ RECORD 2 ]-----------------------------------------Schema
| public
Table
| inventory_fact
Column
| product_key
Type
| int
Size
Default
Not Null
Primary Key
Foreign Key
-[ RECORD 3
Schema
Table
Column
Type
Size
Default
Not Null
Primary Key
Foreign Key
-[ RECORD 4
Schema
Table
Column
Type
Size
Default
Not Null
Primary Key
Foreign Key
-[ RECORD 5
Schema
Table
Column
Type
Size
Default
Not Null
Primary Key
Foreign Key
| 8
|
| t
| f
| public.product_dimension(product_key)
]-----------------------------------------| public
| inventory_fact
| product_version
| int
| 8
|
| t
| f
| public.product_dimension(product_version)
]-----------------------------------------| public
| inventory_fact
| warehouse_key
| int
| 8
|
| t
| f
| public.warehouse_dimension(warehouse_key)
]-----------------------------------------| public
| inventory_fact
| qty_in_stock
| int
| 8
|
| f
| f
|
Use the question mark [ ? ] argument to replace a single character. For example, the ? argument
replaces the last character in the user-created SubQ1 and SubQ2 tables, so the command returns
information about both:
=> \d SubQ?
List of Fields by Tables
Schema | Table | Column | Type | Size | Default | Not Null | Primary Key | Foreign Key
--------+-------+--------+------+------+---------+----------+-------------+------------public | SubQ1 | a
| int |
8 |
| f
| f
|
public | SubQ1 | b
| int |
8 |
| f
| f
|
public | SubQ1 | c
| int |
8 |
| f
| f
|
public | SubQ2 | x
| int |
8 |
| f
| f
|
Page 44 of 429
Connecting to HP Vertica
Using vsql
public | SubQ2 | y
public | SubQ2 | z
(6 rows)
| int
| int
|
|
8 |
8 |
| f
| f
| f
| f
|
|
If you run the \d command and provide both the schema and table name, output includes columns
for tables that match the pattern
VMart=> \x
Expanded display is on.
VMart=> \d v_catalog.types
List of Fields by Tables
-[ RECORD 1 ]-------------------Schema
| v_catalog
Table
| types
Column
| column_size
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 2 ]-------------------Schema
| v_catalog
Table
| types
Column
| creation_parameters
Type
| varchar(128)
Size
| 128
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 3 ]-------------------Schema
| v_catalog
Table
| types
Column
| epoch
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 4 ]-------------------Schema
| v_catalog
Table
| types
Column
| interval_mask
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 5 ]-------------------Schema
| v_catalog
Table
| types
Column
| max_scale
Page 45 of 429
Connecting to HP Vertica
Using vsql
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 6 ]-------------------Schema
| v_catalog
Table
| types
Column
| min_scale
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 7 ]-------------------Schema
| v_catalog
Table
| types
Column
| odbc_subtype
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 8 ]-------------------Schema
| v_catalog
Table
| types
Column
| odbc_type
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 9 ]-------------------Schema
| v_catalog
Table
| types
Column
| type_id
Type
| int
Size
| 8
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
-[ RECORD 10 ]------------------Schema
| v_catalog
Table
| types
Column
| type_name
Type
| varchar(128)
Size
| 128
Default
|
Not Null
| f
Primary Key | f
Foreign Key |
Page 46 of 429
Connecting to HP Vertica
Using vsql
To view all tables in a schema, use the wildcard character. The following command would return all
system tables in the V_CATALOG schema:
=> \d v_catalog.*
\df [ PATTERN ]
The \df [ PATTERN ] meta-command
and the function argument data type. Also returns the procedure names and arguments for all
procedures that are available to the user.
vmartdb=> \df
List of functions
procedure_name | procedure_return_type | procedure_argument_types
-----------------+-----------------------+--------------------------abs
| Float
| Float
abs
| Integer
| Integer
abs
| Interval
| Interval
abs
| Interval
| Interval
abs
| Numeric
| Numeric
acos
| Float
| Float
...
width_bucket
| Integer
| Float, Float, Float, Integer
width_bucket
| Integer
| Interval, Interval, Interval, Integer
width_bucket
| Integer
| Interval, Interval, Interval, Integer
width_bucket
| Integer
| Timestamp, Timestamp, Timestamp, Integer
...
The following example uses the wildcard character to search for all functions that begin with as:
vmartdb=> \df as*
List of functions
procedure_name | procedure_return_type | procedure_argument_types
----------------+-----------------------+-------------------------ascii
| Integer
| Varchar
asin
| Float
| Float
(2 rows)
\dj [ PATTERN ]
The \dj [ PATTERN ] meta-command returns all projections showing the schema, projection
name, owner, and node. The returned rows include superprojections, live aggregate projections,
Top-K projections, and projections with expressions:
vmartdb=> \dj
List of projections
Schema
|
Name
| Owner |
Node
--------------+--------------------------------+---------+--------------------
Page 47 of 429
Connecting to HP Vertica
Using vsql
public
public
public
online_sales
online_sales
online_sales
...
|
|
|
|
|
|
product_dimension_node0001
product_dimension_node0002
product_dimension_node0003
call_center_dimension_node0001
call_center_dimension_node0002
call_center_dimension_node0003
|
|
|
|
|
|
dbadmin
dbadmin
dbadmin
dbadmin
dbadmin
dbadmin
|
|
|
|
|
|
v_wmartdb_node0001
v_wmartdb_node0002
v_wmartdb_node0003
v_wmartdb_node0001
v_wmartdb_node0002
v_wmartdb_node0003
If you supply a projection name as an argument, the system returns fewer records:
vmartdb=> \dj call_center_dimension_n*
List of projections
Schema
|
Name
| Owner |
Node
--------------+--------------------------------+---------+-------------------online_sales | call_center_dimension_node0001 | dbadmin | v_wmartdb_node0001
online_sales | call_center_dimension_node0002 | dbadmin | v_wmartdb_node0002
online_sales | call_center_dimension_node0003 | dbadmin | v_wmartdb_node0003
(3 rows)
\dn [ PATTERN ]
The \dn [ PATTERN ] meta-command returns the schema names and schema owner.
vmartdb=> \dn
List of schemas
Name
| Owner
--------------+--------v_internal
| dbadmin
v_catalog
| dbadmin
v_monitor
| dbadmin
public
| dbadmin
store
| dbadmin
online_sales | dbadmin
(6 rows)
The following command returns all schemas that begin with the letter v:
=> \dn v*
List of schemas
Name
| Owner
------------+--------v_internal | dbadmin
v_catalog | dbadmin
v_monitor | dbadmin
(3 rows)
\dp [ PATTERN ]
The \dp [ PATTERN ] meta-command returns the grantee, grantor, privileges, schema, and name
for all table access privileges in each schema:
Page 48 of 429
Connecting to HP Vertica
Using vsql
vmartdb=> \dp
Access privileges for database "vmartdb"
Grantee | Grantor | Privileges | Schema |
Name
---------+---------+------------+--------+-----------| dbadmin | USAGE
|
| public
| dbadmin | USAGE
|
| v_internal
| dbadmin | USAGE
|
| v_catalog
| dbadmin | USAGE
|
| v_monitor
(4 rows)
\ds [ PATTERN ]
The \ds [ PATTERN ] meta-command (lowercase s) returns a list of sequences and their
parameters.
The following series of commands creates a sequence called my_seq and uses the vsql command
to display its parameters:
=> CREATE SEQUENCE my_seq MAXVALUE 5000 START 150;
CREATE SEQUENCE
=> \ds
List of Sequences
Schema | Sequence | CurrentValue | IncrementBy | Minimum | Maximum | AllowCycle
--------+----------+--------------+-------------+---------+---------+-----------public | my_seq
|
149 |
1 |
1 |
5000 | f
(1 row)
Note: You can return additional information about sequences by issuing SELECT * FROM
SEQUENCES, as described in the SQL Reference Manual.
\dS [ PATTERN ]
The \dS [ PATTERN ] meta-command (uppercase S) returns all system table (monitoring API)
names from the V_CATALOG and V_MONITOR schemas.
Tip: You can get identical results running this query: SELECT * FROM system_tables;
If you specify a schema name, you can view results for tables in that schema only; however, you
must use the wildcard character. For example:
=> \dS v_catalog.*
Page 49 of 429
Connecting to HP Vertica
Using vsql
You can also run the \dS command with a table argument to return information for that table only:
vmartdb=> \dS columns
List of tables
Schema
| Name
| Kind |
Description
| Comment
-----------+---------+--------+--------------------------+--------v_catalog | columns | system | Table column information |
(1 row)
If you provide the schema name with the table name, the output returns information about the table:
vmartdb=> \dS v_catalog.types
List of tables
Schema
| Name | Kind |
Description
| Comment
-----------+-------+--------+----------------------------------------+--------v_catalog | types | system | Information about supported data types |
(1 row)
\dt [ PATTERN ]
The \dt [ PATTERN ] meta-command (lowercase t) is identical to \d and returns all tables in the
databaseunless a table name is specifiedin which case the command lists only the schema,
name, kind and owner for the specified table (or tables if wildcards used).
vmartdb=> \dt inventory_fact
List of tables
Schema |
Name
| Kind | Owner
--------+----------------+-------+--------public | inventory_fact | table | dbadmin
(1 row)
The following command returns all table names that begin with "st":
vmartdb=> \dt st*
List of tables
Schema |
Name
| Kind | Owner
--------+-------------------+-------+--------store | store_dimension
| table | dbadmin
store | store_orders_fact | table | dbadmin
store | store_sales_fact | table | dbadmin
(3 rows)
\dT [ PATTERN ]
The \dT [ PATTERN ] meta-command (uppercase T) lists all supported data types.
Page 50 of 429
Connecting to HP Vertica
Using vsql
vmartdb=> \dT
List of data types
type_name
------------Binary
Boolean
Char
Date
Float
Integer
Interval Day
Interval Day to Hour
Interval Day to Minute
Interval Day to Second
Interval Hour
Interval Hour to Minute
Interval Hour to Second
Interval Minute
Interval Minute to Second
Interval Month
Interval Second
Interval Year
Interval Year to Month
Numeric
Time
TimeTz
Timestamp
TimestampTz
Varbinary
Varchar
(26 rows)
\dtv [ PATTERN ]
The \dtv [ PATTERN ] meta-command lists all tables and views, returning the schema, table or
view name, kind (table of view), and owner.
vmartdb=> \dtv
List of tables
Schema
|
Name
| Kind | Owner
--------------+-----------------------+-------+--------online_sales | call_center_dimension | table | release
online_sales | online_page_dimension | table | release
online_sales | online_sales_fact
| table | release
public
| customer_dimension
| table | release
public
| date_dimension
| table | release
public
| employee_dimension
| table | release
public
| inventory_fact
| table | release
public
| product_dimension
| table | release
public
| promotion_dimension
| table | release
public
| shipping_dimension
| table | release
public
| vendor_dimension
| table | release
public
| warehouse_dimension
| table | release
store
| store_dimension
| table | release
Page 51 of 429
Connecting to HP Vertica
Using vsql
store
store
(15 rows)
| store_orders_fact
| store_sales_fact
| table | release
| table | release
\du [ PATTERN ]
The \du [ PATTERN ] meta-command returns all database users and attributes, such as if user is
a superuser.
vmartdb=> \du
List of users
User name | Is Superuser
-----------+-------------dbadmin
| t
(1 row)
\dv [ PATTERN ]
The \dv [ PATTERN ] meta-command returns the schema name, view name, and view owner.
The following example defines a view using the SEQUENCES system table:
vmartdb=> CREATE VIEW my_seqview AS (SELECT * FROM sequences);
CREATE VIEW
vmartdb=> \dv
List of views
Schema |
Name
| Owner
--------+------------+--------public | my_seqview | dbadmin
(1 row)
If a view name is provided as an argument, the result shows the schema, view name, and the
following for all columns within the view's result set: schema name, view name, column name,
column data type, and data type size.
vmartdb=> \dv my_seqview
List of View Fields
Schema |
View
|
Column
|
Type
| Size
--------+------------+---------------------+--------------+-----public | my_seqview | sequence_schema
| varchar(128) | 128
public | my_seqview | sequence_name
| varchar(128) | 128
public | my_seqview | owner_name
| varchar(128) | 128
public | my_seqview | identity_table_name | varchar(128) | 128
public | my_seqview | session_cache_count | int
|
8
public | my_seqview | allow_cycle
| boolean
|
1
public | my_seqview | output_ordered
| boolean
|
1
public | my_seqview | increment_by
| int
|
8
Page 52 of 429
Connecting to HP Vertica
Using vsql
public |
public |
public |
public |
public |
public |
public |
(15 rows)
my_seqview
my_seqview
my_seqview
my_seqview
my_seqview
my_seqview
my_seqview
|
|
|
|
|
|
|
minimum
maximum
current_value
sequence_schema_id
sequence_id
owner_id
identity_table_id
|
|
|
|
|
|
|
int
int
int
int
int
int
int
|
|
|
|
|
|
|
8
8
8
8
8
8
8
\e \edit [ FILE ]
\e \edit [ FILE ] edits the query buffer (or specified file) with an external editor. When the editor
exits, its content is copied back to the query buffer. If no argument is given, the current query buffer
is copied to a temporary file which is then edited in the same fashion.
The new query buffer is then re-parsed according to the normal rules of vsql, where the whole buffer
up to the first semicolon is treated as a single line. (Thus you cannot make scripts this way. Use \i
for that.) If there is no semicolon, vsql waits for one to be entered (it does not execute the query
buffer).
Tip: vsql searches the environment variables VSQL_EDITOR, EDITOR, and VISUAL (in that
order) for an editor to use. If all of them are unset, vi is used on Linux systems, notepad.exe on
Windows systems.
\echo [ STRING ]
\echo [ STRING ] writes the string to standard output.
Tip: If you use the \o command to redirect your query output you might want to use \qecho
instead of this command.
\f [ String ]
\f [ string ] sets the field separator for unaligned query output. The default is the vertical bar
(|). See also \pset for a generic way of setting output options.
\g
The \g meta-command sends the query in the input buffer (see \p ) to the server. With no
arguments, it displays the results in the standard way.
\g FILE sends the query input buffer to the server, and writes the results to FILE.
Page 53 of 429
Connecting to HP Vertica
Using vsql
\g | COMMAND sends the query buffer to the server, and pipes the results to a shell COMMAND.
See Also
l
\o
\H
\H toggles HTML query output format. This command is for compatibility and convenience, but see
\pset about setting other output options.
\h \help
\h \help displays help information about the meta-commands. Works the same as \? .
=> \h
General
\c[onnect] [DBNAME|- [USER]]
connect to new database (currently "VMart")
\cd [DIR]
change the current working directory
\q
quit vsql
\set [NAME [VALUE]]
set internal variable, or list all if no parameters
\timing
toggle timing of commands (currently off)
\unset NAME
unset (delete) internal variable
\! [COMMAND]
execute command in shell or start interactive shell
\password [USER]
change user's password
Query Buffer
\e [FILE]
edit the query buffer (or file) with external editor
\g
send query buffer to server
\g FILE
send query buffer to server and results to file
\g | COMMAND
send query buffer to server and pipe results to command
\p
show the contents of the query buffer
\r
reset (clear) the query buffer
\s [FILE]
display history or save it to file
\w FILE
write query buffer to file
Input/Output
\echo [STRING] write string to standard output
\i FILE
execute commands from file
\o FILE
send all query results to file
\o | COMMAND
pipe all query results to command
\o
close query-results file or pipe
\qecho [STRING]
write string to query output stream (see \o)
Informational
\d [PATTERN]
describe tables (list tables if no argument is supplied)
\df [PATTERN] list functions
\dj [PATTERN] list projections
\dn [PATTERN] list schemas
\dp [PATTERN] list table access privileges
\ds [PATTERN] list sequences
Page 54 of 429
Connecting to HP Vertica
Using vsql
\i FILE
\i filename command reads input from the file filename and executes it as though it had been
typed on the keyboard.
Note: To see the lines on the screen as they are read, set the variable ECHO to all.
\l
\l provides a list of databases and their owners.
vmartdb=> \l
List of databases
name
| user_name
---------+----------vmartdb | dbadmin
(1 row)
Locale
The vsql \locale command displays the current locale setting or lets you set a new locale for the
session.
This command does not alter the default locale for all database sessions. To change the default for
all sessions, set the DefaultSessionLocale configuration parameter.
Page 55 of 429
Connecting to HP Vertica
Using vsql
Notes
The server locale settings impact only the collation behavior for server-side query processing. The
client application is responsible for ensuring that the correct locale is set in order to display the
characters correctly. Below are the best practices recommended by HP to ensure predictable
results:
l
The locale setting in the terminal emulator for vsql (POSIX) should be set to be equivalent to
session locale setting on server side (ICU) so data is collated correctly on the server and
displayed correctly on the client.
The vsql locale should be set using the POSIX LANG environment variable in terminal emulator.
Refer to the documentation of your terminal emulator for how to set locale.
Server session locale should be set using the set as described in Specify the Default Locale for
the Database.
Note that all input data for vsql should be in UTF-8 and all output data is encoded in UTF-8.
Non UTF-8 encodings and associated locale values are not supported.
Page 56 of 429
Connecting to HP Vertica
Using vsql
\o
The \o meta-command is used to control where vsql directs its query output. The output can be
written to a file, piped to a shell command, or sent to the standard output.
\o FILE sends all subsequent query output to FILE.
\o | COMMAND pipes all subsequent query output to a shell COMMAND.
\o with no argument closes any open file or pipe, and switches back to normal query result output.
Notes
l
Query results includes all tables, command responses, and notices obtained from the database
server.
See Also
l
\g
\p
\p prints the current query buffer to the standard output. For example:
=> \p
CREATE VIEW my_seqview AS (SELECT * FROM sequences);
\password [ USER ]
\password starts the password change process. Users can only change their own passwords. The
command prompts the user for the old password, a new password, and then the new password
again to confirm.
A superuser can change the password of another user by supplying the username. A superuser is
not prompted for the old password, either when changing his or her own password, or when
changing another user's password.
Note: If you want to cancel the password change process, press ENTER until you return the to
vsql prompt.
Page 57 of 429
Connecting to HP Vertica
Using vsql
border
expanded
Page 58 of 429
Connecting to HP Vertica
Using vsql
fieldsep
footer
null
recordsep
tuples_only (or t)
Toggles between tuples only and full display. Full display might show
extra information such as column headers, titles, and various footers.
In tuples only mode, only actual table data is shown.
title [ text ]
Sets the table title for any subsequently printed tables. This can be
used to give your output descriptive tags. If no argument is given, the
title is unset.
pager
Controls use of a pager for query and vsql help output. If the
environment variable PAGER is set, the output is piped to the specified
program. Otherwise a platform-dependent default (such as more) is
used.
When the pager is off, the pager is not used. When the pager is on,
the pager is used only when appropriate; that is, the output is to a
terminal and does not fit on the screen. (vsql does not do a perfect job
of estimating when to use the pager.) \pset pager turns the pager
on and off. Pager can also be set to always, which causes the pager
to be always used.
See illustrations on how these different formats look in the Examples section.
Page 59 of 429
Connecting to HP Vertica
Using vsql
Tip: There are various shortcut commands for \pset. See \a , \C , \H , \t , \T , and \ x .
\q
\q quits the vsql program.
\qecho [ STRING ]
\qecho [ STRING ] is identical to \echo except that the output is written to the query output
stream, as set by \o .
\r
\r resets (clears) the query buffer.
For example, run the \p meta-command to see what is in the query buffer:
=> \p
CREATE VIEW my_seqview AS (SELECT * FROM sequences);
If you reissue the command to see what's in the query buffer, you can see it is now empty:
=> \p
Query buffer is empty.
\s [ FILE ]
\s [ FILE ] prints or saves the command line history to filename. If a filename is not specified, \s
writes the history to the standard output. This option is only available if vsql is configured to use the
GNU Readline library.
Page 60 of 429
Connecting to HP Vertica
Using vsql
Notes
l
Valid variable names are case sensitive and can contain characters, digits, and underscores.
vsql treats several variables as special, which are described in Variables.
The \set parameter ROWS_AT_A_TIME defaults to 1000. It retrieves results as blocks of rows of
that size. The column formatting for the first block is used for all blocks, so in later blocks some
entries could overflow. See \timing for examples.
Page 61 of 429
Connecting to HP Vertica
Using vsql
/home/dbadmin/myinput.txt
The contents of the backquotes are replaced with the results of running the contents in a system
shell interpreter. In this case, the echo $HOME command returns the contents of the HOME system
variable.
\t
\t toggles the display of output column name headings and row count footer. This command is
equivalent to \pset tuples_only and is provided for convenience.
\T [ STRING ]
\T [ STRING ] specifies attributes to be placed within the table tag in HTML tabular output
mode. This command is equivalent to \pset tableattr table_options.
\timing
\timing toggles the timing of commands (currently off). The meta-command displays how long
each SQL statement takes, in milliseconds, and reports both the time required to fetch the first
block of rows from the server and the total until the last block is formatted.
Example
=> \o /dev/null=> SELECT * FROM fact LIMIT 100000;
Time: First fetch (1000 rows): 22.054 ms. All rows formatted: 235.056 ms
Note that the database retrieved the first 1000 rows in 22 ms and completed retrieving and
formatting all rows in 235 ms.
See Also
l
\unset [ NAME ]
\unset [ NAME ] unsets (deletes) the internal variable name that was set using the \set metacommand.
Page 62 of 429
Connecting to HP Vertica
Using vsql
\w [ FILE ]
\w [ FILE ] outputs the current query buffer to the file filename.
\x
\x toggles extended table formatting mode. Is equivalent to \pset expanded.
Note: There is no space between the backslash and the x.
\z
\z lists table access privileges (grantee, grantor, privilege, and name) for all table access privileges
in each schema. Is the same as \dp .
Page 63 of 429
Connecting to HP Vertica
Using vsql
Variables
vsql provides variable substitution features similar to common Linux command shells. Variables are
simply name/value pairs, where the value can be any string of any length. To set variables, use the
vsql meta-command \set :
=> \set fact dim
sets the variable fact to the value dim. To retrieve the content of the variable, precede the name
with a colon and use it as the argument of any slash command:
=> \echo :fact dim
Note: The arguments of \set are subject to the same substitution rules as with other
commands. For example, \set dim :fact is a valid way to copy a variable.
If you call \set without a second argument, the variable is set, with an empty string as value. To
unset (or delete) a variable, use the command \unset .
vsql's internal variable names can consist of letters, numbers, and underscores in any order and
any number. Some of these variables are treated specially by vsql. They indicate certain option
settings that can be changed at run time by altering the value of the variable or represent some state
of the application. Although you can use these variables for any other purpose, this is not
recommended. By convention, all specially treated variables consist of all upper-case letters (and
possibly numbers and underscores). To ensure maximum compatibility in the future, avoid using
such variable names for your own purposes.
SQL Interpolation
An additional useful feature of vsql variables is that you can substitute ("interpolate") them into
regular SQL statements. The syntax for this is again to prepend the variable name with a colon (:).
=> \set fact 'my_table'
=> SELECT * FROM :fact;
would then query the table my_table. The value of the variable is copied literally (except for
backquoted strings, see below), so it can even contain unbalanced quotes or backslash
commands. Make sure that it makes sense where you put it. Variable interpolation is not performed
into quoted SQL entities.
Page 64 of 429
Connecting to HP Vertica
Using vsql
Note: The one exception to variable values being copied literally is strings in backquotes (``).
The contents of backquoted strings are passed to a system shell, and replaced with the shell's
output. See the set metacommand topic for details.
AUTOCOMMIT
When AUTOCOMMIT is set 'on', each SQL command is automatically committed upon successful
completion; for example:
\ set
AUTOCOMMIT on
If AUTOCOMMIT is empty or defined as off, SQL commands are not committed unless you
explicitly issue COMMIT.
Notes
l
AUTOCOMMIT must be in uppercase, but the values, on or off, are case insensitive.
In autocommit-off mode, you must explicitly abandon any failed transaction by entering ABORT
or ROLLBACK.
If you exit the session without committing, your work is rolled back.
Validation on vsql variables is done when they are run, not when they are set.
The COPY statement, by default, commits on completion, so it does not matter which
AUTOCOMMIT mode you use, unless you issue COPY NO COMMIT. Please note that DDL
statements are autocommitted.
AUTOCOMMIT is off if a SELECT * FROM LOCKS shows locks from the statement you just ran.
Page 65 of 429
Connecting to HP Vertica
Using vsql
DBNAME
The name of the database to which you are currently connected. DBNAME is set every time you
connect to a database (including program startup), but it can be unset.
ECHO
If set to all, all lines entered from the keyboard or from a script are written to the standard output
before they are parsed or run.
To select this behavior on program start-up, use the switch -a . If set to queries, vsql merely
prints all queries as they are sent to the server. The switch for this is -e .
ECHO_HIDDEN
When this variable is set and a backslash command queries the database, the query is first shown.
This way you can study the HP Vertica internals and provide similar functionality in your own
programs. (To select this behavior on program start-up, use the switch -E .)
If you set the variable to the value noexec, the queries are just shown but are not actually sent to
the server and run.
ENCODING
The current client character set encoding.
Page 66 of 429
Connecting to HP Vertica
Using vsql
HISTCONTROL
If this variable is set to ignorespace, lines that begin with a space are not entered into the history
list. If set to a value of ignoredups, lines matching the previous history line are not entered. A value
of ignoreboth combines the two options. If unset, or if set to any other value than those previously
mentioned, all lines read in interactive mode are saved on the history list.
Source: Bash.
HISTSIZE
The number of commands to store in the command history. The default value is 500.
Source: Bash.
HOST
The database server host you are currently connected to. This is set every time you connect to a
database (including program startup), but can be unset.
IGNOREEOF
If unset, sending an EOF character (usually Control+D) to an interactive session of vsql terminates
the application. If set to a numeric value, that many EOF characters are ignored before the
application terminates. If the variable is set but has no numeric value, the default is 10.
Source: Bash.
ON_ERROR_STOP
By default, if a script command results in an error, for example, because of a malformed command
or invalid data format, processing continues. If you set ON_ERROR_STOP to on in a script and an
error occurs during processing, the script terminates immediately.
If you set ON_ERROR_STOP to on in a script, run the script from Linux using vsql -f <filename>,
and an error occurs, vsql returns an error code 3 to Linux to indicate that the error occurred in a
script.
To enable ON_ERROR_STOP:
=> \set ON_ERROR_STOP on
To disable ON_ERROR_STOP:
Page 67 of 429
Connecting to HP Vertica
Using vsql
PORT
The database server port to which you are currently connected. This is set every time you connect
to a database (including program start-up), but can be unset.
QUIET
This variable is equivalent to the command line option -q . It is probably not too useful in interactive
mode.
SINGLELINE
This variable is equivalent to the command line option -S .
SINGLESTEP
This variable is equivalent to the command line option -s.
USER
The database user you are currently connected as. This is set every time you connect to a
database (including program startup), but can be unset.
VERBOSITY
This variable can be set to the values default, verbose, or terse to control the verbosity of error
reports.
VSQL_HOME
By default, the vsql program reads configuration files from the user's home directory. In cases
where this is not desirable, the configuration file location can be overridden by setting the VSQL_
HOME environment variable in a way that does not require modifying a shared resource.
In the following example, vsql reads configuration information out of /tmp/jsmith rather than out of ~.
Page 68 of 429
Connecting to HP Vertica
Using vsql
VSQL_SSLMODE
VSQL_SSLMODE specifies how (or whether) clients (like admintools) use SSL when connecting to
servers. The default value is prefer, meaning to use SSL if the server offers it. Legal values are
require, prefer, allow, and disable. This variable is equivalent to the command-line -m option
(or --sslmode).
Prompting
The prompts vsql issues can be customized to your preference. The three variables PROMPT1,
PROMPT2, and PROMPT3 contain strings and special escape sequences that describe the appearance
of the prompt. Prompt 1 is the normal prompt that is issued when vsql requests a new command.
Prompt 2 is issued when more input is expected during command input because the command was
not terminated with a semicolon or a quote was not closed. Prompt 3 is issued when you run a SQL
COPY command and you are expected to type in the row values on the terminal.
The value of the selected prompt variable is printed literally, except where a percent sign (%) is
encountered. Depending on the next character, certain other text is substituted instead. Defined
substitutions are:
%M
The full host name (with domain name) of the database server, or [local] if the
connection is over a socket, or [local:/dir/name], if the socket is not at the compiled
in default location.
%m
The host name of the database server, truncated at the first dot, or [local].
%>
%n
%/
%~
Like %/, but the output is ~ (tilde) if the database is your default database.
Page 69 of 429
Connecting to HP Vertica
Using vsql
%#
If the session user is a database superuser, then a #, otherwise a >. (The expansion
of this value might change during a database session as the result of the command
SET SESSION AUTHORIZATION.)
%R
%x
%digits
The character with the indicated numeric code is substituted. If digits starts with 0x
the rest of the characters are interpreted as hexadecimal; otherwise if the first digit
is 0 the digits are interpreted as octal; otherwise the digits are read as a decimal
number.
%:name:
The value of the vsql variable name. See the section Variables for details.
%`command`
%[ ... %]
Prompts may contain terminal control characters which, for example, change the
color, background, or style of the prompt text, or change the title of the terminal
window. In order for the line editing features of Readline to work properly, these nonprinting control characters must be designated as invisible by surrounding them with
%[ and %]. Multiple pairs of these may occur within the prompt. The following
example results in a boldfaced (1;) yellow-on-black (33;40) prompt on VT100compatible, color-capable terminals:
testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%#%[%033[0m%] '
To insert a percent sign into your prompt, write %%. The default prompts are
'%/%R%# ' for prompts 1 and 2, and '>> ' for prompt 3.
Note: See the specification for terminal control sequences (applicable to gnometerminal and xterm).
Page 70 of 429
Connecting to HP Vertica
Using vsql
The command history is automatically saved when vsql exits and is reloaded when vsql starts up.
Tab-completion is also supported, although the completion logic makes no claim to be a SQL
parser. If for some reason you do not like the tab completion, you can turn it off by putting this in a
file named .teclarc in your home directory:
bind ^I
Notes
The vsql implementation of the tecla library deviates from the tecla documentation as follows:
l
History Files
tecla has no standard name for the history file. In vsql, the file name is called ~/.vsql_hist.
Key Bindings:
Insert switches between insert mode (the default) and overwrite mode.
Page 71 of 429
Connecting to HP Vertica
Using vsql
PAGER - If the query results do not fit on the screen, they are piped through this command.
Typical values are more or less. The default is platform-dependent. The use of the pager can be
disabled by using the \pset command.
VSQL_EDITOR, EDITOR and VISUAL - Editor used by the \e command. The variables are
examined in the order listed; the first that is set is used.
TMPDIR - Directory for storing temporary files. The default is platform-dependant. On Unix-like
systems the default is /tmp.
Locales
The default terminal emulator under Linux is gnome-terminal, although xterm can also be used.
HP recommends that you use gnome-terminal with vsql in UTF-8 mode, which is its default.
Page 72 of 429
Connecting to HP Vertica
Using vsql
Note: This works well for standard keyboards. xterm has a similar UTF-8 option.
Notes
l
vsql has no way of knowing how you have set your terminal emulator options.
The tecla library is prepared to do POSIX-type translations from a local encoding to UTF-8 on
interactive input, using the POSIX LANG, etc., environment variables. This could be useful to
international users who have a non-UTF-8 keyboard. See the tecla documentation for details.
HP recommends the following (or whatever other .UTF-8 locale setting you find appropriate):
export LANG=en_US.UTF-8
The vsql \locale command invokes and tracks the server SET LOCALE TO command,
described in the SQL Reference Manual. vsql itself currently does nothing with this locale
setting, but rather treats its input (from files or from tecla), all its output, and all its interactions
with the server as UTF-8. vsql ignores the POSIX locale variables, except for any "automatic"
uses in printf, and so on.
Files
Before starting up, vsql attempts to read and execute commands from the system-wide vsqlrc file
and the user's ~/.vsqlrc file. The command-line history is stored in the file ~/.vsql_history.
Tip: If you want to save your old history file, open another terminal window and save a copy to
a different file name.
Page 73 of 429
Connecting to HP Vertica
Using vsql
Description
Metacommand
Command-line
Option
\a
-A or --no-align
\t
-t or --tuples-only
\pset fieldsep
-F or --field-separator
\o
-o or --output
N/A
-c or --command
counts.
The following example demonstrates disabling padding and column headers in the output, and
setting a field separator to dump a table to a tab-separated text file within an interactive session.
=> SELECT * FROM my_table;
a |
b
| c
---+-------+--a | one
| 1
b | two
| 2
c | three | 3
d | four | 4
e | five | 5
(5 rows)
=> \a
Output format is unaligned.
=> \t
Showing only tuples.
=> \pset fieldsep '\t'
Field separator is "
".
=> \o dumpfile.txt
=> select * from my_table;
=> \o
=> \! cat dumpfile.txt
Page 74 of 429
Connecting to HP Vertica
Using vsql
a
b
c
d
e
one
two
three
four
five
1
2
3
4
5
Note: You could encounter issues with empty strings being converted to NULLs or the reverse
using this technique. You can prevent any confusion by explicitly setting null values to output a
unique string such as NULLNULLNULL (for example, \pset null 'NULLNULLNULL'). Then,
on the import end, convert the unique string back to a null value. For example, if you are
copying the file back into an HP Vertica database, you would give the argument NULL
'NULLNULLNULL' to the COPY statement.
When logged into one of the database nodes, you can create the same output file directly from the
command line by passing the right parameters to vsql:
$ vsql -U username -F $'\t' -At -o dumpfile.txt -c "SELECT * FROM my_table;"
Password:
$ cat dumpfile.txt
a
one
1
b
two
2
c
three
3
d
four
4
e
five
5
If you want to convert null values to a unique string as mentioned earlier, you can add the argument
-P null='NULLNULLNULL' (or whatever unique string you choose).
By adding the -w vsql command-line option to the example command line, you could use the
command within a batch script to automate the data export. However, the script would contain the
database password as plain text. If you take this approach, you should prevent unauthorized
access to the batch script, and also have the script use a database user account that has limited
access.
To set the field separator value to a control character, use your shell's control character escape
notation. In Bash, you specify a control character in an argument using a dollar sign ($) followed by
a string contained in single quotes. This string can contain C-string escapes (such as \t for tab), or a
backslash (\) followed by an octal value for the character you want to use.
The following example demonstrates setting the separator character to tab (\t), vertical tab (\v) and
the octal value of vertical tab (\013).
$ vsql -At -c "SELECT * FROM testtable;"
A|1|2|3
Page 75 of 429
Connecting to HP Vertica
Using vsql
B|4|5|6
$ vsql -F $'\t' -At -c "SELECT * FROM testtable;"
A
1
2
3
B
4
5
6
$ vsql -F $'\v' -At -c "SELECT * FROM testtable;"
A
1
2
3
B
4
5
6
$ vsql -F $'\013' -At -c "SELECT * FROM testtable;"
A
1
2
3
B
4
5
6
Note: The above example copies the data only, not the table design. The target table for the
Page 76 of 429
Connecting to HP Vertica
Using vsql
data copy must already exist in the target database. You can export the design of the table
using EXPORT_OBJECTS or EXPORT_CATALOG.
If you are using the Bash shell, you can escape special delimiter characters. For example,
DELIMITER E'\t' specifies tab. Shells other than Bash may have other string-literal syntax.
While running, the above command displays a progress bar that looks like this:
0:00:39 [12.6M/s] [=============================>
00:00:40
] 50% ETA
Page 77 of 429
Connecting to HP Vertica
Using vsql
Assume you have filled the table with data and want to take a look at it:
testdb=> SELECT * FROM my_table;
first | second
-------+-------1 | one
2 | two
3 | three
4 | four
(4 rows)
You can display tables in different ways by using the \pset command:
testdb=> \pset border 2
Border style is 2.
testdb=> SELECT * FROM my_table;
+-------+--------+
| first | second |
+-------+--------+
|
1 | one
|
|
2 | two
|
|
3 | three |
|
4 | four
|
+-------+--------+
(4 rows)
=> \pset border 0
Border style is 0.
=> SELECT * FROM my_table;
first second
----- -----1 one
2 two
3 three
4 four
(4 rows)
=> \pset border 1 Border style is 1.
=> \pset format unaligned
Output format is unaligned.
=> \pset fieldsep ','
Field separator is ",".
=> \pset tuples_only
Showing only tuples.
=> SELECT second, first FROM my_table;
one,1
two,2
three,3
four,4
Page 78 of 429
Connecting to HP Vertica
Using vsql
Page 79 of 429
Connecting to HP Vertica
Using vsql
Page 80 of 429
Client Libraries
The HP Vertica client driver libraries provide interfaces for connecting your client applications (or
third-party applications such as Cognos and MicroStrategy) to your HP Vertica database. The
drivers simplify exchanging data for loading, report generation, and other common database tasks.
There are three separate client drivers:
l
ActiveX Data Objects for .NET (ADO.NET)used by clients developed using Microsoft's .NET
Framework and written in C#, Visual Basic .NET, and other .NET languages.
The ODBC driver complies with version 3.5.1 of the ODBC standard.
HP Vertica's JDBC driver is a type 4 driver that complies with the JDBC 3.0 standard. It is
compiled using JDK version 1.5, and is compatible with client applications compiled using JDK
versions 1.5 and 1.6.
The drivers do not support some of the optional features in the standards. See ODBC Feature
Support and JDBC Feature Support and Using ADO.NET for details.
Page 81 of 429
7.0.x
7.0.x, 7.1.x
7.1.x
7.1.x
Page 82 of 429
Connecting to HP Vertica
Client Libraries
4.x and 5.x ODBC/JDBC drivers can be installed on the same machine.
4.x and 6.x ODBC/JDBC drivers can be installed on the same machine.
It is not possible to have both 5.x and 6.x ODBC drivers on a single machine. If you install the 6.x
version, it automatically overlays the existing 5.x installation, and any DSN defined against a 5.x
HP Vertica database is not supported.
Page 83 of 429
Connecting to HP Vertica
Client Libraries
The remainder of this section explain the requirements for the HP Vertica client drivers, and the
procedure for downloading, installing, and configuring them.
Driver Prerequisites
The following topics explain the system requirements for the client drivers. You need to ensure that
your client system meets these requirements before installing and using the client drivers.
ODBC Prerequisites
There are several requirements your client systems must meet before you can install the HP
Vertica ODBC drivers.
Operating System
The HP Vertica ODBC driver requires a supported platform. The list of currently-supported
platforms can be found at HP Vertica Client Drivers.
Page 84 of 429
Connecting to HP Vertica
Client Libraries
See Also
l
ADO.NET Prerequisites
The HP Vertica driver for ADO.NET requires the following software and hardware components:
Operating System
The HP Vertica ADO.NET driver requires a supported Windows operating system. The list of
supported platforms can be found in the Supported Platforms document at
http://www.vertica.com/documentation.
Memory
HP Vertica suggests a minimum of 512MB of RAM.
.NET Framework
The requirements for the .NET framework for ADO.NET in HP Vertica can be found in the
Supported Platforms document at http://www.vertica.com/documentation.
Page 85 of 429
Connecting to HP Vertica
Client Libraries
See Also
l
Python Prerequisites
Python is a free, agile, object-oriented, cross-platform programming language designed to
emphasize rapid development and code readability. Python has been released under several
different open source licenses.
HP Vertica's ODBC driver is tested with multiple versions of Python. See Perl and Python
Requirements for details.
Python Driver
HP Vertica requires the pyodbc driver module. See your system's Python documentation for
installation and configuration information.
Perl Prerequisites
Perl is a free, stable, open source, cross-platform programming language licensed under its Artistic
License, or the GNU General Public License (GPL).
Your Perl scripts access HP Vertica through its ODBC driver, using the Perl Database Interface
(DBI) module with the ODBC Database Driver (DBD::ODBC). The HP Vertica ODBC driver is
known to be compatible with these versions of Perl:
l
5.8
5.10
Perl Drivers
The following Perl driver modules have been tested with the HP Vertica ODBC driver:
Page 86 of 429
Connecting to HP Vertica
Client Libraries
PHP Prerequisites
PHP is a widely-used general-purpose scripting language that is especially suited for Web
development and can be embedded into HTML. PHP is licensed under the PHP License, an opensource BSD-style license certified by the Open Source Initiative.
PHP Modules
The following PHP modules are required:
l
php
php-odbc
php-pdo
For Linux and UNIX clients, you must first install a Linux driver manager. After you have
installed the driver manager, there are two different ways to install the client drivers:
Page 87 of 429
Connecting to HP Vertica
Client Libraries
On Red Hat Enterprise Linux 5, 64-bit and SUSE Linux Enterprise Server 10/11 64-bit, you
can use the HP Vertica client RPM package to install the ODBC and JDBC drivers as well as
the vsql client.
On other Linux platforms and UNIX-like platforms you can download the ODBC and JDBC
drivers and install them individually.
Note: The ODBC and JDBC client drivers are installed by the server .rpm files. If you have
installed HP Vertica Analytics Platform on your Linux system for development or testing
purposes, you do not need to download and install the client drivers on ityou just need to
configure the drivers. To use ODBC, you need to create a DSN (see Creating an ODBC DSN for
Linux, Solaris, AIX, and HP-UX). To use JDBC, you need to add the JDBC client driver to the
Java CLASSPATH (see Modifying the Java CLASSPATH).
l
On Windows clients, download the 32-bit or 64-bit client installer. The installer provides the
ODBC and and JDBC drivers.
There is an additional Windows installer for the ADO.NET client driver. 32-bit and 64-bit versions
of the installer are available. ADO.NET is only available for the Enterprise edition of HP Vertica.
The remainder of this section describes how to install client drivers on different operating systems.
UnixODBC: http://www.unixodbc.org/
iODBC: http://www.iodbc.org
Page 88 of 429
Connecting to HP Vertica
Client Libraries
Installation Procedure
1. Open a Web browser and log in to myVertica portal.
2. Click the Download tab and locate and download the driver package that corresponds to your
client system.
3. If you did not directly download to the client system, transfer the downloaded file to it.
4. Log in to the client system as root.
5. If the directory /opt/vertica/ does not exist, create it:
# mkdir -p /opt/vertica/
Page 89 of 429
Connecting to HP Vertica
Client Libraries
# cp vertica_7.1..xx_odbc_x86_64_linux.tar.gz /opt/vertica/
The odbc.ini configuration file defines the Data Source Names (DSNs) that tell the ODBC how
to access your HP Vertica databases. See Creating an ODBC Data Source Name for
instructions to create this file.
The vertica.ini configuration file defines some HP Vertica-specific settings required by the
drivers. See Additional Linux ODBC Driver Configuration Settings for instructions to create this
file.
Note: If you are upgrading your ODBC driver, you must either update your DSNs to point to the
newly-installed driver or create new DSNs. If your odbc.ini file references drivers defined in
an odbcinst.ini file, you just need to update the odbcinst.ini file. See Creating an ODBC
Data Source Name (DSN) for details.
Page 90 of 429
Connecting to HP Vertica
Client Libraries
Note: The 64-bit client driver RPM installs both the 64-bit and 32-bit ODBC driver libraries,
so you do not need to install both on your 64-bit client system.
3. If you did not directly download the RPM on the client system, transfer the file to the client.
4. Log in to the client system as root.
5. Install the RPM package you downloaded:
# rpm -Uvh package_name.rpm
Note: You receive one or more conflict error messages if there are existing HP Vertica client
driver files on your system. This can happen if you are trying to install the client driver package
on a system that has the server package installed, since the server package also includes the
client drivers. In this case, you don't need to install the client drivers, and can instead use the
drivers installed by the server package. If the conflict arises from an old driver installation or
from a server installation for an older version, you can use the rpm command's --force switch
to force it to overwrite the existing files with the files in the client driver package.
Once you have installed the client package, you need to create a DSN (see Creating an ODBC
DSN for Linux, Solaris, AIX, and HP-UX) and set some additional configuration parameters (see
Additional Linux ODBC Driver Configuration Settings) to use ODBC. To use JDBC, you need to
modify your class path (see Modifying the Java CLASSPATH) before you can use JDBC.
You may also want to add the vsql client to your PATH environment variable so that you do not
need to enter its full path to run it. You add it to your path by adding the following to the .profile file
in your home directory or the global /etc/profile file:
export PATH=$PATH:/opt/vertica/bin
Page 91 of 429
Connecting to HP Vertica
Client Libraries
you do not need to download and install the client drivers on ityou just need to configure the
drivers. To use ODBC, you need to create a DSN (see Creating an ODBC DSN for Linux, Solaris,
AIX, and HP-UX). To use JDBC, you need to add the JDBC client driver to the Java CLASSPATH
(see Modifying the Java CLASSPATH).
Note: For additional details about supported platforms, see Supported Platforms.
The JDBC driver is available for download from myVertica portal. There is a single .jar file that
works on all platforms and architectures. To download and install the file:
1. Open a Web browser and log in to myVertica portal.
2. Click the Download tab and locate and download the JDBC driver.
3. You need to copy the .jar file you downloaded file to a directory in your Java CLASSPATH on
every client system with which you want to access HP Vertica. You can either:
n
Copy the .jar file to its own directory (such as /opt/vertica/java/lib) and then add that
directory to your CLASSPATH (recommended). See Modifying the Java CLASSPATH for
details.
Copy the .jar file to directory that is already in your CLASSPATH (for example, a directory
where you have placed other .jar files on which your application depends).
Note: In the directory where you copied the .jar file, you should create a symbolic link named
vertica_jdk_5.jar to the .jar file. You can reference this symbolic link anywhere you need
to use the name of the JDBC library without having to worry any future upgrade invalidating the
file name. This symbolic link is automatically created on server installs. On clients, you need to
create and manually maintain this symbolic link yourself if you installed the driver manually.
The Installing the Client RPM on Red Hat and SUSE create this link when they install the
JDBC library.
Page 92 of 429
Connecting to HP Vertica
Client Libraries
Note: Note: If you are uninstalling a previous release of the HP Vertica ODBC/JDBC drivers,
delete any DSNs associated with those drivers before you uninstall. Windows requires that the
driver files be present when a DSN is removed. If you uninstall the driver first, then the DSN
cannot be removed. For releases after 5.1 you do not need to uninstall the drivers, as the
installation program upgrades the existing 5.1+ drivers in place.
Page 93 of 429
Connecting to HP Vertica
Client Libraries
The client drivers are available in the ODBC and JDBC folders of the installation directory.
There is no shortcut for the vsql client. vsql is added to the windows PATH environment
variable. Start a command window and type vsql -? at the command prompt to start vsql and
show the help list. See vsql Notes for Windows Users for important details about using vsql in a
Windows console.
You must perform an additional step for some of the client drivers before you use them:
l
If environment variable CLASSPATH is already defined, use the following command to prevent it
from being overwritten:
# export CLASSPATH=$CLASSPATH:/opt/vertica/java/lib/vertica-jdbc-x.x.x.jar
Page 94 of 429
Connecting to HP Vertica
Client Libraries
If you are using a shell other than Bash, consult its documentation to learn how to set environment
variables.
You need to either set the CLASSPATH environment variable for every login session, or insert the
command to set the variable into one of your startup scripts (such as ~/.profile or
/etc/profile).
Windows
Provide the class paths to the .jar, .zip, or .class files.
C:> SET CLASSPATH=classpath1;classpath2...
For example:
C:> SET CLASSPATH=C:\java\MyClasses\vertica-jdbc-x.x.x.jar
As with the Linux/UNIX settings, this setting only lasts for the current session. To set the
CLASSPATH permanently, set an environment variable:
1. On the Windows Control Panel, click System.
2. Click Advanced or Advanced Systems Settings.
3. Click Environment Variables.
4. Under User variables, click New.
5. In the Variable name box, type CLASSPATH.
6. In the Variable value box, type the path to the HP Vertica JDBC .jar file on your system (for
example, C:\Program Files (x86)\Vertica\JDBC\vertica-jdbc-x.x.x.jar)
Page 95 of 429
Connecting to HP Vertica
Client Libraries
Your Java IDE may also let you add directories to your CLASSPATH, or let you import the HP
Vertica JDBC driver into your project. See your IDE documentation for details.
Copy the JDBC .jar file you downloaded to either the system-wide Java Extensions folder
(/Library/Java/Extensions) or your user Java Extensions folder
(/Users/username/Library/Java/Extensions).
Add the directory containing the JDBC .jar file to the CLASSPATH environment variable (see
Modifying the Java CLASSPATH).
Specify the directory containing the JDBC .jar using the -cp argument in the Java command
line you use to start your Java command line.
Page 96 of 429
Connecting to HP Vertica
Client Libraries
The installer is designed to be used with the standard iODBC Driver Manager included in Mac OS
X. While Mac OS X ships with the iODBC Driver Manager already installed, you may choose to
download the most recent version of the driver at the iODBC.org website.
By default, the installer installs the driver in the following location:
/Library/Vertica/ODBC/lib/libverticaodbc.dylib. The installer also automatically registers
a driver named "Vertica" with the iODBC Driver Manager.
To use the unixODBC Driver Manager instead of Apple's iODBC Driver Manager, see the
unixODBC.org website.
Page 97 of 429
Connecting to HP Vertica
Client Libraries
1. On your Mac OS X client system, open a browser, and log in to the myVertica portal.
2. Install the HP Vertica ODBC driver for Mac OS X:
a. Navigate to the Downloads tab, and scroll to the Client Software section.
b. Click the download link for the Mac OS X ODBC installer.
3. Accept the license agreement, and wait for the download to complete.
As an administrator account, if you are installing the driver for system-wide use
2. Open a terminal window. In the Finder, click Applications > Utilities > Terminal.
3. Install the .pkg file containing the ODBC driver using the command:
sudo installer -pkg ~/Downloads/vertica-odbc7.1.pkg -target /
In the preceding .pkg command, change the path to that of the downloaded file, if:
n
You downloaded the driver .pkg file to a directory other than your Downloads directory.
Note: After installing the ODBC driver, you must create a DSN to be able to connect to your
HP Vertica database. For the procedure, see Creating an ODBC DSN for Macintosh OS X
Clients.
Page 98 of 429
Connecting to HP Vertica
Client Libraries
Page 99 of 429
Connecting to HP Vertica
Client Libraries
/etc/odbc.ini
The structure of these files is the same, only their location differs. If both files are present, the
~/.odbc.ini file usually overrides the system-wide /etc/odbc.ini file.
Note: See your ODBC driver manager's documentation for details on where these files should
be located and any other requirements.
Parameter definitions, which contain a parameter name, an equals sign (=), and then the
parameter's value.
The first section of the file is always named [ODBC Data Sources], and contains a list of all the
DSNs that the odbc.ini file defines. The parameters in this section are the names of the DSNs,
which appear as section definitions later in the file. The value is a text description of the DSN and
has no function. For example, an odbc.ini file that defines a single DSN named HP VerticaDSN
could have this ODBC Data Sources section:
Connecting to HP Vertica
Client Libraries
Appearing after the ODBC data sources section are sections that define each DSN. The name of a
DSN section must match one of the names defined in the ODBC Data Sources section.
3. Create a section whose name matches the DSN name you defined in step 2. In this section,
you add parameters that define the DSN's settings. The most commonly-defined parameters
are:
n
Driver The location and designation of the HP Vertica ODBC driver, or the name of a
driver defined in the odbcinst.ini file (see below). For future compatibility, use the name of
the symbolic link in the library directory, rather than the library file:
o
For example, the symbolic link for the 64-bit ODBC driver library is:
/opt/vertica/lib64/libverticaodbc.so
Connecting to HP Vertica
Client Libraries
The symbolic link always points to the most up-to-date version of the HP Vertica client
ODBC library. Use this link so that you do not need to update all of your DSNs when you
update your client drivers.
n
Database The name of the database running on the server. This example uses vmartdb
for the vmartdb.
ServerName The name of the server where HP Vertica is installed. Use localhost if HP
Vertica is installed on the same machine.
You can provide an IPv4 address, IPv6 address, or hostname.
In mixed IPv4/IPv6 networks, the DNS server configuration determines which IP version
address is sent first. Use the PreferredAddressFamily option to force the connection to
use either IPv4 or IPv6.
UID Either the database superuser (same name as database administrator account) or a
user that the superuser has created and granted privileges. This example uses the user
name dbadmin.
PWD The password for the specified user name. This example leaves the password field
blank.
Port The port number on which HP Vertica listens for ODBC connections. For example,
5433.
SSLKeyFile The file path and name of the client's private key. This file can reside
anywhere on the system.
SSLCertFile The file path and name of the client's public certificate. This file can reside
anywhere on the system.
Locale The default locale used for the session. By default, the locale for the database is:
en_US@collation=binary (English as in the United States of America). Specify the locale as
an ICU Locale. See the ICU User Guide (http://userguide.icu-project.org/locale) for a
complete list of parameters that can be used to specify a locale.
PreferredAddressFamily:
Connecting to HP Vertica
Client Libraries
The IP version to use if the client and server have both IPv4 and IPv6 addresses and you
have provided a host name. Valid values are:
o
For example:
[VMart]
Description = Vmart Database
Driver = /opt/vertica/lib64/libverticaodbc.so
Database = vmartdb
Servername = host01
UID = dbadmin
PWD =
Port = 5433
ConnSettings =
SSLKeyFile = /home/dbadmin/client.key
SSLCertFile = /home/dbadmin/client.crt
Locale = en_GB
See Data Source Name (DSN) Connection Parameters for a complete list of parameters including
HP Vertica-specific ones.
For example:
Connecting to HP Vertica
Client Libraries
[HPVertica]
Description = HP Vertica ODBC Driver
Driver = /opt/vertica/lib64/libverticaodbc.so
Then, in your odbc.ini file, use the name of the section you created in the odbcinst.ini file that
describes the driver you want to use. For example:
[VMart]
Description = HP Vertica Vmart database
Driver = HPVertica
If you are using the unixODBC driver manager, you should also add an ODBC section to override
its standard threading settings. By default, unixODBC serializes all SQL calls through ODBC,
which prevents multiple parallel loads. To change this default behavior, add the following to your
odbcinst.ini file:
[ODBC]
Threading = 1
Connecting to HP Vertica
Client Libraries
Note: If you have not set the ErrorMessagesPath in the additional driver configuration settings,
any errors during testing will trigger a missing error message file ("The error message
NoSQLGetPrivateProfileString could not be found in the en-US locale"). See Additional Linux
ODBC Driver Configuration Settings for more information.
Setting Up a DSN
Setting Up a DSN
A Data Source Name (DSN) is the ODBC logical name for the drive and other information the
database needs to access data. The name is used by Internet Information Services (IIS) for a
connection to an ODBC data source.
This section describes how to use the HP Vertica ODBC Driver to set up an ODBC DSN. This
topic assumes that the driver is already installed, as described in Installing Client Drivers on
Windows.
To set up a DSN
1. Open the ODBC Administrator. For example, you could navigate to Start > Control Panel >
Administrative Tools > Data Sources (ODBC).
Note: The method you use to open the ODBC Administrator depends on your version of
Windows. Differences between Windows versions and Start Menu customizations could
require you to take a different action to open the ODBC Administrator.
2. Decide if you want all users on your client system to be able to access to the DSN for the HP
Connecting to HP Vertica
Client Libraries
Vertica database.
n
If you want all users to have access, then click the System DSN tab.
Otherwise, click the User DSN tab to create a DSN that is only usable by your Windows
user account.
Connecting to HP Vertica
Client Libraries
Note: If you have installed more than one version of the HP Vertica client drivers on your
Windows client system, you may see multiple versions of the driver in this list. Choose
the version that you know is compatible with your client application and Vertica Analytic
Database server. If you are unsure, use the latest version of the driver.
Connecting to HP Vertica
Client Libraries
6. Enter the information for your DSN. The following fields are required:
n
DSN Name The name for the DSN. Clients use this name to identify the DSN to which
they want to connect. The DSN name must satisfy the following requirements:
It contains no spaces.
Server The host name or IP address of the HP Vertica server to which you want to
connect. Use localhost, if HP Vertica is installed on the same machine.
You can provide an IPv4 address, IPv6 address, or hostname.
Connecting to HP Vertica
Client Libraries
In mixed IPv4/IPv6 networks, the DNS server configuration determines which IP version
address is sent first. Use the PreferredAddressFamily option to force the connection to
use either IPv4 or IPv6.
The PreferredAddressFamily option is available on the Client Settings tab.
n
User Name The name of the user account to use when connecting to the database. If the
application does not supply its own user name when connecting to the DSN, this account
name is used to log into the database. .
The rest of the fields are optional. See DSN Parameters for detailed information about the DSN
parameters you can define.
7. If you want to test your connection:
a. Enter at least a valid DSN name, Server name, Database, and either User name or
select Windows authentication.
b. If you have not selected Windows authentication, you can enter a password in the
Password box. Alternately, you can select Password prompt to have the driver prompt
you for a password when connecting.
c. Click Test Connection.
8. When you have finished editing and testing the DSN, click OK. The HP Vertica ODBC
DSN configuration window closes, and your new DSN is listed in the ODBC Data Source
Administrator window.
Connecting to HP Vertica
Client Libraries
This administrator window edits a set of DSNs that are associated with the 32-bit ODBC library.
You can then use your 32-bit client applications with the DSNs you create with this version of the
ODBC administrator.
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
d. Click Connect.
Connecting to HP Vertica
Client Libraries
3. When the HP Vertica Connection Dialog box opens, enter the connection information for the
DSN, and click OK.
Connecting to HP Vertica
Client Libraries
4. Click OK on the Create New Data Source dialog box to return to the Choose Data Source
dialog box.
5. Select VMart_Schema*, and verify that the Use the Query Wizard check box is deselected.
Click OK.
Connecting to HP Vertica
Client Libraries
7. When the Microsoft Query window opens, click the SQL button.
8. In the SQL window, write any simple query to test your connection. For example:
SELECT DISTINCT calendar_year FROM date_dimension;
9.
If you see the caution, "SQL Query can't be represented graphically. Continue anyway?"
click OK.
The data values 2003, 2004, 2005, 2006, 2007 indicate that you successfully connected to
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
Setting Up a DSN
1. Using your web browser, download and install the Apple ODBC Administrator Tool.
2. Locate and open the ODBC Administrator Tool after installation:
a. Navigate to Finder > Applications > Utilities.
b. Open the ODBC Administrator Tool.
3. Click the Drivers tab, and verify that the HP Vertica driver is installed.
Connecting to HP Vertica
Client Libraries
4. Specify if you want all users on your client system to be able to access the DSN for the HP
Vertica database:
n
If you want all users to have access, then click the System DSN tab.
Otherwise, click the User DSN tab to create a DSN that is only usable by your Macintosh
user account.
Connecting to HP Vertica
Client Libraries
The following figure shows the minimum parameters that are required to configure a DSN so
that it connects to the database:
Connecting to HP Vertica
Client Libraries
Parameters Description
Default
Value
Driver
none
Database
none
Connecting to HP Vertica
Client Libraries
Parameters Description
Default
Value
none
cluster.
You can provide an IPv4 address, IPv6 address, or hostname.
In mixed IPv4/IPv6 networks, the DNS server configuration determines
which IP version address is sent first. Use the
PreferredAddressFamily option to force the connection to use either
IPv4 or IPv6.
You can also use the aliases "server" and "host" for this parameter.
UID
none
Optional Parameters
These are basic parameters that are optional.
Parameters
Description
Default Value
Port
5433
parameter blank.
PreferredAddressFamily
none
Connecting to HP Vertica
Client Libraries
Advanced Settings
Parameters
Description
Default
AutoCommit
true
none
false
Connecting to HP Vertica
Client Libraries
Parameters
Description
Default
ConnSettings
none
false
Connecting to HP Vertica
Client Libraries
Parameters
Description
Default
DriverStringConversions
OUTPUT
Locale
en_
US@collation=binary
(English as in the
United States of
America)
false
false
Connecting to HP Vertica
Client Libraries
Parameters
Description
Default
ResultBufferSize
131072 (128KB)
Server Default
Read Committed
Serializable
Server Default
Identification
Parameters
Description
Standard/HP
Default Vertica
Description
none
Standard
none
HP Vertica
Required? No
Insert an empty string to leave the description empty.
Label /
Connecting to HP Vertica
Client Libraries
Encryption
Parameters
Description
Standard/HP
Default Vertica
SSLMode
prefer
HP Vertica
none
HP Vertica
none
HP Vertica
require
Connecting to HP Vertica
Client Libraries
Third-Party Compatibility
Parameters
Description
Default
Standard/HP
Vertica
ColumnsAsChar
false
HP Vertica
false
HP Vertica
(UNIX)
true
(Windows)
Connecting to HP Vertica
Client Libraries
Parameters
Description
Default
Standard/HP
Vertica
vertica
HP Vertica
the servername
connection string
HP Vertica
parameter
See Also
l
On UNIX and Linux client platforms, you can edit the odbc.ini file. (See Creating an ODBC
DSN for Linux, Solaris, AIX, and HP-UX.) The location of this file is specific to the driver
manager.
On Windows client platforms, you can edit some DSN parameters using the HP Vertica ODBC
client driver interface. See Creating an ODBC DSN for Windows Clients.
You can also edit the DSN parameters directly by opening the DSN entry in the Windows
registry (for example, at HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DSNname). Directly
editing the registry can be risky, so you should only use this method for parameters that cannot
be set through the ODBC driver's user interface, or via your client code.
You can set parameters in the connection string when opening a connection using the
SQLDriverConnect() function:
sqlRet = SQLDriverConnect(sql_hDBC, 0, (SQLCHAR*)"DSN=DSNName;Locale=en_GB", SQL_NTS,
szDNS, 1024,&nSize, SQL_DRIVER_NOPROMPT);
Connecting to HP Vertica
Client Libraries
Note: In the connection string ';' is a reserved symbol. If you need to set multiple
parameters as part of ConnSettings parameter use '%3B' in place of ';'. Also use '+' instead
of spaces.
For example:
sqlRet = SQLDriverConnect(sql_hDBC, 0, (SQLCHAR*)"DSN=HP
VerticaSQL;ConnSettings=set+search_path+to+a,b,c%3Bset+locale=ch;SSLMode=prefer", SQL_
NTS,
szDNS, 1024,&nSize, SQL_DRIVER_NOPROMPT);
Your client code can retrieve DSN parameter values after a connection has been made to HP
Vertica using the SQLGetConnectAttr() and SQLGetStmtAttr() API calls. Some parameters
can be set and using SQLSetConnectAttr() and SQLSetStmtAttr().
For details of the list of HP Vertica-specific parameters see HP Vertica-specific ODBC Header
File.
Connecting to HP Vertica
Client Libraries
The text encoding used by the driver manager (for example, UTF-8 or UTF-16).
The location of the directory containing the HP Vertica ODBC driver's error message files.
Note: Most of the additional driver configuration settings are automatically set on Windows
platforms. The Windows ODBC driver's DSN Configuration dialog lets you control whether the
ODBC driver logs messages. On Linux/UNIX systems, you must supply the additional
configuration settings before the ODBC drivers can function properly.
The topics in this section describe these settings in greater detail.
On Linux and UNIX platforms, the settings are contained in a text file named vertica.ini
(although you can choose a different filename). You tell the HP Vertica ODBC driver where to
find this file using an environment variable named VERTICAINI.
On Windows platforms, the additional settings are set using the ODBC Data Source
Configuration window. The values for the settings are stored in the Windows registry under the
path HKEY_LOCAL_MACHINE\SOFTWARE\Vertica\Driver.
Connecting to HP Vertica
Client Libraries
The format of the vertica.ini file is similar to the odbc.ini file, with a section followed by
parameter definitions. Unlike the odbc.ini file, vertica.ini contains a single section named
Driver:
[Driver]
Following the section definition, you add setting definitions, one per line. A setting definition
consists of the setting name, followed by an equal sign (=), followed by the value. The value does
not need quotes. For example, to set the ODBCInstLib setting, you add a line like this:
ODBCInstLib=/usr/lib64/libodbcinst.so
See Additional Parameter Settings for a list of the additional settings.
Required Settings
You must configure two settings in order for the ODBC driver to work correctly:
l
ErrorMessagesPath
ODBCInstLib (unless the driver manager's installation library is in a directory listed in the LD_
LIBRARY_PATH or LIB_PATH environment variables).
Also, if your driver manager does not use UTF-8 encoding, you need to set DriverManagerEncoding
to the proper encoding.
If users need individual vertica.ini files, set VERTICAINI in their ~/.profile or similar
configuration file. For example:
export VERTICAINI=~/.vertica.ini
Connecting to HP Vertica
Client Libraries
On Macintosh OS X client systems, you can set the VERTICAINI environment variable in each
user's ~/.MacOSX/environment.plist file. See the Environment Variables entry in the Apple's
Developer's Library for more information.
get its error messages from the standard HP Vertica 64-bit ODBC driver installation directory.
log all warnings and more severe messages to log files stored in the temporary directory.
[Driver]
DriverManagerEncoding=UTF-16
ODBCInstLib=/usr/lib64/libodbcinst.so
ErrorMessagesPath=/opt/vertica/lib64
LogLevel=4
LogPath=/tmp
Logging Settings
These parameters control how messages between the client and server are logged. None of these
settings are required. If they are not set, then the client library does not log any messages. They
apply to both ADO.NET and ODBC.
l
LogLevelThe severity of messages that are logged between the client and the server. The
valid values are:
n
0No logging
1Fatal errors
2Errors
3Warnings
4Info
Connecting to HP Vertica
Client Libraries
5Debug
The value you specify for this setting sets the minimum severity for a message to be logged. For
example, setting LogLevel to 3 means that the client driver logs all warnings, errors, and fatal
errors.
l
Note: These settings are also available for the HP Vertica JDBC driver through connection
properties. See Connection Properties for details.
ODBC-specific Settings
The following settings are used only by the HP Vertica ODBC client driver.
l
DriverManagerEncodingThe UTF encoding standard that the driver manager uses. This
setting needs to match the encoding the driver manager expects. The available values for this
setting are:
n
UTF-8
See the documentation for your driver manager to find the correct value for this setting.
Note: While both UTF-16 and UTF-8 are valid settings for DataDirect, Vertica recommends
that you set the DataDirect driver manager encoding to UTF-16.
If you do not set this parameter, the ODBC driver defaults to the value shown in the following
table. If your driver manager uses a different encoding, you must set this value for the ODBC
driver to be able to work.
Connecting to HP Vertica
Client Libraries
Client Platform
Default Encoding
AIX 32-bit
UTF-16
AIX 64-bit
UTF-32
HPUX 32-bit
UTF-32
HPUX 64-bit
UTF-32
UTF-32
UTF-32
UTF-32
OS X
UTF-32
UTF-32
UTF-32
Windows 32-bit
UTF-16
Windows 64-bit
UTF-16
ErrorMessagesPathThe absolute path to the parent directory that contains the HP Vertica
client driver's localized error message files. These files are usually stored in the same directory
as the HP Vertica ODBC driver files.
Note: This setting is required. If you do not set it, then any error the ODBC driver
encounters will result in an error message about a missing ODBCMessages.xml file.
ODBCInstLibThe absolute path to the file containing the ODBC installer library (ODBCInst).
This setting is required if the directory containing this library is not set in the LD_LIBRARY_
PATH or LIB_PATH environment variables. The library files for the major driver manager are:
n
UnixODBC: libodbcinst.so
Connecting to HP Vertica
Client Libraries
DataDirect: libodbcinst.so
Note: On AIX platforms, you need give the path to the library archive, followed by the name of
the library enclosed in parenthesis. For example:
ODBCInstLib=/usr/lib64/libodbcinst.a(libodbcinst.so.1)
ADO.NET-specific Settings
This setting applies only to the ADO.NET client driver:
C#PreloadLoggingTells the HP Vertica ADO.NET driver to begin logging as soon as possible,
before the driver has fully loaded itself. Normally, logging only starts after the driver has fully
loaded. Valid values for this setting are:
l
Connecting to HP Vertica
Client Libraries
ODBC Architecture
The ODBC architecture has four layers:
l
Client Application
Is an application that opens a data source through a Data Source Name (DSN). It then sends
requests to the data source, and receives the results of those requests. Requests are made in
the form of calls to ODBC functions.
Driver Manager
Is a library on the client system that acts as an intermediary between a client application and one
or more drivers. The driver manager:
n
Loads the driver required to access the specific database defined within the DSN.
Processes ODBC function calls from the client or passing them to the driver.
On Windows and Mac client systems, the driver manager is provided by the operating system.
On Linux and UNIX systems, you usually need to install a driver manager. See ODBC
Prerequisites for a list of driver managers that can be used with HP Vertica on your client
platform.
Connecting to HP Vertica
Client Libraries
Driver
A library on the client system that provides access to a specific database. It translates requests
into the format expected by the database, and translates results back into the format required by
the client application.
Database
The database processes requests initiated at the client application and returns results.
Cursor attributes
More than one open statement per connection. For example you cannot execute a new
statement while another statement has a result set open. If you need to execute multiple
statements at once, open multiple database connections.
Keysets
Bookmarks
The HP Vertica ODBC driver accurately reports its capabilities. If you need to determine whether it
complies with a specific feature, you should query the driver's capabilities directly using the
SQLGetInfo() function.
Connecting to HP Vertica
Client Libraries
Description
BatchInsertEnforceLength Batch inserts behave the same way all other inserts behave. If a
piece of data is too wide for its column, the row will be rejected. To
avoid having rows rejected, either truncate the data yourself or use
the COPY statement directly, which defaults to truncating data.
BinaryDataTransfer
BoolAsChar
Debug
LRSPath and
The ODBC driver now always streams data. It does not cache data
LRSStreaming
SupressWarnings
WideCharSizeIn and
WideCharSizeOut
Description
Connecting to HP Vertica
Client Libraries
Parameter
Description
DriverStringConversions
Determines whether strings sent between the server and the ODBC
client are converted.
ThreePartNaming
Description
Password
SessionLabel This is a new alias for the existing Label parameter that lets you assign a label to
an ODBC connection.
UserName
Function Changes
The following functions have changed their behavior in the version 5.1 drivers.
l
SQLGetInfo() now returns the file name of the ODBC library file when queried for the SQL_
DRIVER_NAME. Previous versions would return the brand name of the driver, which is not part
of the ODBC specifications.
In previous versions of the ODBC driver, passing the SQLGetInfo function SQL_PARAM_
ARRAY_SELECTS returned SQL_PAS_BATCH, indicating that the driver returns a batch for
each set of parameters in a SELECT statement. This return value was incorrect. The driver now
correctly returns SQL_PAS_NO_SELECT, which indicates that the driver does not support
SELECT queries using arrays of parameters.
For better compatibility with the ODBC standards, the time data type in the ODBC driver no
longer contain fractions of a second. In the new driver, functions that convert time values to
strings (for example, a SQLBindCol() call to bind a SQL_TYPE_TIME to a SQL_C_CHAR
value) no longer add fractional second values to the string. Earlier versions of the driver would
return the fractions of a second that the HP Vertica database stores.
Connecting to HP Vertica
Client Libraries
SQLBindParameter() now requires that its column-size argument for variable-width columns
(such as SQL_CHAR, SQL_VARCHAR, SQL_VARBINARY) be non-zero as specified in the
ODBC standards. The implementation of this function in previous versions of the driver allowed
a non-standard zero value to indicate the column width was a default width value.
The driver is now more strict about converting from character data types to numerical data
types. In previous drivers, any portion of the character string that could not be converted to a
numeric value was ignored. The new driver returns an error if any portion of the string cannot be
converted. For example, asking the previous driver to insert the character string "3 days" to an
integer column resulted in the value 3 being stored in the column. Now, the driver returns an error
when attempting to store this character value in an integer column.
Functions that return result sets containing catalog metadata now return SQL_WVARCHAR
columns instead of SQL_VARCHAR columns. This is standard behavior for ODBC 3.52 drivers
that are Unicode capable.
Removed Functions
The LCOPY function has been removed from the version 5.1 driver. You should instead use the
LOCAL option of the COPY SQL statement to copy data from the client system to the server. See
Streaming Data From the Client Using COPY LOCAL.
Call SQLBindParamter() to bind the value to the INTERVAL column before calling SQLPrepare
(). The interval precision is not reset unless you call SQLBindParameter() after you have called
SQLPrepare().
Reset the leading precision by using the SQLSetDescField() function to set SQL_DESC_
DATETIME_INTERVAL_PRECISION to whatever value you want.
SQLDescribeCol() now returns a new width for interval data types. For example, when passed
SQL_INTERVAL_SECOND, the previous driver would return 21 bytes. The new driver returns 16.
Connecting to HP Vertica
Client Libraries
In general, the new drivers are more strict regarding interval values, and throw errors when the old
drivers silently truncated values. If your application throws an exception when dealing with an
interval, your first debugging step is to make sure the values you are inserting are the correct width
and type.
Note: The units interval style is not supported. Do not use the SET INTERVALSTYLE
statement to change the interval style in your client applications.
SQLBindParameter() is more strict about the number of digits you supply in fractions of a second
in a timestamp. For example, the following call generates an error:
SQL_TIMESTAMP_STRUCT ts;ts.fraction = 123456; //represents the fraction 0.000123456
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TIMESTAMP, SQL_TYPE_TIMESTAMP, 0, 6,
(SQLPOINTER)&ts, 0, NULL);
SQLExecute(hstmt);
The error occurs because the fractional value represents more than six digits. Instead you would
need to change the SQLBindParameter call to allow 9 digits in the fraction:
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TIMESTAMP, SQL_TYPE_TIMESTAMP, 0, 9,
(SQLPOINTER)&ts, 0, NULL);
Note that the fraction will be truncated to 0.000123, since timestamps do not have nanosecond
precision. But you still need to allow for all of the fractional digits to be inserted into the timestamp.
Connecting to HP Vertica
Client Libraries
Description
Associated Function
SQL_ATTR_VERTICA_RESULT_BUFFER_
SIZE
SQLSetConnectAttr()
SQLGetConnectAttr()
SQL_ATTR_VERTICA_DIRECT_BATCH_
INSERT
Determines
whether a batch is
inserted directly
SQLSetConnectAttr() SQLSetStmtAttr
()
SQLGetConnectAttr()
SQLGetStmtAttr()
SQLSetConnectAttr()
SQLGetConnectAttr()
US@collation=bina
ry to the ICU locale
specified. See
Setting the Locale
for ODBC
Sessions for an
example of using
this parameter.
Connecting to HP Vertica
Client Libraries
Connecting to
The first step in any ODBC application is to connect to the database. When you create the
connection to a data source using ODBC, you use the name of the DSN that contains the details of
the driver to use, the database host, and other basic information about connecting to the data
source.
There are 4 steps your application needs to take to connect to a database:
1. Call SQLAllocHandle() to allocate a handle for the ODBC environment. This handle is used to
create connection objects and to set application-wide settings.
2. Use the environment handle to set the version of ODBC that your application wants to use.
This ensures that the data source knows which API your application will use to interact with it.
3. Allocate a database connection handle by calling SQLAllocHandle(). This handle represents a
connection to a specific data source.
4. Use the SQLConnect() or SQLDriverConnect() functions to open the connection to the
database.
Note: If you specify a locale either in the connection string or in the DSN, the call to the
connection function returns SQL_SUCCESS_WITH_INFO on a successful connection,
with messages about the state of the locale.
When creating the connection to the database, use SQLConnect() when the only options you need
to set at connection time is the username and password. Use SQLDriverConnect() when you
want to change connection options, such as the locale.
The following example demonstrates connecting to a database using a DSN named ExampleDB.
After it creates the connection successfully, this example simply closes it.
// Demonstrate connecting to Vertica using ODBC.
// Standard i/o library
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// SQL include files that define data types and ODBC API
// functions
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
int main()
Connecting to HP Vertica
Client Libraries
{
SQLRETURN ret;
// Stores return value from ODBC API calls
SQLHENV hdlEnv; // Handle for the SQL environment object
// Allocate an a SQL environment object
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate a handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated an environment handle.\n");
}
// Set the ODBC version we are going to use to
// 3.
ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not set application version to ODBC 3.\n");
exit(EXIT_FAILURE);
} else {
printf("Set application version to ODBC 3.\n");
}
// Allocate a database handle.
SQLHDBC hdlDbc;
ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate database handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated Database handle.\n");
}
// Connect to the database using
// SQL Connect
printf("Connecting to database.\n");
const char *dsnName = "ExampleDB";
const char* userID = "ExampleUser";
const char* passwd = "password123";
ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName,
SQL_NTS,(SQLCHAR*)userID,SQL_NTS,
(SQLCHAR*)passwd, SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not connect to database.\n");
exit(EXIT_FAILURE);
} else {
printf("Connected to database.\n");
}
// We're connected. You can do real
// work here
// When done, free all of the handles to close them
// in an orderly fashion.
printf("Disconnecting and freeing handles.\n");
ret = SQLDisconnect( hdlDbc );
if(!SQL_SUCCEEDED(ret)) {
printf("Error disconnecting from database. Transaction still open?\n");
exit(EXIT_FAILURE);
}
Connecting to HP Vertica
Client Libraries
SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
exit(EXIT_SUCCESS);
}
See Setting the Locale for ODBC Sessions for an example of using SQLDriverConnect to connect
to the database.
Notes
l
If you use the DataDirect driver manager, you should always use the SQL_DRIVER_
NOPROMPT value for the SQLDriverConnect function's DriverCompletion parameter (the final
parameter in the function call) when connecting to HP Vertica. HP Vertica's ODBC driver on
Linux and UNIX platforms does not contain a UI, and therefore cannot prompt users for a
password.
On Windows client platforms, the ODBC driver can prompt users for connection information.
See Prompting Windows Users for Missing Connection Parameters for more information.
If your database does not comply with your HP Vertica license agreement, your application
receives a warning message in the return value of the SQLConnect() function. Always have your
application examine this return value to see if it is SQL_SUCCESS_WITH_INFO. If it is, have
your application extract and display the message to the user.
Connecting to HP Vertica
Client Libraries
client begins the authentication process. See About Native Connection Load Balancing in the
Administrator's Guide for details.
To enable native load balancing on your client, set the ConnectionLoadBalance connection
parameter to true either in the DSN entry or in the connection string. The following example
demonstrates connecting to the database several times with native connection load balancing
enabled, and fetching the name of the node handling the connection from the V_
MONITOR.CURRENT_SESSION system table.
// Demonstrate enabling native load connection balancing.
// Standard i/o library
#include <stdlib.h>
#include <iostream>
#include <assert.h>
// Only needed for Windows clients
// #include <windows.h>
// SQL include files that define data types and ODBC API
// functions
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
using namespace std;
int main()
{
SQLRETURN ret;
// Stores return value from ODBC API calls
SQLHENV hdlEnv; // Handle for the SQL environment object
// Allocate an a SQL environment object
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
assert(SQL_SUCCEEDED(ret));
// Set the ODBC version we are going to use to
// 3.
ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
assert(SQL_SUCCEEDED(ret));
// Allocate a database handle.
SQLHDBC hdlDbc;
ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc);
assert(SQL_SUCCEEDED(ret));
// Connect four times. If load balancing is on, client should
// connect to different nodes.
for (int x=1; x <= 4; x++) {
// Connect to the database using SQLDriverConnect. Set
// ConnectionLoadBalance to 1 (true) to enable load
// balancing.
cout << endl << "Connection attempt #" << x << "... ";
const char *connStr = "DSN=VMart;ConnectionLoadBalance=1;"
"UID=ExampleUser;PWD=password123";
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
Disconnecting.
Connection attempt #4... succeeded
Connected to node v_vmart_node0001
Disconnecting.
Freeing handles...
Done!
Configure your DNS server to return multiple IP addresses for a host name. When you use this
host name in the connection settings, the client attempts to connect to the first IP address from
the DNS lookup. If the host at that IP address is unreachable, the client tries to connect to the
second IP, and so on until it either manages to connect to a host or it runs out of IP addresses.
Supply a list of backup hosts for the client driver to try if the primary host you specify in the
connection parameters is unreachable.
For both methods, the process of failover is transparent to the client application (other than
specifying the list of backup hosts, if you choose to use the list method of failover). If the primary
host is unreachable, the client driver automatically tries to connect to other hosts.
Failover only applies to the initial establishment of the client connection. If the connection breaks,
the driver does not automatically try to reconnect to another host in the database.
Connecting to HP Vertica
Client Libraries
Note: If a host name in the backup host list resolves to multiple IP addresses, the client does
not try all of them. It just tries the first IP address in the list.
The DNS method of failover centralizes the configuration client failover. As you add new nodes to
your Vertica Analytic Database cluster, you can choose to add them to the failover list by editing
the DNS server settings. All client systems that use the DNS server to connect to Vertica Analytic
Database automatically use connection failover without having to change any settings. However,
this method does require administrative access to the DNS server that all clients use to connect to
the Vertica Analytic Database cluster. This may not be possible in your organization.
Using the backup server list is easier than editing the DNS server settings. However, it
decentralizes the failover feature. You may need to update the application settings on each client
system if you make changes to your Vertica Analytic Database cluster.
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
When run, the example's output on the system console is similar to the following:
Connecting to database.
Connected to database.
Connected to node v_vmart_node0002
Disconnecting.
Freeing handles...
Done!
Notice that the connection was made to the first node in the backup list (node 2).
Note: When native connection load balancing is enabled, the additional servers specified in the
BackupServerNode connection parameter are only used for the initial connection to an HP
Vertica host. If host redirects the client to another host in the database cluster to handle its
connection request, the second connection does not use the backup node list. This is rarely an
Connecting to HP Vertica
Client Libraries
issue, since native connection load balancing is aware of which nodes are currently up in the
database. See Enabling Native Connection Load Balancing in ODBC
If either of the above conditions are true, the driver displays an HP Vertica Connection Dialog to the
user to prompt for connection information.
Any parameters supplied in the connection string or DSN filled in on the dialog.
Note: Your connection string at least needs to specify Vertica as the driver, otherwise
Windows will not know to use the Vertica ODBC driver to try to open the connection.
The required fields on the connection dialog are Database, UID, Server, and Port. Once these are
filled in, the form enables the OK button.
Connecting to HP Vertica
Client Libraries
If the user clicks Cancel on the dialog, the SQLDriverConnect function call returns SQL_NO_
DATA immediately, without attempting to connect to HP Vertica. If the user supplies incomplete or
incorrect information for the connection, the connection function returns SQL_ERROR after the
connection attempt fails.
Note: If the DriverCompletion parameter of the SQLDriverConnect function call is SQL_
DRIVER_NOPROMPT, the ODBC driver immediately returns a SQL_ERROR indicating that
it cannot connect because not enough information has been supplied and the driver is not
allowed to prompt the user for the missing information.
The following table shows how the PromptOnNoPassword DSN parameter, the DriverCompletion
parameter of the SQLDriverConnect function, and whether the DSN or connection string contains a
password interact to control whether the HP Vertica Connection dialog appears.
Connecting to HP Vertica
Client Libraries
DSN or
Connection
String
PromptOnNoPassword DriverCompletion Contains
Setting
Value
Password?
HP Vertica
Connection
Dialog
Displays?
Notes
any value
Yes
SQL_DRIVER_
any case
PROMPT
This
DriverCompletion
value forces the
dialog to always
appear, even if all
required
connection
properties are
supplied.
any value
SQL_DRIVER_
any case
No
NOPROMPT
This
DriverCompletion
value always
prevents the
dialog from
appearing.
any value
SQL_DRIVER_
Yes
No
COMPLETE
Connection
dialog displays if
another required
connection
property is
missing.
true
SQL_DRIVER_
No
Yes
No
No
COMPLETE
false (default)
SQL_DRIVER_
COMPLETE
Connection
dialog displays if
another required
connection
property is
missing.
The following example code demonstrates using the PromptOnNoPassword DSN parameter along
with a system DSN.
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
5. If find operation did not locate a folder under the ODBC.INI folder, click Edit > Find Next (or
press F3) until the folder matching your DSN's name is highlighted.
Specify the locale for all connections made using the DSN:
n
On Linux and other UNIX-like platforms: Creating an ODBC DSN for Linux, Solaris, AIX, and
HP-UX
On Windows platforms, set the locale in the ODBC DSN configuration editor's Locale field on
the Server Settings tab. See Creating an ODBC DSN for Windows Clients for detailed
information.
Connecting to HP Vertica
Client Libraries
Set the Locale connection parameter in the connection string in SQLDriverConnect() function.
For example:
SQLDriverConnect(conn, NULL, (SQLCHAR*)"DSN=Vertica;Locale=en_GB", SQL_NTS, szConnOut,
sizeof(szConnOut), &iAvailable, SQL_DRIVER_NOPROMPT)
Notes
l
Having the client system use a non-Unicode locale (such as setting LANG=C on Linux platforms)
and using a Unicode locale for the connection to HP Vertica can result in errors such as "(10170)
String data right truncation on data from data source." If data received from HP Vertica isn't in
UTF-8 format. The driver allocates string memory based on the system's locale setting, and
non-UTF-8 data can trigger an overrun. You can avoid these errors by always using a Unicode
locale on the client system.
If you specify a locale either in the connection string or in the DSN, the call to the connection
function returns SQL_SUCCESS_WITH_INFO on a successful connection, with messages
about the state of the locale.
If ANSI, the data must be in single-byte ASCII, which is compatible with UTF-8 on the
database server.
The ODBC driver converts UCS-2 to UTF-8 when passing to the HP Vertica server and
converts data sent by the HP Vertica server from UTF-8 to UCS-2.
l
If the end-user application is not already in UCS-2, the application is responsible for converting
the input data to UCS-2, or unexpected results could occur. For example:
n
On non-UCS-2 data passed to ODBC APIs, when it is interpreted as UCS-2, it could result in
an invalid UCS-2 symbol being passed to the APIs, resulting in errors.
Or the symbol provided in the alternate encoding could be a valid UCS-2 symbol; in this case,
incorrect data is inserted into the database.
Connecting to HP Vertica
Client Libraries
ODBC applications should set the correct server session locale using SQLSetConnectAttr (if
different from database-wide setting) in order to set the proper collation and string functions
behavior on server.
The following example code demonstrates setting the locale using both the connection string and
through the SQLSetConnectAttr() function.
// Standard i/o library
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// SQL include files that define data types and ODBC API
// functions
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
// Vertica-specific definitions. This include file is located as
// /opt/vertica/include on database hosts.
#include <verticaodbc.h>
int main()
{
SQLRETURN ret;
// Stores return value from ODBC API calls
SQLHENV hdlEnv; // Handle for the SQL environment object
// Allocate an a SQL environment object
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate a handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated an environment handle.\n");
}
// Set the ODBC version we are going to use to 3.
ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not set application version to ODBC 3.\n");
exit(EXIT_FAILURE);
} else {
printf("Set application version to ODBC 3.\n");
}
// Allocate a database handle.
SQLHDBC hdlDbc;
ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate database handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated Database handle.\n");
}
// Connect to the database using SQLDriverConnect
printf("Connecting to database.\n");
// Set the locale to English in Great Britain.
const char *connStr = "DSN=ExampleDB;locale=en_GB;"
"UID=dbadmin;PWD=password123";
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
If AUTOCOMMIT is off, you need to manually commit the transaction after executing a statement.
For example:
ret = SQLExecDirect(hdlStmt, (SQLCHAR*)"INSERT INTO customers VALUES(500,"
"'Smith, Sam', '123-456-789');", SQL_NTS);
// Other inserts and data manipulations
// Commit the statements(s)
ret = SQLEndTran(SQL_HANDLE_DBC, hdlDbc, SQL_COMMIT);
The inserted row is only committed when you call SQLEndTran(). You can roll back the INSERT
and other statements at any point before committing the transaction.
Note: Prepared statements cache the AUTOCOMMIT setting when you create them using
SQLPrepare(). Later changing the connection's AUTOCOMMIT setting has no effect on the
AUTOCOMMIT settings of previously created prepared statements. See Using Prepared
Statements for details.
The following example demonstrates turning off AUTOCOMMIT, executing an insert, then
manually committing the transaction.
// Some standard headers
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// Standard ODBC headers
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
int main()
{
// Set up the ODBC environment
SQLRETURN ret;
SQLHENV hdlEnv;
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate a handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated an environment handle.\n");
}
// Tell ODBC that the application uses ODBC 3.
ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not set application version to ODBC3.\n");
Connecting to HP Vertica
Client Libraries
exit(EXIT_FAILURE);
} else {
printf("Set application to ODBC 3.\n");
}
// Allocate a database handle.
SQLHDBC hdlDbc;
ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate database handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated Database handle.\n");
}
// Connect to the database
printf("Connecting to database.\n");
const char *dsnName = "ExampleDB";
const char* userID = "dbadmin";
const char* passwd = "password123";
ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName,
SQL_NTS,(SQLCHAR*)userID,SQL_NTS,
(SQLCHAR*)passwd, SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not connect to database.\n");
exit(EXIT_FAILURE);
} else {
printf("Connected to database.\n");
}
// Get the AUTOCOMMIT state
SQLINTEGER autoCommitState;
SQLGetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, &autoCommitState, 0, NULL);
printf("Autocommit is set to: %d\n", autoCommitState);
// Disable AUTOCOMMIT
printf("Disabling autocommit.\n");
ret = SQLSetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF,
SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not disable autocommit.\n");
exit(EXIT_FAILURE);
}
// Get the AUTOCOMMIT state again
SQLGetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, &autoCommitState, 0, NULL);
printf("Autocommit is set to: %d\n", autoCommitState);
// Set up a statement handle
SQLHSTMT hdlStmt;
SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt);
Connecting to HP Vertica
Client Libraries
Note: You can also disable AUTOCOMMIT in the ODBC connection string. See Setting DSN
Connection Parameters for more information.
Connecting to HP Vertica
Client Libraries
Use the SQLFetch() function to retrieve a row of the result set, then access column values in
the row by calling SQLGetData().
Use the SQLBindColumn() function to bind a variable or array to a column in the result set, then
call SQLExtendedFetch() or SQLFetchScroll() to read a row of the result set and insert its
values into the variable or array.
In both methods you loop through the result set until you either reach the end (signaled by the SQL_
NO_DATA return status) or encounter an error.
Note: HP Vertica supports one cursor per connection. Attempting to use more than one cursor
per connection will result in an error. For example, you receive an error if you execute a
statement while another statement has a result set open.
The following code example demonstrates retrieving data from HP Vertica by:
1. Connecting to the database.
2. Executing a SELECT statement that returns the IDs and names of all tables.
3. Binds two variables to the two columns in the result set.
4. Loops through the result set, printing the ids and name values.
// Demonstrate running a query and getting results by querying the tables
// system table for a list of all tables in the current schema.
// Some standard headers
#include <stdlib.h>
#include <sstream>
#include <iostream>
#include <assert.h>
// Standard ODBC headers
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
// Use std namespace to make output easier
using namespace std;
// Helper function to print SQL error messages.
template <typename HandleT>
void reportError(int handleTypeEnum, HandleT hdl)
{
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
// See if loop exited for reasons other than running out of data
if (ret != SQL_NO_DATA) {
// Exited for a reason other than no more data... report the error.
reportError<SQLHDBC>( SQL_HANDLE_STMT, hdlStmt );
}
}
Running the example code in the vmart database produces output similar to this:
Connecting to database.
Connected to database.
Fetching results...
45035996273970908 | call_center_dimension
45035996273970836 | customer_dimension
45035996273972958 | customers
45035996273970848 | date_dimension
45035996273970856 | employee_dimension
Connecting to HP Vertica
Client Libraries
45035996273970868
45035996273970904
45035996273970912
45035996273970840
45035996273970844
45035996273970860
45035996273970876
45035996273970894
45035996273970880
45035996273972806
45035996273970852
45035996273970864
Free handles.
|
|
|
|
|
|
|
|
|
|
|
|
inventory_fact
online_page_dimension
online_sales_fact
product_dimension
promotion_dimension
shipping_dimension
store_dimension
store_orders_fact
store_sales_fact
t
vendor_dimension
warehouse_dimension
Preventing SQL injection attacks. A SQL injection attack occurs when user input is either
incorrectly filtered for string literal escape characters embedded in SQL statements or user input
Connecting to HP Vertica
Client Libraries
is not strongly typed and thereby unexpectedly run. Since a prepared statement is parsed
separately from the input data, there is no chance the data can be accidentally executed by the
database.
l
Binding direct variables to return columns. By pointing to data structures, the code doesn't have
to perform extra transformations.
The following example demonstrates a using a prepared statement for a single insert.
// Some standard headers
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// Standard ODBC headers
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
// Some constants for the size of the data to be inserted.
#define CUST_NAME_LEN 50
#define PHONE_NUM_LEN 15
#define NUM_ENTRIES 4
int main()
{
// Set up the ODBC environment
SQLRETURN ret;
SQLHENV hdlEnv;
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate a handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated an environment handle.\n");
}
// Tell ODBC that the application uses ODBC 3.
ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not set application version to ODBC3.\n");
exit(EXIT_FAILURE);
} else {
printf("Set application to ODBC 3.\n");
}
// Allocate a database handle.
SQLHDBC hdlDbc;
ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc);
// Connect to the database
printf("Connecting to database.\n");
const char *dsnName = "ExampleDB";
const char* userID = "dbadmin";
const char* passwd = "password123";
ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName,
SQL_NTS,(SQLCHAR*)userID,SQL_NTS,
(SQLCHAR*)passwd, SQL_NTS);
Connecting to HP Vertica
Client Libraries
if(!SQL_SUCCEEDED(ret)) {
printf("Could not connect to database.\n");
exit(EXIT_FAILURE);
} else {
printf("Connected to database.\n");
}
// Disable AUTOCOMMIT
printf("Disabling autocommit.\n");
ret = SQLSetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF,
SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not disable autocommit.\n");
exit(EXIT_FAILURE);
}
Connecting to HP Vertica
Client Libraries
} else {
printf("Bound custID to prepared statement\n");
}
// Bind CustNames
SQLBindParameter(hdlStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
50, 0, (SQLPOINTER)custName, 0, &strFieldLen);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not bind custNames\n");
SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
exit(EXIT_FAILURE);
} else {
printf("Bound custName to prepared statement\n");
}
// Bind phoneNums
SQLBindParameter(hdlStmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
15, 0, (SQLPOINTER)phoneNum, 0, &strFieldLen);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not bind phoneNums\n");
SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
exit(EXIT_FAILURE);
} else {
printf("Bound phoneNum to prepared statement\n");
}
// Execute the prepared statement.
printf("Running prepared statement...");
ret = SQLExecute(hdlStmt);
if(!SQL_SUCCEEDED(ret)) {
printf("not successful!\n");
} else {
printf("successful.\n");
}
// Done with batches, commit the transaction
printf("Committing transaction\n");
ret = SQLEndTran(SQL_HANDLE_DBC, hdlDbc, SQL_COMMIT);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not commit transaction\n");
} else {
printf("Committed transaction\n");
}
// Clean up
printf("Free handles.\n");
ret = SQLDisconnect( hdlDbc );
if(!SQL_SUCCEEDED(ret)) {
printf("Error disconnecting. Transaction still open?\n");
exit(EXIT_FAILURE);
}
SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
exit(EXIT_SUCCESS);
}
Connecting to HP Vertica
Client Libraries
Note: If the database connection has AUTOCOMMIT enabled, then the transaction is
automatically committed after each batch insert statement which closes the COPY statement.
Leaving AUTOCOMMIT enabled makes your batch load much less efficient, and can cause
added overhead in your database as all of the smaller loads are consolidated.
Even though HP Vertica uses a single COPY statement to insert multiple batches within a
transaction, you can locate which (if any) rows were rejected due to invalid row formats or data type
issues after each batch is loaded. See Tracking Load Status (ODBC) for details.
Note: While you can find rejected rows during the batch load transaction, other types of errors
(such as running out of disk space or a node shutdown that makes the database unsafe) are
only reported when the COPY statement ends.
Since the batch loads share a COPY statement, errors in one batch can cause earlier batches in the
same transaction to be rolled back.
Connecting to HP Vertica
Client Libraries
3. Create a prepared statement that inserts the data you want to load.
4. Bind the parameters of the prepared statement to arrays that will contain the data you want to
load.
5. Populate the arrays with the data for your batches.
6. Execute the prepared statement.
7. Optionally, check the results of the batch load to find rejected rows.
8. Repeat the previous three steps until all of the data you want to load is loaded.
9. Commit the transaction.
10. Optionally, check the results of the entire batch transaction.
The following example code demonstrates a simplified version of the above steps.
// Some standard headers
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// Standard ODBC headers
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
int main()
{
// Number of data rows to insert
const int NUM_ENTRIES = 4;
// Set up the ODBC environment
SQLRETURN ret;
SQLHENV hdlEnv;
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate a handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated an environment handle.\n");
}
// Tell ODBC that the application uses ODBC 3.
ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not set application version to ODBC3.\n");
exit(EXIT_FAILURE);
} else {
printf("Set application to ODBC 3.\n");
}
Connecting to HP Vertica
Client Libraries
// Disable AUTOCOMMIT
printf("Disabling autocommit.\n");
ret = SQLSetConnectAttr(hdlDbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF,
SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not disable autocommit.\n");
exit(EXIT_FAILURE);
}
// Set up a statement handle
SQLHSTMT hdlStmt;
SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt);
// Create a table to hold the data
SQLExecDirect(hdlStmt, (SQLCHAR*)"DROP TABLE IF EXISTS customers",
SQL_NTS);
SQLExecDirect(hdlStmt, (SQLCHAR*)"CREATE TABLE customers "
"(CustID int, CustName varchar(100), Phone_Number char(15));",
SQL_NTS);
// Create the prepared statement. This will insert data into the
// table we created above.
printf("Creating prepared statement\n");
ret = SQLPrepare (hdlStmt, (SQLTCHAR*)"INSERT INTO customers (CustID, "
"CustName, Phone_Number) VALUES(?,?,?)", SQL_NTS) ;
if(!SQL_SUCCEEDED(ret)) {
printf("Could not create prepared statement\n");
exit(EXIT_FAILURE);
} else {
printf("Created prepared statement.\n");
}
// This is the data to be inserted into the database.
SQLCHAR custNames[][50] = { "Allen, Anna", "Brown, Bill", "Chu, Cindy",
Connecting to HP Vertica
Client Libraries
"Dodd, Don" };
SQLINTEGER custIDs[] = { 100, 101, 102, 103};
SQLCHAR phoneNums[][15] = {"1-617-555-1234", "1-781-555-1212",
"1-508-555-4321", "1-617-555-4444"};
// Bind the data arrays to the parameters in the prepared SQL
// statement. First is the custID.
ret = SQLBindParameter(hdlStmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
0, 0, (SQLPOINTER)custIDs, sizeof(SQLINTEGER) , NULL);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not bind custID array\n");
exit(EXIT_FAILURE);
} else {
printf("Bound CustIDs array to prepared statement\n");
}
// Bind CustNames
ret = SQLBindParameter(hdlStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
50, 0, (SQLPOINTER)custNames, 50, NULL);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not bind custNames\n");
exit(EXIT_FAILURE);
} else {
printf("Bound CustNames array to prepared statement\n");
}
// Bind phoneNums
ret = SQLBindParameter(hdlStmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
15, 0, (SQLPOINTER)phoneNums, 15, NULL);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not bind phoneNums\n");
exit(EXIT_FAILURE);
} else {
printf("Bound phoneNums array to prepared statement\n");
}
// Tell the ODBC driver how many rows we have in the
// array.
ret = SQLSetStmtAttr( hdlStmt, SQL_ATTR_PARAMSET_SIZE,
(SQLPOINTER)NUM_ENTRIES, 0 );
if(!SQL_SUCCEEDED(ret)) {
printf("Could not bind set parameter size\n");
exit(EXIT_FAILURE);
} else {
printf("Bound phoneNums array to prepared statement\n");
}
// Add multiple batches to the database. This just adds the same
// batch of data four times for simplicity's sake. Each call adds
// the 4 rows into the database.
for (int batchLoop=1; batchLoop<=5; batchLoop++) {
// Execute the prepared statement, loading all of the data
// in the arrays.
printf("Adding Batch #%d...", batchLoop);
ret = SQLExecute(hdlStmt);
if(!SQL_SUCCEEDED(ret)) {
printf("not successful!\n");
} else {
printf("successful.\n");
}
}
// Done with batches, commit the transaction
Connecting to HP Vertica
Client Libraries
printf("Committing transaction\n");
ret = SQLEndTran(SQL_HANDLE_DBC, hdlDbc, SQL_COMMIT);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not commit transaction\n");
} else {
printf("Committed transaction\n");
}
// Clean up
printf("Free handles.\n");
ret = SQLDisconnect( hdlDbc );
if(!SQL_SUCCEEDED(ret)) {
printf("Error disconnecting. Transaction still open?\n");
exit(EXIT_FAILURE);
}
SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
exit(EXIT_SUCCESS);
}
Connecting to HP Vertica
Client Libraries
103 |
100 |
101 |
102 |
103 |
100 |
101 |
102 |
103 |
100 |
101 |
102 |
103 |
(20 rows)
Dodd, Don
Allen, Anna
Brown, Bill
Chu, Cindy
Dodd, Don
Allen, Anna
Brown, Bill
Chu, Cindy
Dodd, Don
Allen, Anna
Brown, Bill
Chu, Cindy
Dodd, Don
|
|
|
|
|
|
|
|
|
|
|
|
|
1-617-555-4444
1-617-555-1234
1-781-555-1212
1-508-555-4321
1-617-555-4444
1-617-555-1234
1-781-555-1212
1-508-555-4321
1-617-555-4444
1-617-555-1234
1-781-555-1212
1-508-555-4321
1-617-555-4444
Note: An input parameter bound with the SQL_C_NUMERIC data type uses the default
numeric precision (37) and the default scale (0) instead of the precision and scale set by the
SQL_NUMERIC_STRUCT input value. This behavior adheres to the ODBC standard. If you
do not want to use the default precision and scale, use SQLSetDescField() or SQLSetDescRec
() to change them in the statement's attributes.
When your application calls SQLExecute() to insert the batch, the HP Vertica ODBC driver saves
the number of rows that it processed (which is not necessarily the number of rows that were
successfully inserted) in the variable you specified in the SQL_ATTR_PARAMS_PROCESSED_
PTR statement attribute.
Connecting to HP Vertica
Client Libraries
SQLUSMALLINT
rowResults[ NUM_ENTRIES ];
SQLSetStmtAttr(hdlStmt, SQL_ATTR_PARAM_STATUS_PTR, rowResults, 0);
This array must be at least as large as the number of rows being inserted in each batch.
When your application calls SQLExecute to insert a batch, the ODBC driver populates the array with
values indicating whether each row was successfully inserted (SQL_PARAM_SUCCESS or SQL_
PARAM_SUCCESS_WITH_INFO) or encountered an error (SQL_PARAM_ERROR).
The following example expands on the example shown in Using Batch Inserts to include reporting
the number of rows processed and the status of each row inserted.
// Some standard headers
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// Standard ODBC headers
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
// Helper function to print SQL error messages.
template <typename HandleT>
void reportError(int handleTypeEnum, HandleT hdl)
{
// Get the status records.
SQLSMALLINT
i, MsgLen;
SQLRETURN ret2;
SQLCHAR
SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH];
SQLINTEGER
NativeError;
i = 1;
printf("\n");
while ((ret2 = SQLGetDiagRec(handleTypeEnum, hdl, i, SqlState, &NativeError,
Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA) {
printf("error record %d\n", i);
printf("sqlstate: %s\n", SqlState);
printf("detailed msg: %s\n", Msg);
printf("native error code: %d\n\n", NativeError);
i++;
}
}
int main()
{
// Number of data rows to insert
const int NUM_ENTRIES = 4;
SQLRETURN ret;
SQLHENV hdlEnv;
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate a handle.\n");
exit(EXIT_FAILURE);
} else {
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
// Clean up
printf("Free handles.\n");
ret = SQLDisconnect( hdlDbc );
if(!SQL_SUCCEEDED(ret)) {
printf("Error disconnecting. Transaction still open?\n");
exit(EXIT_FAILURE);
}
SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
exit(EXIT_SUCCESS);
}
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
should explicitly end the COPY statement at the end of your batch load and handle any errors
at that time.
Connecting to HP Vertica
Client Libraries
file resides on the database server. One drawback is that only a database superuser can use
COPY, since it requires privilege in order to access the filesystem of the database node.
One drawback of using COPY instead of performing batch loads is that you can only get results of
the load (the number of accepted and rejected rows) when the COPY statement has finished. With
batch loads, you can monitor the progress as batches are inserted. The ability to monitor the
progress of a load can be a useful feature if you want to stop loading if a large portion of the data is
being rejected.
A primary concern when bulk loading data using COPY is deciding whether the data should be
loaded directly into ROS using the DIRECT option, or by using the AUTO method (loading into
WOS until it fills, then loading into ROS). You should load directly into the ROS when your
transaction will load a large (more than 100MB of data or so) amount of data.
Note: The exceptions/rejections files are created on the client machine when the exceptions
and rejected data modifiers are specified on the COPY command. Specify a local path and
filename for these modifiers when executing a COPY query from the driver.
The following example loads data into the WOS (Write Optimized Store) until it fills, then stores
additional data directly in ROS (Read Optimized Store).
ret=SQLExecDirect(hdlStmt, (SQLCHAR*)"COPY customers "
"FROM '/data/customers.txt' AUTO",SQL_NTS);
The following example loads data into the ROS (Read Optimized Store.
ret=SQLExecDirect(hdlStmt, (SQLCHAR*)"COPY customers "
"FROM '/data/customers.txt' DIRECT",SQL_NTS);
See the COPY statement in the SQL Reference Manual for more information about its syntax and
use.
The following example demonstrates using the COPY command.
// Some standard headers
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// Standard ODBC headers
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
// Helper function to determine if an ODBC function call returned
// successfully.
bool notSuccess(SQLRETURN ret) {
Connecting to HP Vertica
Client Libraries
Connecting to HP Vertica
Client Libraries
SQL_NTS);
SQLExecDirect(hdlStmt, (SQLCHAR*)"CREATE TABLE customers"
"(Last_Name char(50) NOT NULL, First_Name char(50),Email char(50), "
"Phone_Number char(15));",
SQL_NTS);
// Run the copy command to load data into ROS.
ret=SQLExecDirect(hdlStmt, (SQLCHAR*)"COPY customers "
"FROM '/data/customers.txt' DIRECT",
SQL_NTS);
if(notSuccess(ret)) {
printf("Data was not successfully loaded.\n");
exit(EXIT_FAILURE);
} else {
// Get number of rows added.
SQLLEN numRows;
ret=SQLRowCount(hdlStmt, &numRows);
printf("Successfully inserted %d rows.\n", numRows);
}
// Done with batches, commit the transaction
printf("Committing transaction\n");
ret = SQLEndTran(SQL_HANDLE_DBC, hdlDbc, SQL_COMMIT);
if(notSuccess(ret)) {
printf("Could not commit transaction\n");
} else {
printf("Committed transaction\n");
}
// Clean up
printf("Free handles.\n");
SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
exit(EXIT_SUCCESS);
}
Connecting to HP Vertica
Client Libraries
transferring data files from the client to the server much easier.
The LOCAL option of COPY works transparently through the ODBC driver. Just have your client
application execute a statement containing a COPY LOCAL statement, and the ODBC driver will
read and stream the data file from the client to the server. For example:
// Some standard headers
#include <stdio.h>
#include <stdlib.h>
// Only needed for Windows clients
// #include <windows.h>
// Standard ODBC headers
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
int main()
{
// Set up the ODBC environment
SQLRETURN ret;
SQLHENV hdlEnv;
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not allocate a handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Allocated an environment handle.\n");
}
// Tell ODBC that the application uses ODBC 3.
ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not set application version to ODBC3.\n");
exit(EXIT_FAILURE);
} else {
printf("Set application to ODBC 3.\n");
}
// Allocate a database handle.
SQLHDBC hdlDbc;
ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not aalocate a database handle.\n");
exit(EXIT_FAILURE);
} else {
printf("Set application to ODBC 3.\n");
}
// Connect to the database
printf("Connecting to database.\n");
const char *dsnName = "ExampleDB";
const char* userID = "dbadmin";
const char* passwd = "password123";
ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName,
SQL_NTS,(SQLCHAR*)userID,SQL_NTS,
(SQLCHAR*)passwd, SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not connect to database.\n");
exit(EXIT_FAILURE);
} else {
Connecting to HP Vertica
Client Libraries
printf("Connected to database.\n");
}
// Set up a statement handle
SQLHSTMT hdlStmt;
SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt);
This example is essentially the same as the example shown in Using the COPY Statement, except
it uses the COPY statement's LOCAL option to load data from the client system rather than from
the filesystem of the database node.
Note: On Windows clients, the path you supply for the COPY LOCAL file is limited to 216
characters due to limitations in the Windows API.
Connecting to HP Vertica
Client Libraries
See Also
l
COPY LOCAL
Note: Do not use inefficient encoding formats for LONG VARBINARY and LONG VARCHAR
values. HP Vertica cannot load encoded values larger than 32MB, even if the decoded value is
less than 32 MB in size. For example, HP Vertica returns an error if you attempt to load a 32MB
LONG VARBINARY value encoded in octal format, since the octal encoding quadruples the
size of the value (each byte is converted into a backslash followed by three digits).
Connecting to HP Vertica
Cursors are forward only and are not scrollable. Result sets cannot be updated.
A connection supports executing a single statement at any time. If you want to execute multiple
statements simultaneously, you must open multiple connections.
Because HP Vertica does not have stored procedures, CallableStatement is not supported.
The DatabaseMetaData.getProcedures() and .getProcedureColumns() methods return
information about SQL functions (including User Defined Functions) instead of stored
procedures.
Connecting to HP Vertica
Only the Statement interface supports executing strings containing multiple SQL statements. You
cannot use multiple statement strings with PreparedStatement. COPY statements that copy a file
from a host file system work in a multiple statement string. However, client COPY statements
(COPY FROM STDIN) do not work.
Connecting to HP Vertica
Class.forName("com.vertica.Driver");
Class.forName("com.vertica.jdbc.Driver");
Note: The HP Vertica version 7.0 JDBC driver introduces JDBC 4.0 compatibility which
includes the JNDI service registration that eliminates the need to manually load the JDBC
driver. See New Features in the Version JDBC Driver for details.
VerticaConnection
PGStatement
VerticaStatement
Normally, you reference these interfaces only when casting a Connection or Statement object to
access HP Vertica-specific methods or properties. Many of the HP Vertica-specific methods and
properties have been removed from the version 5.1 client drivers in favor of JDBC-standard
methods and properties. You should not need to cast to these interfaces as often when using the
new client drivers. See Converting From PGConnection to VerticaConnection and Converting From
PGStatement to VerticaStatement for more information.
Removed Classes
The HP Vertica version 5.1 JDBC driver has removed several legacy classes.
Connecting to HP Vertica
4.1 Methods
5.1 Property
Name
Description
getBatchDirectInsert()setBatchDirectInsert()
DirectBatchInsert
getMaxLRSMemory()setMaxLRSMemory()
ResultBufferSize
Connecting to HP Vertica
creating the database connection. See Connection Properties and Setting and Getting Connection
Property Values for more information.
Deprecated Methods
The following methods of the PGConnection class were deprecated in the version 4.1 drivers, and
are not implemented by VerticaConnection:
Removed Methods
Reason
getBatchInsertEnforceLength()setBatchInsertEnforceLength()
getBinaryBatchInsert()setBinaryBatchInsert()
Connecting to HP Vertica
Removed Methods
Reason
getLocale()setLocale()
getStreamingLRS()setStreamingLRS()
getEncoding()setEncoding()
getFastPathAPI()
getLargeObjectAPI()
getManagedBatchInsert()
setManagedBatchInsert()
getObject()
getPGType()
getPrepareThreshold()
setPrepareThreshold()
getSQLType()
getUse35CopyFormat()
setUse35CopyFormat()
getUse35CopyParameters()
setUser35CopyParameters()
addDataType()
Savepoint Support
The version 5.1 JDBC driver implements the Savepoint interface, allowing you to use savepoints
to segment your transactions and later roll back a portion of the transaction.
Connecting to HP Vertica
Deprecated Methods
VerticaStatement does not implement the following PGStatement methods because they are
obsolete:
l
executeCopyIn()
executeCopyOut()
finishLoad()
getLastOID()
addStreamtoCopyIn()
startCopyIn()
finishCopyIn()
Instead, the new VerticaCopyStream class implements a stream copying feature. See Streaming
Data Via JDBC.
Connecting to HP Vertica
The stmtA object has its DirectBatchInsert property set to true, since that was the property's value
on the VerticaConnection used to instantiate it. Since this property is specific to the statement,
stmtA's DirectBatchInsert property remains unchanged when the connection's DirectBatchInsert
property changes to false later.
Note: The VerticaStatement interface does not cache any of the other connection properties.
If you change another property (such as Locale) on a VerticaConnection object, the change
affects all of the VerticaStatement objects instantiated using that connection object.
Only the Statement interface supports executing strings containing multiple SQL statements. You
cannot use multiple statement strings with PreparedStatement. COPY statements that copy a file
from a host file system work in a multiple statement string. However, client COPY statements
(COPY FROM STDIN) do not work.
Connecting to HP Vertica
Description
ConnSettings
LogLevel
Sets the types of messages that the client writes to a log file.
LogNameSpace
Limits the messages written to the log to only those generated by classes
in the given namespace.
LogPath
TransactionIsolation Previously could only be accessed using a getter and setter method on
the PGConnection object. It can now be set using the same methods as
other connection properties.
ThreePartNaming
Controls whether the database metadata uses the database name as the
catalog name. This property is only used for backwards compatibility with
some client software.
See Connection Properties for more information about these new properties.
Renamed Properties
Several properties have been renamed to make connection properties more consistent across the
different client libraries:
4.1 Property
Name
5.1 Name
Description
defaultAutoCommit
Autocommit
SessionLabel
Label
maxLRSMemory
ResultBufferSize Sets the buffer size the driver uses when retrieving a
result set from the server. In addition, the default value
has been changed from 8MB to 8KB.
Connecting to HP Vertica
Description
batchInsertEnforceLength
Controlled whether inserting data that is too wide for its column
would cause an error. Removed to make batch inserts
consistent with other types of data inserts. Attempting to insert
data that is too wide for a column always results in an error.
batchInsertRecordTerminator Set the record terminator for a batch insert. This property was
deprecated and was only available for backwards compatibility.
binaryBatchInsert
BinaryDataTransfer
KeepAlive
Locale
prepareThreshold
streamingLRS
Connecting to HP Vertica
Connecting to HP Vertica
new methods to report information about the client back to the server.
new callback methods to alert client applications to the expiration of a connection or statement.
Normally, your client application will not use this API directly. Instead, you use an application
framework that handles connection pooling for you. See Using a Pooling Data Source for more
information.
Connecting to HP Vertica
ConnectionLoadBalance to enable load balancing on the client side of the connection. See Enabling
Native Connection Load Balancing in JDBC for more information.
Connecting to HP Vertica
You may also want to import the Properties class. You can use an instance of this class to pass
connection properties when instantiating a connection, rather than encoding everything within the
connection string:
import java.util.Properties;
If your application needs to run in a Java 5 JVM, it uses the older JDBC 3.0-compliant driver. This
driver requires that you to manually load the HP Vertica JDBC driver using the Class.forName()
method:
// Only required for old JDBC 3.0 driver
try {
Class.forName("com.vertica.jdbc.Driver");
} catch (ClassNotFoundException e) {
// Could not find the driver class. Likely an issue
// with finding the .jar file.
System.err.println("Could not find the JDBC driver class.");
e.printStackTrace();
return; // Exit. Cannot do anything further.
}
Your application may run in a Java 6 or later JVM. If so, then the JVM automatically loads the HP
Vertica JDBC 4.0-compatible driver without requiring the call to Class.forName. However, making
this call does not adversely affect the process.Thus, if you want your application to be compatible
with both Java 5 and Java 6 (or later) JVMs, it can still call Class.forName.
Connecting to HP Vertica
The first three parameters are always supplied as part of the connection string, a URL that tells the
JDBC driver where to find the database. The format of the connection string is:
"jdbc:vertica://VerticaHost:portNumber/databaseName"
The first portion of the connection string selects the HP Vertica JDBC driver, followed by the
location of the database.
You can provide the last two parameters, username and password, to theJDBC driver, in one of
three ways:
l
As part of the connection string. The parameters are encoded similarly to URL parameters:
"jdbc:vertica://VerticaHost:portNumber/databaseName?user=username&password=password"
In a Properties object:
Properties myProp = new Properties();
myProp.put("user", "username");
myProp.put("password", "password");
Connection conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:portNumber/databaseName", myProp);
Connecting to HP Vertica
Of these three methods, the Properties object is the most flexible because it makes passing
additional connection properties to the getConnection() method easy. See Connection Properties
and Setting and Getting Connection Property Values for more information about the additional
connection properties.
If there is any problem establishing a connection to the database, the getConnection() method
throws a SQLException on one of its subclasses. . To prevent an exception, enclose the method
within a try-catch block, as shown in the following complete example of establishing a connection.
import java.sql.*;
import java.util.Properties;
public class VerySimpleVerticaJDBCExample {
public static void main(String[] args) {
/*
* If your client needs to run under a Java 5 JVM, It will use the older
* JDBC 3.0-compliant driver, which requires you manually load the
* driver using Class.forname
*/
/*
* try { Class.forName("com.vertica.jdbc.Driver"); } catch
* (ClassNotFoundException e) { // Could not find the driver class.
* Likely an issue // with finding the .jar file.
* System.err.println("Could not find the JDBC driver class.");
* e.printStackTrace(); return; // Bail out. We cannot do anything
* further. }
*/
Properties myProp = new Properties();
myProp.put("user", "dbadmin");
myProp.put("password", "vertica");
myProp.put("loginTimeout", "35");
myProp.put("binaryBatchInsert", "true");
Connection conn;
try {
conn = DriverManager.getConnection(
"jdbc:vertica://docd04.verticacorp.com:5433/vmart", myProp);
System.out.println("Connected!");
conn.close();
} catch (SQLTransientConnectionException connException) {
// There was a potentially temporary network error
// Could automatically retry a number of times here, but
// instead just report error and exit.
System.out.print("Network connection issue: ");
System.out.print(connException.getMessage());
System.out.println(" Try again later!");
return;
} catch (SQLInvalidAuthorizationSpecException authException) {
// Either the username or password was wrong
System.out.print("Could not log into database: ");
System.out.print(authException.getMessage());
System.out.println(" Check the login credentials and try again.");
return;
} catch (SQLException e) {
// Catch-all for other exceptions
e.printStackTrace();
}
Connecting to HP Vertica
}
}
Usage Considerations
l
When you disconnect a user session, any uncommitted transactions are automatically rolled
back.
If your database is not compliant with your HP Vertica license terms, HP Vertica issues a
SQLWarning when you establish the connection to the database. You can retrieve this warning
using the Connection.getWarnings() method. See Managing Your License Key in the
Administrator's Guide for more information about complying with your license terms.
Include the property name and value as part of the connection string you pass to the
DriverManager.getConnection() method.
Use the VerticaConnection.setProperty() method. With this approach, you can change
only those connection properties that remain changeable after the connection has been
established.
In addition, some of the standard JDBC connection properties have getters and setters on the
Connection interface (such as Connection.setAutocommit()).
The following tables list the properties supported by the HP Vertica JDBC driver, and explain which
are required in order for the connection to be established.
Connection Properties
The properties in the following table can only be set before you open the connection to the
database. Two of them are required for every connection.
Connecting to HP Vertica
Property
Description
ConnSettings
Label
Sets a label for the connection on the server. This value appears in
the client_label column of the V_MONITOR.SESSIONS system
table.
Required?: No
Default Value: jdbc-driver_version-random_number
LoginTimeout
SSL
When set to true, use SSL to encrypt the connection to the server.
HP Vertica must be configured to handle SSL connections before you
can establish an SSL-encrypted connection to it. See Implementing
SSL in the Administrator's Guide.
Required?: No
Default Value: false
Password
User
Connecting to HP Vertica
Property
Description
ConnectionLoadBalance A Boolean value indicating whether the client is willing to have its
connection redirected to another host in the HP Vertica database.
This setting has an effect only if the server has also enabled
connection load balancing. See About Native Connection Load
Balancing in the Administrator's Guide for more information about
native connection load balancing.
Required?: No
Default Value: false
BackupServerNode
PreferredAddressFamily
The IP version to use if the client and server have both IPv4 and IPv6
addresses and you have provided a host name. Valid values are:
l
Required?: No
Default Value: none
General Properties
The following properties can be set after the connection is established. None of these properties are
required.
Connecting to HP Vertica
Property
Description
AutoCommit
DirectBatchInsert
Determines whether a batch insert stored data directly into ROS (true) or
using AUTO mode (false).
When you load data using AUTO mode, HP Vertica inserts the data first
into the WOS. If the WOS is full, then HP Vertica inserts the data directly
into ROS. See the COPY statement for more details.
Set After Connection: VerticaConnection.setProperty()
Default Value: false
ReadOnly
When set to true, makes the data connection read-only. Any queries
attempting to update the database using a read-only connection cause a
SQLException.
Set After Connection: Connection.setReadOnly()
Default Value: false
ResultBufferSize
Sets the size of the buffer the HP Vertica JDBC driver uses to temporarily
store result sets.
Note: This property was named maxLRSMemory in previous versions of
the HP Vertica JDBC driver.
Set After Connection: VerticaConnection.setProperty()
Default Value: 8912 (8KB)
Connecting to HP Vertica
Property
Description
SearchPath
Sets the schema search path for the connection. This value is a string
containing a comma-separated list of schema names. See Setting Search
Paths in the Administrator's Guide for more information on the schema
search path.
Set After Connection: VerticaConnection.setProperty()
Default Value: "$user", public, v_catalog, v_monitor, v_internal
ThreePartNaming
TransactionIsolation Sets the isolation level of the transactions that use the connection. See
Changing the Transaction Isolation Level for details.
Note: In previous versions of the HP Vertica JDBC driver, this property
was only available using a getter and setter on the PGConnection object.
You can now set it in the same way as other connection properties.
Set After Connection: Connection.setTransactionIsolation()
Default Value: TRANSACTION_READ_COMMITTED
Logging Properties
The properties that control client logging must be set before the connection is opened. None of
these properties are required, and none can be changed after the Connection object has been
instantiated.
Connecting to HP Vertica
Property
Description
LogLevel
Sets the type of information logged by the JDBC driver. The value is set to one
of the following values:
l
"DEBUG"
"ERROR"
"TRACE"
"WARNING"
"INFO"
"OFF"
Connecting to HP Vertica
Description
JAASConfigName
Provides the name of the JAAS configuration that contains the JAAS
Krb5LoginModule and its settings
Default Value: verticajdbc
KerberosServiceName Provides the service name portion of the HP Vertica Kerberos principal,
for example: vertica/[email protected]
Default Value: vertica
KerberosHostname
Description
EnableRoutableQueries
FailOnMultiNodePlans
Connecting to HP Vertica
Parameters
Description
MaxPooledConnections
PerNode
Note: You can also use VerticaConnection.setProperty() method to set properties that
have standard JDBC Connection setters, such as AutoCommit.
For information about manipulating these attributes, see Setting and Getting Connection Property
Values.
Include the property name and value as part of the connection string you pass to the
DriverManager.getConnection() method.
Use the VerticaConnection.setProperty() method. With this approach, you can change
only those connection properties that remain changeable after the connection has been
established.
Connecting to HP Vertica
In addition, some of the standard JDBC connection properties have getters and setters on the
Connection interface (such as Connection.setAutocommit()).
In the connection string, using the same URL parameter format that you can use to set the
username and password. The following example sets the SSL connection parameter to true:
"jdbc:vertica://VerticaHost:5433/db?user=UserName&password=Password&ssl=true"
Setting a host name using the setProperty() method overrides the host name set in a
connection string as seen above. If this occurs, Vertica may not be able to connect to a host. For
example, using the connection string above, the following overrides the VerticaHost name:
Properties props = new Properties();
props.setProperty("dataSource", dataSourceURL);
props.setProperty("database", database);
props.setProperty("user", user);
props.setProperty("password", password);
ps.setProperty("jdbcDriver", jdbcDriver);
props.setProperty("hostName", "NonVertica_host");
However, if a new connection or override connection is needed, you may enter a valid host name
in the hostname properties object.
The NonVertica_host hostname overrides VerticaHost name in the connection string. To
avoid this issue comment out the props.setProperty("hostName", "NonVertica_host");
line:
//props.setProperty("hostName", "NonVertica_host");
In a Properties object that you pass to the getConnection() call. You will need to import the
java.util.Properties class in order to instantiate a Properties object. Then you use the put
() method to add the property name and value to the object:
Properties myProp = new Properties();
myProp.put("user", "ExampleUser");
myProp.put("password", "password123");
myProp.put("LoginTimeout", "35");
Connection conn;
try {
Connecting to HP Vertica
conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:/ExampleDB", myProp);
} catch (SQLException e) {
e.printStackTrace();
}
Note: The data type of all of the values you set in the Properties object are strings, even if
the property value's data type is integer or Boolean.
Connecting to HP Vertica
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
When run, the example prints the following on the standard output:
DirectBatchInsert state: true
DirectBatchInsert state is now: false
Connecting to HP Vertica
Running the above example displays the following on the system console:
Query reports that Locale is set to: en_GB (LEN)
Query now reports that Locale is set to: en_US (LEN)
Notes:
l
JDBC applications use a UTF-16 character set encoding and are responsible for converting any
non-UTF-16 encoded data to UTF-16. Failing to convert the data can result in errors or the data
being stored incorrectly.
The JDBC driver converts UTF-16 data to UTF-8 when passing to the HP Vertica server and
converts data sent by HP Vertica server from UTF-8 to UTF-16 .
Connecting to HP Vertica
A transaction retains its isolation level until it completes, even if the session's transaction isolation
level changes mid-transaction. HP Vertica internal processes (such as the Tuple Mover and
refresh operations) and DDL operations are always run at SERIALIZABLE isolation level to ensure
consistency.
You can change the transaction isolation level connection property after the connection has been
established using the Connection object's setter (setTransactionIsolation()) and getter
(getTransactionIsolation()). The value for transaction isolation property is an integer. The
Connection interface defines constants to help you set the value in a more intuitive manner:
Constant
Value
Connection.TRANSACTION_READ_COMMITTED 2
Connection.TRANSACTION_SERIALIZABLE
Note: The Connection interface also defines several other transaction isolation constants
(READ_UNCOMMITTED and REPEATABLE_READ). Since HP Vertica does not support these
isolation levels, they are converted to READ_COMMITTED and SERIALIZABLE, respectively.
The following example demonstrates setting the transaction isolation level to SERIALIZABLE.
import java.sql.*;
import java.util.Properties;
public class SetTransactionIsolation {
public static void main(String[] args) {
Properties myProp = new Properties();
myProp.put("user", "ExampleUser");
myProp.put("password", "password123");
Connection conn;
try {
conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:5433/ExampleDB",
myProp);
// Get default transaction isolation
System.out.println("Transaction Isolation Level: "
+ conn.getTransactionIsolation());
// Set transaction isolation to SERIALIZABLE
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
// Get the transaction isolation again
System.out.println("Transaction Isolation Level: "
+ conn.getTransactionIsolation());
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Connecting to HP Vertica
Running the example results in the following being printed out to the console:
Transaction Isolation Level: 2Transaction Isolation Level: 8
Connecting to HP Vertica
second host proceeds as usualif SSL is enabled, then SSL negotiations begin, otherwise the
client begins the authentication process. See About Native Connection Load Balancing in the
Administrator's Guide for details.
To enable native load balancing on your client, set the ConnectionLoadBalance connection
parameter to true. The following example demonstrates connecting to the database several times
with native connection load balancing enabled, and fetching the name of the node handling the
connection from the V_MONITOR.CURRENT_SESSION system table.
import java.sql.*;
import java.util.Properties;
import com.vertica.jdbc.DataSource;
public class ConnectionLoadBalancingExample {
public static void main(String[] args) {
/*
* If your client needs to run under a Java 5 JVM, It will use the older
* JDBC 3.0-compliant driver, which requires you manually load the
* driver using Class.forname
*/
Properties myProp = new Properties();
myProp.put("user", "dbadmin");
myProp.put("password", "vertica");
// Enable connection load balancing on this client. Only works if it is set on
the
// server as well.
myProp.put("ConnectionLoadBalance", 1);
Connection conn;
// Connect 4 times. See if we connect to a different node each time.
for (int x=1; x <= 4; x++) {
try {
System.out.print("Connect attempt #" + x + "...");
conn = DriverManager.getConnection(
"jdbc:vertica://docd03.verticacorp.com:5433/vmart", myProp);
Statement stmt = conn.createStatement();
// Query system to table to see what node we are connected to. Assume a
single row
// in response set.
ResultSet rs = stmt.executeQuery("SELECT node_name FROM v_
monitor.current_session;");
rs.next();
System.out.println("Connected to node " + rs.getString(1).trim());
conn.close();
} catch (SQLException e) {
// Catch-all for other exceptions
System.out.println("Error!");
e.printStackTrace();
}
}
}
}
Connecting to HP Vertica
Configure your DNS server to return multiple IP addresses for a host name. When you use this
host name in the connection settings, the client attempts to connect to the first IP address from
the DNS lookup. If the host at that IP address is unreachable, the client tries to connect to the
second IP, and so on until it either manages to connect to a host or it runs out of IP addresses.
Supply a list of backup hosts for the client driver to try if the primary host you specify in the
connection parameters is unreachable.
For both methods, the process of failover is transparent to the client application (other than
specifying the list of backup hosts, if you choose to use the list method of failover). If the primary
host is unreachable, the client driver automatically tries to connect to other hosts.
Failover only applies to the initial establishment of the client connection. If the connection breaks,
the driver does not automatically try to reconnect to another host in the database.
Connecting to HP Vertica
not try all of them. It just tries the first IP address in the list.
The DNS method of failover centralizes the configuration client failover. As you add new nodes to
your Vertica Analytic Database cluster, you can choose to add them to the failover list by editing
the DNS server settings. All client systems that use the DNS server to connect to Vertica Analytic
Database automatically use connection failover without having to change any settings. However,
this method does require administrative access to the DNS server that all clients use to connect to
the Vertica Analytic Database cluster. This may not be possible in your organization.
Using the backup server list is easier than editing the DNS server settings. However, it
decentralizes the failover feature. You may need to update the application settings on each client
system if you make changes to your Vertica Analytic Database cluster.
Connecting to HP Vertica
// Assume using JDBC 4.0 driver on JVM 6+. No driver loading needed.
Properties myProp = new Properties();
myProp.put("user", "dbadmin");
myProp.put("password", "vertica");
// Set two backup hosts to be used if connecting to the first host
// fails. All of these hosts will be tried in order until the connection
// succeeds or all of the connections fail.
myProp.put("BackupServerNode", "VerticaHost02,VerticaHost03");
Connection conn;
try {
// The connection string is set to try to connect to a known
// bnad host (in this case, a host that never existed).
conn = DriverManager.getConnection(
"jdbc:vertica://BadVerticaHost:5433/vmart", myProp);
System.out.println("Connected!");
// Query system to table to see what node we are connected to.
// Assume a single row in response set.
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT node_name FROM v_monitor.current_session;");
rs.next();
System.out.println("Connected to node " + rs.getString(1).trim());
// Done with connection.
conn.close();
} catch (SQLException e) {
// Catch-all for other exceptions
e.printStackTrace();
}
}
}
When run, the example outputs output similar to the following on the system console:
Connected!
Connected to node v_vmart_node0002
Notice that the connection was made to the first node in the backup list (node 2).
Notes
l
When native connection load balancing is enabled, the additional servers specified in the
BackupServerNode connection parameter are only used for the initial connection to an HP
Vertica host. If host redirects the client to another host in the database cluster to handle its
connection request, the second connection does not use the backup node list. This is rarely an
issue, since native connection load balancing is aware of which nodes are currently up in the
database. See Enabling Native Connection Load Balancing in JDBC for more information.
Connecting to HP Vertica
BIGINT
INT
INT8
BIGINT
SMALLINT
TINYINT
DOUBLE PRECISION
DOUBLE PRECISION
FLOAT5
FLOAT8
REAL
DECIMAL
NUMERIC
NUMERIC
NUMBER
MONEY
If a client application retrieves the values into smaller data types, HP Vertica JDBC driver does not
check for overflows. The following example demonstrates the results of this overflow.
import java.sql.*;
import java.util.Properties;
Connecting to HP Vertica
Connecting to HP Vertica
} catch (SQLException e) {
e.printStackTrace();
}
}
}
The above example prints the following on the console when run:
Column 1 (INTEGER)
getColumnType()
getColumnTypeName()
getShort()
getLong()
getInt()
getByte()
Column 2 (TINYINT)
getColumnType()
getColumnTypeName()
getShort()
getLong()
getInt()
getByte()
Column 3 (DECIMAL)
getColumnType()
getColumnTypeName()
getShort()
getLong()
getInt()
getByte()
Column 4 (MONEY)
getColumnType()
getColumnTypeName()
getShort()
getLong()
getInt()
getByte()
Column 5 (DOUBLE PRECISION)
getColumnType()
getColumnTypeName()
getShort()
getLong()
getInt()
getByte()
Column 6 (REAL)
getColumnType()
getColumnTypeName()
getShort()
getLong()
getInt()
getByte()
-5
BIGINT
455
111111111111
-558038585
-57
-5
BIGINT
444
444
444
-68
2
NUMERIC
-1
55555555555
2147483647
-1
2
NUMERIC
-13455
77777777
77777777
113
8
DOUBLE PRECISION
-1
88888888888888900
2147483647
-1
8
DOUBLE PRECISION
8466
10101010
10101010
18
Connecting to HP Vertica
The following example demonstrates inserting data into a table containing a day/time interval and a
year/month interval:
import java.sql.*;
import java.util.Properties;
// Need to import the Vertica JDBC classes to be able to instantiate
// the interval classes.
import com.vertica.jdbc.*;
public class IntervalDemo {
public static void main(String[] args) {
// If running under a Java 5 JVM, use you need to load the JDBC driver
// using Class.forname here
Properties myProp = new Properties();
myProp.put("user", "ExampleUser");
myProp.put("password", "password123");
Connection conn;
try {
conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:5433/VMart", myProp);
// Create table for interval values
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE IF EXISTS interval_demo");
stmt.executeUpdate("CREATE TABLE interval_demo("
+ "DayInt INTERVAL DAY TO SECOND, "
Connecting to HP Vertica
Connecting to HP Vertica
1 is a INTERVAL
1's value is 10
2 is a INTERVAL
2's value is 10
1 is a INTERVAL
1's value is 10
2 is a INTERVAL
2's value is 12
DAY TO SECOND
Days 7 Hours 5 Minutes
YEAR TO MONTH
Years 6 Months
DAY TO SECOND
Days 10 Hours 10 Minutes
YEAR TO MONTH
Years 9 Months
Another option is to use database metadata to find columns that contain intervals.
// Determine the interval data types by examining the database
Connecting to HP Vertica
// metadata.
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet dbMeta = dbmd.getColumns(null, null, "interval_demo", null);
int colcount = 0;
while (dbMeta.next()) {
// Get the metadata type for a column.
int javaType = dbMeta.getInt("DATA_TYPE");
System.out.println("Column " + ++colcount + " Type name is " +
dbMeta.getString("TYPE_NAME"));
if(javaType == Types.OTHER) {
// The SQL_DATETIME_SUB column in the metadata tells you
// Specifically which subtype of interval you have.
// The VerticaDayTimeInterval.isDayTimeInterval()
// methods tells you if that value is a day time.
//
int intervalType = dbMeta.getInt("SQL_DATETIME_SUB");
if(VerticaDayTimeInterval.isDayTimeInterval(intervalType)) {
// Now you know it is one of the 10 day/time interval types.
// When you select this column you can cast to
// VerticaDayTimeInterval.
// You can get more specific by checking intervalType
// against each of the 10 constants directly, but
// they all are represented by the same object.
System.out.println("column " + colcount + " is a " +
"VerticaDayTimeInterval intervalType = "
+ intervalType);
} else if(VerticaYearMonthInterval.isYearMonthInterval(
intervalType)) {
//now you know it is one of the 3 year/month intervals,
//and you can select the column and cast to
// VerticaYearMonthInterval
System.out.println("column " + colcount + " is a " +
"VerticaDayTimeInterval intervalType = "
+ intervalType);
} else {
System.out.println("Not an interval type.");
}
}
}
Connecting to HP Vertica
a DML query
Note: The HP Vertica JDBC driver does not support scrollable cursors. You can only read
forwards through the result set.
Connecting to HP Vertica
Note: The HP Vertica JDBC driver's Statement class supports executing multiple statements
in the SQL string you pass to the execute method. The PreparedStatement class does not
support using multiple statements in a single execution.
Connecting to HP Vertica
When loading data into HP Vertica, you need to decide whether to write data to the Write
Optimized Store (WOS) or the Read Optimized Store (ROS). By default, most data loading
methods insert data into the WOS until it fills up, then insert any additional data directly into ROS
containers (called AUTO mode). This is the best method to use when frequently loading small
amounts of data (often referred to as trickle-loading). When performing less frequent large data
loads (any loads over 100MB of data at once), you should change this behavior to insert data
directly into the ROS.
The following sections explain in detail how you load data using JDBC.
This method has a few drawbacks: you need convert your data to string and escape any special
characters in your data. A better way to insert data is to use prepared statements. See Batch
Inserts Using JDBC Prepared Statements.
Connecting to HP Vertica
the conversion (for example, between a Java String object and a LONG VARCHAR). The
following example code demonstrates inserting and retrieving a LONG VARCHAR string. It uses
the JDBC Types class to determine the data type of the string returned by HP Vertica, although it
does not actually need to know whether the database column is a LONG VARCHAR or just a
VARCHAR in order to retrieve the value.
import java.sql.*;
import java.util.Properties;
public class LongVarcharExample {
public static void main(String[] args) {
try {
Class.forName("com.vertica.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.err.println("Could not find the JDBC driver class.");
e.printStackTrace();
return;
}
Properties myProp = new Properties();
myProp.put("user", "ExampleUser");
myProp.put("password", "password123");
Connection conn;
try {
conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:5433/ExampleDB",
myProp);
// establish connection and make a table for the data.
Statement stmt = conn.createStatement();
// How long we want the example string to be. This is
// larger than can fit into a traditional VARCHAR (which is limited
// to 65000.
int length = 100000;
// Create a table with a LONG VARCHAR column that can store
// the string we want to insert.
stmt.execute("DROP TABLE IF EXISTS longtable CASCADE");
stmt.execute("CREATE TABLE longtable (text LONG VARCHAR(" + length
+ "))");
// Build a long string by appending an integer to a string builder
// until we hit the size limit. Will result in a string
// containing 01234567890123....
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++)
{
sb.append(i % 10);
}
String value = sb.toString();
System.out.println("String value is " + value.length() +
" characters long.");
// Create the prepared statement
PreparedStatement pstmt = conn.prepareStatement(
"INSERT INTO longtable (text)" +
" VALUES(?)");
try {
Connecting to HP Vertica
Note: Do not use inefficient encoding formats for LONG VARBINARY and LONG
VARCHAR values. HP Vertica cannot load encoded values larger than 32MB, even if the
decoded value is less than 32 MB in size. For example, HP Vertica returns an error if you
attempt to load a 32MB LONG VARBINARY value encoded in octal format, since the
octal encoding quadruples the size of the value (each byte is converted into a backslash
followed by three digits).
Connecting to HP Vertica
You then set the parameters using data-type-specific methods on the PreparedStatement object,
such as setString() and setInt(). Once your parameters are set, call the addBatch() method to
add the row to the batch. When you have a complete batch of data ready, call the executeBatch()
method to execute the insert batch.
Behind the scenes, the batch insert is converted into a COPY statement. When the connection's
AutoCommit parameter is disabled, HP Vertica keeps the COPY statement open and uses it to
load subsequent batches until the transaction is committed, the cursor is closed, or your application
executes anything else (or executes any statement using another Statement or
PreparedStatement object). Using a single COPY statement for multiple batch inserts makes
loading data more efficient. If you are loading multiple batches, you should disable the AutoCommit
property of the database to take advantage of this increased efficiency.
When performing batch inserts, experiment with various batch and row sizes to determine the
settings that provide the best performance.
The following example demonstrates using a prepared statement to batch insert data.
import java.sql.*;
import java.util.Properties;
public class BatchInsertExample {
public static void main(String[] args) {
Properties myProp = new Properties();
myProp.put("user", "ExampleUser");
myProp.put("password", "password123");
//Set streamingBatchInsert to True to enable streaming mode for batch inserts.
//myProp.put("streamingBatchInsert", "True");
Connection conn;
try {
conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:5433/ExampleDB",
myProp);
// establish connection and make a table for the data.
Statement stmt = conn.createStatement();
Connecting to HP Vertica
Connecting to HP Vertica
Anna Allen
Bill Brown
Cindy Chu
Don Dodd
Eric Estavez
addBatch()
cache.
Connecting to HP Vertica
executeBatch()
clearBatch()
database in a single
action.
addBatch() attempt.
rows.
Notes
l
The PreparedStatement object caches the connection's AutoCommit property when the
statement is prepared. Later changes to the AutoCommit property have no effect on the
prepared statement.
Connecting to HP Vertica
If you will be using the connection for inserting both large and small batches (or you do not know the
size batches you will be inserting when you create the Connection object), you can set the
DirectBatchInsert property after the connection has been established using the
VerticaConnection.setProperty method:
((VerticaConnection)conn).setProperty("DirectBatchInsert", true);
See Setting and Getting Connection Property Values for a full example of setting DirectBatchInsert.
setting the connection's AutoCommit property to true before inserting the last batch in the load
Note: The COPY statement also closes if you execute any non-insert statement or execute
any statement using a different Statement or PreparedStatement object. Ending the COPY
statement using either of these methods can lead to confusion and a harder-to-maintain
application, since you would need to handle batch load errors in a non-batch load statement.
You should explicitly end the COPY statement at the end of your batch load and handle any
errors at that time.
Connecting to HP Vertica
Connecting to HP Vertica
Connecting to HP Vertica
}
// Cleanup
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Running the above example produces the following output on the console:
Error message: [Vertica][VJDBC](100172) One or more rows were rejected by the
server.Return value from inserting batch: [1, 1, -3, 1, 1]
1 - Anna Allen
2 - Bill Brown
4 - Don Dodd
5 - Eric Estavez
Notice that the third row failed to insert because its phone number is too long for the Phone_Number
column. All of the rest of the rows in the batch (including those after the error) were correctly
inserted.
Note: It is more efficient for you to ensure that the data you are inserting is the correct data
type and width for the table column you are inserting it into than to handle exceptions after the
fact.
Connecting to HP Vertica
Connecting to HP Vertica
// Commit it.
System.out.println("Batch insert successful. Committing.");
conn.commit();
} catch (BatchUpdateException e) {
System.out.println("Error message: " + e.getMessage());
// Batch results isn't set due to exception, but you
// can get it from the exception object.
batchResults = e.getUpdateCounts();
// Roll back the batch transaction.
System.out.println("Rolling back batch insertion");
conn.rollback();
}
catch (SQLException e) {
// General SQL errors, such as connection issues, throw
// SQLExceptions. Your application should do something more
// than just print a stack trace,
e.printStackTrace();
}
System.out.println("Return value from inserting batch: "
+ Arrays.toString(batchResults));
System.out.println("Customers table contains:");
Running the above example prints the following on the system console:
Error message: [Vertica][VJDBC](100172) One or more rows were rejected by the
server.Rolling back batch insertion
Return value from inserting batch: [1, 1, -3, 1, 1]
Customers table contains:
The return values indicate whether each rows was successfully inserted. The value 1 means the
row inserted without any issues, and a -3 indicates the row failed to insert.
The customers table is empty since the batch insert was rolled back due to the error caused by the
third column.
Connecting to HP Vertica
Connecting to HP Vertica
The example prints the following out to the system console when run (assuming that the
customers.txt file contained two million valid rows):
Number of accepted rows = 2000000
Using VerticaCopyStream
The VerticaCopyStream class lets you stream data from the client system to an HP Vertica
database. It lets you use the SQL COPY statement directly without having to copy the data to a
host in the database cluster first. Using the COPY command to load data from the host requires
Connecting to HP Vertica
superuser privileges to be able to access the host's filesystem. The COPY statement used to load
data from a stream does not require superuser privileges so your client can connect using any user
account that has INSERT privileges on the table that will receive the data.
To copy streams into the database:
1. Disable the database connections AutoCommit connection parameter.
2. Instantiate a VerticaCopyStreamObject, passing it at least the database connection objects
and a string containing a COPY statement to load the data. This statement must copy data
from the STDIN into your table. You can use whatever parameters are appropriate for your data
load.
Note: If you used either the REJECTED DATA or EXCEPTIONS options in the COPY
statement you passed to VerticaCopyStreamObject the object in step 2, .getRejects()
returns an empty list. You can only use one method of tracking the rejected rows at a time.
Connecting to HP Vertica
Since .start() and .finish() also call .execute() to send any pending streams to the server,
you should also call .getRejects() after these methods as well.
The following example demonstrates loading the content of five text files stored on the client
system into a table.
import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import com.vertica.jdbc.VerticaConnection;
import com.vertica.jdbc.VerticaCopyStream;
public class CopyMultipleStreamsExample {
public static void main(String[] args) {
// Note: If running on Java 5, you need to call Class.forName
// to manually load the JDBC driver.
// Set up the properties of the connection
Properties myProp = new Properties();
myProp.put("user", "ExampleUser"); // Must be superuser
myProp.put("password", "password123");
// When performing bulk loads, you should always disable the
// connection's AutoCommit property to ensure the loads happen as
// efficiently as possible by reusing the same COPY command and
// transaction.
myProp.put("AutoCommit", "false");
Connection conn;
try {
conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:5433/ExampleDB", myProp);
Statement stmt = conn.createStatement();
// Create a table to receive the data
stmt.execute("DROP TABLE IF EXISTS customers");
stmt.execute("CREATE TABLE customers (Last_Name char(50), "
+ "First_Name char(50),Email char(50), "
+ "Phone_Number char(15))");
// Prepare the query to insert from a stream. This query must use
// the COPY statement to load data from STDIN. Unlike copying from
// a file on the host, you do not need superuser privileges to
// copy a stream. All your user account needs is INSERT privileges
// on the target table.
String copyQuery = "COPY customers FROM STDIN "
+ "DELIMITER '|' DIRECT ENFORCELENGTH";
// Create an instance of the stream class. Pass in the
// connection and the query string.
VerticaCopyStream stream = new VerticaCopyStream(
(VerticaConnection) conn, copyQuery);
// Keep running count of the number of rejects
int totalRejects = 0;
Connecting to HP Vertica
// start() starts the stream process, and opens the COPY command.
stream.start();
//
//
//
//
Connecting to HP Vertica
// getRowCount().
System.out.println("Number of rows accepted: "
+ stream.getRowCount());
System.out.println("Total number of rows rejected: " + totalRejects);
// Commit the loaded data
conn.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Running the above example on some sample data results in the following output:
Loading file: C:\Data\customers-1.txtNumber of rows rejected in load #1: 3
Rejected row #1 is row 3
Rejected row #2 is row 7
Rejected row #3 is row 51
Loading file: C:\Data\customers-2.txt
Number of rows rejected in load #2: 5Rejected row #1 is row 4143
Rejected row #2 is row 6132
Rejected row #3 is row 9998
Rejected row #4 is row 10000
Rejected row #5 is row 10050
Loading file: C:\Data\customers-3.txt
Number of rows rejected in load #3: 9
Rejected row #1 is row 14142
Rejected row #2 is row 16131
Rejected row #3 is row 19999
Rejected row #4 is row 20001
Rejected row #5 is row 20005
Rejected row #6 is row 20049
Rejected row #7 is row 20056
Rejected row #8 is row 20144
Rejected row #9 is row 20236
Loading file: C:\Data\customers-4.txt
Number of rows rejected in load #4: 8
Rejected row #1 is row 23774
Rejected row #2 is row 24141
Rejected row #3 is row 25906
Rejected row #4 is row 26130
Rejected row #5 is row 27317
Rejected row #6 is row 28121
Rejected row #7 is row 29321
Rejected row #8 is row 29998
Loading file: C:\Data\customers-5.txt
Number of rows rejected in load #5: 1
Rejected row #1 is row 39997
Finish returned 39995
Number of rows accepted: 39995
Total number of rows rejected: 26
Note: The above example shows a simple load process that targets one node in the HP
Connecting to HP Vertica
Vertica cluster. It is more efficient to simultaneously load multiple streams to multiple database
nodes. Doing so greatly improves performance because it spreads the processing for the load
across the cluster.
import java.sql.*;
import java.util.Properties;
public class COPYLocal {
public static void main(String[] args) {
// Note: If using Java 5, you must call Class.forName to load the
// JDBC driver.
Properties myProp = new Properties();
myProp.put("user", "ExampleUser"); // Do not need to superuser
myProp.put("password", "password123");
Connection conn;
try {
conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:5433/ExampleDB",myProp);
// Disable AutoCommit
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
// Create a table to hold data.
stmt.execute("DROP TABLE IF EXISTS customers;");
stmt.execute("CREATE TABLE IF NOT EXISTS customers (Last_Name char(50) "
+ "NOT NULL, First_Name char(50),Email char(50), "
+ "Phone_Number char(15))");
// Use the COPY command to load data. Load directly into ROS, since
// this load could be over 100MB. Use ENFORCELENGTH to reject
// strings too wide for their columns.
boolean result = stmt.execute("COPY customers FROM LOCAL "
Connecting to HP Vertica
The result of running this code appears below. In this case, the customers.txt file contains 10000
rows, seven of which get rejected because they contain data too wide to fit into their database
columns.
Got countNumber of accepted rows = 9993
Connecting to HP Vertica
Handling Errors
When the HP Vertica JDBC driver encounters an error, it throws a SQLException or one of its
subclasses. The specific subclass it throws depends on the type of error that has occurred. Most of
the JDBC method calls can result in several different types of errors, in response to which the
JDBC driver throws a specific SQLException subclass. Your client application can choose how to
react to the error based on the specific exception that the JDBC driver threw.
Note: The specific SQLException subclasses were introduced in the JDBC 4.0 standard. If
your client application runs in a Java 5 JVM, it will use the older JDBC 3.0-compliant driver
which lacks these subclasses. In that case, all errors throw a SQLException.
The hierarchy of SQLException subclasses is arranged to help your client application determine
what actions it can take in response to an error condition. For example:
l
The JDBC driver throws SQLTransientException subclasses when the cause of the error may
be a temporary condition, such as a timeout error (SQLTimeoutException) or a connection issue
(SQLTransientConnectionIssue). Your client application can choose to retry the operation
without making any sort of attempt to remedy the error, since it may not reoccur.
The JDBC driver throws SQLNonTransientException subclasses when the client needs to take
some action before it could retry the operation. For example, executing a statement with a SQL
syntax error results in the JDBC driver throwing the a SQLSyntaxErrorException (a subclass
of SQLNonTransientException). Often, your client application just has to report these errors
back to the user and have him or her resolve them. For example, if the user supplied your
application with a SQL statement that triggered a SQLSyntaxErrorException, it could prompt
the user to fix the SQL error.
See Vertica Analytic Database SQLState Mapping to Java Exception Classes for a list Java
exceptions thrown by the JDBC driver.
Description
Class 00
Successful Completion
SQLException
Connecting to HP Vertica
SQLSTATE
Class or Value
Description
Class 01
Warning
SQLWarning
Class 02
No Data
SQLException
Class 03
SQLException
Complete
Class 08
Client Connection
SQLNonTransientConnectionException
Exception
Class 09
Triggered Action
SQLException
Exception
Class 0A
SQLFeatureNotSupportedException
Class 0B
Invalid Transaction
SQLException
Initiation
Class 0F
Locator Exception
SQLException
Class 0L
Invalid Grantor
SQLException
Class 0P
SQLException
Class 21
Cardinality Violation
SQLException
Class 22
Data Exception
SQLDataException
ERRCODE_INVALID_
SQLNonTransientException
22V21
EPOCH
Class 23
Integrity Constraint
SQLIntegrityConstraintViolationException
Violation
Class 24
SQLException
Class 25
SQLTransactionRollbackException
Class 26
SQLException
Name
Class 27
SQLException
Violation
Connecting to HP Vertica
SQLSTATE
Class or Value
Description
Class 28
Invalid Authorization
SQLInvalidAuthorizationException
Specification
Class 2B
Dependent Privilege
SQLDataException
Invalid Transaction
SQLException
Termination
Class 2F
SQLException
Class 34
SQLException
Class 38
External Routine
SQLException
Exception
Class 39
External Routine
SQLException
Invocation Exception
Class 3B
Savepoint Exception
SQLException
Class 3D
SQLException
Class 3F
SQLException
Class 40
Transaction Rollback
SQLTransactionRollbackException
Class 42
SQLSyntaxErrorException
Rule Violation
Class 44
SQLException
Violation
Class 53
53300
Insufficient Resources
SQLTransientException
ERRCODE_TOO_
SQLNonTransientConnectionException
MANY_CONNECTIONS
Class 54
SQLNonTransientException
Class 55
Object Not In
SQLNonTransientException
Prerequisite State
Connecting to HP Vertica
SQLSTATE
Class or Value
55V03
Description
ERRCODE_LOCK_
SQLTransactionRollbackException
NOT_AVAILABLE
Class 57
57V01
Operator Intervention
SQLTransientException
ERRCODE_ADMIN_
SQLNonTransientConnectionException
SHUTDOWN
57V02
ERRCODE_CRASH_
SQLNonTransientConnectionException
SHUTDOWN
57V03
ERRCODE_CANNOT_
SQLNonTransientConnectionException
CONNECT_NOW
Class 58
System Error
SQLException
Class V1
Vertica-specific multi-
SQLException
Vertica-specific
SQLException
miscellaneous errors
class
V2000
ERRCODE_AUTH_
SQLInvalidAuthorizationException
FAILED
Class VC
SQLNonTransientException
Class VD
DB Designer errors
SQLNonTransientException
Class VP
SQLNonTransientException
Class VX
Internal Error
SQLException
Connecting to HP Vertica
Connecting to HP Vertica
//e.printStackTrace();
}
}
conn.close();
// This catches exceptions caused by a bad connection.
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Connecting to HP Vertica
To effectively route a request to a single node, the client must determine the specific node on which
the data resides. For the client to be able to determine the correct node, the table must segmented
by one or more columns. For example, if you segment a table on a Primary Key (PK) column, then
the client can determine on which node the data resides based on the Primary Key and directly
connect to that node to quickly fulfill the request.
The Routable Query API provides two classes for performing routable queries;
VerticaRoutableExecutor and VGet. VerticaRoutableExecutor provides a more expressive SQLbased API while VGet provides a more structured API for programmatic access.
l
The VerticaRoutableExecutor class, available starting in Release 7.1 SP1, allows you to use
traditional SQL with a reduced feature set to query data on a single node. Note that the client and
server must be at Release 7.1 SP1 to use the VerticaRoutableExecutor.
For joins, the table must be joined on a key column that exists in each table you are joining, and
the tables must be segmented on that key, except for unsegmented tables, which can always be
joined (since all the data in an unsegmented table is available on all nodes).
The VGet class does not use traditional SQL syntax. Instead, it uses a data structure that you
build by defining predicates and predicate expressions and outputs and output expressions. This
class is ideal for doing Key/Value type lookups on single tables.
The data structure used for querying the table must provide a predicate for each segmented
column defined in the projection for the table. You must provide, at a minimum, a predicate with
a constant value for each segmented column. For example, an id with a value of 12234 if the
table is segmented only on the id column. You can also specify additional predicates for the
other, non-segmented, columns in the table. Predicates act like an SQL WHERE clause and
multiple predicates/predicate expressions apply together with an SQL AND modifier. Predicates
Connecting to HP Vertica
must be defined with a constant value. Predicate expressions can be used to refine the query
and can contain any arbitrary SQL expressions (such as less than, greater than, etc.) for any of
the non-segmented columns in the table.
Java doc for all classes and methods in the JDBC Driver is available in the HP Vertica JDBC Java
doc.
Note: The JDBC Routable Query API is read-only and requires JDK 1.6 or greater.
See Also
l
Creating Tables and Projections for use with the Routable Query API
Defining the Query for Routable Queries Using the VGet Class
Defining the Query for Routable Queries using the VerticaRoutableExecutor Class
Connecting to HP Vertica
This table is segmented based on the id column (and ordered by id to make lookups faster). To
build a query for this table using the Routable Query API, you only need to provide a single
predicate for the id column which returns a single row when queried.
However, if you were to add multiple columns to the segmentation clause, such as this table:
CREATE TABLE users2 (
id INT NOT NULL PRIMARY KEY,
username VARCHAR(32),
email VARCHAR(64),
business_unit VARCHAR(16))
ORDER BY id, business_unit
SEGMENTED BY HASH(id, business_unit)
ALL NODES;
Then you would need to provide two predicates when querying the users2 table, since the
segmentation clause uses both the id and the business_unit columns. However, if you know both id
and business_unit when you perform the queries, then it is beneficial to segment on both columns,
as it makes it easier for the client to determine that this projection is the best projection to use to
determine the correct node.
Connecting to HP Vertica
Note that for each projection, only the "public.users.id" column is specified,meaning you need
to provide a predicate for this column when you build your query.
If the table was segmented on multiple columns, for example id and business_unit, then you would
need to provide both columns as predicates to the routable query.
Connecting to HP Vertica
Example:
You can create the connection using a JDBC data source:
com.vertica.jdbc.DataSource jdbcSettings = new com.vertica.jdbc.DataSource();
jdbcSettings.setDatabase("exampleDB");
jdbcSettings.setHost("doc1.verticacorp.com");
jdbcSettings.setUserID("dbadmin");
jdbcSettings.setPassword("password");
jdbcSettings.setEnableRoutableQueries(true);
jdbcSettings.setPort((short) 5433);
VerticaRoutableConnection conn;
conn = (VerticaRoutableConnection)jdbcSettings.getConnection();
You can also create the connection using a connection string and the
DriverManager.getConnection() method:
String connectionString =
"jdbc:vertica://doc.verticacorp.com:5433/exampleDB?user=dbadmin&password=&
EnableRoutableQueries=true";
VerticaRoutableConnection conn = (VerticaRoutableConnection) DriverManager.getConnection
(connectionString);
Connecting to HP Vertica
MetadataCacheLifetime: The time in seconds to keep projection metadata. The API caches
metadata about the projection used for the query (such as projections). The cache is used on
subsequent queries to reduce response time. The default is 300 seconds.
If joining tables, all tables being joined must be segmented (by hash) on the same set of columns
referenced in the join predicate, unless the table being joined is unsegmented.
When using multiple conditions in WHERE clauses, the WHERE clause must use AND between the
conditions. OR's in the WHERE clause cause the query to degenerate to a multi-node plan. OR, IN
list, or range conditions on columns outside of the join condition are acceptable if the data exists
on the same node.
You can only execute a single statement per request. "Chained" SQL statements are not
permitted.
Your query may be used in a driver-generated subquery to help determine if the query can be
executed on a single node, Therefore, you cannot include the semi-colon at the end of the
statement and you cannot include SQL comments (using -- ), as these would cause the drivergenerated query to fail.
Connecting to HP Vertica
VerticaRoutableExecutor Methods
VerticaRoutableExecutor has the following methods:
l
execute(query string, [ column, value | Map ]) - Runs the query. Accepts as input the
query to be executed, and either:
The column and value when the lookup is being done on just a single value. For example:
A Java map of the column names and corresponding values if the lookup is being done on one
or more columns. For example: ResultSet rs = q.execute(query, map);. The table must
have at least one projection segmented by a set of columns exactly matching the columns in
the map. Note that each column defined in the map must have only one value. You cannot
include more than one value for the same column. For example:
Map<String, Object> map = new HashMap<String, Object>();
map.put("customer_key", 1);
map.put("another_key", 42);
ResultSet rs = q.execute(query, map);
The query being executed uses regular SQL. The SQL must meet the rules of the
VerticaRoutableExecutor Class. For example, you can add limits and sorts, or use aggregate
functions provided the data exists on a single node.
Important: The JDBC client uses the column/value or map arguments to determine on
which node to execute the query. You must make sure that the content of the query uses
the same values that you provide in the column/value or map arguments.
Note: The following data types cannot be used as column values. Additionally, if a table is
segmented on any columns with the following data types then the table cannot be queried
using the Routable Query API:
n
interval
timetz
timsestamptz
Connecting to HP Vertica
Note: The driver does not verify the syntax of the query before it sends it to the server. If
your expression is incorrect then the query fails.
2. Create a sales table, then create the projections which segment on the customer_key. Since
Connecting to HP Vertica
both the customer and sales tables are segmented on the same key, they are able to be joined
with the VerticaRoutableExecutor Routable Query lookup.
CREATE TABLE sales (sale_key INT, customer_key INT, date_key INT, sales_amount
FLOAT);
CREATE PROJECTION sales_proj_b0 AS
(SELECT *
FROM sales) segmented BY HASH (customer_key) ALL NODES;
CREATE PROJECTION sales_proj_b1 AS
(SELECT *
FROM sales) segmented BY HASH (customer_key) ALL NODES
OFFSET 1;
CREATE PROJECTION sales_proj_b2 AS
(SELECT *
FROM sales) segmented BY HASH (customer_key) ALL NODES
OFFSET 2;
select start_refresh();
customers
customers
customers
customers
customers
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
COMMIT;
sales
sales
sales
sales
sales
sales
sales
sales
sales
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES(1,
VALUES(2,
VALUES(3,
VALUES(4,
VALUES(5,
VALUES(6,
VALUES(7,
VALUES(8,
VALUES(9,
(1,
(2,
(3,
(4,
(5,
1,
2,
3,
4,
5,
1,
1,
1,
1,
'Fred', '[email protected]');
'Sue', '[email protected]');
'Dave', '[email protected]');
'Ann', '[email protected]');
'Jamie', '[email protected]');
1, '100.00');
2, '200.00');
3, '300.00');
4, '400.00');
5, '400.00');
15, '500.00');
15, '400.00');
35, '300.00');
35, '200.00');
4. Create an unsegmented projection of the VMart date_dimension table for use in this example.
Note you must run select start_refresh(); to unsegment the existing data,
CREATE PROJECTION date_dim_unsegment AS
(SELECT *
Connecting to HP Vertica
Using the customer, sales, and date_dimension data, you can now create a Routable Query lookup
that uses joins and a group by to query the customers table and return the total amount of
purchases per day for a given customer:
import
import
import
import
java.sql.*;
java.util.HashMap;
java.util.Map;
com.vertica.jdbc.kv.*;
Connecting to HP Vertica
Date: 2003-01-15:
Date: 2003-02-04:
Date: 2003-01-01:
Amount: 900.0
Amount: 500.0
Amount: 100.0
Note that your dates may be different, because the VMart schema randomly generates the dates in
the date_dimension table.
VGet Methods
VGet has the following methods:
l
addPredicate(string, object) - adds a predicate column and a constant value to the query.
You must include a predicate for each column on which the table is segmented. The predicate
acts as the "WHERE" clause to the query. Multiple addPredicate() method calls are joined by
AND modifiers. Note that the VGet retains this value after each call to execute. To remove it,
use ClearPredicates().
Note: The following data types cannot be used as predicates. Additionally, if a table is
segmented on any columns with the following data types then the table cannot be queried
using the Routable Query API:
n
interval
timetz
timsestamptz
Connecting to HP Vertica
Note: The driver does not verify the syntax of the expression before it sends it to the server.
If your expression is incorrect then the query fails.
Note: The driver does not verify the syntax of the expression before it sends it to the server.
If your expression is incorrect then the query fails.
Note: addOutputExpression() is not supported when querying Flex Tables. If you attempt
to use addOutputExpression() on a Flex Table query, then a
SQLFeatureNotSupportedException is thrown.
Connecting to HP Vertica
execute() - Runs the query. Care must be taken to ensure that the predicate columns exist on
the table and projection used by VGet, and that the expressions do not require multiple nodes to
execute. If an expression is sufficiently complex as to require more than one node to execute,
execute() throws a SQLException if the FailOnMultiNodePlans connection property is true.
close() - Closes this VGet by releasing resources used by this VGet. It does not close the
parent JDBC connection to HP Vertica.
getWarnings() - Retrieves the first warning reported by calls on this VGet. Additional warnings
are chained and can be accessed with the JDBC getNextWarning() method.
You call the execute() method to run query. By default, the VGet fetches all the columns of all the
rows that satisfy the logical AND of all the predicates passed via the addPredicate() method. To
further customize the get operation use the addOutputColumn(), addOutputExpression(),
addPredicateExpression(), addSortColumn() and setLimit() methods.
Note: VGet operations span multiple JDBC connections (and multiple HP Vertica sessions)
and do not honor the parent connection's transaction semantics. If consistency is required
across multiple executions, the parent VerticaRoutableConnection's consistent read API can
be used to guarantee all operations occur at the same epoch.
VGet is thread safe, but all methods are synchronized, so threads that share a VGet instance
are never run in parallel. For better parallelism, each thread should have its own VGet instance.
Different VGet instances that operate on the same table share pooled connections and
metadata in a manner that enables a high degree of parallelism.
Example
You can query the table defined in Creating Tables and Projections for use with the Routable Query
API with the following example code. The table defines an id column that is segmented by hash.
import java.sql.*;
import com.vertica.jdbc.kv.*;
public class verticaKV2 {
public static void main(String[] args) {
com.vertica.jdbc.DataSource jdbcSettings
= new com.vertica.jdbc.DataSource();
jdbcSettings.setDatabase("exampleDB");
jdbcSettings.setHost("docg01.verticacorp.com");
jdbcSettings.setUserID("dbadmin");
jdbcSettings.setPassword("password");
jdbcSettings.setEnableRoutableQueries(true);
Connecting to HP Vertica
jdbcSettings.setPort((short) 5433);
VerticaRoutableConnection conn;
try {
conn = (VerticaRoutableConnection)
jdbcSettings.getConnection();
System.out.println("Connected.");
VGet get = conn.prepareGet("public", "users");
get.addPredicate("id", 5);
ResultSet rs = get.execute();
rs.next();
System.out.println("ID: " +
rs.getString("id"));
System.out.println("Username: "
+ rs.getString("username"));
System.out.println("Email: "
+ rs.getString("email"));
System.out.println("Closing Connection.");
conn.close();
} catch (SQLException e) {
System.out.println("Error! Stacktrace:");
e.printStackTrace();
}
}
}
The output:
Connected.
ID: 5
Username: userE
Email: [email protected]
Closing Connection.
Connecting to HP Vertica
find a row. To prevent the server from opening unneeded processing threads, you should create a
specific resource pool for Routable Query clients. Consider the following settings for the resource
pool you use for Routable Queries:
l
Set execution parallelism to 1 to force single-threaded queries. This setting improves Routable
Query performance.
Use CPU affinity to limit the resource pool to a specific CPU or CPU set. The setting ensures
that the Routable Queries have resources available to them, but it also prevents Routable
Queries from significantly impacting performance on the system for other general queries.
If you do not set a CPU affinity for the resource pool, consider setting the maximum concurrency
value of the resource pool to a setting that ensures good performance for Routable Queries, but
does not negatively impact the performance of general queries.
Predicate Requirements
You must provide the same number of predicates that correspond to the columns of the table
segmented by hash. To determine the segmented columns, run select get_table_projections
('tableName'). You must provide a predicate for each column displayed in the "Seg Cols" field.
Connecting to HP Vertica
For VGet, this means you must literally use addPredicate() to add each of the columns. For
VerticaRoutableExecutor, this means you must provide all of the predicates and values in the map
sent to execute().
Multi-node Failures
It is possible to define the correct number of predicates, but still have a failure because multiple
nodes contain the data. This failure occurs because the projection's data is not segmented in such
a way that the data being queried is contained on a single node. Enable logging for the connection
and view the logs to verify the projection being used. If the client is not picking the correct
projection, then try to query the projection directly by specifying the projection instead of the table in
the create/prepare statement, for example:
l
Additionally, you can use the EXPLAIN command in vsql to help determine if your query can run in
single node. EXPLAIN can help you understand why the query is being run as single or multi-node.
Connecting to HP Vertica
Overview of ADO.NET
All queries are now Auto Committed. The only exception is that queries run using a Transaction
are not committed until the Commit(); method is called.
Performance Improvements
l
Prepared INSERT statements now run significantly faster than in previous driver versions. For
the best performance, prepared statements should be executed as part of a transaction.
Namespace Change
l
Connecting to HP Vertica
Connection Properties
l
DSN is no longer a valid connection string keyword. You cannot connect to HP Vertica using
ADO.net with a DSN.
There is no longer a locale connection string keyword and you cannot set the locale through the
connection string. To change the locale, run the query "set locale to..."
The connection property to enable or disable auto commit has been removed. All queries outside
of transactions are auto-committed.
Result Buffering
l
The driver now buffers all results, and always uses streaming. Because of this, the following
functionality has changed:
n
VerticaCommandBehavior enum has been removed. This enum extended the ADO.NET
CommandBehavior enum to add support for buffering results. Results are now buffered in HP
Vertica 5.1.x.
Logging Changes
l
Log properties are no longer configured on the connection string. Log properties are now
configured through the VerticaLogProperties class.
Connecting to HP Vertica
verticaType.Integer
VerticaType.BigInt
verticaType.Bigint
VerticaType.BigInt
verticaType.Timestamp
VerticaType.DateTime
verticaType.Interval
VerticaType.IntervalDay
VerticaType.IntervalDayToHour
VerticaType.IntervalDayToMinute
etc.
verticaType.Real
VerticaType.Double
verticaType.Text
VerticaType.VarChar
verticaType.Smallint
VerticaType.BigInt
verticaType.Varbinary
VerticaType.VarBinary
ADO.NET applications use a UTF-16 character set encoding and are responsible for converting
any non-UTF-16 encoded data to UTF-16. The same cautions as for ODBC apply if this
encoding is violated.
The ADO.NET driver converts UTF-16 data to UTF-8 when passing to the HP Vertica server
and converts data sent by HP Vertica server from UTF-8 to UTF-16
ADO.NET applications should set the correct server session locale by executing the SET
LOCALE TO command in order to get expected collation and string functions behavior on the
server.
If there is no default session locale at the database level, ADO.NET applications need to set the
correct server session locale by executing the SET LOCALE TO command in order to get
Connecting to HP Vertica
expected collation and string functions behavior on the server. See the SET LOCALE command
in the SQL Reference Manual
Import the server and client certificates into the Windows Key Store.
If required by your certificates, import the public certificate of your Certifying Authority.
Import the Server and Client Certificates into the Windows Key
store:
1. Copy the server.crt file you generated when you enabled SSL on the server to your Windows
Machine.
2. Double-click the certificate.
3. Let Windows determine the key type, and click Install.
Connecting to HP Vertica
Connecting to HP Vertica
4. Create a command object and associate it with a connection. All VerticaCommand objects
must be associated with a connection.
VerticaCommand command = _conn.CreateCommand();
Connecting to HP Vertica
Connection Properties for a list of available properties to use in your connection string. At a
minimum, you need to specify the Host, Database, and User.
builder.Host = "node01";
builder.Database = "VMart";
builder.User = "dbadmin";
5. Create a command object and associate it with a connection. All VerticaCommand objects
must be associated with a connection.
VerticaCommand command = _conn.CreateCommand;
Note: If your database is not in compliance with your HP Vertica license, the call to
VerticaConnection.open() returns a warning message to the console and the log. See
Managing Your License Key in the Administrator's Guide for more information.
Example Usage:
using System;
using System.Collections.Generic;
Connecting to HP Vertica
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder
();
builder.Host = "192.168.1.10";
builder.Database = "VMart";
builder.User = "dbadmin";
VerticaConnection _conn = new VerticaConnection(builder.ToString());
_conn.Open();
//Perform some operations
_conn.Close();
}
}
}
Include the property name and value as part of the connection string you pass to a
VerticaConnection.
Set the properties in a VerticaConnectionStringBuilder object, and then pass the object as
a string to a VerticaConnection.
Property
Description
Default Value
Database
none
Connecting to HP Vertica
Property
Description
Default Value
User
none
HP Vertica/.
Port
5433
running.
Host
none
Vertica.Data.VerticaClient.AddressFamilyPr
eference.None
Ipv4Connect to the
server using IPv4.
Ipv6Connect to the
server using IPv6.
NoneUse the IP
address provided by the
DNS server.
Connecting to HP Vertica
Property
Description
Default Value
Password
string.Empty
string.Empty
System.Data.
IsolationLevel.Unspecified
string
false
Connecting to HP Vertica
Property
Description
Default Value
ResultBufferSize
8192
a connection. A value of 0
means no timeout.
ReadOnly
false
false
minimum number of
connections to pool.
Valid Values: Cannot be
greater than the number of
connections that the server
is configured to allow.
Otherwise, an exception
results.
Default: 55
Connecting to HP Vertica
Property
Description
Default Value
MaxPoolSize
20
maximum number of
connections to pool.
Valid Values: Cannot be
greater than the number of
connections that the server
is configured to allow.
Otherwise, an exception
results.
Connecting to HP Vertica
Property
Description
Default Value
LoadBalanceTimeo
ut
0 (no timeout)
expressed in seconds, to
timeout or remove unused
pooled connections.
Disable: Set to 0 (no
timeouts)
If you are using a cluster
environment to load-balance
the work, then pool is
restricted to the servers in
the cluster when the pool
was created. If additional
servers are added to the
cluster, and the pool is not
removed, then the new
servers are never added to
the connection pool unless
LoadBalanceTimeout is set
and exceeded or
VerticaConnection.Clear
AllPools() is called
manually from an
application. If you are using
load balancing, then set this
property to a value that
considers when new servers
are added to the cluster.
However, do not set it so low
that pools are frequently
removed and rebuilt, doing
so makes pooling
ineffective.
SSL
false
Connecting to HP Vertica
Property
Description
Default Value
IntegratedSecuri
ty
false
KerberosServiceN
ame
vertica
KerberosHostname
string property
Connecting to HP Vertica
using
using
using
using
System;
System.Text;
System.Data;
Vertica.Data.VerticaClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder =
new VerticaConnectionStringBuilder();
builder.Host = "node01.example.com";
builder.Database = "VMart";
builder.User = "dbadmin";
// Enable native client load balancing in the client,
// must also be enabled on the server!
builder.ConnectionLoadBalance = true;
// Connect 3 times to verify a new node is connected
// for each connection.
for (int i = 1; i <= 4; i++)
{
try
{
VerticaConnection _conn =
new VerticaConnection(builder.ToString());
_conn.Open();
if (i == 1)
{
// On the first connection, check the server policy for load
balance
VerticaCommand sqlcom = _conn.CreateCommand();
sqlcom.CommandText =
"SELECT LOAD_BALANCE_POLICY FROM V_CATALOG.DATABASES";
var returnValue = sqlcom.ExecuteScalar();
Console.WriteLine("Status of load balancy policy
on server: " + returnValue.ToString() + "\n");
}
VerticaCommand command = _conn.CreateCommand();
command.CommandText =
"SELECT node_name FROM V_MONITOR.CURRENT_SESSION";
VerticaDataReader dr = command.ExecuteReader();
while (dr.Read())
{
Console.Write("Connect attempt #" + i + "... ");
Console.WriteLine("Connected to node " + dr[0]);
}
dr.Close();
_conn.Close();
Console.WriteLine("Disconnecting.\n");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
Connecting to HP Vertica
}
}
Configure your DNS server to return multiple IP addresses for a host name. When you use this
host name in the connection settings, the client attempts to connect to the first IP address from
the DNS lookup. If the host at that IP address is unreachable, the client tries to connect to the
second IP, and so on until it either manages to connect to a host or it runs out of IP addresses.
Supply a list of backup hosts for the client driver to try if the primary host you specify in the
connection parameters is unreachable.
For both methods, the process of failover is transparent to the client application (other than
specifying the list of backup hosts, if you choose to use the list method of failover). If the primary
host is unreachable, the client driver automatically tries to connect to other hosts.
Connecting to HP Vertica
Failover only applies to the initial establishment of the client connection. If the connection breaks,
the driver does not automatically try to reconnect to another host in the database.
Connecting to HP Vertica
System;
System.Text;
System.Data;
Vertica.Data.VerticaClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder =
new VerticaConnectionStringBuilder();
builder.Host = "not.a.real.host:5433";
builder.Database = "VMart";
builder.User = "dbadmin";
builder.BackupServerNode =
"another.broken.node:5433,docg02.verticacorp.com:5433";
try
{
VerticaConnection _conn =
new VerticaConnection(builder.ToString());
_conn.Open();
VerticaCommand sqlcom = _conn.CreateCommand();
sqlcom.CommandText = "SELECT node_name FROM current_session";
var returnValue = sqlcom.ExecuteScalar();
Console.WriteLine("Connected to node: " +
returnValue.ToString() + "\n");
_conn.Close();
Console.WriteLine("Disconnecting.\n");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
Notes
l
When native connection load balancing is enabled, the additional servers specified in the
BackupServerNode connection parameter are only used for the initial connection to an HP
Vertica host. If host redirects the client to another host in the database cluster to handle its
connection request, the second connection does not use the backup node list. This is rarely an
issue, since native connection load balancing is aware of which nodes are currently up in the
Connecting to HP Vertica
Connections to a host taken from the BackupServerNode list are not pooled for ADO.NET
connections.
VerticaLogProperties
VerticaLogProperties is a static class that allows you to set and get the log settings for the ADO.net
driver. You can control the log level, log path, and log namespace using this class.
The log is created when the first connection is opened. Once the connection is opened, you cannot
change the log path. It must be set prior to opening the connection. You can change the log level
and log namespace at any time.
Each of the methods requires a boolean persist argument. When set to true, the persist argument
causes the setting to be written to the client's Windows Registry, where it is used for all
subsequent connections. If set to false, then the log property only applies to the current session.
SetLogPath
The SetLogPath method takes as its arguments a string containing the path to the log file and the
persist argument. If the path string contains only a directory path, then the log file is created with the
name vdp-driver-MM-dd_HH.mm.ss.log (where MM-dd_HH.mm.ss is the date and time the log
Connecting to HP Vertica
was created). If the path ends in a filename, such as log.txt or log.log, then the log is created with
that filename.
If SetLogPath is called with an empty string for the path argument, then the client executable's
current directory is used as the log path.
If SetLogPath is not called and no registry entry exists for the log path, and you have called any of
the other VerticaLogProperties methods, then the client executable's current directory is used as
the log path.
When the persist argument is set to true, the path specified is copied to the registry verbatim. If no
filename was specified, then the filename is not saved to the registry.
Note: Note: The path must exist on the client system prior to calling this method. The method
does not create directories.
Example Usage:
//set the log path
string path = "C:\\log";
VerticaLogProperties.SetLogPath(path, false);
SetLogNamespace
The SetLogNamespace method takes as its arguments a string containing the namespace to log
and the persist argument. The namespace string to log can be one of the following:
l
Vertica
Vertica.Data.VerticaClient
Vertica.Data.Internal.IO
Vertica.Data.Internal.DataEngine
Vertica.Data.Internal.Core
Namespaces can be truncated to include multiple child namespaces. For example, you can specify
"Vertica.Data.Internal" to log for all of the Vertica.Data.Internal namespaces.
If a log namespace is not set, and no value is stored in the registry, then the "Vertica" namespace is
used for logging.
Example Usage:
Connecting to HP Vertica
SetLogLevel
The SetLogLevel method takes as its arguments a VerticaLogLevel type and the persist argument.
The VerticaLogLevel argument can be one of:
l
VerticaLogLevel.None
VerticaLogLevel.Fatal
VerticaLogLevel.Error
VerticaLogLevel.Warning
VerticaLogLevel.Info
VerticaLogLevel.Debug
VerticaLogLevel.Trace
If a log level is not set, and no value is stored in the registry, then VerticaLogLevel.None is used.
Example Usage:
//set log level
VerticaLogLevel level = VerticaLogLevel.Debug;
VerticaLogProperties.SetLogLevel(level, false);
LogPath
LogNamespace
LogLevel
Example Usage:
Connecting to HP Vertica
Connecting to HP Vertica
}
}
Log Settings:
Path:
Level: None
Namespace:
Log Settings:
Path: C:\log
Level: Debug
Namespace: Vertica
Connecting to HP Vertica
Note: The ExecuteNonQuery() method used to query the database returns an int32 with the
number of rows affected by the query. The maximum size of an int32 type is a constant and is
defined to be 2,147,483,547. If your query returns more results than the int32 max, then
ADO.NET throws an exception because of the overflow of the int32 type. However the query is
still processed by HP Vertica even when the reporting of the return value fails. This is a
limitation in .NET, as ExecuteNonQuery() is part of the standard ADO.NET interface.
3. Insert data using an INSERT statement. The following is an example of a simple insert. Note
that is does not contain a COMMIT statement because the HP Vertica ADO.NET driver
operates in autocommit mode.
command.CommandText =
"INSERT into test values(2, 'username', 'email', 'password')";
4. Execute the query. The rowsAdded variable contains the number of rows added by the insert
statement.
Int32 rowsAdded = command.ExecuteNonQuery();
Connecting to HP Vertica
The ExecuteNonQuery() method returns the number of rows affected by the command for
UPDATE, INSERT, and DELETE statements. For all other types of statements it returns -1. If
a rollback occurs then it is also set to -1.
Example Usage:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder
();
builder.Host = "192.168.1.10";
builder.Database = "VMart";
builder.User = "dbadmin";
VerticaConnection _conn = new VerticaConnection(builder.ToString());
_conn.Open();
VerticaCommand command = _conn.CreateCommand();
command.CommandText =
"INSERT into test values(2, 'username', 'email', 'password')";
Int32 rowsAdded = command.ExecuteNonQuery();
Console.WriteLine( rowsAdded + " rows added!");
_conn.Close();
}
}
}
Using Parameters
You can use parameters to execute similar SQL statements repeatedly and efficiently.
Using Parameters
VerticaParameters are an extension of the System.Data.DbParameter base class in ADO.NET
and are used to set parameters in commands sent to the server. Use Parameters in all queries
(SELECT/INSERT/UPDATE/DELETE) for which the values in the WHERE clause are not static;
that is for all queries that have a known set of columns, but whose filter criteria is set dynamically
by an application or end user. Using parameters in this way greatly decreases the chances of an
SQL injection issue that can occur when simply creating a SQL query from a number of variables.
Connecting to HP Vertica
Parameters require that a valid DbType, VerticaDbType, or System type be assigned to the
parameter. See SQL Data Types and ADO.NET Data Types for a mapping of System, Vertica, and
DbTypes.
To create a parameter placeholder, place either the at sign (@) or a colon (:) character in front of the
parameter name in the actual query string. Do not insert any spaces between the placeholder
indicator (@ or :) and the placeholder.
Note: The @ character is the preferred way to identify parameters. The colon (:) character is
supported for backward compatibility.
For example, the following typical query uses the string 'MA' as a filter.
SELECT customer_name, customer_address, customer_city, customer_state
FROM customer_dimension WHERE customer_state = 'MA';
Instead, the query can be written to use a parameter. In the following example, the string MA is
replaced by the parameter placeholder @STATE.
SELECT customer_name, customer_address, customer_city, customer_state
FROM customer_dimension WHERE customer_state = @STATE;
For example, the ADO.net code for the prior example would be written as:
VerticaCommand command = _conn.CreateCommand();
command.CommandText = SELECT customer_name, customer_address, customer_city, customer_
state
FROM customer_dimension WHERE customer_state = @STATE;
command.Parameters.Add(new VerticaParameter( STATE, VerticaType.VarChar));
command.Parameters["STATE"].Value = "MA";
Note: Although the VerticaCommand class supports a Prepare() method, you do not need to
call the Prepare() method for parameterized statements because HP Vertica automatically
prepares the statement for you.
Connecting to HP Vertica
rollback a transaction before it is committed if your code determines that a transaction should not
commit.
Transactions use the VerticaTransaction object, which is an implementation of DbTransaction. You
must associate the transaction with the VerticaCommand object.
The following code uses an explicit transaction to insert one row each into to tables of the VMart
schema.
Connecting to HP Vertica
command.ExecuteNonQuery();
command.CommandText = "insert into product_dimension values( 838929, 6, 'New item 6' )";
// try insert and catch any errors
bool error = false;
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
error = true;
}
if (error)
{
txn.Rollback();
Console.WriteLine("Errors. Rolling Back.");
}
else
{
txn.Commit();
Console.WriteLine("Queries Successful. Committing.");
}
Connecting to HP Vertica
See Also
l
Connecting to HP Vertica
default transaction isolation level for a connection, use the IsolationLevel keyword in the
VerticaConnectionStringBuilder string (see Connection String Keywords for details). To set the
isolation level for an individual transaction, pass the isolation level to the
VerticaConnection.BeginTransaction() method call to start the transaction.
Example usage:
The following example demonstrates:
l
Connecting to HP Vertica
{
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder
();
builder.Host = "192.168.1.10";
builder.Database = "VMart";
builder.User = "dbadmin";
VerticaConnection _conn1 = new VerticaConnection(builder.ToString());
_conn1.Open();
VerticaTransaction txn1 = _conn1.BeginTransaction();
Console.WriteLine("\n Transaction 1 Transaction Isolation Level: " +
txn1.IsolationLevel.ToString());
txn1.Rollback();
VerticaTransaction txn2 = _conn1.BeginTransaction
(IsolationLevel.Serializable);
Console.WriteLine("\n Transaction 2 Transaction Isolation Level: " +
txn2.IsolationLevel.ToString());
txn2.Rollback();
VerticaTransaction txn3 = _conn1.BeginTransaction
(IsolationLevel.ReadCommitted);
Console.WriteLine("\n Transaction 3 Transaction Isolation Level: " +
txn3.IsolationLevel.ToString());
_conn1.Close();
}
}
}
When run, the example code prints the following to the system console:
Transaction 1 Transaction Isolation Level: ReadCommitted
Transaction 2 Transaction Isolation Level: Serializable
Transaction 3 Transaction Isolation Level: ReadCommitted
Connecting to HP Vertica
3. Create a query. This query works with the example VMart database.
command.CommandText =
"SELECT fat_content, product_description " +
"FROM (SELECT DISTINCT fat_content, product_description" +
"
FROM product_dimension " +
"
WHERE department_description " +
"
IN ('Dairy') " +
"
ORDER BY fat_content) AS food " +
"LIMIT 10;";
4. Execute the reader to return the results from the query. The following command calls the
ExecuteReader method of the VerticaCommand object to obtain the VerticaDataReader
object.
VerticaDataReader dr = command.ExecuteReader();
5. Read the data. The data reader returns results in a sequential stream. Therefore, you must read
data from tables row-by-row. The following example uses a while loop to accomplish this:
Console.WriteLine("\n\n Fat Content\t Product Description");
Console.WriteLine("------------\t -------------------");
int rows = 0;
while (dr.Read())
{
Console.WriteLine("
" + dr[0] + "
\t " + dr[1]);
++rows;
}
Console.WriteLine("------------\n (" + rows + " rows)\n");
Connecting to HP Vertica
Example Usage:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder
();
builder.Host = "192.168.1.10";
builder.Database = "VMart";
builder.User = "dbadmin";
VerticaConnection _conn = new VerticaConnection(builder.ToString());
_conn.Open();
VerticaCommand command = _conn.CreateCommand();
command.CommandText =
"SELECT fat_content, product_description " +
"FROM (SELECT DISTINCT fat_content, product_description" +
"
FROM product_dimension " +
"
WHERE department_description " +
"
IN ('Dairy') " +
"
ORDER BY fat_content) AS food " +
"LIMIT 10;";
VerticaDataReader dr = command.ExecuteReader();
Console.WriteLine("\n\n Fat Content\t Product Description");
Console.WriteLine("------------\t -------------------");
int rows = 0;
while (dr.Read())
{
Console.WriteLine("
" + dr[0] + "
\t " + dr[1]);
++rows;
}
Console.WriteLine("------------\n (" + rows + " rows)\n");
dr.Close();
_conn.Close();
}
}
}
Connecting to HP Vertica
Batching Updates
When using the Update() method to update a dataset, you can optionally use the UpdateBatchSize
() method prior to calling Update() to reduce the number of times the client communicates with the
server to perform the update. The default value of UpdateBatchSize is 1. If you have multiple
rows.Add() commands for a data set, then you can change the batch size to an optimal size to
speed up the operations your client must perform to complete the update.
Connecting to HP Vertica
Connecting to HP Vertica
Reading Data From HP Vertica into a Data set and Changing data:
The following example shows how to use a data adapter to read from and insert into a dimension
table of the VMart schema.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Vertica.Data.VerticaClient
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder
();
builder.Host = "192.168.1.10";
builder.Database = "VMart";
builder.User = "dbadmin";
VerticaConnection _conn = new VerticaConnection(builder.ToString());
_conn.Open();
//Set up the insert command for the data adapter, and bind variables for some of the columns
da.InsertCommand = new
VerticaCommand("insert into product_dimension values( :key,
:version, :desc )",
Connecting to HP Vertica
_conn);
da.InsertCommand.Parameters.Add(new VerticaParameter("key",
VerticaType.BigInt));
da.InsertCommand.Parameters.Add(new VerticaParameter("version",
VerticaType.BigInt));
da.InsertCommand.Parameters.Add(new VerticaParameter("desc",
VerticaType.VarChar));
da.InsertCommand.Parameters[0].SourceColumn = "product_key";
da.InsertCommand.Parameters[1].SourceColumn = "product_version";
da.InsertCommand.Parameters[2].SourceColumn = "product_description";
da.TableMappings.Add("product_key", "product_key");
da.TableMappings.Add("product_version", "product_version");
da.TableMappings.Add("product_description", "product_description");
//Create and fill a Data set for this dimension table, and get the resulting DataTable.
DataSet ds = new DataSet();
da.Fill(ds, 0, 0, "product_dimension");
DataTable dt = ds.Tables[0];
//Merge the changes into the original Data set, and mark it up to date.
ds.Merge(ds2);
ds.AcceptChanges();
Console.WriteLine(updateCount + " updates made!");
}
}
catch (Exception e)
{
Connecting to HP Vertica
Console.WriteLine(e.Message);
}
_conn.Close();
}
}
}
Connecting to HP Vertica
VerticaParameter("id", VerticaType.BigInt));
VerticaParameter("username",
VerticaParameter("email", VerticaType.VarChar));
VerticaParameter("password",
Connecting to HP Vertica
//commit if no errors
Console.WriteLine("No Errors. Committing Transaction.");
txn.Commit();
Console.WriteLine("Inserted " + rows + " rows. ");
}
_conn.Close();
}
}
}
Example usage:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
Connecting to HP Vertica
class Program
{
static void Main(string[] args)
{
VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder
();
builder.Host = "192.168.1.10";
builder.Database = "VMart";
builder.User = "dbadmin";
builder.DirectBatchInsert = true;
VerticaConnection _conn = new VerticaConnection(builder.ToString());
_conn.Open();
//Perform some operations
_conn.Close();
}
}
}
Use Transactions and disable auto commit on the copy command for better performance.
Disable auto commit using the copy command with the 'no commit' modifier. You must explicitly
disable commits. Enabling transactions does not disable autocommit when using
VerticaCopyStream.
Connecting to HP Vertica
VerticaCopyStream.rejects is zeroed every time execute is called. If you want to capture the
number of rejects, assign the value of VerticaCopyStream.rejects to another variable before
calling execute again.
Example usage:
The following example demonstrates using VerticaCopyStream to copy a file stream into HP
Vertica.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
();
//start a transaction
VerticaTransaction txn = _conn.BeginTransaction();
copy_table", _conn);
Connecting to HP Vertica
delimiter '|'"
//create a new copy stream instance with the connection and copy statement
VerticaCopyStream vcs = new VerticaCopyStream(_conn, copy);
//finish stream and write out the list of inserted and rejected rows
long rowsInserted = vcs.Finish();
IList<long>
rowsRejected = vcs.Rejects; // does not work when rejected or exceptions defined
Console.WriteLine("Number of Rows inserted: " + rowsInserted);
Console.WriteLine("Number of Rows rejected: " + rowsRejected.Count);
if (rowsRejected.Count > 0)
{
for (int i = 0; i < rowsRejected.Count; i++)
{
Console.WriteLine("Rejected row #{0} is row {1}", i,
rowsRejected[i]);
}
}
Connecting to HP Vertica
txn.Commit();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
3. Copy data. The following is an example of using the COPY command to load data. It uses the
LOCAL modifier to copy a file local to the client issuing the command.
command.CommandText = "copy lcopy_table from '/home/dbadmin/customers.txt'"
+ " record terminator E'\n' delimiter '|'"
+ " enforcelength ";
Int32 insertedRows = command.ExecuteNonQuery();
Console.WriteLine(insertedRows + " inserted.");
Connecting to HP Vertica
Example Usage:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//start a transaction
VerticaTransaction txn = _conn.BeginTransaction();
Connecting to HP Vertica
Connecting to HP Vertica
3. Execute your queries. If a message is generated, then the event handle function is run.
4. You can unsubscribe from the event with the following command:
_conn.InfoMessage -= new VerticaInfoMessageEventHandler(conn_InfoMessage);
Example usage:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
class Program
{
//create message handler instance by subscribing it to the InfoMessage event of the connection
Connecting to HP Vertica
For example:
DataTable table = _conn.GetSchema("Tables", new string[] { null, null, null, "SYSTEM TABLE" });
database_name, schema_name, table_name can be set to null, be a specific name, or use a LIKE
pattern.
table_type can be one of:
l
"SYSTEM TABLE"
"TABLE"
"GLOBAL TEMPORARY"
"LOCAL TEMPORARY"
Connecting to HP Vertica
"VIEW"
null
If table_type is set to null, then the metadata for all metadata tables is returned.
Example Usage:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Connecting to HP Vertica
Console.WriteLine("============================");
}
ADO.NET
DbType
VerticaType
HP Vertica
Data Type
VerticaDataReader
getter
Boolean
Boolean
Bit
Boolean
GetBoolean()
byte[]
Binary
Binary
Binary
GetBytes()
VarBinary
VarBinary
LongVarBinary
LongVarBinary
Connecting to HP Vertica
.NET
Framework
Type
ADO.NET
DbType
VerticaType
HP Vertica
Data Type
VerticaDataReader
getter
Datetime
DateTime
Date
Date
GetDateTime()
Time
Time
TimeStamp
TimeStamp
DateTimeOffset DateTimeOffset
TimestampTZ
TimestampTZ
TimeTZ
TimeTZ
GetDateTimeOffset()
Note: The Date
portion of the
DateTime is set to
DateTime.MinValu
e
Decimal
Decimal
Numeric
Numeric
GetDecimal()
Connecting to HP Vertica
.NET
Framework
Type
ADO.NET
DbType
VerticaType
HP Vertica
Data Type
VerticaDataReader
getter
Double
Double
Double
Double
GetDouble()
Precision
Note: HP Vertica
Double type uses a
default precision of
53.
Int64
Int64
BigInt
Integer
GetInt64()
TimeSpan
Object
13 Interval
13 Interval
GetInterval()
Types
Types
Note: There are 13
VerticaType values
for the 13 types of
intervals. The
specific
VerticaType used
determines the
conversion rules
that the driver
applies.
Year/Month
intervals
represented as
365/30 days
String
String
Varchar
Varchar
LongVarChar
LongVarChar
GetString()
String
StringFixedLengt
Char
Char
GetString()
Object
Object
N/A
N/A
GetValue()
Connecting to HP Vertica
In order to use Python with HP Vertica, you must install the pyodbc module and an HP Vertica
ODBC driver on the machine where Python is installed. See Python Prerequisites.
Python on Linux
Most Linux distributions come with Python preinstalled. If you want a more recent version, you can
download and build it from the source code, though sometimes RPMs are also available. See the
Python Web site and click an individual release for details. See also Python documentation.
To determine the Python version on your Linux operating systems, type the following at a command
prompt:
# python -V
Python on Windows
Python is not required to run natively on Windows operating systems, so it is not preinstalled. The
ActiveState Web site distributes a free Windows installer for Python called ActivePython.
If you need installation instructions for Windows, see Using Python on Windows at python.org.
Python on Windows at diveintopython.org provides installation instructions for both the
ActivePython and python.org packages.
Connecting to HP Vertica
External Resources
l
Python documentation
Connecting to HP Vertica
export LD_LIBRARY_PATH=/path-to-vertica-odbc-driver:$LD_LIBRARY_PATH
Important: If you skip Step 2, the ODBC manager cannot find the driver in order to load it.
These steps are relevant only for unixODBC and iODBC. See their respective documentation for
details on odbc.ini.
See Also
l
Example Script
The following example script shows how to query HP Vertica using Python 3, pyodbc, and an
ODBC DSN.
import pyodbc
cnxn = pyodbc.connect("DSN=VerticaDSN", ansi=True)
cursor = cnxn.cursor()
# create table
cursor.execute("CREATE TABLE TEST("
"C_ID INT,"
"C_FP FLOAT,"
"C_VARCHAR VARCHAR(100),"
"C_DATE DATE, C_TIME TIME,"
"C_TS TIMESTAMP,"
"C_BOOL BOOL)")
cursor.execute("INSERT INTO test VALUES(1,1.1,'abcdefg1234567890','1901-0101','23:12:34','1901-01-01 09:00:09','t')")
cursor.execute("INSERT INTO test VALUES(2,3.4,'zxcasdqwe09876543','1991-1111','00:00:01','1981-12-31 19:19:19','f')")
cursor.execute("SELECT * FROM TEST")
rows = cursor.fetchall()
Connecting to HP Vertica
Notes
SQLPrimaryKeys returns the table name in the primary (pk_name) column for unnamed primary
constraints. For example:
l
See Also
l
Connecting to HP Vertica
Connect to HP Vertica
The HP Vertica ODBC drivers installed and configured. See Installing the HP Vertica Client
Drivers for details.
Connecting to HP Vertica
A Data Source Name (DSN) containing the connection parameters for your HP Vertica. See
Creating an ODBC Data Source Name. (Optionally, your Perl script can connect to HP Vertica
without using a DSN as described in Connecting From Perl Without a DSN).
Perl on Linux
Most Linux distributions come with Perl preinstalled. See your Linux distribution's documentation
for details of installing and configuring its Perl package is it is not already installed.
To determine the Perl version on your Linux operating systems, type the following at a command
prompt:
# perl -v
Perl on Windows
Perl is not installed by default on Windows platforms. There are several different Perl packages you
can download and install on your Windows system:
l
Connecting to HP Vertica
If the command exits without printing anything, then DBI is installed. If it prints an error, such as:
Can't locate DBI.pm in @INC (@INC contains: /usr/local/lib64/perl5/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl
/usr/lib64/perl5 /usr/share/perl5 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
You can also run the following Perl script to determine if DBI and DBD::ODBC are installed. If they
are, the script lists any available DSNs.
#!/usr/bin/perl
use strict;
# Attempt to load the DBI module in an eval using require. Prevents
# script from erroring out if DBI is not installed.
eval
{
require DBI;
DBI->import();
};
if ($@) {
# The eval failed, so DBI must not be installed
print "DBI module is not installed\n";
} else {
# Eval was successful, so DBI is installed
print "DBI Module is installed\n";
# List the drivers that DBI knows about.
my @drivers = DBI->available_drivers;
print "Available Drivers: \n";
foreach my $driver (@drivers) {
print "\t$driver\n";
}
# See if DBD::ODBC is installed by searching driver array.
if (grep {/ODBC/i} @drivers) {
Connecting to HP Vertica
The exact output of the above code will depend on the configuration of your system. The following
is an example of running the code on a Windows computer:
DBI Module is installed
Available Drivers:
ADO
DBM
ExampleP
File
Gofer
ODBC
Pg
Proxy
SQLite
Sponge
mysql
DBD::ODBC is installed.
Defined ODBC Data Sources:
dbi:ODBC:dBASE Files
dbi:ODBC:Excel Files
dbi:ODBC:MS Access Database
dbi:ODBC:VerticaDSN
For most Perl installations, you use the cpan command to install modules. If the cpan command
alias isn't installed on your system, you can try to start CPAN by using the command:
perl -MCPAN -e shell
Connecting to HP Vertica
Some Linux distributions provide Perl modules as packages that can be installed with the
system package manager (such as yum or apt). See your Linux distribution's documentation for
details.
On ActiveState Perl for Windows, you use the Perl Package Manager (PPM) program to install
Perl modules. See the Activestate's PPM documentation for details.
Note: Installing Perl modules usually requires administrator or root privileges. If you do not
have these permissions on your client system, you need to ask your system administrator to
install these modules for you.
The username and password parameters are optional. However, if you do not supply them (or just
the username for a passwordless account) and they are not set in the DSN, attempting to connect
always fails.
The connect function returns a database handle if it connects to HP Vertica. If it does not, it returns
undef. In that case, you can access the DBI module's error string property ($DBI::errstr) to get
the error message.
Note: By default, the DBI module prints an error message to STDERR whenever it encounters
an error. If you prefer to display your own error messages or handle errors in some other
manner, you may want to disable these automatic messages by setting DBI's PrintError
connection attribute to false. See Setting Perl DBI Connection Attributes for details.
Otherwise, users may see two error messages: the one that DBI prints automatically, and the
one that your script prints on its own.
Connecting to HP Vertica
The following example demonstrates connecting to HP Vertica using a DSN named VerticaDSN.
The call to connect supplies a username and password. After connecting, it calls the database
handle's disconnect function, which closes the connection.
#!/usr/bin/perl -w
use strict;
use DBI;
# Open a connection using a DSN. Supply the username and password.
my $dbh = DBI->connect("dbi:ODBC:VerticaDSN","ExampleUser","password123");
unless (defined $dbh) {
# Conection failed.
die "Failed to connect: $DBI::errstr";
}
print "Connected!\n";
$dbh->disconnect();
See Data Source Name (DSN) Connection Parameters for a list of the connection parameters you
can set in the source data string.
Connecting to HP Vertica
You can set the DBI connection attributes when establishing a connection by passing the DBI
connect function a hash containing attribute and value pairs. For example, to set the DBI
connection attribute AutoCommit to false, you would use:
# Create a hash that holds attributes for the connection
my $attr = {AutoCommit => 0};
# Open a connection using a DSN. Supply the username and password.
my $dbh = DBI->connect("dbi:ODBC:VerticaDSN","ExampleUser","password123",
$attr);
See the DBI documentation's Database Handle Attributes section for a full description of the
attributes you can set on the database connection.
After your script has connected, it can access and modify the connection attributes through the
database handle by using it as a hash reference. For example:
print "The AutoCommit attribute is: " . $dbh->{AutoCommit} . "\n";
RaiseError controls whether the DBI driver generates a Perl error if it encounters a database
error. Usually, you set this to true (1) if you want your Perl script to exit if there is a database
error.
AutoCommit controls whether statements automatically commit their transactions when they
complete. DBI defaults to HP Vertica's default AutoCommit value of true. Always set
AutoCommit to false (0) when bulk loading data to increase database efficiency.
#!/usr/bin/perl
use strict;
use DBI;
# Create a hash that holds attributes for the connection
my $attr = {
RaiseError => 1, # Make database errors fatal to script
AutoCommit => 0, # Prevent statements from committing
# their transactions.
};
# Open a connection using a DSN. Supply the username and password.
my $dbh = DBI->connect("dbi:ODBC:VerticaDSN","ExampleUser","password123",
$attr);
if (defined $dbh->err) {
# Connection failed.
die "Failed to connect: $DBI::errstr";
}
print "Connected!\n";
# The database handle lets you access the connection attributes directly:
print "The AutoCommit attribute is: " . $dbh->{AutoCommit} . "\n";
print "The RaiseError attribute is: " . $dbh->{RaiseError} . "\n";
Connecting to HP Vertica
On Windows, the name assigned to the HP Vertica ODBC driver by the driver manager is
Vertica.
On Linux and other UNIX-like operating systems, the HP Vertica ODBC driver's name is
assigned in the system's odbcinst.ini file. For example, if your /etc/odbcint.ini contains
the following:
[HPVertica]
Description = HP Vertica ODBC Driver
Driver = /opt/vertica/lib64/libverticaodbc.so
you would use the name HPVertica. See Creating an ODBC DSN for Linux, Solaris, AIX, and
HP-UX for more information about the odbcinst.ini file.
You can take advantage of Perl's variable expansion within strings to use variables for most of the
connection properties as the following example demonstrates.
#!/usr/bin/perl
use strict;
use DBI;
my $server='VerticaHost';
my $port = '5433';
my $database = 'VMart';
my $user = 'ExampleUser';
my $password = 'password123';
# Connect without a DSN by supplying all of the information for the connection.
Connecting to HP Vertica
# The DRIVER value on UNIX platforms depends on the entry in the odbcinst.ini
# file.
my $dbh = DBI->connect("dbi:ODBC:DRIVER={Vertica};Server=$server;" .
"Port=$port;Database=$database;UID=$user;PWD=$password")
or die "Could not connect to database: " . DBI::errstr;
print "Connected!\n";
$dbh->disconnect();
Note: Surrounding the driver name with braces ({ and }) in the source string is optional.
Note: The do function returns the number of rows that were affected by the statement (or -1 if
the count of rows doesn't apply or is unavailable). Usually, the only time you need to consult
this value is after you deleted a number of rows or if you used a bulk load command such as
COPY. You use other DBI functions instead of do to perform batch inserts and selects (see
Connecting to HP Vertica
Batch Loading Data Using Perl and Querying Using Perl for details).
The prepare function returns a statement handle that you will use to insert the data.
3. Assign data to the placeholders. There are several ways to do this. The easiest is to populate
an array with a value for each placeholder in your INSERT statement.
4. Call the statement handle's execute function to insert a row of data into HP Vertica. The return
value of this function call lets you know whether HP Vertica accepted or rejected the row.
5. Repeat steps 3 and 4 until you have loaded all of the data you need to load.
6. Call the database handle's commit function to commit the data you inserted.
The following example demonstrates inserting a small batch of data by populating an array of arrays
with data, then looping through it and inserting each row.
#!/usr/bin/perl
use strict;
use DBI;
# Create a hash reference that holds a hash of parameters for the
# connection.
my $attr = {AutoCommit => 0, # Turn off autocommit
PrintError => 0
# Turn off automatic error printing.
# This is handled manually.
};
# Open a connection using a DSN. Supply the username and password.
my $dbh = DBI->connect("dbi:ODBC:VerticaDSN","ExampleUser","password123",
$attr);
if (defined DBI::err) {
# Conection failed.
die "Failed to connect: $DBI::errstr";
}
Connecting to HP Vertica
Connecting to HP Vertica
Note that one of the rows was not inserted because it contained a string value that could not be
stored in an integer column. See Conversions Between Perl and Data Types for details of data type
handling in Perl scripts that communicate with HP Vertica.
Connecting to HP Vertica
The data.txt file is a text file containing a row of data on each line. The columns are delimited by
pipe (|) characters. This is the default format that the COPY command accepts, which makes the
COPY LOCAL statement in the example code simple. See the COPY statement entry in the SQL
Reference Manual for handling data files that are in different formats. Here is an example of the
content in this file:
1|Georgia|Gomez|[email protected]|1937-10-03
2|Abdul|Alexander|[email protected]|1941-03-10
3|Nigel|Contreras|[email protected]|1955-06-01
4|Gray|Holt|[email protected]|1945-12-06
5|Candace|Bullock|[email protected]|1932-05-27
6|Matthew|Dotson|[email protected]|1956-09-30
7|Haviva|Hopper|[email protected]|1975-05-10
8|Stewart|Sweeney|[email protected]|2003-06-20
9|Allen|Rogers|[email protected]|2006-06-17
10|Trevor|Dillon|[email protected]|1988-11-27
11|Leroy|Ashley|[email protected]|1958-07-25
12|Elmo|Malone|[email protected]|1978-08-29
13|Laurel|Ball|[email protected]|1989-09-20
14|Zeus|Phillips|[email protected]|1996-08-08
15|Alexis|Mclean|[email protected]|2008-01-07
The example code produces the following output when run on a large sample file:
Connecting to HP Vertica
Connected!
Loading file /home/dbadmin/Perl/data.txt
Copied 1000000 rows into database.
ID First
Last
EMail
== =====
====
=====
1 Georgia
Gomez
[email protected]
2 Abdul
Alexander
[email protected]
3 Nigel
Contreras
[email protected]
4 Gray
Holt
[email protected]
5 Candace
Bullock
[email protected]
6 Matthew
Dotson
[email protected]
7 Haviva
Hopper
[email protected]
8 Stewart
Sweeney
[email protected]
9 Allen
Rogers
[email protected]
10 Trevor
Dillon
[email protected]
11 Leroy
Ashley
[email protected]
12 Elmo
Malone
[email protected]
13 Laurel
Ball
[email protected]
14 Zeus
Phillips
[email protected]
Birthday
========
1937-10-03
1941-03-10
1955-06-01
1945-12-06
1932-05-27
1956-09-30
1975-05-10
2003-06-20
2006-06-17
1988-11-27
1958-07-25
1978-08-29
1989-09-20
1996-08-08
Note: Loading a single, large data file into HP Vertica through a single data connection is less
efficient than loading a number of smaller files onto multiple nodes in parallel. Loading onto
multiple nodes prevents any one node from becoming a bottleneck.
Connecting to HP Vertica
use strict;
use DBI;
my $attr = {RaiseError => 1 }; # Make errors fatal to the Perl script.
# Open a connection using a DSN. Supply the username and password.
my $dbh = DBI->connect("dbi:ODBC:VerticaDSN","ExampleUser","password123",
$attr);
# Prepare a query to get the content of the table
my $sth = $dbh->prepare("SELECT * FROM TEST ORDER BY C_ID ASC");
# Execute the query by calling execute on the statement handle
$sth->execute();
# Loop through result rows while we have them, getting each row as an array
while (my @row = $sth->fetchrow_array()) {
# The @row array contains the column values for this row of data
# Loop through the column values
foreach my $column (@row) {
if (!defined $column) {
# NULLs are signaled by undefs. Set to NULL for clarity
$column = "NULL";
}
print "$column\t"; # Output the column separated by a tab
}
print "\n";
}
$dbh->disconnect();
1.111
Hello World!
2001-01-01
01:01:01
2001-01-01 01:01:01
2.22222 How are you?
2002-02-02
02:02:02
2002-02-02 02:02:02
4.22222 NULL
2002-02-02
02:02:02
2002-02-02 02:02:02
0
1
0
Connecting to HP Vertica
The output of this example is identical to the output of the previous example.
Connecting to HP Vertica
Connecting to HP Vertica
# Conection failed.
die "Failed to connect: $DBI::errstr";
}
print "Connection AutoCommit state is: " . $dbh->{AutoCommit} . "\n";
# Create table to hold inserted data
$dbh->do("DROP TABLE IF EXISTS TEST CASCADE;");
$dbh->do("CREATE TABLE TEST( \
C_ID INT, \
C_FP FLOAT,\
C_VARCHAR VARCHAR(100),\
C_DATE DATE, C_TIME TIME,\
C_TS TIMESTAMP,\
C_BOOL BOOL)");
# Populate an array of arrays with values.
my @data = (
# Start with matching data types
[1,1.111,'Matching datatypes','2001-01-01','01:01:01'
,'2001-01-01 01:01:01','t'],
# Force floats -> int and int -> float.
[2.0,2,"Ints <-> floats",'2002-02-02','02:02:02'
,'2002-02-02 02:02:02',1],
# Float -> int *only* works when there is no loss of precision.
# this row will fail to insert:
[3.1,3,"float -> int with trunc?",'2003-03-03','03:03:03'
,'2003-03-03 03:03:03',1],
# String values are converted into numbers
["4","4.4","Strings -> numbers", '2004-04-04','04:04:04',
,'2004-04-04 04:04:04',0],
# String -> numbers only works if the entire string can be
# converted into a number
["5 and a half","5.5","Strings -> numbers", '2005-05-05',
'05:05:05', ,'2005-05-05 05:05:05',0],
# Number are converted into string values automatically,
# assuming they fit into the column width.
[6,6.6,3.14159, '2006-06-06','06:06:06',
,'2006-06-06 06:06:06',0],
# There are some variations in the accepted date strings
[7,7.7,'Date/time formats', '07/07/2007','07:07:07',
,'07-07-2007 07:07:07',1],
);
# Create a prepared statement to use parameters for inserting values.
my $sth = $dbh->prepare_cached("INSERT into test values(?,?,?,?,?,?,?)");
my $rowcount = 0; # Count # of rows
# Loop through the arrays to insert values
foreach my $tuple (@data) {
$rowcount++;
# Insert the row
my $retval = $sth->execute(@$tuple);
# See if the row was successfully inserted.
if ($retval == 1) {
# Value of 1 means the row was inserted (1 row was affected by insert)
print "Row $rowcount successfully inserted\n";
} else {
print "Inserting row $rowcount failed with error " .
$sth->state . " " . $sth->errstr . "\n";
}
}
Connecting to HP Vertica
Connecting to HP Vertica
details. You can check the DBD::ODBC-specific connection attribute named odbc_has_unicode
to see if Unicode support is enabled in the driver.
The following example Perl script demonstrates directly inserting UTF-8 strings into HP Vertica and
then reading them back. The example writes a text file with the output, since there are may
problems displaying Unicode characters in terminal windows or consoles.
#!/usr/bin/perl
use strict;
use DBI;
# Open a connection using a DSN.
my $dbh = DBI->connect("dbi:ODBC:VerticaDSN","ExampleUser","password123");
unless (defined $dbh) {
# Conection failed.
die "Failed to connect: $DBI::errstr";
}
# Output to a file. Displaying Unicode characters to a console or terminal
# window has many problems. This outputs a UTF-8 text file that can
# be handled by many Unicode-aware text editors:
open OUTFILE, '>:utf8', "unicodeout.txt";
# See if the DBD::ODBC driver was compiled with Unicode support. If this returns
# 1, your Perl script will get get strings from the driver with the UTF-8
# flag set on them, ensuring that Perl handles them correctly.
print OUTFILE "Was DBD::ODBC compiled with Unicode support? " .
$dbh->{odbc_has_unicode} . "\n";
# Create a table to hold VARCHARs
$dbh->do("DROP TABLE IF EXISTS TEST CASCADE;");
# Create a table to hold data. Remember that the width of the VARCHAR column
# is the number of bytes set aside to store strings, which often does not equal
# the number of characters it can hold when it comes to Unicode!
$dbh->do("CREATE TABLE test( C_VARCHAR VARCHAR(100) )");
print OUTFILE "Inserting data...\n";
# Use Do to perform simple inserts
$dbh->do("INSERT INTO test VALUES('Hello')");
# This string contains several non-latin accented characters and symbols, encoded
# with Unicode escape notation. They are converted by Perl into UTF-8 characters
$dbh->do("INSERT INTO test VALUES('My favorite band is " .
"\N{U+00DC}ml\N{U+00E4}\N{U+00FC}t \N{U+00D6}v\N{U+00EB}rk\N{U+00EF}ll" .
" \N{U+263A}')");
# Some Chinese (Simplified) characters. This again uses escape sequence
# that Perl translates into UTF-8 characters.
$dbh->do("INSERT INTO test VALUES('\x{4F60}\x{597D}')");
print OUTFILE "Getting data...\n";
# Prepare a query to get the content of the table
my $sth = $dbh->prepare_cached("SELECT * FROM test");
# Execute the query by calling execute on the statement handle
$sth->execute();
# Loop through result rows while we have them
while (my @row = $sth->fetchrow_array()) {
# Loop through the column values
foreach my $column (@row) {
print OUTFILE "$column\t";
}
print OUTFILE "\n";
Connecting to HP Vertica
}
close OUTFILE;
$dbh->disconnect();
Hello
Note: Terminal windows and consoles often have problems properly displaying Unicode
characters. That is why the example writes the output to a text file. With some text editors, you
may need to manually set the encoding of the text file to UTF-8 in order for the characters to
properly appear (and the font used to display text must have a full Unicode character set). If the
character still do not show up, it may be that your version of DBD::ODBC was not compiled
with UTF-8 support.
See Also
l
Connecting to HP Vertica
php
php-odbc
php-pdo
PHP on Linux
PHP is available with most Linux operating systems as a module for the Apache web server.
Check your particular Linux repository for PHP RPMs or Debian packages. You can also build PHP
from source. See the PHP web site for documentation and source downloads.
PHP on Windows
PHP is available for windows for both the Apache and IIS web servers. You can download PHP for
Windows and view installation instructions at the PHP web site.
Setup
You must read Programming ODBC Client Applications before connecting to HP Vertica through
PHP. The following example ODBC configuration entries detail the typical settings required for
PHP ODBC connections. The driver location assumes you have copied the HP Vertica drivers to
/usr/lib64.
Connecting to HP Vertica
Example odbc.ini
[ODBC Data Sources]
VerticaDSNunixodbc = exampledb
VerticaDNSiodbc = exampledb2
[VerticaDSNunixodbc]
Description = VerticaDSN Unix ODBC driver
Driver = /usr/lib64/libverticaodbc.so
Database = Telecom
Servername = localhost
UserName = dbadmin
Password =
Port = 5433
[VerticaDSNiodbc]
Description = VerticaDSN iODBC driver
Driver = /usr/lib64/libverticaodbc.so
Database = Telecom
Servername = localhost
UserName = dbadmin
Password =
Port = 5433
Example odbcinst.ini
# Vertica
[VerticaDSNunixodbc]
Description = VerticaDSN Unix ODBC driver
Driver = /usr/lib64/libverticaodbc.so
[VerticaDNSiodbc]
Description = VerticaDSN iODBC driver
Driver = /usr/lib64/libverticaodbc.so
[ODBC]
Threading = 1
Connecting to HP Vertica
isql -v VerticaDSN
Connecting to HP Vertica
Example Output
The following is the example output from the script.
Success: CREATE TABLE TEST( C_ID INT, C_FP FLOAT, C_VARCHAR VARCHAR(100), C_DATE DATE, C_
TIME TIME, C_TS TIMESTAMP, C_BOOL BOOL)
Success: INSERT into test values(1,1.1,'abcdefg1234567890','1901-01-01','23:12:34
','1901-01-01 09:00:09','t')
Success: odbc_execute.
Success: SELECT * FROM TEST
Array
(
[C_ID] => 1
[C_FP] => 1.1
[C_VARCHAR] => abcdefg1234567890
[C_DATE] => 1901-01-01
[C_TIME] => 23:12:34
[C_TS] => 1901-01-01 09:00:09
[C_BOOL] => 1
)
Array
(
[C_ID] => 2
[C_FP] => 2.28
[C_VARCHAR] => abcdefg1234567890
[C_DATE] => 1901-01-01
[C_TIME] => 23:12:34
[C_TS] => 1901-01-01 23:12:34
[C_BOOL] => 1
)
Success: DROP TABLE TEST CASCADE
Connecting to HP Vertica
Connecting to HP Vertica
Management API
Management API
The Management API is a REST API that you can use to view and manage HP Vertica databases
with scripts or applications that understand REST and JSON. The response format for all requests
is JSON.
GET api
POST backups/:config_script_base
GET backups/:config_script_base/:archive_id
POST restore/:archive_id
Restores a backup.
Databases
GETdatabases
POST databases
GET databases/:database_name
PUT databases/:database_name
Connecting to HP Vertica
Management API
DELETE databases/:database_name
GET databases/:database_name/configuration
PUT databases/:database_name/configuration
GET databases/:database_name/hosts
POST databases/:database_name/hosts
DELETE databases/:database_
name/hosts/:host_id
POST databases/:database_name/hosts/:host_
id/process
host.
DELETE databases/:database_
name/hosts/:host_id/process
POST databases/:database_name/hosts/:host_
id/replace_with/:host_id_new
database.
GET databases/:database_name/license
PUT databases/:database_name/license
GET databases/:database_name/licenses
GET databases/:database_name/nodes
GET databases/:database_name/nodes/:node_id
POST databases/:database_name/process
GET databases/:database_name/process
DELETE databases/:database_name/process
Connecting to HP Vertica
Management API
POST databases/:database_
name/rebalance/process
POST databases/:database_name/wla/process
Hosts
GET hosts
GET hosts/:hostid
Jobs
GET jobs
GET jobs/:id
Licenses
POST licenses
GET licenses
Nodes
GET nodes
GET nodes/:nodeid
Connecting to HP Vertica
Management API
Webhooks
GET webhooks
POST webhooks/subscribe
DELETE webhooks/:subscriber_id
cURL
cURL is a command-line tool and application library used to transfer data to or from a server. It uses
URL syntax, such as HTTP and HTTPS. All API requests sent to an HP Vertica server must be
made using HTTPS. A request made using HTTP will fail.
There are four HTTP requests that can be passed using cURL to call API methods:
Request
Description
GET
Retrieves data.
PUT
Updates data.
POST
DELETE
Deletes data.
Syntax
curl https://<NODE>:5444/
Options
-h --help
-H --header
Allows you to use custom headers in your command. This is useful for sending a
request that requires a VerticaAPIKEY.
curl -H "VerticaApiKey: ValidAPIKey" https://<NODE>:5444/
Connecting to HP Vertica
Management API
-k --insecure
-X --request
GET
PUT
POST
DELETE
There are many more options available to add to your cURL query. For a comprehensive list with
descriptions, visit the cURL Documentation Website.
Connecting to HP Vertica
Management API
VerticaAPIKey
The Management API requires an authentication key, named VerticaAPIKEY, to access some API
resources. You can manage API keys by using the apikeymgr command-line tool.
usage: apikeymgr [-h] [--user REQUESTOR] [--app APPLICATION] [--delete]
[--create] [--update] [--migrate]
[--secure {restricted,normal,admin}] [--list]
API key management tool
optional arguments:
-h, --help
show this help message and exit
--user REQUESTOR
The name of the person requesting the key
--app APPLICATION
The name of the application that will use the key
--delete
Delete the key for the given R & A
--create
Create a key for the given R & A
--update
Update a key for the given R & A
--migrate
migrate the keyset to the latest format
--secure {restricted,normal,admin}
Set the keys security level
--list
List all the keys known
Example Request
To create a new VerticaAPIKEY for the dbadmin user with admin access, enter the following:
$ apikeymgr --user dbadmin --app vertica --create --secure admin
Response:
Requestor : dbadmin
Application: vertica
API Key
: ValidAPIKey
Synchronizing cluster...
Connecting to HP Vertica
Management API
GET /
Returns API version information and a list of links to child resources for the Management API.
Resource URL
https://<NODE>:5444/
Authentication
Not required.
Parameters
None.
Example Request
GET
https://<NODE>:5444/
Response:
{
"body": {
"mime-types": [
"default",
"application/vertica.database.configuration.json-v2",
"application/json",
"application/vertica.nodes.json-v2",
"default",
"application/json",
"default",
"application/json",
"application/vertica.jobs.json-v2",
"default",
"application/vertica.hosts.json-v2",
"application/json",
"default",
"application/vertica.hosts.json-v2",
"application/json",
"default",
"application/json",
"application/vertica.host.json-v2",
"default",
"application/vertica.hosts.json-v2",
Connecting to HP Vertica
Management API
"application/json",
"application/vertica.nodes.json-v2",
"default",
"application/json",
"default",
"application/json",
"application/vertica.database.json-v2",
"default",
"application/vertica.hosts.json-v2",
"application/json",
"default",
"application/vertica.hosts.json-v2",
"application/json",
"default",
"application/json",
"application/vertica.databases.json-v2",
"application/vertica.nodes.json-v2",
"default",
"application/json",
"application/vertica.agent.json-v2",
"default",
"application/json",
"default",
"application/vertica.users.json-v2",
"application/json"
],
"version": "7.1.0"
},
"href": "/",
"links": [
"/databases",
"/hosts",
"/nodes",
"/licenses",
"/webhooks",
"/backups",
"/restore",
"/jobs"
],
"mime-type": "application/vertica.agent.json-v2"
}
Connecting to HP Vertica
Management API
GET api
Displays a list of all Management API commands and a brief description for each command. You
can also access an HTML version of this information at https://<NODE>:5444/api.html.
Replace <NODE> with the URL of a cluster node.
Resource URL
https://<NODE>:5444/api
Authentication
Not required.
Parameters
None.
Example Request
GET
https://<NODE>:5444/api
Response:
[
{
"accepts": {},
"description": " Returns the agent specific information useful for version
checking and service discovery ",
"method": "GET",
"params": [],
"route": "/"
},
{
"accepts": {},
"description": " build the list of cluster objects and properties and return it
as a JSON formatted array ",
"method": "GET",
"params": [],
"route": "/api"
},
{
"accepts": {},
"description": " list all the backups that have been created for all vbr
Connecting to HP Vertica
Management API
configuration files ( *.ini ) that are located in the /opt/vertica/config directory. ",
"method": "GET",
"params": [],
"route": "/backups"
},
{
"accepts": {},
"description": " create a new backup as defined by the given vbr configuration
script base (filename minus the .ini extenstion) ",
"method": "POST",
"params": [],
"route": "/backups/:config_script_base"
},
{
"accepts": {},
"description": " get the detail for a specific backup archive ",
"method": "GET",
"params": [],
"route": "/backups/:config_script_base/:archive_id"
},
{
"accepts": {},
"description": " delete a backup based on the config ini file script",
"method": "DELETE",
"params": [],
"route": "/backups/:config_script_base/:backup_id"
},
{
"accepts": {},
"description": " build the list of databases, their properties, and current
status ( from cache ) and return it as a JSON formatted array ",
"method": "GET",
"params": [],
"route": "/databases"
},
{
"accepts": {},
"description": " Create a new database by supplying a valid set of parameters ",
"method": "POST",
"params": [
"name
: name of the database to create",
"passwd : password used by the database administrative user",
"only
: optional list of hostnames to include in database",
"exclude : optional list of hostnames to exclude from the database",
"catalog : directory used for the vertica catalog",
"data
: directory used for the initial vertica storage location",
"port
: port the database will listen on (default 5433)"
],
"route": "/databases"
},
{
"accepts": {},
"description": " Retrieve the database properties structure ",
"method": "GET",
"params": [],
"route": "/databases/:database_name"
},
{
Connecting to HP Vertica
Management API
"accepts": {},
"description": " Control / alter a database values using the PUT http method ",
"method": "PUT",
"params": [
"action : value one of start|stop|rebalance|wla"
],
"route": "/databases/:database_name"
},
{
"accepts": {},
"description": " Delete an existing database ",
"method": "DELETE",
"params": [],
"route": "/databases/:database_name"
},
{
"accepts": {},
"description": " retrieve the current parameters from the database. if its
running return 503 Service Unavailable ",
"method": "GET",
"params": [
"user_id : vertica database username",
"passwd
: vertica database password"
],
"route": "/databases/:database_name/configuration"
},
{
"accepts": {},
"description": " set a list of parameters in the database. if its not running
return 503 Service Unavailable ",
"method": "PUT",
"params": [
"user_id : vertica database username",
"passwd
: vertica database password",
"parameter : value vertica parameter/key combo"
],
"route": "/databases/:database_name/configuration"
},
{
"accepts": {},
"description": " list the hosts that are current used by this database",
"method": "GET",
"params": [],
"route": "/databases/:database_name/hosts"
},
{
"accepts": {},
"description": " add a host to the database ",
"method": "POST",
"params": [
"user_id : vertica database username",
"passwd
: vertica database password"
],
"route": "/databases/:database_name/hosts"
},
{
"accepts": {},
"description": " remove a host from the database",
Connecting to HP Vertica
Management API
"method": "DELETE",
"params": [],
"route": "/databases/:database_name/hosts/:host_id"
},
{
"accepts": {},
"description": " start the database process on a specific host participating in
this database.",
"method": "POST",
"params": [],
"route": "/databases/:database_name/hosts/:host_id/process"
},
{
"accepts": {},
"description": " run the stop action against the given database for a specific
host",
"method": "DELETE",
"params": [],
"route": "/databases/:database_name/hosts/:host_id/process"
},
{
"accepts": {},
"description": " replace a host with a standby host in the database ",
"method": "POST",
"params": [
"user_id : vertica database username",
"passwd
: vertica database password"
],
"route": "/databases/:database_name/hosts/:host_id/replace_with/:host_id_new"
},
{
"accepts": {},
"description": " return the vertica license that this database is using ",
"method": "GET",
"params": [
"user_id : vertica database user",
"passwd
: vertica databse password"
],
"route": "/databases/:database_name/license"
},
{
"accepts": {},
"description": " this method upgrades the license in the database by using the
license in /opt/vertica/config/share ",
"method": "PUT",
"params": [
"user_id : vertica database user",
"passwd
: vertica databse password"
],
"route": "/databases/:database_name/license"
},
{
"accepts": {},
"description": " return all the feature licenses that this database is using ",
"method": "GET",
"params": [
"user_id : vertica database user",
"passwd
: vertica databse password"
Connecting to HP Vertica
Management API
],
"route": "/databases/:database_name/licenses"
},
{
"accepts": {},
"description": " build the list of nodes for a given database, their properties,
and current status ( from cache ) and return it as a JSON formatted array ",
"method": "GET",
"params": [],
"route": "/databases/:database_name/nodes"
},
{
"accepts": {},
"description": " build the list of nodes for a given database, their properties,
and current status and return it as a JSON formatted array ",
"method": "GET",
"params": [],
"route": "/databases/:database_name/nodes/:node_id"
},
{
"accepts": {},
"description": " run the start action against the given database ",
"method": "POST",
"params": [
"epoch
: start the database from this epoch",
"include : start the database on these hosts only"
],
"route": "/databases/:database_name/process"
},
{
"accepts": {},
"description": " easy way to see if a database is running -- returns state of UP
or DOWN",
"method": "GET",
"params": [],
"route": "/databases/:database_name/process"
},
{
"accepts": {},
"description": " run the stop action against the given database ",
"method": "DELETE",
"params": [
"user_id : vertica database username",
"passwd
: vertica database password"
],
"route": "/databases/:database_name/process"
},
{
"accepts": {},
"description": " run the rebalance data action against the given database could be very long running! ",
"method": "POST",
"params": [
"user_id : vertica database username",
"passwd
: vertica database password"
],
"route": "/databases/:database_name/rebalance/process"
},
Connecting to HP Vertica
Management API
{
"accepts": {},
"description": " Retrieve the database properties structure ",
"method": "GET",
"params": [],
"route": "/databases/:database_name/status"
},
{
"accepts": {},
"description": " run the analyze workload action against the given database could be very long running! ",
"method": "POST",
"params": [
"user_id : vertica database username",
"passwd
: vertica database password"
],
"route": "/databases/:database_name/wla/process"
},
{
"accepts": {},
"description": " build a list of nodes in the cluster independent of their
database associations ",
"method": "GET",
"params": [],
"route": "/hosts"
},
{
"accepts": {},
"description": " lists the properties of a given host in the cluster by calling
the RESTful service on that agent. ",
"method": "GET",
"params": [],
"route": "/hosts/:hostid"
},
{
"accepts": {},
"description": " Returns a list of jobs the agent is tracking along with their
current status and exit codes ",
"method": "GET",
"params": [],
"route": "/jobs"
},
{
"accepts": {},
"description": " Deletes a specific job by canceling any outstanding activity
associated with it. ",
"method": "DELETE",
"params": [],
"route": "/jobs/:id"
},
{
"accepts": {},
"description": " Returns the details (the saved output) for a specific job ",
"method": "GET",
"params": [],
"route": "/jobs/:id"
},
{
Connecting to HP Vertica
Management API
"accepts": {},
"description": " POST your vertica license to this url using HTTP file upload
format. ",
"method": "POST",
"params": [
"license : the file to upload (use html form post format)"
],
"route": "/licenses"
},
{
"accepts": {},
"description": " list the license fiel that will be used by databases created on
this cluster found in /opt/vertica/config/share/license.key ",
"method": "GET",
"params": [],
"route": "/licenses"
},
{
"accepts": {},
"description": " build a list of nodes in the topology independent of their
database associations ",
"method": "GET",
"params": [],
"route": "/nodes"
},
{
"accepts": {},
"description": " build a list of nodes in the topology independent of their
database associations ",
"method": "GET",
"params": [],
"route": "/nodes/:nodeid"
},
{
"accepts": {},
"description": " restore a backup given then archive id as defined via the 'GET'
method ",
"method": "POST",
"params": [],
"route": "/restore/:archive_id"
},
{
"accepts": {},
"description": " delete a subscription from this agent. ",
"method": "DELETE",
"params": [],
"route": "/webhooks/:subscriber_id"
},
{
"accepts": {},
"description": " post a request with a callback url to subscribe to events from
this agent. Returns a subscription_id that can be used to unsubscribe from the service.
@returns subscription_id ",
"method": "POST",
"params": [
"url : full url to the callback resource"
],
"route": "/webhooks/subscribe"
Connecting to HP Vertica
Management API
}
]
Connecting to HP Vertica
Management API
GET backups
Returns a list of all backups created for vbr configuration (*.ini) files that reside in
/opt/vertica/config and provides details about each backup.
Resource URL
https://<NODE>:5444/backups
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/backups
Response:
[
{
"backups": [
{
"backup": "backup3_20140707_114852",
"epoch": "61",
"hosts": "v_vmart_node0001(10.20.100.247)",
"objects": ""
}
],
"config_file": "/opt/vertica/config/backup3.ini",
"num_backups": 1
},
{
"backups": [
{
"backup": "backup_20140707_113737",
"epoch": "61",
"hosts": "v_vmart_node0001(10.20.100.247)",
Connecting to HP Vertica
Management API
"objects": ""
},
{
"backup": "backup_archive20140707_113645",
"epoch": "60",
"hosts": "v_vmart_node0001(10.20.100.247)",
"objects": ""
}
],
"config_file": "/opt/vertica/config/backup.ini",
"num_backups": 2
}
]
Connecting to HP Vertica
Management API
POST backups/:config_script_base
Creates a new backup job for the backup defined in the vbr.py configuration script :config_
script_base. The vbr.py configuration script must reside in /opt/vertica/configuration. The
:config_script_base value does not include the .ini filename extention.
To determine valid :config_script_base values, see GET backups.
Returns a job ID that you can use to determine the status of the job.
Resource URL
https://<NODE>:5444/backups/:config_script_base
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
POST
https://<NODE>:5444/backups/backup3
Response:
{
"id": "CreateBackup-VMart-1404750602.03",
"url": "/jobs/CreateBackup-VMart-1404750602.03"
}
Connecting to HP Vertica
Management API
GET backups/:config_script_base/:archive_id
Returns details on a specific backup. You must provide the :config_script_base. This value is
the name of a vbr.py config file (without the .ini filename extension) that resides in
/opt/vertica/config. The :archive_id is the value of the backup field that the GET backups
command returns.
Resource URL
https://<NODE>:5444/backups/:config_script_base/:archive_id
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/backups/backup3/backup3_20140707_123254
Response:
{
"backup": "backup3_20140707_123254",
"config_file": "/opt/vertica/config/backup3.ini",
"epoch": "62",
"hosts": "v_vmart_node0001(10.20.100.247)",
"objects": ""
}
Connecting to HP Vertica
Management API
POST restore/:archive_id
Creates a new restore job to restore the database from the backup archive identified by :archive_
id. The :archive_id is the value of a backup field that the GET backups command returns.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/restore/:archive_id
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
POST
https://<NODE>:5444/restore/backup3_20140707_132904
Response:
{
"id": "RestoreBackup-VMart-1404760113.71",
"url": "/jobs/RestoreBackup-VMart-1404760113.71"
}
Connecting to HP Vertica
Management API
GETdatabases
Returns a list of databases, their current status, and database properties.
Resource URL
https://<NODE>:5444/databases
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/databases
Response:
{
"body": [
{
"href": "/databases/VMart",
"mime-type": [
"application/vertica.database.json-v2"
],
"name": "VMart",
"port": "5433",
"status": "UP"
},
{
"href": "/databases/testDB",
"mime-type": [
"application/vertica.database.json-v2"
Connecting to HP Vertica
Management API
],
"name": "testDB",
"port": "5433",
"status": "DOWN"
}
],
"href": "/databases",
"links": [
"/:database_name"
],
"mime-type": "application/vertica.databases.json-v2"
}
Connecting to HP Vertica
Management API
POST databases
Creates a job to create a new database with the provided parameters.
Important: You must stop any running databases on the nodes on which you want to create
the new database. If you do not, database creation fails.
Returns a job ID that can be used to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/database
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have admin level security.
Parameters
name
passwd
only
exclude
catalog
data
port
Port where the database listens for client connections. Default is 5433.
Example Request
POST
https://<NODE>:5444/databases?passwd=vertica&name=testDB
&catalog=%2Fhome%2Fdbadmin%2FtestDB
&data=%2Fhome%2Fdbadmin%2FtestDB
Connecting to HP Vertica
Management API
Response:
{
"jobid": "CreateDatabase-testDB-2014-07-07 15:49:53.219445",
"resource": "/jobs/CreateDatabase-testDB-2014-07-07 15:49:53.219445",
"userid": "dbadmin"
}
Connecting to HP Vertica
Management API
GET databases/:database_name
Returns details about a specific database. The :database_name is the value of the name field that
the GETdatabases command returns.
Resource URL
https://<NODE>:5444/databases/:database_name
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/databases/VMart
Response:
{
"body": {
"database_id": "VMart",
"id": "VMart",
"nodes": "v_vmart_node0001,v_vmart_node0002,v_vmart_node0003",
"nodes_new": [
{
"catalog_base": "/home/dbadmin",
"data_base": "/home/dbadmin",
"host": "10.20.100.247",
"id": "v_vmart_node0001"
},
{
"catalog_base": "/home/dbadmin",
"data_base": "/home/dbadmin",
"host": "10.20.100.248",
"id": "v_vmart_node0002"
},
{
Connecting to HP Vertica
Management API
"catalog_base": "/home/dbadmin",
"data_base": "/home/dbadmin",
"host": "10.20.100.249",
"id": "v_vmart_node0003"
}
],
"path": "/home/dbadmin/VMart",
"port": "5433",
"restartpolicy": "ksafe",
"status": "UP"
},
"href": "/databases/VMart",
"links": [
"/configuration",
"/hosts",
"/license",
"/nodes",
"/process",
"/rebalance/process",
"/status",
"/wla/process"
],
"mime-type": "application/vertica.database.json-v2"
}
Connecting to HP Vertica
Management API
PUT databases/:database_name
Creates a job to run the action specified by the action parameter against the database identified by
:database_name. The :database_name is the value of the name field that the GETdatabases
command returns.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have normal level security or higher.
Parameters
user_id
A database username.
passwd
action
Example Request
PUT
https://<NODE>:5444/databases/testDB?user_
id=dbadmin"&"passwd=vertica"&"action=stop
Response:
Connecting to HP Vertica
Management API
{
"id": "StopDatabase-testDB-2014-07-20 13:28:49.321744",
"url": "/jobs/StopDatabase-testDB-2014-07-20 13:28:49.321744"
}
Connecting to HP Vertica
Management API
DELETE databases/:database_name
Creates a job to delete (drop) an existing database on the cluster. To perform this operation, you
must first stop the database. The :database_name is the value of the name field that the
GETdatabases command returns.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have admin level security.
Parameters
None.
Example Request
DELETE
https://<NODE>:5444/databases/TestDB
Response:
{
"id": "DropDatabase-TestDB-2014-07-18 12:50:33.332383",
"url": "/jobs/DropDatabase-TestDB-2014-07-18 12:50:33.332383"
}
Connecting to HP Vertica
Management API
GET databases/:database_name/configuration
Returns a list of configuration parameters for the database identified by :database_name. The
:database_name is the value of the name field that the GETdatabases command returns.
Resource URL
https://<NODE>:5444/databases/:database_name/configuration
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
user_id
A database username.
passwd
Example Request
GET
https://<NODE>:5444/databases/testDB/configuration
Response:
This API call returns over100 configuration parameters.. The followin response is a small subset of
the total amount returned.
[
{
"catalog_value": "1",
"change_requires_restart": "f",
"change_under_support_guidance": "f",
"current_value": "1",
"database_value": "1",
"default_value": "1",
"description": "No of active partitions",
"groups": "",
"is_mismatch": "f",
"node_name": "ALL",
Connecting to HP Vertica
Management API
"parameter_name": "ActivePartitionCount",
"source": "DEFAULT"
},
{
"catalog_value": "180",
"change_requires_restart": "f",
"change_under_support_guidance": "f",
"current_value": "180",
"database_value": "180",
"default_value": "180",
"description": "Interval between advancing the AHM (seconds)",
"groups": "",
"is_mismatch": "f",
"node_name": "ALL",
"parameter_name": "AdvanceAHMInterval",
"source": "DEFAULT"
},
{
"catalog_value": "3",
"change_requires_restart": "f",
"change_under_support_guidance": "f",
"current_value": "3",
"database_value": "3",
"default_value": "3",
"description": "HDFS replication factor for Vertica data",
"groups": "",
"is_mismatch": "f",
"node_name": "ALL",
"parameter_name": "HadoopFSReplication",
"source": "DEFAULT"
},
{
"catalog_value": "",
"change_requires_restart": "f",
"change_under_support_guidance": "f",
"current_value": "",
"database_value": "",
"default_value": "",
"description": "Path to the java binary for executing UDx written in Java",
"groups": "",
"is_mismatch": "f",
"node_name": "ALL",
"parameter_name": "JavaBinaryForUDx",
"source": "DEFAULT"
},
{
"catalog_value": "80",
"change_requires_restart": "f",
"change_under_support_guidance": "f",
"current_value": "80",
"database_value": "80",
"default_value": "80",
"description": "The max amount of memory TopK(Heap) can use in MB",
"groups": "",
"is_mismatch": "f",
"node_name": "ALL",
"parameter_name": "TopKHeapMaxMem",
"source": "DEFAULT"
Connecting to HP Vertica
Management API
},
{
"catalog_value": "READ COMMITTED",
"change_requires_restart": "f",
"change_under_support_guidance": "f",
"current_value": "READ COMMITTED",
"database_value": "READ COMMITTED",
"default_value": "READ COMMITTED",
"description": "READ COMMITTED (Default) - Last epoch for reads and current epoch
for writes.
SERIALIZABLE - Current epoch for reads and writes",
"groups": "",
"is_mismatch": "f",
"node_name": "ALL",
"parameter_name": "TransactionIsolationLevel",
"source": "DEFAULT"
}
]
Connecting to HP Vertica
Management API
PUT databases/:database_name/configuration
Sets one or more configuration parameters for the database identified by :database_name. The
:database_name is the value of the name field that the GETdatabases command returns.
Returns the parameter name, the requested value, and the result of the attempted change (Success
or Failed).
Resource URL
https://<NODE>:5444/databases/:database_name/configuration
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have admin level security.
Parameters
user_id
A database username.
passwd
parameter_name
Example Request
PUT
https://<NODE>:5444/databases/testDB/configuration?user_
id=dbadmin"&"passwd=vertica
"&"JavaBinaryForUDx=%2Fusr%2Fbin%2Fjava"&"TransactionIsolationLevel=SERIALIZABL
E
Response:
[
{
"key": "JavaBinaryForUDx",
Connecting to HP Vertica
Management API
"result": "Success",
"value": "/usr/bin/java"
},
{
"key": "TransactionIsolationLevel",
"result": "Success",
"value": "SERIALIZABLE"
}
]
Connecting to HP Vertica
Management API
GET databases/:database_name/hosts
Returns the hostname/IP address, node name, and UP/DOWN status of each host associated with
the database identified by :database_name. The :database_name is the value of the name field
that the GETdatabases command returns.
Resource URL
https://<NODE>:5444/databases/:database_name/hosts
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/databases/VMart/hosts
Response:
{
"body": [
{
"hostname": "10.20.100.247",
"nodename": "v_vmart_node0001",
"status": "UP",
"ts": "2014-07-18T13:12:31.904191"
},
{
"hostname": "10.20.100.248",
"nodename": "v_vmart_node0002",
"status": "UP",
"ts": "2014-07-18T13:12:31.904209"
},
{
"hostname": "10.20.100.249",
"nodename": "v_vmart_node0003",
"status": "UP",
Connecting to HP Vertica
Management API
"ts": "2014-07-18T13:12:31.904215"
}
],
"href": "/databases/VMart/hosts",
"links": [],
"mime-type": "application/vertica.hosts.json-v2"
}
Connecting to HP Vertica
Management API
POST databases/:database_name/hosts
Creates a job to add a host to the database identified by :database_name. This host must already
be part of the cluster. The :database_name is the value of the name field that the GETdatabases
command returns.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444//:database_name/hosts
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have admin level security.
Parameters
user_id
A database username.
passwd
hostname
The hostname to add to the database. Thishost must already be part of the
cluster.
Example Request
POS
T
https://<NODE>:5444/databases/testDB/hosts?hostname=192.168.232.181&user_
id=dbadmin"&"passwd=vertica
Response:
{
"id": "AddHostToDatabase-testDB-2014-07-20 12:24:04.088812",
"url": "/jobs/AddHostToDatabase-testDB-2014-07-20 12:24:04.088812"
}
Connecting to HP Vertica
Management API
DELETEdatabases/:database_name/hosts/:host_
id
Creates a job to remove the host identified by :host_id from the database identified by
:database_name. The :database_name is the value of the name field that the GETdatabases
command returns. The :host_id is the value of the host field returned by GET
databases/:database_name.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name/hosts/:host_id
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have admin level security.
Parameters
user_id
A database username.
passwd
Example Request
DELET
E
https://<NODE>:5444/databases/testDB/hosts/192.168.232.181?user_
id=dbadmin"&"passwd=vertica
Response:
{
"id": "RemoveHostFromDatabase-testDB-2014-07-20 13:41:15.646235",
"url": "/jobs/RemoveHostFromDatabase-testDB-2014-07-20 13:41:15.646235"
}
Connecting to HP Vertica
Management API
POST databases/:database_name/hosts/:host_
id/process
Creates a job to start the vertica process for the database identified by :database_name on the host
identified by :host_id. The :database_name is the value of the name field that the GETdatabases
command returns. The :host_id is the value of the host field returned by GET
databases/:database_name.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/:database_name/hosts/:host_id/process
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
POST
https://<NODE>:5444/databases/testDB/hosts/192.168.232.181/process
Response:
{
"id": "StartDatabase-testDB-2014-07-20 13:14:03.968340",
"url": "/jobs/StartDatabase-testDB-2014-07-20 13:14:03.968340"
}
Connecting to HP Vertica
Management API
DELETE databases/:database_name/hosts/:host_
id/process
Creates a job to stop the vertica process for the database identified by :database_name on the host
identified by :host_id. The :database_name is the value of the name field that the GETdatabases
command returns. The :host_id is the value of the host field returned by GET
databases/:database_name.
Returns a job ID that can be used to determine the status of the job. See GET jobs.
Note: If stopping the database on the hosts causes the database to no longer be k-safe, then
the all database nodes may shut down.
Resource URL
https://<NODE>:5444/databases/:database_name/hosts/:host_id/process
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
DELETE
https://<NODE>:5444/databases/testDB/hosts/192.168.232.181/process
Response:
{
"id": "StopDatabase-testDB-2014-07-20 13:02:08.453547",
"url": "/jobs/StopDatabase-testDB-2014-07-20 13:02:08.453547"
}
Connecting to HP Vertica
Management API
POST databases/:database_name/hosts/:host_
id/replace_with/:host_id_new
Creates a job to replace the host identified by hosts/:host_id with the host identified by
replace_with/:host_id. HP Vertica performs these operations for the database identified by
:database_name. The :database_name is the value of the name field that the GETdatabases
command returns. The :host_id is the value of the host field as returned by GET
databases/:database_name. You can find valid replacement hosts using GET hosts. The
replacement host cannot already be part of the database. You must stop the vertica process on the
host being replaced.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name/hosts/:host_id/replace_with/:host_id_new
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have admin level security.
Parameters
user_id
A database username.
passwd
Example Request
PO
ST
https://<NODE>:5444/databases/testDB/hosts/192.168.232.180/replace_
with/192.168.232.181?user_id=dbadmin"&"passwd=vertica
Response:
{
"id": "ReplaceNode-testDB-2014-07-20 13:50:28.423509",
"url": "/jobs/ReplaceNode-testDB-2014-07-20 13:50:28.423509"
Connecting to HP Vertica
Management API
Connecting to HP Vertica
Management API
GET databases/:database_name/license
Returns details about the database license being used by the database identified by :database_
name. The :database_name is the value of the name field that the GETdatabases command
returns.
Resource URL
https://<NODE>:5444/:database_name/license
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
user_id
A database username.
passwd
Example Request
GET
https://<NODE>:5444/VMart/license
Response:
{
"body": {
"details": {
"assigned_to": "Vertica Systems, Inc.",
"grace_period": 0,
"is_ce": false,
"is_unlimited": false,
"name": "vertica",
"not_after": "Perpetual",
"not_before": "2007-08-03"
},
"last_audit": {
"audit_date": "2014-07-18 13:49:22.530105-04",
"database_size_bytes": "814060522",
Connecting to HP Vertica
Management API
"license_size_bytes": "536870912000",
"usage_percent": "0.00151630588248372"
}
},
"href": "/databases/VMart/license",
"links": [],
"mime-type": "application/vertica.license.json-v2"
}
Connecting to HP Vertica
Management API
GET databases/:database_name/licenses
Returns details about all license being used by the database identified by :database_name. The
:database_name is the value of the name field that the GETdatabases command returns.
Resource URL
https://<NODE>:5444/:database_name/licenses
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
user_id
A database username.
passwd
Example Request
GET
https://<NODE>:5444/VMart/licenses
Response:
{
"body": [
{
"details": {
"assigned_to": "Vertica Systems, Inc.",
"audit_date": "2014-07-19 21:35:25.111312",
"is_ce": "False",
"name": "vertica",
"node_restriction": "",
"not_after": "Perpetual",
"not_before": "2007-08-03",
"size": "500GB"
},
"last_audit": {
"audit_date": "2014-07-19 21:35:26.318378-04",
"database_size_bytes": "819066288",
Connecting to HP Vertica
Management API
"license_size_bytes": "536870912000",
"usage_percent": "0.00152562984824181"
}
},
{
"details": {
"assigned_to": "Vertica Systems, Inc., FlexTable",
"audit_date": "2014-07-19 21:35:25.111312",
"is_ce": "False",
"name": "com.vertica.flextable",
"node_restriction": "",
"not_after": "Perpetual",
"not_before": "2007-08-03",
"size": "500GB"
},
"last_audit": {
"audit_date": "2014-07-19 21:35:25.111312",
"database_size_bytes": 0,
"license_size_bytes": 536870912000,
"usage_percent": 0
}
}
],
"href": "/databases/VMart/licenses",
"links": [],
"mime-type": "application/vertica.features.json-v2"
}
Connecting to HP Vertica
Management API
GET databases/:database_name/nodes
Returns a comma-separated list of node IDs for the database identified by :database_name. The
:database_name is the value of the name field that the GETdatabases command returns.
Resource URL
https://<NODE>:5444/:database_name/nodes
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/VMart/nodes
Response:
[
{
"database_id": "VMart",
"node_id": "v_vmart_node0001,v_vmart_node0002,v_vmart_node0003",
"status": "Unknown"
}
]
Connecting to HP Vertica
Management API
GET databases/:database_name/nodes/:node_id
Returns details about the node identified by :node_id. The :node_id is one of the node IDs
returned by GET databases/:database_name/nodes.
Resource URL
https://<NODE>:5444/:database_name/nodes/:node_id
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/databases/VMart/nodes/v_vmart_node0001
Response:
{
"db": "VMart",
"host": "10.20.100.247",
"name": "v_vmart_node0001",
"state": "UP"
}
Connecting to HP Vertica
Management API
POST databases/:database_name/process
Creates a job to start the database identified by :database_name. The :database_name is the
value of the namefield that the GETdatabases command returns.
Returns a job ID that can be used to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name/process
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
epoch
include
Include only these hosts when starting the database. Use a commaseparated list of hostnames.
Example Request
POST
https://<NODE>:5444/databases/:testDB/process
Response:
{
"id": "StartDatabase-testDB-2014-07-20 12:41:46.061408",
"url": "/jobs/StartDatabase-testDB-2014-07-20 12:41:46.061408"
}
Connecting to HP Vertica
Management API
GET databases/:database_name/process
Returns a state of UP or DOWN for the database identified by :database_name. The :database_
name is the value of the namefield that the GETdatabases command returns.
Resource URL
https://<NODE>:5444/databases/:database_name/process
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/databases/VMart/process
Response:
{
"state": "UP"
}
Connecting to HP Vertica
Management API
DELETE databases/:database_name/process
Creates a job to stop the database identified by :database_name. The :database_name is the
value of the namefield that the GETdatabases command returns.
Returns a job ID that you can useto determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name/process
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
user_id
A database username.
passwd
Example Request
DELETE
https://<NODE>:5444/databases/testDB/process?user_
id=dbadmin"&"passwd=vertica
Response:
{
"id": "StopDatabase-testDB-2014-07-20 12:46:04.406637",
"url": "/jobs/StopDatabase-testDB-2014-07-20 12:46:04.406637"
}
Connecting to HP Vertica
Management API
POST databases/:database_
name/rebalance/process
Creates a job to run a rebalance on the database identified by host identified by :database_name.
The :database_name is the value of the namefield that the GETdatabases command returns.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name/rebalance/process
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
user_id
A database username.
passwd
Example Request
POST
https://<NODE>:5444/databases/testDB/rebalance/process
Response:
{
"id": "RebalanceData-testDB-2014-07-20 21:42:45.731038",
"url": "/jobs/RebalanceData-testDB-2014-07-20 21:42:45.731038"
}
Connecting to HP Vertica
Management API
POST databases/:database_name/wla/process
Creates a job to run Workload Analyzer on the database identified by host identified by :database_
name. The :database_name is the value of the name field that the GETdatabases command
returns.
Returns a job ID that you can use to determine the status of the job. See GET jobs.
Resource URL
https://<NODE>:5444/databases/:database_name/wla/process
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
user_id
A database username.
passwd
Example Request
POST
https://<NODE>:5444/databases/testDB/wla/process
Response:
{
"id": "AnalyzeWorkLoad-testDB-2014-07-20 21:48:27.972989",
"url": "/jobs/AnalyzeWorkLoad-testDB-2014-07-20 21:48:27.972989"
}
Connecting to HP Vertica
Management API
GET hosts
Returns a list of the hosts in the cluster and the hardware, software, and network details about each
host.
Resource URL
https://<NODE>:5444/hosts
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/hosts
Response:
{
"body": [
{
"cpu_info": {
"cpu_type": " Intel(R) Xeon(R) CPU E5-2695 v2 @ 2.40GHz",
"number_of_cpus": 2
},
"host_id": "10.20.100.247",
"hostname": "doch01.verticacorp.com",
"max_user_proc": "3833",
"nics": [
{
"broadcast": "10.20.100.255",
"ipaddr": "10.20.100.247",
"name": "eth0",
"netmask": "255.255.255.0",
"speed": "unknown"
},
{
Connecting to HP Vertica
Management API
"broadcast": "255.255.255.255",
"ipaddr": "127.0.0.1",
"name": "lo",
"netmask": "255.0.0.0",
"speed": "locallink"
}
],
"total_memory": 3833,
"vertica": {
"arch": "x86_64",
"brand": "vertica",
"release": "20140716",
"version": "7.1.0"
}
},
{
"cpu_info": {
"cpu_type": " Intel(R) Xeon(R) CPU E5-2695 v2 @ 2.40GHz",
"number_of_cpus": 2
},
"host_id": "10.20.100.248",
"hostname": "doch02.verticacorp.com",
"max_user_proc": "3833",
"nics": [
{
"broadcast": "10.20.100.255",
"ipaddr": "10.20.100.248",
"name": "eth0",
"netmask": "255.255.255.0",
"speed": "unknown"
},
{
"broadcast": "255.255.255.255",
"ipaddr": "127.0.0.1",
"name": "lo",
"netmask": "255.0.0.0",
"speed": "locallink"
}
],
"total_memory": 3833,
"vertica": {
"arch": "x86_64",
"brand": "vertica",
"release": "20140716",
"version": "7.1.0"
}
},
{
"cpu_info": {
"cpu_type": " Intel(R) Xeon(R) CPU E5-2695 v2 @ 2.40GHz",
"number_of_cpus": 2
},
"host_id": "10.20.100.249",
"hostname": "doch03.verticacorp.com",
"max_user_proc": "3833",
"nics": [
{
"broadcast": "10.20.100.255",
Connecting to HP Vertica
Management API
"ipaddr": "10.20.100.249",
"name": "eth0",
"netmask": "255.255.255.0",
"speed": "unknown"
},
{
"broadcast": "255.255.255.255",
"ipaddr": "127.0.0.1",
"name": "lo",
"netmask": "255.0.0.0",
"speed": "locallink"
}
],
"total_memory": 3833,
"vertica": {
"arch": "x86_64",
"brand": "vertica",
"release": "20140716",
"version": "7.1.0"
}
}
],
"href": "/hosts",
"links": [
"/:hostid"
],
"mime-type": "application/vertica.hosts.json-v2"
}
Connecting to HP Vertica
Management API
GET hosts/:hostid
Returns hardware, software, and network details about the host identified by :host_id. You can
find :host_id for each host using GET hosts.
Resource URL
https://<NODE>:5444/hosts/:hostid
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/hosts/10.20.100.247
Response:
{
"body": {
"cpu_info": {
"cpu_type": " Intel(R) Xeon(R) CPU E5-2695 v2 @ 2.40GHz",
"number_of_cpus": 2
},
"hostname": "doch01.verticacorp.com",
"max_user_proc": "3833",
"nics": [
{
"broadcast": "10.20.100.255",
"ipaddr": "10.20.100.247",
"name": "eth0",
"netmask": "255.255.255.0",
"speed": "unknown"
},
{
"broadcast": "255.255.255.255",
"ipaddr": "127.0.0.1",
Connecting to HP Vertica
Management API
"name": "lo",
"netmask": "255.0.0.0",
"speed": "locallink"
}
],
"total_memory": 3833,
"vertica": {
"arch": "x86_64",
"brand": "vertica",
"release": "20140716",
"version": "7.1.0"
}
},
"href": "/hosts/10.20.100.247",
"links": [],
"mime-type": "application/vertica.host.json-v2"
}
Connecting to HP Vertica
Management API
GET jobs
Returns a list of jobs being tracked by the agent and job details.
Jobs always start immediately. The is_running field is a Boolean value. If is_running is false,
then the job is complete.
The exit_code details the status of the job. The exit_code is different for certain types of jobs:
l
0 indicates success.
-9 indicates success.
Resource URL
https://<NODE>:5444/jobs
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/jobs
Response:
Connecting to HP Vertica
Management API
{
"body": [
{
"exit_code": 0,
"id": "CreateBackup-VMart-1405012447.75",
"is_running": false,
"status": "unused",
"ts": "1405012461.18"
},
{
"exit_code": 1,
"id": "CreateBackup-VMart-1405012454.88",
"is_running": false,
"status": "unused",
"ts": "1405012455.18"
}
],
"href": "/jobs",
"links": [
"/:jobid"
],
"mime-type": "application/vertica.jobs.json-v2"
}
Connecting to HP Vertica
Management API
GET jobs/:id
Gets the details for a specific job with the provided :id. You can determine the list of job :ids
usingGET jobs.
Details for a specific job are the same as the details provided for all jobs byGET jobs.
Note: You must URL encode the :id as some IDs may contain spaces or other special
characters.
Resource URL
https://<NODE>:5444/jobs/:id
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/jobs/CreateBackup-VMart-1405012454.88
Connecting to HP Vertica
Management API
POST licenses
Uploads and applies a license file to this cluster.
You must provide the license file as an HTTP POST form upload, identified by the name license.
For example, you can use cURL:
curl -k --request POST -H "VerticaApiKey:ValidAPIKey" \
https://node01:5444/licenses --form "[email protected]"
Resource URL
https://<NODE>:5444/licenses
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have admin level security.
Parameters
None.
Example Request
POST
https://<NODE>:5444/licenses
Response:
There is no HTTP body response for successful uploads. A successful upload returns an HTTP
200/OK header.
Connecting to HP Vertica
Management API
GET licenses
Returns any license files that are used by this cluster when creating databases. License files must
reside in /opt/vertica/config/share.
Resource URL
https://<NODE>:5444/licenses
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/licenses
Response:
{
"body": [
{
"comment": "Vertica license is valid",
"end": "Perpetual",
"grace": "0",
"size": "1TB CE Nodes 3",
"start": "2011-11-22",
"status": true,
"vendor": "Vertica Community Edition"
}
],
"href": "/license",
"links": [],
"mime-type": "application/vertica.license.json-v2"
}
Connecting to HP Vertica
Management API
GET nodes
Returns a list of nodes associated with this cluster.
Resource URL
https://<NODE>:5444/nodes
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/nodes
Response:
{
"body": [
"node0001",
"node0002",
"node0003",
"v_testdb_node0001",
"v_testdb_node0002",
"v_testdb_node0003",
"v_vmart_node0001",
"v_vmart_node0002",
"v_vmart_node0003"
],
"href": "/nodes",
"links": [
"/:nodeid"
],
"mime-type": "application/vertica.nodes.json-v2"
}
Connecting to HP Vertica
Management API
GET nodes/:nodeid
Returns details about the node identified by :node_id. You can find the :node_id for each node
using GET nodes.
In the body field, the following information is detailed in comma-separated format:
l
Node Name
Host Address
Catalog Directory
Data Directory
Resource URL
https://<NODE>:5444/nodes/:node_id
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/nodes/v_vmart_node0001
Response:
{
"body": [
"v_vmart_node0001",
"10.20.100.247,/home/dbadmin,/home/dbadmin"
],
"href": "/nodes/v_vmart_node0001",
"links": [],
Connecting to HP Vertica
Management API
"mime-type": "application/vertica.node.json-v2"
}
Connecting to HP Vertica
Management API
GET webhooks
Returns a list of active webhooks for this cluster.
Resource URL
https://<NODE>:5444/webhooks
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
GET
https://<NODE>:5444/webhooks
Response:
{
"body": [
{
"host": "192.168.232.1",
"id": "79c1c8a18be02804b3d2f48ea6462909",
"port": 80,
"timestamp": "2014-07-20 22:54:09.829642",
"url": "/gettest.htm"
},
{
"host": "192.168.232.1",
"id": "9c32cb0f3d2f9a7cb10835f1732fd4a7",
"port": 80,
"timestamp": "2014-07-20 22:54:09.829707",
"url": "/getwebhook.php"
}
],
"href": "/webhooks",
"links": [
"/subscribe",
"/:subscriber_id"
Connecting to HP Vertica
Management API
],
"mime-type": "application/vertica.webhooks.json-v2"
}
Connecting to HP Vertica
Management API
POST webhooks/subscribe
Creates a subscription for a webhook.
Resource URL
https://<NODE>:5444/webhooks/subscribe
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
url
Example Request
POS
T
https://<NODE>:5444//webhooks/subscribe?url=https%3A%2F%2F1.800.gay%3A443%2Fhttp%2Fexample.com%2Fgetwebho
ok.php
Response:
The response is not JSON encoded. The only text response is the ID of the webhook subscription.
Additionally, an HTTP 200/OK header indicates success.
79c1c8a18be02804b3d2f48ea6462909
Connecting to HP Vertica
Management API
DELETE webhooks/:subscriber_id
Deletes the webhook identified by :subscriber_id. The :subscriber_id is the value of the id
field that the GET webhooks command returns.
Resource URL
https://<NODE>:5444/webhooks/:subscriber_id
Authentication
Requires a VerticaAPIKey in the request header.
The API key must have restricted level security or higher.
Parameters
None.
Example Request
DELETE
https://<NODE>:5444/webhooks/79c1c8a18be02804b3d2f48ea6462909
Response:
There is no HTTP body response for successful deletes. A successful delete returns an HTTP
200/OK header.
Connecting to HP Vertica
Management API