Professional Documents
Culture Documents
HP Vertica 7.1.x SQL Reference Manual
HP Vertica 7.1.x SQL Reference Manual
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 - 2015 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 1873
Contents
Contents
SQL Overview
49
49
49
Joins
49
Transactions
49
System Limits
51
53
54
Keywords
54
Reserved Words
57
Identifiers
58
Non-ASCII Characters
Literals
59
61
Number-Type Literals
61
String Literals
64
64
64
65
66
67
67
69
69
71
Page 3 of 1873
SQLReference Manual
Contents
71
72
Date/Time Literals
75
75
76
Month Names
76
Interval Values
78
Interval-Literal
79
Interval-Qualifier
82
Operators
84
Binary Operators
84
Boolean Operators
86
Comparison Operators
87
88
Date/Time Operators
90
Mathematical Operators
92
NULL Operators
93
94
Expressions
96
Operator Precedence
96
97
Aggregate Expressions
97
CASE Expressions
98
Column References
100
Comments
101
Date/Time Expressions
102
NULL Value
104
Page 4 of 1873
SQLReference Manual
Contents
Numeric Expressions
Predicates
105
106
BETWEEN-predicate
106
Boolean-Predicate
107
Column-Value-Predicate
108
IN-predicate
108
INTERPOLATE
109
Join-Predicate
114
LIKE-predicate
114
NULL-predicate
119
121
123
128
129
130
132
132
DATE
133
DATETIME
135
INTERVAL
135
136
137
139
Specifying Precision
140
141
141
143
Page 5 of 1873
SQLReference Manual
Contents
144
144
145
Interval-Literal
148
Interval-Qualifier
150
SMALLDATETIME
151
TIME
152
153
TIMESTAMP
155
160
162
165
166
INTEGER
169
NUMERIC
170
174
175
181
Assignment Conversion
SQL Functions
Aggregate Functions
184
185
186
APPROXIMATE_COUNT_DISTINCT
186
APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS
189
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS
191
AVG [Aggregate]
192
BIT_AND
193
BIT_OR
195
Page 6 of 1873
SQLReference Manual
Contents
BIT_XOR
197
CORR
198
COUNT [Aggregate]
199
COVAR_POP
203
COVAR_SAMP
204
GROUP_ID
204
GROUPING
206
GROUPING_ID
207
MAX [Aggregate]
210
MIN [Aggregate]
211
REGR_AVGX
212
REGR_AVGY
213
REGR_COUNT
213
REGR_INTERCEPT
214
REGR_R2
215
REGR_SLOPE
215
REGR_SXX
216
REGR_SXY
216
REGR_SYY
217
STDDEV [Aggregate]
218
STDDEV_POP [Aggregate]
219
STDDEV_SAMP [Aggregate]
220
SUM [Aggregate]
221
SUM_FLOAT [Aggregate]
223
VAR_POP [Aggregate]
223
VAR_SAMP [Aggregate]
224
VARIANCE [Aggregate]
225
Page 7 of 1873
SQLReference Manual
Contents
Analytic Functions
228
228
228
window_partition_clause
230
window_order_clause
231
window_frame_clause
234
Window Aggregates
238
named_windows
240
AVG [Analytic]
241
CONDITIONAL_CHANGE_EVENT [Analytic]
242
CONDITIONAL_TRUE_EVENT [Analytic]
244
COUNT [Analytic]
245
CUME_DIST [Analytic]
247
DENSE_RANK [Analytic]
249
EXPONENTIAL_MOVING_AVERAGE [Analytic]
251
FIRST_VALUE [Analytic]
254
LAG [Analytic]
257
LAST_VALUE [Analytic]
261
LEAD [Analytic]
263
MAX [Analytic]
266
MEDIAN [Analytic]
267
MIN [Analytic]
269
NTILE [Analytic]
270
PERCENT_RANK [Analytic]
272
PERCENTILE_CONT [Analytic]
274
PERCENTILE_DISC [Analytic]
276
RANK [Analytic]
278
Page 8 of 1873
SQLReference Manual
Contents
ROW_NUMBER [Analytic]
281
STDDEV [Analytic]
283
STDDEV_POP [Analytic]
285
STDDEV_SAMP [Analytic]
286
SUM [Analytic]
288
VAR_POP [Analytic]
289
VAR_SAMP [Analytic]
290
VARIANCE [Analytic]
292
294
294
Behavior Type
294
Syntax
294
Behavior
294
Examples
294
See Also
295
Date/Time Functions
296
Usage
296
296
297
ADD_MONTHS
297
AGE_IN_MONTHS
299
AGE_IN_YEARS
300
CLOCK_TIMESTAMP
301
CURRENT_DATE
302
CURRENT_TIME
303
CURRENT_TIMESTAMP
304
DATE_PART
305
Page 9 of 1873
SQLReference Manual
Contents
DATE
314
DATE_TRUNC
315
DATEDIFF
317
DAY
324
DAYOFMONTH
325
DAYOFWEEK
325
DAYOFWEEK_ISO
326
DAYOFYEAR
328
DAYS
328
EXTRACT
329
GETDATE
337
GETUTCDATE
338
HOUR
339
ISFINITE
339
JULIAN_DAY
340
LAST_DAY
341
LOCALTIME
342
LOCALTIMESTAMP
342
MICROSECOND
343
MIDNIGHT_SECONDS
344
MINUTE
344
MONTH
345
MONTHS_BETWEEN
346
NEW_TIME
348
NEXT_DAY
350
NOW [Date/Time]
351
OVERLAPS
352
Page 10 of 1873
SQLReference Manual
Contents
QUARTER
353
ROUND [Date/Time]
354
SECOND
356
STATEMENT_TIMESTAMP
356
SYSDATE
357
TIME_SLICE
358
TIMEOFDAY
364
TIMESTAMPADD
364
TIMESTAMPDIFF
366
TIMESTAMP_ROUND
368
TIMESTAMP_TRUNC
369
TRANSACTION_TIMESTAMP
371
TRUNC [Date/Time]
372
WEEK
374
WEEK_ISO
374
YEAR
376
YEAR_ISO
377
Formatting Functions
379
TO_BITSTRING
379
TO_CHAR
380
TO_DATE
383
TO_HEX
385
TO_TIMESTAMP
386
TO_TIMESTAMP_TZ
388
TO_NUMBER
390
392
394
Page 11 of 1873
SQLReference Manual
Contents
395
397
397
397
398
398
398
399
399
399
400
400
BB_WITHIN
401
BEARING
402
CHORD_TO_ARC
403
DWITHIN
404
ECEF_CHORD
405
ECEF_x
406
ECEF_y
406
ECEF_z
407
ISLEFT
408
KM2MILES
409
LAT_WITHIN
410
LL_WITHIN
411
LLD_WITHIN
412
LON_WITHIN
413
MILES2KM
414
Page 12 of 1873
SQLReference Manual
Contents
RADIUS_LON
415
RADIUS_M
416
RADIUS_N
416
RADIUS_R
417
RADIUS_Ra
418
RADIUS_Rc
419
RADIUS_Rv
419
RADIUS_SI
420
RAYCROSSING
421
WGS84_a
423
WGS84_b
423
WGS84_e2
424
WGS84_f
424
WGS84_if
425
WGS84_r1
425
IP Conversion Functions
427
INET_ATON
427
INET_NTOA
428
V6_ATON
429
V6_NTOA
430
V6_SUBNETA
431
V6_SUBNETN
433
V6_TYPE
434
Mathematical Functions
437
ABS
437
ACOS
438
ASIN
438
Page 13 of 1873
SQLReference Manual
Contents
ATAN
439
ATAN2
439
CBRT
440
CEILING (CEIL)
441
COS
442
COT
442
DEGREES
443
DISTANCE
444
DISTANCEV
445
EXP
445
FLOOR
446
HASH
448
LN
449
LOG
449
MOD
450
MODULARHASH
451
PI
452
453
RADIANS
453
RANDOM
454
RANDOMINT
455
ROUND
456
SIGN
458
SIN
458
SQRT
459
TAN
459
TRUNC
460
Page 14 of 1873
SQLReference Manual
Contents
WIDTH_BUCKET
461
NULL-handling Functions
464
COALESCE
464
IFNULL
465
ISNULL
467
NULLIF
468
NULLIFZERO
469
NVL
470
NVL2
472
ZEROIFNULL
474
476
EVENT_NAME
476
MATCH_ID
478
PATTERN_ID
479
482
ISUTF8
482
REGEXP_COUNT
483
REGEXP_INSTR
485
REGEXP_LIKE
488
REGEXP_REPLACE
492
REGEXP_SUBSTR
495
Sequence Functions
499
NEXTVAL
499
CURRVAL
501
LAST_INSERT_ID
504
String Functions
ASCII
507
507
Page 15 of 1873
SQLReference Manual
Contents
BIT_LENGTH
508
BITCOUNT
509
BITSTRING_TO_BINARY
510
BTRIM
511
CHARACTER_LENGTH
512
CHR
513
COLLATION
514
CONCAT
518
DECODE
519
GREATEST
520
GREATESTB
522
HEX_TO_BINARY
524
HEX_TO_INTEGER
525
INET_ATON
526
INET_NTOA
527
INITCAP
528
INITCAPB
529
INSERT
530
INSTR
531
INSTRB
534
ISUTF8
535
LEAST
536
LEASTB
537
LEFT
539
LENGTH
540
LOWER
541
LOWERB
542
Page 16 of 1873
SQLReference Manual
Contents
LPAD
543
LTRIM
544
MD5
545
OCTET_LENGTH
545
OVERLAY
547
OVERLAYB
548
POSITION
549
POSITIONB
551
QUOTE_IDENT
552
QUOTE_LITERAL
553
REPEAT
554
REPLACE
555
RIGHT
556
RPAD
557
RTRIM
558
SPACE
559
SPLIT_PART
560
SPLIT_PARTB
561
STRPOS
563
STRPOSB
564
SUBSTR
564
SUBSTRB
566
SUBSTRING
567
TO_BITSTRING
568
TO_HEX
569
TRANSLATE
570
TRIM
571
Page 17 of 1873
SQLReference Manual
Contents
UPPER
572
UPPERB
573
V6_ATON
574
V6_NTOA
575
V6_SUBNETA
577
V6_SUBNETN
578
V6_TYPE
579
582
CURRENT_DATABASE
582
CURRENT_SCHEMA
582
CURRENT_USER
584
DBNAME (function)
584
HAS_TABLE_PRIVILEGE
585
SESSION_USER
587
USER
588
USERNAME
588
VERSION
589
Timeseries Functions
590
TS_FIRST_VALUE
590
TS_LAST_VALUE
592
594
URI_PERCENT_DECODE
594
URI_PERCENT_ENCODE
595
HP Vertica Meta-Functions
Alphabetical List of HP Vertica Meta-Functions
ADD_LOCATION
Storage Location Subdirectories
596
597
597
598
Page 18 of 1873
SQLReference Manual
Contents
ADVANCE_EPOCH
599
ALTER_LOCATION_USE
600
601
601
ALTER_LOCATION_LABEL
602
ANALYZE_CONSTRAINTS
603
604
606
ANALYZE_CORRELATIONS
612
ANALYZE_EXTERNAL_ROW_COUNT
614
ANALYZE_HISTOGRAM
615
ANALYZE_STATISTICS
619
ANALYZE_WORKLOAD
623
AUDIT
627
AUDIT_FLEX
631
AUDIT_LICENSE_SIZE
634
AUDIT_LICENSE_TERM
634
BUILD_FLEXTABLE_VIEW
635
CANCEL_REBALANCE_CLUSTER
639
CANCEL_REFRESH
639
CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY
640
CHANGE_RUNTIME_PRIORITY
641
CLEAR_CACHES
642
CLEAR_DATA_COLLECTOR
643
CLEAR_PROFILING
645
CLEAR_PROJECTION_REFRESHES
645
CLEAR_RESOURCE_REJECTIONS
647
Page 19 of 1873
SQLReference Manual
Contents
CLEAR_OBJECT_STORAGE_POLICY
647
CLOSE_SESSION
648
Controlling Sessions
651
CLOSE_ALL_SESSIONS
652
Controlling Sessions
655
COMPUTE_FLEXTABLE_KEYS
656
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
658
CURRENT_SCHEMA
659
DATA_COLLECTOR_HELP
660
DISABLE_DUPLICATE_KEY_ERROR
662
DISABLE_ELASTIC_CLUSTER
666
DISABLE_LOCAL_SEGMENTS
666
DISABLE_PROFILING
667
DISPLAY_LICENSE
668
DO_TM_TASK
669
DROP_EXTERNAL_ROW_COUNT
671
DROP_LICENSE
672
DROP_LOCATION
673
674
674
674
DROP_PARTITION
675
DROP_STATISTICS
679
DUMP_CATALOG
681
DUMP_LOCKTABLE
681
DUMP_PARTITION_KEYS
683
DUMP_PROJECTION_PARTITION_KEYS
684
Page 20 of 1873
SQLReference Manual
Contents
DUMP_TABLE_PARTITION_KEYS
685
EMPTYMAP
686
ENABLE_ELASTIC_CLUSTER
688
ENABLE_LOCAL_SEGMENTS
689
ENABLE_PROFILING
689
ENFORCE_OBJECT_STORAGE_POLICY
690
EVALUATE_DELETE_PERFORMANCE
691
EXPORT_CATALOG
695
EXPORT_OBJECTS
696
EXPORT_STATISTICS
698
EXPORT_TABLES
700
FLUSH_DATA_COLLECTOR
702
GET_AHM_EPOCH
703
GET_AHM_TIME
703
GET_AUDIT_TIME
704
GET_COMPLIANCE_STATUS
705
GET_CURRENT_EPOCH
706
GET_DATA_COLLECTOR_POLICY
706
GET_LAST_GOOD_EPOCH
707
GET_NUM_ACCEPTED_ROWS
708
GET_NUM_REJECTED_ROWS
709
GET_PROJECTION_STATUS
710
GET_PROJECTIONS, GET_TABLE_PROJECTIONS
711
HAS_ROLE
713
IMPORT_STATISTICS
715
INTERRUPT_STATEMENT
717
INSTALL_LICENSE
720
Page 21 of 1873
SQLReference Manual
Contents
LAST_INSERT_ID
721
MAKE_AHM_NOW
723
MAPAGGREGATE
725
MAPCONTAINSKEY
727
MAPCONTAINSVALUE
728
MAPITEMS
730
MAPKEYS
733
MAPKEYSINFO
735
MAPLOOKUP
737
739
741
742
743
MAPSIZE
745
MAPTOSTRING
746
MAPVALUES
749
MAPVERSION
750
MARK_DESIGN_KSAFE
751
MATERIALIZE_FLEXTABLE_COLUMNS
754
MEASURE_LOCATION_PERFORMANCE
756
MERGE_PARTITIONS
758
MOVE_PARTITIONS_TO_TABLE
759
Examples
760
MOVE_RETIRED_LOCATION_DATA
761
PARTITION_PROJECTION
763
PARTITION_TABLE
765
PURGE
767
Page 22 of 1873
SQLReference Manual
Contents
PURGE_PARTITION
768
PURGE_PROJECTION
769
PURGE_TABLE
771
REALIGN_CONTROL_NODES
772
REBALANCE_CLUSTER
773
REBALANCE_TABLE
775
REENABLE_DUPLICATE_KEY_ERROR
776
REFRESH
777
RELEASE_ALL_JVM_MEMORY
779
RELEASE_JVM_MEMORY
780
RELOAD_SPREAD
781
RESET_LOAD_BALANCE_POLICY
782
RESTORE_LOCATION
783
783
784
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
784
RETIRE_LOCATION
785
786
786
787
SET_AHM_EPOCH
788
SET_AHM_TIME
790
SET_AUDIT_TIME
792
SET_CONTROL_SET_SIZE
793
SET_DATA_COLLECTOR_POLICY
794
SET_DATA_COLLECTOR_TIME_POLICY
796
SET_LOAD_BALANCE_POLICY
799
Page 23 of 1873
SQLReference Manual
Contents
SET_LOCATION_PERFORMANCE
800
SET_SCALING_FACTOR
801
SET_OBJECT_STORAGE_POLICY
802
803
803
803
SHUTDOWN
804
SLEEP
806
START_REBALANCE_CLUSTER
806
START_REFRESH
808
SWAP_PARTITIONS_BETWEEN_TABLES
809
SYNCH_WITH_HCATALOG_SCHEMA
811
VALIDATE_STATISTICS
813
816
DROP_LICENSE
816
DUMP_CATALOG
816
EXPORT_CATALOG
817
EXPORT_OBJECTS
818
INSTALL_LICENSE
820
MARK_DESIGN_KSAFE
821
SYNCH_WITH_HCATALOG_SCHEMA
823
825
SET_LOAD_BALANCE_POLICY
825
RESET_LOAD_BALANCE_POLICY
826
827
SET_CONTROL_SET_SIZE
827
REALIGN_CONTROL_NODES
828
Page 24 of 1873
SQLReference Manual
Contents
RELOAD_SPREAD
829
REBALANCE_CLUSTER
830
833
CANCEL_REBALANCE_CLUSTER
833
DISABLE_ELASTIC_CLUSTER
833
DISABLE_LOCAL_SEGMENTS
834
ENABLE_ELASTIC_CLUSTER
835
ENABLE_LOCAL_SEGMENTS
835
REBALANCE_CLUSTER
836
SET_SCALING_FACTOR
838
START_REBALANCE_CLUSTER
839
841
ANALYZE_CONSTRAINTS
841
842
843
ANALYZE_CORRELATIONS
849
DISABLE_DUPLICATE_KEY_ERROR
851
LAST_INSERT_ID
855
REENABLE_DUPLICATE_KEY_ERROR
858
859
Related Topics
859
CLEAR_DATA_COLLECTOR
859
DATA_COLLECTOR_HELP
860
FLUSH_DATA_COLLECTOR
862
GET_DATA_COLLECTOR_POLICY
863
SET_DATA_COLLECTOR_POLICY
864
SET_DATA_COLLECTOR_TIME_POLICY
866
Page 25 of 1873
SQLReference Manual
Contents
870
DESIGNER_ADD_DESIGN_QUERIES
872
DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS
874
DESIGNER_ADD_DESIGN_QUERY
876
DESIGNER_ADD_DESIGN_TABLES
878
DESIGNER_CANCEL_POPULATE_DESIGN
880
DESIGNER_CREATE_DESIGN
881
DESIGNER_DESIGN_PROJECTION_ENCODINGS
883
DESIGNER_DROP_ALL_DESIGNS
885
DESIGNER_DROP_DESIGN
886
DESIGNER_OUTPUT_ALL_DESIGN_PROJECTIONS
887
DESIGNER_OUTPUT_DEPLOYMENT_SCRIPT
889
DESIGNER_RESET_DESIGN
890
DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY
891
DESIGNER_SET_ANALYZE_CORRELATIONS_MODE
893
DESIGNER_SET_DESIGN_KSAFETY
895
DESIGNER_SET_DESIGN_TYPE
897
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
899
DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS
901
DESIGNER_WAIT_FOR_DESIGN
902
904
CLEAR_RESOURCE_REJECTIONS
904
DUMP_LOCKTABLE
904
DUMP_PARTITION_KEYS
906
EXPORT_TABLES
907
HAS_ROLE
909
SET_CONFIG_PARAMETER
911
Page 26 of 1873
SQLReference Manual
Contents
SHUTDOWN
Epoch Management Functions
912
915
ADVANCE_EPOCH
915
GET_AHM_EPOCH
915
GET_AHM_TIME
916
GET_CURRENT_EPOCH
917
GET_LAST_GOOD_EPOCH
917
MAKE_AHM_NOW
918
SET_AHM_EPOCH
920
SET_AHM_TIME
922
924
BUILD_FLEXTABLE_VIEW
924
COMPUTE_FLEXTABLE_KEYS
928
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
930
EMPTYMAP
931
MAPAGGREGATE
932
MAPCONTAINSKEY
934
MAPCONTAINSVALUE
936
MAPDELIMITEDEXTRACTOR
937
Parameters
937
Examples
938
See Also
940
MAPITEMS
940
MAPJSONEXTRACTOR
944
Parameters
944
Examples
945
See Also
947
Page 27 of 1873
SQLReference Manual
Contents
MAPKEYS
947
MAPKEYSINFO
949
MAPLOOKUP
951
952
954
955
957
MAPREGEXEXTRACTOR
959
Parameters
959
Examples
959
See Also
960
MAPSIZE
961
MAPTOSTRING
962
MAPVALUES
964
MAPVERSION
966
MATERIALIZE_FLEXTABLE_COLUMNS
967
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
969
972
AUDIT
972
AUDIT_FLEX
976
AUDIT_LICENSE_SIZE
979
AUDIT_LICENSE_TERM
979
GET_AUDIT_TIME
980
GET_COMPLIANCE_STATUS
981
DISPLAY_LICENSE
982
SET_AUDIT_TIME
983
984
Page 28 of 1873
SQLReference Manual
Contents
DROP_PARTITION
984
DUMP_PROJECTION_PARTITION_KEYS
987
DUMP_TABLE_PARTITION_KEYS
989
MOVE_PARTITIONS_TO_TABLE
990
Examples
991
PARTITION_PROJECTION
992
PARTITION_TABLE
993
PURGE_PARTITION
995
SWAP_PARTITIONS_BETWEEN_TABLES
997
Profiling Functions
1000
CLEAR_PROFILING
1000
DISABLE_PROFILING
1001
ENABLE_PROFILING
1001
1003
EVALUATE_DELETE_PERFORMANCE
1003
GET_PROJECTION_STATUS
1006
GET_PROJECTIONS, GET_TABLE_PROJECTIONS
1008
REFRESH
1009
START_REFRESH
1012
Purge Functions
1015
PURGE
1015
PURGE_PARTITION
1016
PURGE_PROJECTION
1018
PURGE_TABLE
1019
1021
CANCEL_REFRESH
1021
CLOSE_ALL_SESSIONS
1022
Page 29 of 1873
SQLReference Manual
Contents
Controlling Sessions
CLOSE_SESSION
Controlling Sessions
1024
1026
1028
GET_NUM_ACCEPTED_ROWS
1030
GET_NUM_REJECTED_ROWS
1031
INTERRUPT_STATEMENT
1032
RELEASE_ALL_JVM_MEMORY
1035
RELEASE_JVM_MEMORY
1036
1038
ANALYZE_EXTERNAL_ROW_COUNT
1038
ANALYZE_HISTOGRAM
1039
ANALYZE_STATISTICS
1043
DROP_EXTERNAL_ROW_COUNT
1047
DROP_STATISTICS
1048
EXPORT_STATISTICS
1051
IMPORT_STATISTICS
1052
VALIDATE_STATISTICS
1054
1057
ADD_LOCATION
Storage Location Subdirectories
ALTER_LOCATION_USE
1057
1058
1059
1060
1060
ALTER_LOCATION_LABEL
1061
CLEAR_CACHES
1062
CLEAR_OBJECT_STORAGE_POLICY
1063
DROP_LOCATION
1064
Page 30 of 1873
SQLReference Manual
Contents
1065
1065
1065
ENFORCE_OBJECT_STORAGE_POLICY
1066
MEASURE_LOCATION_PERFORMANCE
1067
MOVE_RETIRED_LOCATION_DATA
1069
RESTORE_LOCATION
1071
1072
1072
RETIRE_LOCATION
1073
1073
1074
1074
SET_LOCATION_PERFORMANCE
1075
SET_OBJECT_STORAGE_POLICY
1076
1077
1077
1077
1079
DO_TM_TASK
1079
1082
ANALYZE_WORKLOAD
1082
CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY
1085
CHANGE_RUNTIME_PRIORITY
1086
CLEAR_CACHES
1087
SLEEP
1088
SQL Statements
1091
Page 31 of 1873
SQLReference Manual
Contents
1091
ALTERAUTHENTICATION
1092
ALTER DATABASE
1096
1098
ALTER FUNCTION
1099
ALTER LIBRARY
1102
ALTER NODE
1104
1106
1107
ALTER PROFILE
1108
1112
1113
1125
ALTER SCHEMA
1126
ALTER SEQUENCE
1127
ALTER SESSION
1131
ALTER SUBNET
1132
ALTER TABLE
1132
1145
1145
Locked Tables
1145
1146
1146
1146
Table-Constraint
1148
1149
1149
Page 32 of 1873
SQLReference Manual
Contents
ALTER USER
1149
ALTER VIEW
1155
BEGIN
1156
COMMENT ON Statements
1160
COMMENT ON COLUMN
1160
COMMENT ON CONSTRAINT
1162
COMMENT ON FUNCTION
1164
COMMENT ON LIBRARY
1165
COMMENT ON NODE
1167
COMMENT ON PROJECTION
1168
COMMENT ON SCHEMA
1170
COMMENT ON SEQUENCE
1171
COMMENT ON TABLE
1173
1174
COMMENT ON VIEW
1176
COMMIT
1177
CONNECT
1178
Connection Details
COPY
1179
1179
1192
1194
1194
1195
1195
COPY LOCAL
1196
1197
1197
Page 33 of 1873
SQLReference Manual
Contents
1198
1200
CREATE ACCESSPOLICY
1202
CREATE AUTHENTICATION
1203
1206
1209
1210
1211
1211
1213
1216
1217
1217
1220
CREATE FILTER
1221
1224
1228
CREATE PARSER
1231
CREATE SOURCE
1234
1236
1237
CREATEHCATALOGSCHEMA
1239
CREATE LIBRARY
1242
1245
CREATE LOCATION
1247
WebHDFSURIs
CREATE NETWORK INTERFACE
1249
1251
Page 34 of 1873
SQLReference Manual
Contents
CREATE PROCEDURE
1251
CREATE PROFILE
1253
Example
1257
CREATE PROJECTION
1258
Projection Naming
1264
Encoding-Type
1265
1265
ENCODING BLOCK_DICT
1265
ENCODING BLOCKDICT_COMP
1266
ENCODING BZIP_COMP
1266
ENCODING COMMONDELTA_COMP
1266
ENCODING DELTARANGE_COMP
1267
ENCODING DELTAVAL
1267
ENCODING GCDDELTA
1267
ENCODINGGZIP_COMP
1267
ENCODING RLE
1268
ENCODING NONE
1268
Hash-Segmentation-Clause
1268
GROUPEDClause
1270
1271
1277
1277
1279
Privileges
1290
Built-In Pools
1292
1295
1295
Page 35 of 1873
SQLReference Manual
Contents
GENERAL
1296
SYSQUERY
1298
SYSDATA
1298
WOSDATA
1299
TM
1300
REFRESH
1300
RECOVERY
1301
DBD
1302
JVM
1302
CREATE ROLE
1303
CREATE SCHEMA
1303
CREATE SEQUENCE
1305
1308
Removing a Sequence
1308
CREATE SUBNET
1311
CREATE TABLE
1312
1319
Partition Clauses
1320
Column-Definition (table)
1324
Column-Name-List (table)
1326
Column-Constraint
1328
Table-Constraint
1335
1336
1337
Hash-Segmentation-Clause (table)
1337
1339
1346
Page 36 of 1873
SQLReference Manual
Contents
1349
1352
1353
CREATE USER
1356
CREATE VIEW
1362
1363
Dropping a View
1364
Renaming a View
1365
DELETE
Using the DELETE Statement
1365
1366
DISCONNECT
1367
1368
1369
DROPAUTHENTICATION
1371
1372
DROP FUNCTION
1374
DROP SOURCE
1375
DROP FILTER
1377
DROP PARSER
1378
DROP LIBRARY
1380
1381
DROP PROCEDURE
1381
DROP PROFILE
1382
Example
1383
DROP PROJECTION
1383
1385
1386
Page 37 of 1873
SQLReference Manual
Contents
1386
DROP ROLE
1387
DROP SCHEMA
1388
DROP SEQUENCE
1389
DROP SUBNET
1390
DROP TABLE
1391
1393
1394
DROP USER
1396
DROP VIEW
1397
END
1398
EXPLAIN
1399
EXPORT TO VERTICA
1400
1401
1404
GRANT(Authentication)
1404
GRANT (Database)
1405
GRANT (Procedure)
1407
1408
GRANT (Role)
1409
Creating Roles
1410
Activating a Role
1410
1411
1411
1411
GRANT (Schema)
1412
GRANT (Sequence)
1413
Page 38 of 1873
SQLReference Manual
Contents
1415
GRANT (Table)
1417
1419
GRANT (View)
1422
INSERT
1423
MERGE
1426
1431
1431
PROFILE
1432
1433
1433
1433
RELEASE SAVEPOINT
1434
REVOKE Statements
1436
REVOKE (Authentication)
1436
REVOKE (Database)
1438
REVOKE (Procedure)
1439
1440
REVOKE (Role)
1442
REVOKE (Schema)
1443
REVOKE (Sequence)
1444
1446
REVOKE (Table)
1448
1450
REVOKE (View)
1452
ROLLBACK
1454
ROLLBACK TO SAVEPOINT
1455
Page 39 of 1873
SQLReference Manual
Contents
SAVEPOINT
1456
SELECT
1458
Parameters
1459
EXCEPT Clause
1461
FROM Clause
1465
Table-Reference
1466
Table-Primary
1466
Joined-Table
1467
GROUP BY Clause
1467
ROLLUP Aggregate
1470
GROUP_ID
1473
GROUPING
1475
GROUPING_ID
1476
CUBE Aggregate
1479
1482
HAVING Clause
1485
INTERSECT Clause
1486
INTO Clause
1490
LIMIT Clause
1492
MATCH Clause
1493
1497
MINUS Clause
1498
OFFSET Clause
1498
ORDER BY Clause
1500
TIMESERIES Clause
1501
UNION Clause
1504
WHERE Clause
1508
Page 40 of 1873
SQLReference Manual
Contents
WINDOW Clause
1510
WITH Clause
1510
SET DATESTYLE
1513
SET ESCAPE_STRING_WARNING
1515
SET INTERVALSTYLE
1516
1516
1516
1517
SET LOCALE
1517
SET ROLE
1521
SET SEARCH_PATH
1523
1525
1526
1527
1527
1527
1528
1528
1530
1531
1532
SET STANDARD_CONFORMING_STRINGS
1534
1536
1537
1539
1540
1541
Page 41 of 1873
SQLReference Manual
Contents
1541
SHOW CURRENT
1542
SHOW DATABASE
1543
SHOW NODE
1544
SHOW SESSION
1544
START TRANSACTION
1546
TRUNCATE TABLE
1548
UPDATE
1549
1555
V_CATALOG Schema
1556
ACCESS_POLICY
1556
ALL_TABLES
1557
CLIENT_AUTH
1558
CLIENT_AUTH_PARAMS
1560
CLUSTER_LAYOUT
1561
COLUMNS
1563
COMMENTS
1566
CONSTRAINT_COLUMNS
1567
DATABASES
1569
DUAL
1569
ELASTIC_CLUSTER
1570
EPOCHS
1572
FAULT_GROUPS
1573
FOREIGN_KEYS
1574
GRANTS
1576
HCATALOG_COLUMNS
1580
HCATALOG_SCHEMATA
1584
Page 42 of 1873
SQLReference Manual
Contents
HCATALOG_TABLES
1586
HCATALOG_TABLE_LIST
1589
LARGE_CLUSTER_CONFIGURATION_STATUS
1590
LICENSE_AUDITS
1591
LICENSES
1592
MATERIALIZE_FLEXTABLE_COLUMNS_RESULTS
1593
NODES
1594
ODBC_COLUMNS
1596
PASSWORD_AUDITOR
1598
PASSWORDS
1600
PRIMARY_KEYS
1600
PROFILE_PARAMETERS
1601
PROFILES
1602
PROJECTION_CHECKPOINT_EPOCHS
1603
PROJECTION_COLUMNS
1605
PROJECTION_DELETE_CONCERNS
1613
PROJECTIONS
1614
RESOURCE_POOL_DEFAULTS
1619
RESOURCE_POOLS
1619
ROLES
1624
SCHEMATA
1625
SEQUENCES
1626
STORAGE_LOCATIONS
1629
SYSTEM_COLUMNS
1633
SYSTEM_TABLES
1635
TABLE_CONSTRAINTS
1636
TABLES
1638
Page 43 of 1873
SQLReference Manual
Contents
TYPES
1640
USER_AUDITS
1642
USER_CLIENT_AUTH
1643
USER_FUNCTIONS
1644
USER_PROCEDURES
1646
USER_TRANSFORMS
1646
USERS
1647
VIEW_COLUMNS
1650
VIEWS
1651
V_MONITOR Schema
1654
ACTIVE_EVENTS
1654
COLUMN_STORAGE
1656
CONFIGURATION_CHANGES
1660
CONFIGURATION_PARAMETERS
1661
CPU_USAGE
1663
CRITICAL_HOSTS
1664
CRITICAL_NODES
1665
CURRENT_SESSION
1665
DATA_COLLECTOR
1672
DATABASE_BACKUPS
1675
DATABASE_CONNECTIONS
1677
DATABASE_SNAPSHOTS
1677
DELETE_VECTORS
1679
DEPLOY_STATUS
1679
DEPLOYMENT_PROJECTION_STATEMENTS
1681
DEPLOYMENT_PROJECTIONS
1683
DESIGN_QUERIES
1685
Page 44 of 1873
SQLReference Manual
Contents
DESIGN_STATUS
1687
DESIGN_TABLES
1689
DESIGNS
1690
DISK_RESOURCE_REJECTIONS
1693
DISK_STORAGE
1694
1696
ERROR_MESSAGES
1699
EVENT_CONFIGURATIONS
1701
EXECUTION_ENGINE_PROFILES
1702
HOST_RESOURCES
1716
IO_USAGE
1719
LOAD_STREAMS
1720
LOCK_USAGE
1722
LOCKS
1726
LOGIN_FAILURES
1730
MEMORY_USAGE
1732
MONITORING_EVENTS
1733
NETWORK_INTERFACES
1736
NETWORK_USAGE
1737
NODE_RESOURCES
1738
NODE_STATES
1740
OUTPUT_DEPLOYMENT_STATUS
1742
OUTPUT_EVENT_HISTORY
1744
PARTITION_COLUMNS
1748
PARTITION_REORGANIZE_ERRORS
1750
PARTITION_STATUS
1751
PARTITIONS
1753
Page 45 of 1873
SQLReference Manual
Contents
PROCESS_SIGNALS
1754
PROJECTION_RECOVERIES
1755
PROJECTION_REFRESHES
1759
PROJECTION_STORAGE
1763
PROJECTION_USAGE
1767
QUERY_EVENTS
1768
QUERY_METRICS
1774
QUERY_PLAN_PROFILES
1775
QUERY_PROFILES
1778
QUERY_REQUESTS
1780
REBALANCE_PROJECTION_STATUS
1784
REBALANCE_TABLE_STATUS
1786
RECOVERY_STATUS
1788
RESOURCE_ACQUISITIONS
1790
RESOURCE_POOL_MOVE
1793
RESOURCE_POOL_STATUS
1796
RESOURCE_QUEUES
1807
RESOURCE_REJECTION_DETAILS
1808
RESOURCE_REJECTIONS
1810
RESOURCE_USAGE
1813
SESSION_PARAMETERS
1816
See Also
1817
SESSION_PROFILES
1817
SESSIONS
1820
STORAGE_CONTAINERS
1825
STORAGE_POLICIES
1829
STORAGE_TIERS
1830
Page 46 of 1873
SQLReference Manual
Contents
STORAGE_USAGE
1831
STRATA
1833
STRATA_STRUCTURES
1836
SYSTEM
1839
SYSTEM_RESOURCE_USAGE
1840
SYSTEM_SERVICES
1842
SYSTEM_SESSIONS
1844
TRANSACTIONS
1848
TUNING_RECOMMENDATIONS
1851
TUPLE_MOVER_OPERATIONS
1853
UDX_FENCED_PROCESSES
1856
USER_LIBRARIES
1857
USER_LIBRARY_MANIFEST
1859
USER_SESSIONS
1859
WOS_CONTAINER_STORAGE
1863
1867
1867
1873
Page 47 of 1873
SQLReference Manual
Contents
Page 48 of 1873
SQLReference Manual
SQL Overview
SQL Overview
An abbreviation for Structured Query Language, SQL is a widely-used, industry standard data
definition and data manipulation language for relational databases.
Note: In HP Vertica, use a semicolon to end a statement or to combine multiple statements on
one line.
Joins
HP Vertica supports typical data warehousing query joins. For details, see Joins in the Analyzing
Data Guide.
HP Vertica also provides the INTERPOLATE predicate, which allows for a special type of join. The
event series join is an HP Vertica SQL extension that lets you analyze two event series when their
measurement intervals dont align preciselysuch as when timestamps don't match. These joins
provide a natural and efficient way to query misaligned event data directly, rather than having to
normalize the series to the same measurement interval. See Event Series Joins in the Analyzing
Data Guide for details.
Transactions
Session-scoped isolation levels determine transaction characteristics for transactions within a
specific user session. You set them through the SET SESSION CHARACTERISTICS command.
Specifically, they determine what data a transaction can access when other transactions are
running concurrently. See Transactions in the Concepts Guide.
Page 49 of 1873
SQLReference Manual
SQL Overview
Page 50 of 1873
SQLReference Manual
System Limits
System Limits
This section describes the system limits on the size and number of objects in an HP Vertica
database. In most cases, computer memory and disk drive are the limiting factors.
Item
Limit
Number of nodes
Database size
Approximates the number of files times the file size on a platform, depending
on the maximum disk configuration.
Table size
2^64 rows per node, or 2^63 bytes per column, whichever is smaller.
Row size
32,768,000 bytes. The row size is approximately the sum of its maximum
column sizes, where, for example, a VARCHAR(80) has a maximum size of
80 bytes.
Key size
Number of
tables/projections
per database
Number of
Default of 50, limited by physical RAM (or threads per process), typically
concurrent
1024.
connections per
node
Number of
Limited by physical RAM of a single node (or threads per process), typically
concurrent
1024.
connections per
cluster
Number of
1600.
2^63.
per load
Page 51 of 1873
SQLReference Manual
System Limits
Item
Limit
Number of
1024.
partitions
l
65000 bytes.
variable-length
column
Length of basic
128 bytes. Basic names include table names, column names, etc.
names
Query length
No limit.
Depth of nesting
subqueries
Page 52 of 1873
SQLReference Manual
SQL Language Elements
Page 53 of 1873
SQLReference Manual
SQL Language Elements
Keywords
Keyword are words that are specially handled by the grammar. Every SQL statement contains one
or more keywords.
Begins
with
Keyword
A
Page 54 of 1873
SQLReference Manual
SQL Language Elements
Begins
with
Keyword
D
JOIN
KEY, KSAFE
Page 55 of 1873
SQLReference Manual
SQL Language Elements
Begins
with
Keyword
N
OBJECT, OCTETS, OF, OFF, OFFSET, OIDS, OLD, ON, ONLY, OPERATOR,
OPTION, OR, ORDER, OTHERS, OUT, OUTER, OVER, OVERLAPS, OVERLAY,
OWNER
QUEUETIMEOUT, QUOTE
Page 56 of 1873
SQLReference Manual
SQL Language Elements
Begins
with
Keyword
T
YEAR
ZONE
Reserved Words
Many SQL keywords are also reserved words, but a reserved word is not necessarily a keyword.
For example, a reserved word might be reserved for other/future use. In HP Vertica, reserved words
can be used anywhere identifiers can be used, as long as you double-quote them.
Begins
with
Reserved Word
A
BINARY, BOTH
Page 57 of 1873
SQLReference Manual
SQL Language Elements
Begins
with
Reserved Word
H
HAVING
JOIN
KSAFE
MATCH
REFERENCES
Identifiers
Identifiers (names) of objects such as schema, table, projection, column names, and so on, can be
up to 128 bytes in length.
Unquoted Identifiers
Unquoted SQL identifiers must begin with one of the following:
l
Underscore (_)
Page 58 of 1873
SQLReference Manual
SQL Language Elements
Underscore (_)
Digits(09)
Dollar sign ($). Dollar sign is not allowed in identifiers according to the SQL standard and could
cause application portability problems.
Quoted Identifiers
Identifiers enclosed in double quote (") characters can contain any character. If you want to include
a double quote, you need a pair of them; for example """". You can use names that would
otherwise be invalid, such as names that include only numeric characters ("123") or contain space
characters, punctuation marks, keywords, and so on; for example:
CREATE SEQUENCE "my sequence!";
Double quotes are required for non-alphanumerics and SQL keywords such as "1time", "Next
week" and "Select".
Note: Identifiers are not case-sensitive. Thus, identifiers "ABC", "ABc", and "aBc" are
synonymous, as are ABC, ABc, and aBc.
Non-ASCII Characters
HP Vertica accepts non-ASCII UTF-8 Unicode characters for table names, column names, and
other Identifiers, extending the cases in which upper/lower case distinctions are ignored (casefolded) to all alphabets, including Latin, Cyrillic, and Greek.
Page 59 of 1873
SQLReference Manual
SQL Language Elements
The following statements are variations of the same query and all return identical results:
=> SELECT * FROM ALLCAPS;
=> SELECT * FROM allcaps;
=> SELECT * FROM "allcaps";
Note that the system returns an error if you try to create table AllCaps:
=> CREATE TABLE AllCaps(c1 varchar(30));
ROLLBACK: table "AllCaps" already exists
Tip: Use the case-insensitive ILIKE predicate to return the expected results.
Page 60 of 1873
SQLReference Manual
SQL Language Elements
Literals
Literals are numbers or strings used in SQL as constants. Literals are included in the select-list,
along with expressions and built-in functions and can also be constants.
HP Vertica provides support for number-type literals (integers and numerics), string literals,
VARBINARY string literals, and date/time literals. The various string literal formats are discussed
in this section.
Number-Type Literals
There are three types of numbers in HP Vertica: Integers, numerics, and floats.
l
Integers are whole numbers less than 2^63 and must be digits.
Numerics are whole numbers larger than 2^63 or that include a decimal point with a precision
and a scale. Numerics can contain exponents. Numbers that begin with 0x are hexadecimal
numerics.
Numeric-type values can also be generated using casts from character strings. This is a more
general syntax. See the Examples section below, as well as Data Type Coercion Operators
(CAST).
Syntax
digits
digits.[digits] | [digits].digits
digits e[+-]digits | [digits].digits e[+-]digits | digits.[digits] e[+-]digits
Parameters
digits
Notes
l
At least one digit must follow the exponent marker (e), if e is present.
Page 61 of 1873
SQLReference Manual
SQL Language Elements
Leading plus (+) or minus () signs are not considered part of the constant; they are unary
operators applied to the constant.
In most cases a numeric-type constant is automatically coerced to the most appropriate type
depending on context. When necessary, you can force a numeric value to be interpreted as a
specific data type by casting it as described in Data Type Coercion Operators (CAST).
Floating point literals are not supported. If you specifically need to specify a float, you can cast
as described in Data Type Coercion Operators (CAST).
HP Vertica follows the IEEE specification for floating point, including NaN (not a number) and
Infinity (Inf).
A NaN is not greater than and at the same time not less than anything, even itself. In other
words, comparisons always return false whenever a NaN is involved. See Numeric Expressions
for examples.
Dividing INTEGERS (x / y) yields a NUMERIC result. You can use the // operator to truncate
the result to a whole number.
Examples
The following are examples of number-type literals:
42
3.5
4.
.001
5e2
1.925e-3
Scientific notation:
=> SELECT NUMERIC '1e10';
?column?
------------10000000000
(1 row)
BINARY scaling:
=> SELECT NUMERIC '1p10';
?column?
---------1024
Page 62 of 1873
SQLReference Manual
SQL Language Elements
(1 row)
=> SELECT FLOAT 'Infinity';
?column?
---------Infinity
(1 row)
The following examples illustrated using the / and // operators to divide integers:
VMart=> SELECT 40/25;
?column?
---------------------1.600000000000000000
(1 row)
VMart=> SELECT 40//25;
?column?
---------1
(1 row)
See Also
l
Page 63 of 1873
SQLReference Manual
SQL Language Elements
String Literals
String literals are string values surrounded by single or double quotes. Double-quoted strings are
subject to the backslash, but single-quoted strings do not require a backslash, except for \' and \\.
You can embed single quotes and backslashes into single-quoted strings.
To include other backslash (escape) sequences, such as \t (tab), you must use the double-quoted
form.
Precede single-quoted strings with a space between the string and its preceding word, since single
quotes are allowed in identifiers.
See Also
l
SET STANDARD_CONFORMING_STRINGS
SET ESCAPE_STRING_WARNING
Internationalization Parameters
Syntax
'characters'
Parameters
characters
Page 64 of 1873
SQLReference Manual
SQL Language Elements
Examples
=> SELECT 'This is a string';
?column?
-----------------This is a string
(1 row)
=> SELECT 'This \is a string';
WARNING: nonstandard use of escape in a string literal at character 8
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
?column?
-----------------This is a string
(1 row)
vmartdb=> SELECT E'This \is a string';
?column?
-----------------This is a string
=> SELECT E'This is a \n new line';
?column?
---------------------This is a
new line
(1 row)
=> SELECT 'String''s characters';
?column?
-------------------String's characters
(1 row)
Page 65 of 1873
SQLReference Manual
SQL Language Elements
See Also
l
SET STANDARD_CONFORMING_STRINGS
SET ESCAPE_STRING_WARNING
Internationalization Parameters
Syntax
$$characters$$
Parameters
characters
Dollar-quoted string content is treated as a literal. Single quote, backslash, and dollar sign
characters have no special meaning within a dollar-quoted string.
Notes
A dollar-quoted string that follows a keyword or identifier must be separated from the preceding
word by whitespace; otherwise, the dollar-quoting delimiter is taken as part of the preceding
identifier.
Examples
=> SELECT $$Fred's\n car$$;
?column?
Page 66 of 1873
SQLReference Manual
SQL Language Elements
------------------Fred's\n car
(1 row)
=> SELECT 'SELECT 'fact';';
ERROR: syntax error at or near "';'" at character 21
LINE 1: SELECT 'SELECT 'fact';';
=> SELECT 'SELECT $$fact';$$;
?column?
--------------SELECT $$fact
(1 row)
=> SELECT 'SELECT ''fact'';';
?column?
---------------SELECT 'fact';
(1 row)
Parameters
characters
A single character from the source language character set other than
a hexit, plus sign (+), quote ('), double quote (''), or white space
To treat backslashes as escape characters for the current session, use the SET STANDARD_
CONFORMING_STRINGS statement.
Page 67 of 1873
SQLReference Manual
SQL Language Elements
Examples
To enter a Unicode character in hexadecimal, such as the Russian phrase for "thank you, use the
following syntax:
=> SET STANDARD_CONFORMING_STRINGS TO ON;
=> SELECT U&'\0441\043F\0430\0441\0438\0431\043E' as 'thank you';
thank you
----------
(1 row)
See Also
l
SET STANDARD_CONFORMING_STRINGS
SET ESCAPE_STRING_WARNING
Internationalization Parameters
Page 68 of 1873
SQLReference Manual
SQL Language Elements
Syntax
X'<hexadecimal digits>'
B'<binary digits>'
Parameters
X or x
B or b
Examples
=> SELECT X'abcd';
?column?
---------\253\315
(1 row)
=> SELECT B'101100';
?column?
---------,
(1 row)
Parameters
characters
Page 69 of 1873
SQLReference Manual
SQL Language Elements
You can use C-style backslash sequence in extended string literals, which are an extension to the
SQL standard. You specify an extended string literal by writing the letter E as a prefix (before the
opening single quote); for example:
E'extended character string\n'
Within an extended string, the backslash character (\) starts a C-style backslash sequence, in
which the combination of backslash and following character or numbers represent a special byte
value, as shown in the following list. Any other character following a backslash is taken literally; for
example, to include a backslash character, write two backslashes (\\).
l
\\ is a backslash
\b is a backspace
\f is a form feed
\n is a newline
\r is a carriage return
\t is a tab
\###, where ### is a 1, 2, or 3-digit octal number representing a byte with the corresponding
code.
When an extended string literal is concatenated across lines, write only E before the first opening
quote:
=> SELECT E'first part o'
->
'f a long line';
?column?
--------------------------first part of a long line
(1 row)
Page 70 of 1873
SQLReference Manual
SQL Language Elements
The two sections that follow help you identify issues between HP Vertica 3.5 and 4.0.
Page 71 of 1873
SQLReference Manual
SQL Language Elements
Note: HP recommends that you migrate your application to use Standard Conforming
Strings at your earliest convenience.
2. Turn on the EscapeStringWarning parameter. (ON is the default in HP Vertica Version 4.0 and
later.)
=> ALTER DATABASE mydb SET EscapeStringWarning = 1;
HP Vertica now returns a warning each time it encounters an escape string within a string
literal. For example, HP Vertica interprets the \n in the following example as a new line:
=> SELECT 'a\nb';
WARNING: nonstandard use of escape in a string literal at character 8
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
?column?
---------a
b
(1 row)
Or if the string has quoted single quotes, double them; for example, 'one'' double'.
3. Turn on the StandardConformingStrings parameter for all sessions:
=> ALTER DATABASE mydb SET StandardConformingStrings = 1;
Page 72 of 1873
SQLReference Manual
SQL Language Elements
HP Vertica recognizes two consecutive single quotes within a string literal as one single quote
character. For example, the following inputs, 'You''re here!' ignored the second consecutive
quote and returns the following:
=> SELECT 'You''re here!';
?column?
-------------You're here!
(1 row)
This is the SQL standard representation and is preferred over the form, 'You\'re here!', because
backslashes are not parsed as before. You need to escape the backslash:
=> SELECT (E'You\'re here!');
?column?
-------------You're here!
(1 row)
This behavior change introduces a potential incompatibility in the use of the vsql \set command,
which automatically concatenates its arguments. For example, the following works in both HP
Vertica 3.5 and 4.0:
\set file
'\''
`pwd`
'/file.txt'
'\''\echo :file
In HP Vertica 3.5 the above \set file command could be written all with the arguments run
together, but in 4.0 the adjacent single quotes are now parsed differently:
\set file '\''`pwd`'/file.txt''\''\echo :file
'/home/vertica/file.txt''
Note the extra single quote at the end. This is due to the pair of adjacent single quotes together with
the backslash-quoted single quote.
The extra quote can be resolved either as in the first example above, or by combining the literals as
follows:
\set file '\''`pwd`'/file.txt'''\echo :file
'/home/vertica/file.txt'
In either case the backslash-quoted single quotes should be changed to doubled single quotes as
follows:
Page 73 of 1873
SQLReference Manual
SQL Language Elements
Additional Examples
=> SELECT 'This \is a string';
?column?
-----------------This \is a string
(1 row)
=> SELECT E'This \is a string';
?column?
-----------------This is a string
=> SELECT E'This is a \n new line';
?column?
---------------------This is a
new line
(1 row)
=> SELECT 'String''s characters';
?column?
-------------------String's characters
(1 row)
Page 74 of 1873
SQLReference Manual
SQL Language Elements
Date/Time Literals
Date or time literal input must be enclosed in single quotes. Input is accepted in almost any
reasonable format, including ISO 8601, SQL-compatible, traditional POSTGRES, and others.
HP Vertica is more flexible in handling date/time input than the SQL standard requires.The exact
parsing rules of date/time input and for the recognized text fields including months, days of the
week, and time zones are described in Date/Time Expressions.
Although the DATE type does not have an associated time zone, the TIME type can. Time
zones in the real world have little meaning unless associated with a date as well as a time, since
the offset can vary through the year with daylight-saving time boundaries.
HP Vertica assumes your local time zone for any data type containing only date or time.
The default time zone is specified as a constant numeric offset from UTC. It is therefore not
possible to adapt to daylight-saving time when doing date/time arithmetic across DST
boundaries.
To address these difficulties, HP recommends using Date/Time types that contain both date and
time when you use time zones. HP recommends that you do not use the type TIME WITH TIME
ZONE, even though it is supported it for legacy applications and for compliance with the SQL
standard.
Time zones and time-zone conventions are influenced by political decisions, not just earth
geometry. Time zones around the world became somewhat standardized during the 1900's, but
continue to be prone to arbitrary changes, particularly with respect to daylight-savings rules.
HP Vertica currently supports daylight-savings rules over the time period 1902 through 2038,
corresponding to the full range of conventional UNIX system time. Times outside that range are
taken to be in "standard time" for the selected time zone, no matter what part of the year in which
they occur.
Example Description
PST
Page 75 of 1873
SQLReference Manual
SQL Language Elements
Example Description
-8:00
-800
-8
zulu
Abbreviations
SUNDAY
SUN
MONDAY
MON
TUESDAY
TUE, TUES
FRIDAY
FRI
SATURDAY
SAT
Month Names
The following tokens are recognized as names of months:
Month
Abbreviations
JANUARY
JAN
FEBRUARY
FEB
MARCH
MAR
APRIL
APR
Page 76 of 1873
SQLReference Manual
SQL Language Elements
Month
Abbreviations
MAY
MAY
JUNE
JUN
JULY
JUL
AUGUST
AUG
SEPTEMBER
SEP, SEPT
OCTOBER
OCT
NOVEMBER
NOV
DECEMBER
DEC
Page 77 of 1873
SQLReference Manual
SQL Language Elements
Interval Values
An interval value represents the duration between two points in time.
Syntax
[ @ ] quantity unit [ quantity unit... ] [ AGO ]
Parameters
@
quantity
unit
AGO
DAYWEEK
MONTH
YEAR
DECADECENTURY
MILLENNIUM
[Optional] specifies a negative interval value (an interval going back in time). 'AGO' is
a synonym for '-'.
The amounts of different units are implicitly added up with appropriate sign accounting.
Notes
l
Quantities of days, hours, minutes, and seconds can be specified without explicit unit markings.
For example:
'1 12:59:10' is read the same as '1 day 12 hours 59 min 10 sec'
296533 years 3 mons 21 days 04:00:54.775807 to -296533 years -3 mons -21 days 04:00:54.775807
The range of an interval constant is +/ 263 1 (plus or minus two to the sixty-third minus one)
microseconds.
In HP Vertica, the interval fields are additive and accept large floating-point numbers.
Page 78 of 1873
SQLReference Manual
SQL Language Elements
Examples
=> SELECT INTERVAL '1 12:59:10';
?column?
-----------1 12:59:10
(1 row)
=> SELECT INTERVAL '9223372036854775807 usec';
?column?
--------------------------106751991 04:00:54.775807
(1 row)
=> SELECT INTERVAL '-9223372036854775807 usec';
?column?
----------------------------106751991 04:00:54.775807
(1 row)
=> SELECT INTERVAL '-1 day 48.5 hours';
?column?
----------3 00:30
(1 row)
=> SELECT TIMESTAMP 'Apr 1, 07' - TIMESTAMP 'Mar 1, 07';
?column?
---------31
(1 row)
=> SELECT TIMESTAMP 'Mar 1, 07' - TIMESTAMP 'Feb 1, 07';
?column?
---------28
(1 row)
=> SELECT TIMESTAMP 'Feb 1, 07' + INTERVAL '29 days';
?column?
--------------------03/02/2007 00:00:00
(1 row)
=> SELECT TIMESTAMP WITHOUT TIME ZONE '1999-10-01 00:00:01' +
INTERVAL '1 month - 1 second' AS "Oct 31";
Oct 31
--------------------1999-10-31 00:00:00
(1 row)
Interval-Literal
The following table lists the units allowed for the required interval-literal parameter.
Page 79 of 1873
SQLReference Manual
SQL Language Elements
Unit
Description
ago
c, cent, century
Century
centuries
Centuries
d, day
Day
days
Days
dec, decade
Decade
decades, decs
Decades
h, hour, hr
Hour
hours, hrs
Hours
ka
microsecond
Microsecond
microseconds
Microseconds
mil, millennium
Millennium
millennia, mils
Millennia
millisecond
Millisecond
milliseconds
Milliseconds
min, minute, mm
Minute
mins, minutes
Minutes
mon, month
Month
mons, months
Months
Millisecond
Page 80 of 1873
SQLReference Manual
SQL Language Elements
Unit
Description
mseconds, msecs
Milliseconds
q, qtr, quarter
Quarter
qtrs, quarters
Quarters
s, sec, second
Second
seconds, secs
Seconds
us, usec
Microsecond
Microseconds
w, week
Week
weeks
Weeks
y, year, yr
Year
years, yrs
Years
In the first INSERT statement, the values are inserted as 1 year, six months:
=> INSERT INTO int_test VALUES('1 year 6 months');
The second INSERT statement results in an error from specifying minutes for a YEAR TO MONTH
interval. At runtime, the result will be a NULL:
=> INSERT INTO int_test VALUES('1 year 6 minutes');
ERROR: invalid input syntax for type interval year to month: "1 year 6 minutes"
In the third INSERT statement, the 'm' is processed as months (not minutes), because DAY TO
SECOND is truncated:
=> INSERT INTO int_test VALUES('1 year 6 m');
Page 81 of 1873
SQLReference Manual
SQL Language Elements
In the following command, the 'm' counts as minutes, because the DAY TO SECOND interval-qualifier
extracts day/time values from the input:
=> SELECT INTERVAL '1y6m' DAY TO SECOND;
?column?
----------365 days 6 mins
(1 row)
Interval-Qualifier
The following table lists the optional interval qualifiers. Values in INTERVAL fields, other than
SECOND, are integers with a default precision of 2 when they are not the first field.
You cannot combine day/time and year/month qualifiers. For example, the following intervals are
not allowed:
l
DAY TO YEAR
HOUR TO MONTH
Interval
Type
Units
Day/time
DAY
Unconstrained.
DAY TO HOUR
DAY TO MINUTE
intervals
Page 82 of 1873
SQLReference Manual
SQL Language Elements
Interval
Type
Units
DAY TO SECOND
HOUR
HOUR TO MINUTE
HOUR TO SECOND
MINUTE
MINUTE TO SECOND
SECOND
Year/month MONTH
intervals
YEAR
Unconstrained.
YEAR TO MONTH
Page 83 of 1873
SQLReference Manual
SQL Language Elements
Operators
Operators are logical, mathematical, and equality symbols used in SQL to evaluate, compare, or
calculate values.
Binary Operators
Each of the functions in the following table works with BINARY and VARBINARY data types.
Operator Function
Description
'='
binary_eq
Equal to
'<>'
binary_ne
Not equal to
'<'
binary_lt
Less than
'<='
binary_le
'>'
binary_gt
Greater than
binary_ge
'&'
binary_and
And
'~'
binary_not
Not
'|'
binary_or
Or
'#'
binary_xor
Either or
'||'
binary_cat
Concatenate
'>='
Notes
l
If the arguments vary in length binary operators treat the values as though they are all equal in
length by right-extending the smaller values with the zero byte to the full width of the column
(except when using the binary_cat function). For example, given the values 'ff' and 'f', the
value 'f' is treated as 'f0'.
Operators are strict with respect to nulls. The result is null if any argument is null. For example,
null <> 'a'::binary returns null.
To apply the OR ('|') operator to a VARBINARY type, explicitly cast the arguments; for
Page 84 of 1873
SQLReference Manual
SQL Language Elements
example:
=> SELECT '1'::VARBINARY | '2'::VARBINARY;
?column?
---------3
(1 row)
Similarly, to apply the LENGTH, REPEAT, TO_HEX, and SUBSTRING functions to a BINARY
type, explicitly cast the argument; for example:
=> SELECT LENGTH('\\001\\002\\003\\004'::varbinary(4));
LENGTH
-------4
(1 row)
When applying an operator or function to a column, the operator's or function's argument type is
derived from the column type.
Examples
In the following example, the zero byte is not removed from column cat1 when values are
concatenated:
=> SELECT 'ab'::BINARY(3) || 'cd'::BINARY(2) AS cat1,
'ab'::VARBINARY(3) ||
'cd'::VARBINARY(2) AS cat2;
cat1
| cat2
----------+-----ab\000cd | abcd
(1 row)
When the binary value 'ab'::binary(3) is translated to varbinary, the result is equivalent to
'ab\\000'::varbinary(3); for example:
=> SELECT 'ab'::binary(3); binary
-------ab\000
(1 row)
The following example performs a bitwise AND operation on the two input values (see also BIT_
AND):
=> SELECT '10001' & '011' as AND;
AND
Page 85 of 1873
SQLReference Manual
SQL Language Elements
----1
(1 row)
The following example performs a bitwise OR operation on the two input values (see also BIT_OR):
=> SELECT '10001' | '011' as OR;
OR
------10011
(1 row)
Boolean Operators
Syntax
[ AND | OR | NOT ]
Parameters
SQL uses a three-valued Boolean logic where the null value represents "unknown."
a
a AND b a OR b
TRUE
TRUE
TRUE
TRUE
FALSE FALSE
TRUE
TRUE
NULL
TRUE
NULL
TRUE
FALSE
FALSE NULL
FALSE
NULL
NULL
NULL
NULL
NULL
Page 86 of 1873
SQLReference Manual
SQL Language Elements
NOT a
TRUE
FALSE
FALSE TRUE
NULL
NULL
Notes
l
The operators AND and OR are commutative, that is, you can switch the left and right operand
without affecting the result. However, the order of evaluation of subexpressions is not defined.
When it is essential to force evaluation order, use a CASE construct.
Do not confuse Boolean operators with the Boolean-Predicate or the Boolean data type, which
can have only two values: true and false.
Comparison Operators
Comparison operators are available for all data types where comparison makes sense. All
comparison operators are binary operators that return values of True, False, or NULL.
less than
>
greater than
<=
>=
= or <=>
equal
<> or !=
not equal
Notes
l
The != operator is converted to <> in the parser stage. It is not possible to implement != and <>
operators that do different things.
The comparison operators return NULL (signifying "unknown") when either operand is null.
Page 87 of 1873
SQLReference Manual
SQL Language Elements
The <=> operator performs an equality comparison like the = operator, but it returns true, instead
of NULL, if both operands are NULL, and false, instead of NULL, if one operand is NULL.
Syntax
SELECT CAST ( expression AS data_type )
SELECT expression::data_type
SELECT data_type 'string'
Parameters
expression
data_type
Notes
l
In HP Vertica, data type coercion (casting) can be invoked by an explicit cast request. It must
use one of the following constructs:
=> SELECT CAST ( expression AS data_type )
=> SELECT expression::data_type
=> SELECT data_type 'string'
Page 88 of 1873
SQLReference Manual
SQL Language Elements
The explicit type cast can be omitted if there is no ambiguity as to the type the constant must be.
For example, when a constant is assigned directly to a column, it is automatically coerced to the
column's data type.
If a binary value is cast (implicitly or explicitly) to a binary type with a smaller length, the value is
silently truncated. For example:
=> SELECT 'abcd'::BINARY(2);
?column?
---------ab
(1 row)
Similarly, if a character value is cast (implicitly or explicitly) to a character value with a smaller
length, the value is silently truncated. For example:
=> SELECT 'abcd'::CHAR(3);
?column?
---------abc
On binary data that contains a value with fewer bytes than the target column, values are rightextended with the zero byte '\0' to the full width of the column. Trailing zeros on variable-length
binary values are not right-extended:
=> SELECT 'ab'::BINARY(4), 'ab'::VARBINARY(4), 'ab'::LONG VARBINARY(4);
?column? | ?column? | ?column?
------------+----------+---------ab\000\000 | ab
| ab
(1 row)
Examples
=> SELECT CAST((2 + 2) AS VARCHAR);
?column?
Page 89 of 1873
SQLReference Manual
SQL Language Elements
---------4
(1 row)
=> SELECT (2 + 2)::VARCHAR;
?column?
---------4
(1 row)
=> SELECT INTEGER '123';
?column?
---------123
(1 row)
=> SELECT (2 + 2)::LONG VARCHAR
?column?
---------4
(1 row)
=> SELECT '2.2' + 2;
ERROR: invalid input syntax for integer: "2.2"
=> SELECT FLOAT '2.2' + 2;
?column?
---------4.2
(1 row)
See Also
l
Date/Time Operators
Syntax
[ + | | * | / ]
Parameters
+
*
/
Addition
Subtraction
Multiplication
Division
Page 90 of 1873
SQLReference Manual
SQL Language Elements
Notes
l
The operators described below that take TIME or TIMESTAMP inputs actually come in two
variants: one that takes TIME WITH TIME ZONE or TIMESTAMP WITH TIME ZONE, and one that
takes TIME WITHOUT TIME ZONE or TIMESTAMP WITHOUT TIME ZONE. For brevity, these
variants are not shown separately.
The + and * operators come in commutative pairs (for example both DATE + INTEGER and
INTEGER + DATE); only one of each such pair is shown.
Example
Result Type
Result
DATE
'2001-10-05'
TIMESTAMP
'2001-09-28 01:00:00'
TIMESTAMP
'2001-09-28 03:00:00'
INTERVAL
TIMESTAMP
'2001-09-29 00:00:00'
TIME
'04:00:00'
INTERVAL
'-23:00:00'
INTEGER
'3'
DATE
'2001-09-24'
TIMESTAMP
'2001-09-27 23:00:00'
INTERVAL
'02:00:00'
TIME '05:00'
'2 HOURS'
TIME
'03:00:00'
TIMESTAMP
'2001-09-28 00:00:00'
INTERVAL
INTERVAL
INTERVAL
'00:15:00'
INTERVAL
Page 91 of 1873
SQLReference Manual
SQL Language Elements
Example
Result Type
Result
INTERVAL
'21 DAYS'
INTERVAL
'03:30:00'
INTERVAL
'00:40:00'
Mathematical Operators
Mathematical operators are provided for many data types.
Operator Description
Example
Result
Factorial
5 !
120
Addition
2 + 3
Subtraction
2 3
Multiplication
2 * 3
4 / 2
2.00...
//
117.32 // 2.5
46
NUMERIC.
%
Modulo (remainder)
5 % 4
Exponentiation
2.0 ^ 3.0
|/
Square root
|/ 25.0
||/
Cube root
||/ 27.0
!!
!! 5
120
Absolute value
@ -5.0
&
Bitwise AND
91 & 15
11
Bitwise OR
32 | 3
35
Bitwise XOR
17 # 5
20
Bitwise NOT
~1
-2
Page 92 of 1873
SQLReference Manual
SQL Language Elements
Operator Description
Example
Result
<<
1 << 4
16
>>
8 >> 2
Notes
l
The bitwise operators work only on integer data types, whereas the others are available for all
numeric data types.
HP Vertica supports the use of the factorial operators on positive and negative floating point
(DOUBLE PRECISION) numbers as well as integers. For example:
=> SELECT 4.98!;
?column?
-----------------115.978600750905
(1 row)
Factorial is defined in term of the gamma function, where (-1) = Infinity and the other negative
integers are undefined. For example:
(4)! = NaN
! = (4!) = 24
Factorial is defined as z! = gamma(z+1) for all complex numbers z. See the Handbook of
Mathematical Functions (1964) Section 6.1.5.
NULL Operators
To check whether a value is or is not NULL, use the constructs:
expression IS NULL expression IS NOT NULL
Do not write expression = NULL because NULL represents an unknown value, and two unknown
values are not necessarily equal. This behavior conforms to the SQL standard.
Page 93 of 1873
SQLReference Manual
SQL Language Elements
Note: Some applications might expect that expression = NULL returns true if expression
evaluates to null. HP Vertica strongly recommends that these applications be modified to
comply with the SQL standard.
Syntax
string || string
Parameters
string
Notes
l
|| is used to concatenate expressions and constants. The expressions are cast to VARCHAR if
possible, otherwise to VARBINARY, and must both be one or the other.
Two consecutive strings within a single SQL statement on separate lines are automatically
concatenated
Examples
The following example is a single string written on two lines:
=> SELECT E'xx'-> '\\';
?column?
---------xx\
(1 row)
Page 94 of 1873
SQLReference Manual
SQL Language Elements
Page 95 of 1873
SQLReference Manual
SQL Language Elements
Expressions
SQL expressions are the components of a query that compare a value or values against other
values. They can also perform calculations. Expressions found inside any SQL command are
usually in the form of a conditional statement.
Operator Precedence
The following table shows operator precedence in decreasing (high to low) order.
Note: When an expression includes more than one operator, HP recommends that you specify
the order of operation using parentheses, rather than relying on operator precedence.
left
::
left
typecast
[ ]
left
right
unary minus
left
exponentiation
* / %
left
+ -
left
addition, subtraction
IS
IN
set membership
BETWEEN
range containment
OVERLAPS
LIKE
< >
right
equality, assignment
NOT
right
logical negation
Page 96 of 1873
SQLReference Manual
SQL Language Elements
left
logical conjunction
OR
left
logical disjunction
A CASE construct used in this fashion defeats optimization attempts, so use it only when
necessary. (In this particular example, it would be best to avoid the issue by writing y > 1.5*x
instead.)
Aggregate Expressions
An aggregate expression represents the application of an aggregate function across the rows or
groups of rows selected by a query.
Using AVG() as an example, the syntax of an aggregate expression is one of the following:
l
Invokes the aggregate across all input rows for which the given expression yields a non-null
value:
AVG (expression)
Page 97 of 1873
SQLReference Manual
SQL Language Elements
Invokes the AVG() function across all input rows for all distinct, non-null values of the
expression, where expression is any value expression that does not itself contain an aggregate
expression.
AVG (DISTINCT expression)
An aggregate expression only can appear in the select list or HAVING clause of a SELECT statement.
It is forbidden in other clauses, such as WHERE, because those clauses are evaluated before the
results of aggregates are formed.
CASE Expressions
The CASE expression is a generic conditional expression that can be used wherever an expression
is valid. It is similar to case and if/then/else statements in other languages.
Syntax (form 1)
CASE
WHEN condition THEN result
[ WHEN condition THEN result ]
...
[ ELSE result ]
END
Parameters
condition
result
ELSE result
If no condition is true then the value of the CASE expression is the result in the
ELSE clause. If the ELSE clause is omitted and no condition matches, the result is
null.
Syntax (form 2)
CASE expression
WHEN value THEN result
[ WHEN value THEN result ]
...
Page 98 of 1873
SQLReference Manual
SQL Language Elements
[ ELSE result ]
END
Parameters
expression
An expression that is evaluated and compared to all the value specifications in the
WHEN clauses until one is found that is equal.
value
result
Specifies the value to return when the expression is equal to the specified value.
ELSE result
Specifies the value to return when the expression is not equal to any value; if no
ELSE clause is specified, the value returned is null.
Notes
The data types of all the result expressions must be convertible to a single output type.
Examples
The following examples show two uses of the CASE statement.
=> SELECT * FROM test;
a
--1
2
3
=> SELECT a,
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END
FROM test;
a | case
---+------1 | one
2 | two
3 | other
=> SELECT a,
CASE a WHEN 1 THEN 'one'
WHEN 2 THEN 'two'
ELSE 'other'
END
FROM test;
a | case
---+------1 | one
Page 99 of 1873
SQLReference Manual
SQL Language Elements
2 | two
3 | other
Special Example
A CASE expression does not evaluate subexpressions that are not needed to determine the result.
You can use this behavior to avoid division-by-zero errors:
=> SELECT x FROM T1 WHERE
CASE WHEN x <> 0 THEN y/x > 1.5
ELSE false
END;
Column References
Syntax
[ [ [db-name.]schema. ] tablename. ] columnname
Parameters
[ [db-name.]schema. ]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that
are not unique within the current search path. (See Setting Search
Paths.)
tablename.
columnname
Is one of:
l
Is the name of a column that must be unique across all the tables being
used in a query
Notes
There are no space characters in a column reference.
If you do not specify a schema, HP Vertica searches the existing schemas according to the order
defined in the SET SEARCH_PATH command.
SQLReference Manual
SQL Language Elements
Example
This example uses the schema from the VMart database. See Introducing the VMart Example
Database.
In the following command, transaction_type and transaction_time are the unique column
references, store is the name of the schema, and store_sales_fact is the table name:
=> SELECT transaction_type, transaction_time
FROM store.store_sales_fact
ORDER BY transaction_time;
transaction_type | transaction_time
------------------+-----------------purchase
| 00:00:23
purchase
| 00:00:32
purchase
| 00:00:54
purchase
| 00:00:54
purchase
| 00:01:15
purchase
| 00:01:30
purchase
| 00:01:50
return
| 00:03:34
return
| 00:03:35
purchase
| 00:03:39
purchase
| 00:05:13
purchase
| 00:05:20
purchase
| 00:05:23
purchase
| 00:05:27
purchase
| 00:05:30
purchase
| 00:05:35
purchase
| 00:05:35
purchase
| 00:05:42
return
| 00:06:36
purchase
| 00:06:39
(20 rows)
Comments
A comment is an arbitrary sequence of characters beginning with two consecutive hyphen
characters and extending to the end of the line. For example:
-- This is a standard SQL comment
A comment is removed from the input stream before further syntax analysis and is effectively
replaced by white space.
Alternatively, C-style block comments can be used where the comment begins with /* and extends
to the matching occurrence of */.
/* multiline comment
SQLReference Manual
SQL Language Elements
These block comments nest, as specified in the SQL standard. Unlike C, you can comment out
larger blocks of code that might contain existing block comments.
Date/Time Expressions
HP Vertica uses an internal heuristic parser for all date/time input support. Dates and times are
input as strings, and are broken up into distinct fields with a preliminary determination of what kind
of information might be in the field. Each field is interpreted and either assigned a numeric value,
ignored, or rejected. The parser contains internal lookup tables for all textual fields, including
months, days of the week, and time zones.
The date/time type inputs are decoded using the following procedure.
l
Break the input string into tokens and categorize each token as a string, time, time zone, or
number.
If the numeric token contains a colon (:), this is a time string. Include all subsequent digits and
colons.
If the numeric token contains a dash (-), slash (/), or two or more dots (.), this is a date string
which might have a text month.
If the token is numeric only, then it is either a single field or an ISO 8601 concatenated date (for
example, 19990113 for January 13, 1999) or time (for example, 141516 for 14:15:16).
If the token starts with a plus (+) or minus (), then it is either a time zone or a special field.
Do a binary-search table lookup for the token as either a special string (for example, today), day
(for example, Thursday), month (for example, January), or noise word (for example, at, on).
Set field values and bit mask for fields. For example, set year, month, day for today, and
additionally hour, minute, second for now.
If not found, do a similar binary-search table lookup to match the token with a time zone.
SQLReference Manual
SQL Language Elements
If there are eight or six digits, and if no other date fields have been previously read, then interpret
as a "concatenated date" (for example, 19990118 or 990118). The interpretation is YYYYMMDD or
YYMMDD.
If the token is three digits and a year has already been read, then interpret as day of year.
If four or six digits and a year has already been read, then interpret as a time (HHMM or HHMMSS).
If three or more digits and no date fields have yet been found, interpret as a year (this forces yymm-dd ordering of the remaining date fields).
Otherwise the date field ordering is assumed to follow the DateStyle setting: mm-dd-yy, ddmm-yy, or yy-mm-dd. Throw an error if a month or day field is found to be out of range.
If BC has been specified, negate the year and add one for internal storage. (There is no year zero
in the our implementation, so numerically 1 BC becomes year zero.)
If BC was not specified, and if the year field was two digits in length, then adjust the year to four
digits. If the field is less than 70, then add 2000, otherwise add 1900.
Tip: Gregorian years AD 199 can be entered by using 4 digits with leading zeros (for example,
0099 is AD 99).
Description
epoch
DATE, TIMESTAMP
SQLReference Manual
SQL Language Elements
String
Description
INFINITY
TIMESTAMP
-INFINITY
TIMESTAMP
NOW
TODAY
DATE, TIMESTAMP
Midnight today
TOMORROW
DATE, TIMESTAMP
Midnight tomorrow
YESTERDAY
DATE, TIMESTAMP
Midnight yesterday
ALLBALLS
TIME
00:00:00.00 UTC
The following SQL-compatible functions can also be used to obtain the current time value for the
corresponding data type:
l
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
LOCALTIME
LOCALTIMESTAMP
The latter four accept an optional precision specification. (See Date/Time Functions.) However,
these functions are SQL functions and are not recognized as data input strings.
NULL Value
NULL is a reserved keyword used to indicate that a data value is unknown.
Be very careful when using NULL in expressions. NULL is not greater than, less than, equal to, or not
equal to any other expression. Use the Boolean-Predicate for determining whether an expression
value is NULL.
SQLReference Manual
SQL Language Elements
Notes
l
HP Vertica stores data in projections, which are sorted in a specific way. All columns are
stored in ASC (ascending) order. For columns of data type NUMERIC, INTEGER, DATE, TIME,
TIMESTAMP, and INTERVAL, NULL values are placed at the beginning of sorted projections (NULLS
FIRST), while for columns of data type FLOAT, STRING, and BOOLEAN, NULL values are placed at
the end (NULLS LAST). For details, see Analytics Null Placement and Minimizing Sort
Operations in the Analyzing Data Guide.
HP Vertica also accepts NUL characters ('\0') in constant strings and no longer removes null
characters from VARCHAR fields on input or output. NUL is the ASCII abbreviation for the NULL
character.
You can write queries with expressions that contain the <=> operator for NULL=NULL joins. See
Equi-joins and Non Equi-Joins in the Analyzing Data Guide.
See Also
l
NULL-handling Functions
Numeric Expressions
HP Vertica follows the IEEE specification for floating point, including NaN.
A NaN is not greater than and at the same time not less than anything, even itself. In other words,
comparisons always return false whenever a NaN is involved.
Examples
=> SELECT CBRT('Nan'); -- cube root
CBRT
-----NaN
(1 row)
=> SELECT 'Nan' > 1.0;
?column?
---------f
(1 row)
SQLReference Manual
SQL Language Elements
Predicates
Predicates are truth-tests. If the predicate test is true, it returns a value. Each predicate is
evaluated per row, so that when the predicate is part of an entire table SELECT statement, the
statement can return multiple results.
Predicates consist of a set of parameters and arguments. For example, in the following example
WHERE clause:
WHERE name = 'Smith';
l
'Smith' is an expression
BETWEEN-predicate
The special BETWEEN predicate is available as a convenience.
Syntax
WHERE a BETWEEN x AND y
Examples
WHERE a BETWEEN x AND y
is equivalent to:
WHERE a >= x AND a <= y
Similarly:
WHERE a NOT BETWEEN x AND y
is equivalent to:
WHERE a < x OR a > y
SQLReference Manual
SQL Language Elements
=> COPY t1
Enter data
End with a
>> 1 | 2 |
>> 2 | 3 |
>> 3 | 4 |
>> 4 | 5 |
>> 5 | 6 |
>> 6 | 7 |
>> 7 | 8 |
>> 8 | 9 |
>> \.
You can also use the NOWandINTERVALkeywords to select from a date range:
=> SELECT * FROM t1 WHERE c3 BETWEEN NOW()-INTERVAL '1 week' AND NOW();
c1 | c2 |
c3
----+----+-----------7 | 8 | 2014-08-01
1 | 2 | 2014-07-26
2 | 3 | 2014-07-27
3 | 4 | 2014-07-28
4 | 5 | 2014-07-29
5 | 6 | 2014-07-30
6 | 7 | 2014-07-31
(7 rows)
Boolean-Predicate
Retrieves rows where the value of an expression is true, false, or unknown (null).
Syntax
expression IS [NOT] TRUE
expression IS [NOT] FALSE
expression IS [NOT] UNKNOWN
SQLReference Manual
SQL Language Elements
Notes
l
IS UNKNOWN and IS NOT UNKNOWN are effectively the same as the NULL-predicate, except that
the input expression does not have to be a single column value. To check a single column value
for NULL, use the NULL-predicate.
Do not confuse the boolean-predicate with Boolean Operators or the Boolean data type, which
can have only two values: true and false.
Column-Value-Predicate
Syntax
column-name comparison-op constant-expression
Parameters
column-name
comparison-op
A Comparison Operators.
constant-expression
Notes
To check a column value for NULL, use the NULL-predicate.
Examples
table.column1 = 2
table.column2 = 'Seafood'
table.column3 IS NULL
IN-predicate
Syntax
column-expression [ NOT ] IN ( list-expression )
SQLReference Manual
SQL Language Elements
Parameters
column-expression
One or more columns from the tables specified in the FROM Clause.
list-expression
Examples
x, y IN ((1,2), (3, 4)), OR x, y IN
(SELECT a, b FROM table)x IN (5, 6, 7)
INTERPOLATE
Used to join two event series together using some ordered attribute, event series joins let you
compare values from two series directly, rather than having to normalize the series to the same
measurement interval.
Syntax
expression1 INTERPOLATE PREVIOUS VALUE expression2
Parameters
expression1expression2
PREVIOUS VALUE
Pads the non-preserved side with the previous values from relation
when there is no match.
Input rows are sorted in ascending logical order of the join column.
Note: An ORDER BY clause, if used, does not determine the input
order but only determines query output order.
SQLReference Manual
SQL Language Elements
Notes
l
An event series join is an extension of a regular outer join. Instead of padding the non-preserved
side with null values when there is no match, the event series join pads the non-preserved side
with the previous values from the table.
The difference between expressing a regular outer join and an event series join is the
INTERPOLATE predicate, which is used in the ON clause. See the Examples section below
Notes and Restrictions. See also Event Series Joins in the Analyzing Data Guide.
Data is logically partitioned on the table in which it resides, based on other ON clause equality
predicates.
Interpolated values come from the table that contains the null, not from the other table.
HP Vertica does not guarantee that there will be no null values in the output. If there is no
previous value for a mismatched row, that row will be padded with nulls.
Event series join requires that both tables be sorted on columns in equality predicates, in any
order, followed by the INTERPOLATED column. If data is already sorted in this order, then an
explicit sort is avoided, which can improve query performance. For example, given the following
tables:
ask: exchange, stock, ts, pricebid: exchange,
stock, ts, price
SQLReference Manual
SQL Language Elements
Restrictions
l
INTERPOLATE expressions are used only with ANSI SQL-99 syntax (the ON clause), which is
already true for full outer joins.
The AND operator is supported but not the OR and NOT operators.
Expressions and implicit or explicit casts are not supported, but subqueries are allowed.
Example
The examples that follow use this simple schema.
CREATE TABLE t(x TIME);
CREATE TABLE t1(y TIME);
INSERT INTO t VALUES('12:40:23');
INSERT INTO t VALUES('14:40:25');
INSERT INTO t VALUES('14:45:00');
INSERT INTO t VALUES('14:49:55');
INSERT INTO t1 VALUES('12:40:23');
INSERT INTO t1 VALUES('14:00:00');
COMMIT;
SQLReference Manual
SQL Language Elements
In this case, the rows with no entry point are padded with values from the previous row.
x
|
y
----------+---------12:40:23 | 12:40:23
12:40:23 | 14:00:00
14:40:25 | 14:00:00
14:45:00 | 14:00:00
14:49:55 | 14:00:00
(5 rows)
Inner Joins
For inner joins, there is no difference between a regular inner join and an event series inner join.
Since null values are eliminated from the result set, there is nothing to interpolate.
SQLReference Manual
SQL Language Elements
A regular inner join returns only the single matching row at 12:40:23:
=> SELECT * FROM t INNER JOIN t1 ON t.x = t1.y;
x
|
y
----------+---------12:40:23 | 12:40:23
(1 row)
An event series inner join finds the same single-matching row at 12:40:23:
=> SELECT * FROM t INNER JOIN t1 ON t.x INTERPOLATE
PREVIOUS VALUE t1.y;
x
|
y
----------+---------12:40:23 | 12:40:23
(1 row)
Semantics
When you write an event series join in place of normal join, values are evaluated as follows (using
the schema in the above examples):
l
For each row in outer table t, the ON clause predicates are evaluated for each combination of
each row in the inner table t1.
If the ON clause predicates evaluate to true for any combination of rows, those combination
the row from t along with the columns of t1 chosen from the row in t1 with the greatest t1.y
value such that t1.y < t.x; If no such row is found, pad with nulls.
See Also
l
SQLReference Manual
SQL Language Elements
Join-Predicate
Combines records from two or more tables in a database.
Syntax
column-reference
= column-reference
Parameters
column-reference
LIKE-predicate
Retrieves rows where the string value of a column matches a specified pattern. The pattern can
contain one or more wildcard characters. ILIKE is equivalent to LIKE except that the match is caseinsensitive (non-standard extension).
Syntax
string [ NOT ]{ LIKE | ILIKE | LIKEB | ILIKEB }
... pattern
[ESCAPE 'escape-character' ]
Parameters
string
NOT
Returns true if LIKE returns false, and the reverse; equivalent to NOT string
LIKE pattern.
pattern
SQLReference Manual
SQL Language Elements
ESCAPE
escape-character
Notes
l
In the default locale, LIKE and ILIKE handle UTF-8 character-at-a-time, locale-insensitive
comparisons. ILIKE handles language-independent case-folding.
The LIKEB and ILIKEB predicates do byte-at-a-time ASCII comparisons, providing access to
HP Vertica 4.0 functionality.
LIKE and ILIKE are stable for character strings, but immutable for binary strings, while LIKEB
and ILIKEB are both immutable.
For collation=binary settings, the behavior is similar to HP Vertica 4.0. For other collations,
LIKE operates on UTF-8 character strings, with the exact behavior dependent on collation
parameters, such as strength. In particular, ILIKE works by setting S=2 (ignore case) in the
current session locale. See Locale Specification in the Administrator's Guide.
Although the SQL standard specifies no default ESCAPE character, in HP Vertica the default is
the backslash (\) and works for CHAR and VARCHAR strings only.
Tip: HP recommends that you specify an explicit escape character in all cases, to avoid
problems should this behavior change. To use a backslash character as a literal, either
SQLReference Manual
SQL Language Elements
ESCAPE expressions evaluate to exactly one octetor one UTF-8 character for non-default
locales.
An ESCAPE character can be used only to escape itself, _, and %. This is enforced only for nondefault collations.
LIKE requires that the entire string expression match the pattern. To match a sequence of
characters anywhere within a string, the pattern must start and end with a percent sign.
The LIKE predicate does not ignore trailing "white space" characters. If the data values that you
want to match have unknown numbers of trailing spaces, tabs, etc., terminate each LIKE
predicate pattern with the percent sign wildcard character.
To use binary data types, you must use a valid binary character as the escape character, since
backslash is not a valid BINARY character.
LIKE
LIKEB
ILIKE
ILIKEB
NOT LIKE
NOT LIKEB
NOT ILIKE
NOT IILIKEB
HP Vertica extends support for single-row subqueries as the pattern argument for LIKEB and
ILIKEB; for example:
SELECT * FROM t1 WHERE t1.x LIKEB (SELECT MAX (t2.a)
FROM t2);
SQLReference Manual
SQL Language Elements
Tip: Use the case-insensitive ILIKE predicate to return the expected results.
Examples
'abc' LIKE 'abc' true'abc' LIKE 'a%'
'abc' LIKE '_b_' true
'abc' LIKE 'c'
false
'abc' LIKE 'ABC' false
'abc' ILIKE 'ABC' true
'abc' not like 'abc' false
not 'abc' like 'abc' false
true
Querying the src table in the default locale returns both ss and sharp s.
=> SELECT * FROM src;
c1
---
ss
(2 rows)
The following query combines pattern-matching predicates to return the results from column c1:
=> SELECT c1, c1 = 'ss' AS equality, c1 LIKE 'ss'
SQLReference Manual
SQL Language Elements
Now change the locale to German with a strength of 1 (ignore case and accents):
\locale LDE_S1
=> SELECT c1, c1 = 'ss' AS equality,
c1 LIKE 'ss' as LIKE, c1 ILIKE 'ss' AS ILIKE from src;
c1 | equality | LIKE | ILIKE
----+----------+------+------ | t
| t
| t
ss | t
| t
| t
(2 rows)
SQLReference Manual
SQL Language Elements
c
| ?column? | ?column? | ?column?
------+----------+----------+---------\000 | f
| f
| f
\377 | t
| t
| t
(2 rows)
NULL-predicate
Tests for null values.
Syntax
value_expression IS [ NOT ] NULL
Parameters
value_expression
Examples
Column name:
=> SELECT date_key FROM date_dimension WHERE date_key IS NOT NULL;
date_key
---------1
366
1462
1097
2
3
6
7
8
...
Function:
=> SELECT MAX(household_id) IS NULL FROM customer_dimension;
?column?
---------f
(1 row)
Literal:
SQLReference Manual
SQL Language Elements
See Also
l
NULL Value
SQLReference Manual
SQL Data Types
Description
NULL
Sorting
BINARY
1 to 65000
NULLS LAST
VARBINARY
1 to 65000
NULLS LAST
LONG VARBINARY
1 to
NULLS LAST
NULLS LAST
Type
Binary types
32,000,000
BYTEA
1 to 65000
VARBINARY)
RAW
1 to 65000
NULLS LAST
VARBINARY)
Boolean types
BOOLEAN
NULLS LAST
CHAR
1 to 65000
NULLS LAST
VARCHAR
1 to 65000
NULLS LAST
LONG VARCHAR
1 to
NULLS LAST
Character types
32,000,000
Date/time types
DATE
NULLS FIRST
DATETIME
NULLS FIRST
NULLS FIRST
SQLReference Manual
SQL Data Types
Type
Size
(bytes)
Description
NULL
Sorting
TIME
NULLS FIRST
TIME WITHTIMEZONE
NULLS FIRST
TIMESTAMP
NULLS FIRST
timezone
TIMESTAMP WITHTIMEZONE
NULLS FIRST
INTERVAL
NULLS FIRST
points in time
Approximate numeric types
DOUBLE PRECISION
NULLS LAST
NULLS LAST
NULLS LAST
NULLS LAST
NULLS LAST
NULLS FIRST
storage
INT
NULLS FIRST
storage
BIGINT
NULLS FIRST
storage
INT8
NULLS FIRST
storage
SQLReference Manual
SQL Data Types
Type
Size
(bytes)
Description
NULL
Sorting
SMALLINT
NULLS FIRST
storage
TINYINT
NULLS FIRST
DECIMAL
8+
NULLS FIRST
NUMERIC
8+
NULLS FIRST
NUMBER
8+
NULLS FIRST
MONEY
8+
NULLS FIRST
Syntax
BINARY ( length ){ VARBINARY | BINARY VARYING | BYTEA | RAW } ( max-length )
Parameters
length | max-length
Specifies the length of the string (column width, declared in bytes (octets),
in CREATE TABLE statements).
Notes
l
The data types BINARY and BINARY VARYING (VARBINARY) are collectively referred to as binary
string types and the values of binary string types are referred to as binary strings.
SQLReference Manual
SQL Data Types
A binary string is a sequence of octets, or bytes. Binary strings store raw-byte data, while
character strings store text.
The binary data types, BINARY and VARBINARY, are similar to the Character Data Types, CHAR
and VARCHAR, respectively, except that binary data types contain byte strings, rather than
character strings.
BINARYA fixed-width string of length bytes, where the number of bytes is declared as an
optional specifier to the type. If length is omitted, the default is 1. Where necessary, values are
right-extended to the full width of the column with the zero byte. For example:
=> SELECT TO_HEX('ab'::BINARY(4));
to_hex
---------61620000
You can use several formats when working with binary values, but the hexadecimal format is
generally the most straightforward and is emphasized in HP Vertica documentation.
Binary operands &, ~, | and # have special behavior for binary data types, as described in
Binary Operators.
Both functions take a VARCHAR argument and return a VARBINARY value. See the Examples
section below.
SQLReference Manual
SQL Data Types
Binary values can also be represented in octal format by prefixing the value with a backslash
'\'.
Note: If you use vsql, you must use the escape character (\) when you insert another
backslash on input; for example, input '\141' as '\\141'.
You can also input values represented by printable characters. For example, the hexadecimal
value '0x61' can also be represented by the symbol '.
See Bulk Loading Data in the Administrator's Guide.
l
Like the input format the output format is a hybrid of octal codes and printable ASCII characters.
A byte in the range of printable ASCII characters (the range [0x20, 0x7e]) is represented by
the corresponding ASCII character, with the exception of the backslash ('\'), which is escaped
as '\\'. All other byte values are represented by their corresponding octal values. For example,
the bytes {97,92,98,99}, which in ASCII are {a,\,b,c}, are translated to text as 'a\\bc'.
The following aggregate functions are supported for binary data types:
n
BIT_AND
BIT_OR
BIT_XOR
MAX
MIN
BIT_AND, BIT_OR, and BIT_XOR are bitwise operations that are applied to each non-null value in a
group, while MAX and MIN are bytewise comparisons of binary values.
l
Like their binary operator counterparts, if the values in a group vary in length, the aggregate
functions treat the values as though they are all equal in length by extending shorter values with
zero bytes to the full width of the column. For example, given a group containing the values
'ff', null, and 'f', a binary aggregate ignores the null value and treats the value 'f' as
'f0'. Also, like their binary operator counterparts, these aggregate functions operate on
VARBINARY types explicitly and operate on BINARY types implicitly through casts. See Data Type
Coercion Operators (CAST).
SQLReference Manual
SQL Data Types
Examples
The following example shows VARBINARY HEX_TO_BINARY(VARCHAR) and VARCHAR TO_HEX
(VARBINARY) usage.
Table t and and its projection are created with binary columns:
=> CREATE TABLE t (c BINARY(1));
=> CREATE PROJECTION t_p (c) AS SELECT c FROM t;
Binary values can then be formatted in hex on output using the TO_HEX function:
=> SELECT TO_HEX(c) FROM t;
to_hex
-------00
ff
(2 rows)
The BIT_AND, BIT_OR, and BIT_XORfunctions are interesting when operating on a group of values.
For example, create a sample table and projections with binary columns:
This example uses the following schema, which creates table t with a single column of VARBINARY
data type:
=>
=>
=>
=>
CREATE
INSERT
INSERT
INSERT
TABLE t ( c VARBINARY(2) );
INTO t values(HEX_TO_BINARY('0xFF00'));
INTO t values(HEX_TO_BINARY('0xFFFF'));
INTO t values(HEX_TO_BINARY('0xF00F'));
Now issue the bitwise AND operation. Because these are aggregate functions, an implicit GROUP
BY operation is performed on results using (ff00&(ffff)&f00f):
SQLReference Manual
SQL Data Types
See Also
l
BIT_AND
BIT_OR
BIT_XOR
MAX [Aggregate]
MIN [Aggregate]
Binary Operators
COPY
INET_ATON
INET_NTOA
V6_ATON
SQLReference Manual
SQL Data Types
V6_NTOA
V6_SUBNETA
V6_SUBNETN
V6_TYPE
BITCOUNT
BITSTRING_TO_BINARY
HEX_TO_BINARY
LENGTH
REPEAT
SUBSTRING
TO_HEX
TO_BITSTRING
Syntax
BOOLEAN
Parameters
Valid literal data values for input are:
TRUE
't'
'true'
'y'
'yes'
'1'
FALSE
'f'
'false'
'n'
'no'
'0'
SQLReference Manual
SQL Data Types
Notes
l
Do not confuse the BOOLEAN data type with Boolean Operators or the Boolean-Predicate.
The keywords TRUE and FALSE are preferred and are SQL-compliant.
See Also
l
NULL Value
Syntax
[ CHARACTER | CHAR ] ( octet_length )[ VARCHAR | CHARACTER VARYING ] ( octet_length )
Parameters
octet_length
Specifies the length of the string (column width, declared in bytes (octets), in
CREATE TABLE statements).
Notes
l
The data types CHARACTER (CHAR) and CHARACTER VARYING (VARCHAR) are collectively referred to
as character string types, and the values of character string types are known as character
strings.
SQLReference Manual
SQL Data Types
CHAR is conceptually a fixed-length, blank-padded string. Any trailing blanks (spaces) are
removed on input, and only restored on output. The default length is 1, and the maximum length
is 65000 octets (bytes).
VARCHAR is a variable-length character data type. The default length is 80, and the maximum
length is 65000 octets. Values can include trailing spaces.
When you define character columns, specify the maximum size of any string to be stored in a
column. For example, to store strings up to 24 octets in length, use either of the following
definitions:
CHAR(24)
The maximum length parameter for VARCHAR and CHAR data type refers to the number of octets
that can be stored in that field, not the number of characters (Unicode code points). When using
multibyte UTF-8 characters, the fields must be sized to accommodate from 1 to 4 octets per
character, depending on the data. If the data loaded into a VARCHAR/CHAR column exceeds the
specified maximum size for that column, data is truncated on UTF-8 character boundaries to fit
within the specified size. See COPY.
Note: Remember to include the extra octets required for multibyte characters in the columnwidth declaration, keeping in mind the 65000 octet column-width limit.
Due to compression in HP Vertica, the cost of overestimating the length of these fields is
incurred primarily at load time and during sorts.
NULL appears last (largest) in ascending order. See also GROUP BY Clause for additional
information about NULL ordering.
SQLReference Manual
SQL Data Types
See Also
l
SQLReference Manual
SQL Data Types
Name
Description
Low Value
High Value
Resolut
ion
DATE
Dates only
(no time of
day)
~ 25e+15 BC
~ 25e+15 AD
1 day
TIME [(p]
Time of day
only
(no date)
00:00:00.00
23:59:60.999999
1 s
TIMETZ [(p)]
Time of day
only,
with time
zone
00:00:00.00+14
23:59:59.999999-14
1 s
TIMESTAMP [(p)]
290279-12-22
19:59:05.224194 BC
294277-01-09
04:00:54:775806 AD
1 s
TIMESTAMPTZ [(p)]
290279-12-22
19:59:05.224194 BC UTC
294277-01-09
04:00:54:775806 AD UTC
1 s
INTERVAL [(p)]DAY
TO SECOND
+-106751991 days
04:00:54.775807
1 s
INTERVAL [(p)]YEAR
TO MONTH
~ 768e15 yrs
1 month
SQLReference Manual
SQL Data Types
Notes
l
HP Vertica uses Julian dates for all date/time calculations, which can correctly predict and
calculate any date more recent than 4713 BC to far into the future, based on the assumption that
the average length of the year is 365.2425 days.
All the date/time data types accept the special literal value NOW to specify the current date and
time. For example:
=> SELECT TIMESTAMP 'NOW';
?column?
---------------------------2012-03-13 11:42:22.766989
(1 row)
interval qualifiers, that divide the INTERVAL type into two primary subtypes, DAY TO SECOND
(the default) and YEAR TO MONTH. You use the SET INTERVALSTYLE command to change the
intervalstyle run-time parameter for the current session.
Intervals are represented internally as some number of microseconds and printed as up to 60
seconds, 60 minutes, 24 hours, 30 days, 12 months, and as many years as necessary. Fields
can be positive or negative.
See Also
l
TZ Environment Variable
DATE
Consists of a month, day, and year.
SQLReference Manual
SQL Data Types
Syntax
DATE
Parameters/Limits
Low Value
~ 25e+15 BC
~ 25e+15 AD
1 DAY
Description
January 8, 1999
1999-01-08
1/8/1999
1/18/1999
01/02/03
1999-Jan-08
Jan-08-1999
08-Jan-1999
99-Jan-08
08-Jan-99
Jan-08-99
19990108
990108
1999.008
J2451187
Julian day
SQLReference Manual
SQL Data Types
Example
Description
January 8, 99 BC
DATETIME
DATETIME is an alias for TIMESTAMP.
INTERVAL
Measures the difference between two points in time. The INTERVAL data type is divided into two
major subtypes:
l
A day/time interval represents a span of days, hours, minutes, seconds, and fractional seconds. A
year/month interval represents a span of years and months. Intervals can be positive or negative.
Syntax
INTERVAL [ (p) ] [ - ] 'Interval-Literal' [ Interval-Qualifier ]
Parameters
(p)
[Optional] Specifies the precision for the number of digits retained in the
seconds field. Enter the precision value in parentheses (). The interval
precision can range from 0 to 6. The default is 6.
'interval-literal'
interval-qualifier
SQLReference Manual
SQL Data Types
Limits
Name
Low Value
High Value
Resolution
106751991 days
+/106751991 days
1 microsecond
04:00:54.775807
04:00:54.775807
~/ 768e15 yrs
~ 768e15 yrs
1 month
When INTERVALSTYLE is set to PLAIN, units are omitted from the output, even if you specify the
units in the query:
=> SELECT INTERVAL '3 days 2 hours';
?column?
---------3 02:00
When INTERVALSTYLE is set to UNITS to display units in the result, the DATESTYLE setting controls
the format of the units in the output.
SQLReference Manual
SQL Data Types
If you set DATESTYLE to SQL, interval units are omitted from the output, even if you set
INTERVALSTYLE to UNITS:
=> SET INTERVALSTYLE TO UNITS;
SET
=> SET DATESTYLE TO SQL;
SET
=> SELECT INTERVAL '3 2';
?column?
---------3 02:00
The following command uses the same interval-literal as the previous example, but specifies a
MINUTE interval-qualifier to so that the results are displayed only in minutes:
=> SELECT INTERVAL '3 days 2 hours' MINUTE;
?column?
-----------
SQLReference Manual
SQL Data Types
4440 mins
HP Vertica allows combinations of units in the interval-qualifier, as in the next three examples:
=> SELECT INTERVAL '1 second 1 millisecond' DAY TO SECOND;
?column?
-------------1.001 secs
=> SELECT INTERVAL '28 days 3 hours 65 min' HOUR TO MINUTE;
?column?
----------676 hours 5 mins
Units less than a month are not valid for YEAR TO MONTH interval-qualifiers:
=> SELECT INTERVAL '1 Y 30 DAYS' YEAR TO MONTH;
ERROR: invalid input syntax for type interval year to month: "1 Y 30 DAYS"
If you replace DAYS in the interval-literal with M to represent months, HP Vertica returns the correct
information of 1 year, 3 months:
=> SELECT INTERVAL '1 Y 3 M' YEAR TO MONTH;
?column?
---------1 year 3 months
in the previous example, M was used as the interval-literal, representing months. If you specify a
DAY TO SECOND interval-qualifier, HP Vertica knows that M represents minutes, as in the following
example:
=> SELECT INTERVAL '1 D 3 M' DAY TO SECOND;
?column?
---------1 day 3 mins
The next two examples use units in the input to return microseconds:
=> SELECT INTERVAL '4:5 1 2 34us';
?column?
------------------1 day 04:05:02.000034
=> SELECT INTERVAL '4:5 1d 2 34us' HOUR TO SECOND;
?column?
----------------28 hours 5 mins 2.000034 secs
SQLReference Manual
SQL Data Types
However, if you change the interval-qualifier to YEAR TO MONTH, you get the following results:
=> SELECT INTERVAL '2 years 6 months' YEAR TO MONTH;
?column?
----------------2 years 6 months
An interval-qualifier can extract other values from the input parameters. For example, the following
command extracts the HOUR value from the input parameters:
=> SELECT INTERVAL '3 days 2 hours' HOUR;
?column?
---------74 hours
When specifying intervals that use subtype YEAR TO MONTH, the returned value is kept as months:
=> SELECT INTERVAL '2 years 6 months' YEAR TO MONTH;
?column?
----------2 years 6 months
The primary day/time (DAY TO SECOND) and year/month (YEAR TO MONTH) subtype ranges can be
restricted to more specific range of types by an interval-qualifier. For example, HOUR TO MINUTE is
a limited form of day/time interval, which can be used to express time zone offsets.
=> SELECT INTERVAL '1 3' HOUR to MINUTE;
?column?
SQLReference Manual
SQL Data Types
--------------01:03
The formats hh:mm:ss and hh:mm are used only when at least two of the fields specified in the
interval-qualifier are non-zero and there are no more than 23 hours or 59 minutes:
=> SELECT INTERVAL '2 days 12 hours 15 mins' DAY TO MINUTE;
?column?
-------------2 days 12:15
=> SELECT INTERVAL '15 mins 20 sec' MINUTE TO SECOND;
?column?
---------00:15:20
=> SELECT INTERVAL '1 hour 15 mins 20 sec' MINUTE TO SECOND;
?column?
----------------75 mins 20 secs
Specifying Precision
SQL:2008 allows you to specify precision for the interval output by entering the precision value in
parentheses after the INTERVAL keyword or the interval-qualifier. HP Vertica rounds the input to the
number of decimal places specified. SECOND(2) and SECOND (2) produce the same result:
If you specify two different precisions, HP Vertica picks the lesser of the two:
=> SELECT INTERVAL(1) '1.2467' SECOND(2);
?column?
---------1.2 secs
When you specify a precision inside an interval-literal, HP Vertica processes the precision by
removing the parentheses. In this example, (3) is processed as 3 minutes, the first omitted field:
=> SELECT INTERVAL '28 days 3 hours 1.234567 second(3)';
?column?
-------------------28 days 03:03:01.234567
The following command specifies that the day field can hold 4 digits, the hour field 2 digits, the
minutes field 2 digits, the seconds field 2 digits, and the fractional seconds field 6 digits:
=> SELECT INTERVAL '1000 12:00:01.123456' DAY(4) TO SECOND(6);
?column?
--------------------------1000 days 12:00:01.123456
SQLReference Manual
SQL Data Types
AN HP Vertica extension lets you specify the seconds precision on the INTERVAL keyword. The
result is the same:
=> SELECT INTERVAL(6) '1000 12:00:01.123456' DAY(4) TO SECOND;
1000 days 12:00:01.123456
You can cast intervals within the day/time or the year/month subtypes but not between them. Use
CAST to convert interval types:
=> SELECT CAST(INTERVAL '4440' MINUTE as INTERVAL);
?column?
---------3 days 2 hours
=> SELECT CAST(INTERVAL -'01:15' as INTERVAL MINUTE);
?column?
----------75 mins
SQLReference Manual
SQL Data Types
Use one of the following commands instead to return the intended result:
=> SELECT INTERVAL -'1 month 1 second';
?column?
----------30 days 1 sec
=> SELECT INTERVAL -'30 00:00:01';
?column?
----------30 days 1 sec
You can use the year-month syntax with no spaces. HP Vertica allows the input of negative months
but requires two negatives when paired with years.
=> SELECT INTERVAL '3-3' YEAR TO MONTH;
?column?
---------3 years 3 months
=> SELECT INTERVAL '3--3' YEAR TO MONTH;
?column?
---------2 years 9 months
When the interval-literal looks like a year/month type, but the type is day/second, or vice versa, HP
Vertica reads the interval-literal from left to right, where number-number is years-months, and
number <space> <signed number> is whatever the units specify. HP Vertica processes the
following command as () 1 year 1 month = () 365 + 30 = 395 days:
=> SELECT INTERVAL '-1-1' DAY TO HOUR;
?column?
----------395 days
SQLReference Manual
SQL Data Types
If you insert a space in the interval-literal, HP Vertica processes it based on the subtype DAY TO
HOUR: () 1 day 1 hour = () 24 1 = 23 hours:
=> SELECT INTERVAL '-1 -1' DAY TO HOUR;
?column?
----------23 hours
Two negatives together returns a positive, so HP Vertica processes the following command as () 1
year 1 month = () 365 30 = 335 days:
=> SELECT INTERVAL '-1--1' DAY TO HOUR;
?column?
----------335 days
If you omit the value after the hyphen, HP Vertica assumes 0 months and processes the following
command as 1 year 0 month 1 day = 365 + 0 1 = 364 days:
=> SELECT INTERVAL '1- -1' DAY TO HOUR;
?column?
---------364 days
If HP Vertica cannot determine the units, it applies the quantity to any missing units based on the
interval-qualifier. In the next two examples, HP Vertica uses the default interval-qualifier (DAY TO
SECOND(6)) and assigns the trailing 1 to days, since it has already processed hours, minutes, and
seconds in the output:
SQLReference Manual
SQL Data Types
In the next two examples, HP Vertica recognizes 4:5 as hours:minutes. The remaining values in
the interval-literal are assigned to the missing units; 1 is assigned to days and 2 is assigned to
seconds:
SELECT INTERVAL '4:5 1 2';
?column?
-----------1 day 04:05:02
=> SELECT INTERVAL '1 4:5 2';
?column?
-----------1 day 04:05:02
SQLReference Manual
SQL Data Types
If you add INTERVAL and TIME, the result is TIME, modulo 24 hours:
=> SELECT INTERVAL '1' HOUR + TIME '1:30';
?column?
-----------02:30:00
HP Vertica allows fractional minutes. The fractional minutes are rounded into seconds:
=> SELECT INTERVAL '10.5 minutes';
?column?
-----------00:10:30
=> select interval '10.659 minutes';
?column?
------------00:10:39.54
=> select interval '10.3333333333333 minutes';
?column?
---------00:10:20
SQLReference Manual
SQL Data Types
Notes
l
The HP Vertica INTERVAL data type is SQL:2008 compliant, with extensions. On HP Vertica
databases created prior to version 4.0, all INTERVAL columns are interpreted as INTERVAL DAY
TO SECOND, as in the previous releases.
An INTERVAL can include only the subset of units that you need; however, year/month intervals
represent calendar years and months with no fixed number of days, so year/month interval
values cannot include days, hours, minutes. When year/month values are specified for day/time
intervals, the intervals extension assumes 30 days per month and 365 days per year. Since the
length of a given month or year varies, day/time intervals are never output as months or years,
only as days, hours, minutes, and so on.
Day/time and year/month intervals are logically independent and cannot be combined with or
compared to each other. In the following example, an interval-literal that contains DAYS cannot be
combined with the YEAR TO MONTH type:
=> SELECT INTERVAL '1 2 3' YEAR TO MONTH;
ERROR 3679: Invalid input syntax for interval year to month: "1 2 3"
INTERVAL YEAR TO MONTH can be used in an analytic RANGE window when the ORDER BY
column type is TIMESTAMP/TIMESTAMP WITH TIMEZONE, or DATE. Using TIME/TIME WITH
TIMEZONE are not supported.
You can use INTERVAL DAY TO SECOND when the ORDER BY column type is
TIMESTAMP/TIMESTAMP WITH TIMEZONE, DATE, and TIME/TIME WITH TIMEZONE.
Examples
The table in this section contains additional interval examples. The INTERVALSTYLE is set to PLAIN
(omitting units on output) for brevity.
Note: If you omit the Interval-Qualifier, the interval type defaults to DAY TO SECOND(6).
Command
Result
1 17:40
2500
SQLReference Manual
SQL Data Types
Command
Result
2500
675:00
28 03:00
28
03:01:14.074
28
03:00:01.235
675:18
675:21
675:22:12
29:37:46.5888
29:37:46.6656
96
29:37:46.666
29:37:46.67
01:00:01.235
255:01.111
00:05
-00:05
00:05
SQLReference Manual
SQL Data Types
See Also
l
Interval Values
SET INTERVALSTYLE
SET DATESTYLE
AGE_IN_MONTHS
AGE_IN_YEARS
Interval-Literal
The following table lists the units allowed for the required interval-literal parameter.
Unit
Description
ago
c, cent, century
Century
centuries
Centuries
d, day
Day
days
Days
dec, decade
Decade
decades, decs
Decades
h, hour, hr
Hour
hours, hrs
Hours
ka
microsecond
Microsecond
SQLReference Manual
SQL Data Types
Unit
Description
microseconds
Microseconds
mil, millennium
Millennium
millennia, mils
Millennia
millisecond
Millisecond
milliseconds
Milliseconds
min, minute, mm
Minute
mins, minutes
Minutes
mon, month
Month
mons, months
Months
Millisecond
mseconds, msecs
Milliseconds
q, qtr, quarter
Quarter
qtrs, quarters
Quarters
s, sec, second
Second
seconds, secs
Seconds
us, usec
Microsecond
Microseconds
w, week
Week
weeks
Weeks
y, year, yr
Year
years, yrs
Years
SQLReference Manual
SQL Data Types
In the first INSERT statement, the values are inserted as 1 year, six months:
=> INSERT INTO int_test VALUES('1 year 6 months');
The second INSERT statement results in an error from specifying minutes for a YEAR TO MONTH
interval. At runtime, the result will be a NULL:
=> INSERT INTO int_test VALUES('1 year 6 minutes');
ERROR: invalid input syntax for type interval year to month: "1 year 6 minutes"
In the third INSERT statement, the 'm' is processed as months (not minutes), because DAY TO
SECOND is truncated:
=> INSERT INTO int_test VALUES('1 year 6 m');
-- the m counts as months
In the following command, the 'm' counts as minutes, because the DAY TO SECOND interval-qualifier
extracts day/time values from the input:
=> SELECT INTERVAL '1y6m' DAY TO SECOND;
?column?
----------365 days 6 mins
(1 row)
Interval-Qualifier
The following table lists the optional interval qualifiers. Values in INTERVAL fields, other than
SECOND, are integers with a default precision of 2 when they are not the first field.
You cannot combine day/time and year/month qualifiers. For example, the following intervals are
not allowed:
SQLReference Manual
SQL Data Types
DAY TO YEAR
HOUR TO MONTH
Interval
Type
Units
Day/time
DAY
Unconstrained.
DAY TO HOUR
DAY TO MINUTE
DAY TO SECOND
intervals
HOUR TO MINUTE
HOUR TO SECOND
MINUTE
MINUTE TO SECOND
SECOND
Year/month MONTH
intervals
YEAR
Unconstrained.
YEAR TO MONTH
SMALLDATETIME
SMALLDATETIME is an alias for TIMESTAMP.
SQLReference Manual
SQL Data Types
TIME
Consists of a time of day with or without a time zone.
Syntax
TIME [ (p) ] [ { WITH | WITHOUT } TIME ZONE ] | TIMETZ
[ AT TIME ZONE ]
Parameters
p
Specifies that valid values do not include a time zone (default). If a time zone
is specified in the input it is silently ignored.
TIMETZ
Limits
Name
Low Value
High Value
Resolution
TIME [p]
00:00:00.00
23:59:60.999999
1 s
00:00:00.00+14 23:59:59.999999-14 1 s
Example
Description
04:05:06.789
ISO 8601
04:05:06
ISO 8601
04:05
ISO 8601
040506
ISO 8601
04:05 AM
04:05 PM
SQLReference Manual
SQL Data Types
Example
Description
ISO 8601
040506-08
ISO 8601
04:05:06 PST
Notes
l
HP Vertica permits coercion from TIME and TIME WITH TIME ZONE types to TIMESTAMP or
TIMESTAMP WITH TIME ZONE or INTERVAL (Day to Second).
See Also
l
Syntax
timestamp AT TIME ZONE zone
SQLReference Manual
SQL Data Types
Parameters
timestamp
TIMESTAMP
Desired time zone specified either as a text string (for example: 'PST') or as an
interval (for example: INTERVAL '-08:00'). In the text case, the available zone
names are abbreviations.
The files in /opt/vertica/share/timezonesets define the default list of strings
accepted in the zone parameter
Examples
The local time zone is PST8PDT. The first example takes a zone-less timestamp and interprets it as
MST time (UTC-7) to produce a UTC timestamp, which is then rotated to PST (UTC-8) for display:
=> SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST';
timezone
-----------------------2001-02-16 22:38:40-05
(1 row)
The second example takes a timestamp specified in EST (UTC-5) and converts it to local time in
MST (UTC-7):
=> SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
timezone
--------------------2001-02-16 18:38:40
(1 row)
SQLReference Manual
SQL Data Types
TIMESTAMP
Consists of a date and a time with or without a time zone and with or without a historical epoch (AD
or BC).
Syntax
TIMESTAMP [ (p) ] [ { WITH | WITHOUT } TIME ZONE ] | TIMESTAMPTZ[
AT TIME ZONE
Parameters
p
Specifies that valid values must include a time zone. All TIMESTAMP WITH
TIME ZONE values are stored internally in UTC.
They are converted to local time in the zone specified by the time zone
configuration parameter before being displayed to the client.
Specifies that valid values do not include a time zone (default). If a time zone
is specified in the input it is silently ignored.
TIMESTAMPTZ
Limits
In the following table, values are rounded. See Date/Time Data Types for additional detail.
Name
290279 BC
294277 AD
1 s
290279 BC
294277 AD
1 s
Notes
l
Valid input for TIMESTAMP types consists of a concatenation of a date and a time, followed by an
optional time zone, followed by an optional AD or BC.
SQLReference Manual
SQL Data Types
AD/BC can appear before the time zone, but this is not the preferred ordering.
The SQL standard differentiates TIMESTAMP WITHOUT TIME ZONE and TIMESTAMP WITH TIME
ZONE literals by the existence of a "+"; or "-". Hence, according to the standard:
TIMESTAMP '2004-10-19 10:23:54' is a TIMESTAMP WITHOUT TIME ZONE.
TIMESTAMP '2004-10-19 10:23:54+02' is a TIMESTAMP WITH TIME ZONE.
Note: HP Vertica differs from the standard by requiring that TIMESTAMP WITH TIME ZONE
literals be explicitly typed:
TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02'
If a literal is not explicitly indicated as being of TIMESTAMP WITH TIME ZONE, HP Vertica silently
ignores any time zone indication in the literal. That is, the resulting date/time value is derived
from the date/time fields in the input value, and is not adjusted for time zone.
For TIMESTAMP WITH TIME ZONE, the internally stored value is always in UTC. An input value
that has an explicit time zone specified is converted to UTC using the appropriate offset for that
time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone
indicated by the system's TIME ZONE parameter, and is converted to UTC using the offset for
the TIME ZONE zone.
When a TIMESTAMP WITH TIME ZONE value is output, it is always converted from UTC to the
current TIME ZONE zone and displayed as local time in that zone. To see the time in another time
zone, either change TIME ZONE or use the AT TIME ZONE construct.
Conversions between TIMESTAMP WITHOUT TIME ZONE and TIMESTAMP WITH TIME ZONE
normally assume that the TIMESTAMP WITHOUT TIME ZONE value are taken or given as TIME
ZONE local time. A different zone reference can be specified for the conversion using AT TIME
ZONE.
TIMESTAMPTZ and TIMETZ are not parallel SQL constructs. TIMESTAMPTZ records a time and date
in GMT, converting from the specified TIME ZONE. TIMETZ records the specified time and the
specified time zone, in minutes, from GMT.timezone
1999-01-08 04:05:06
SQLReference Manual
SQL Data Types
In HP Vertica, intervals are represented internally as some number of microseconds and printed
as up to 60 seconds, 60 minutes, 24 hours, 30 days, 12 months, and as many years as
necessary. Fields are either positive or negative.
Examples
You can return infinity by specifying 'infinity':
=> SELECT TIMESTAMP 'infinity';
timestamp
----------infinity
(1 row)
To use the minimum TIMESTAMP value lower than the minimum rounded value:
=> SELECT '-infinity'::timestamp;
timestamp
-----------infinity
(1 row)
Notice the results are the same if you move the BC after the 1:
SELECT TIMESTAMPTZ 'June 1 BC, 2000 03:20 PDT';
timestamptz
--------------------------2000-06-01 05:20:00-05 BC
(1 row)
SQLReference Manual
SQL Data Types
The following example returns the year 45 before the Common Era:
=> SELECT TIMESTAMP 'April 1, 45 BC';
timestamp
-----------------------0045-04-01 00:00:00 BC
(1 row)
If you omit the BC from the date input string, the system assumes you want the year 45 in the
current century:
=> SELECT TIMESTAMP 'April 1, 45';
timestamp
--------------------2045-04-01 00:00:00
(1 row)
In the following example, HP Vertica returns results in years, months, and days, whereas other
RDBMS might return results in days only:
=> SELECT TIMESTAMP WITH TIME ZONE '02/02/294276'- TIMESTAMP WITHOUT TIME ZONE
'02/20/2009' AS result;
result
-----------------------------292266 years 11 mons 12 days
(1 row)
To specify a specific time zone, add it to the statement, such as the use of 'ACST' in the following
example:
=> SELECT T1 AT TIME ZONE 'ACST', t2 FROM test;
timezone
| t2
---------------------+------------2009-01-01 04:00:00 | 02:00:00-07
2009-01-01 01:00:00 | 02:00:00-04
2009-01-01 04:00:00 | 02:00:00-06
SQLReference Manual
SQL Data Types
2009-03-18 21:35:23.633-04
(1 row)
The following example illustrates the difference between TIMESTAMPTZ with and without a
precision specified:
=> SELECT TIMESTAMPTZ(3) 'now', TIMESTAMPTZ 'now';
timestamptz
timestamptz
----------------------------+------------------------------2009-02-24 11:40:26.177-05 | 2009-02-24 11:40:26.177368-05
(1 row)
The following statement returns an error because the TIMESTAMP is out of range:
=> SELECT TIMESTAMP '294277-01-09 04:00:54.775808';
ERROR: date/time field value out of range: "294277-01-09 04:00:54.775808"
The following commands create a table with a TIMESTAMP column that contains milliseconds:
CREATE TABLE temp (datecol TIMESTAMP);
INSERT INTO temp VALUES (TIMESTAMP '2010-03-25 12:47:32.62');
INSERT INTO temp VALUES (TIMESTAMP '2010-03-25 12:55:49.123456');
INSERT INTO temp VALUES (TIMESTAMP '2010-03-25 01:08:15.12374578');
SELECT * FROM temp;
datecol
---------------------------2010-03-25 12:47:32.62
2010-03-25 12:55:49.123456
2010-03-25 01:08:15.123746
(3 rows)
Additional Examples
Command
Result
16 10:10
2 08:17:08.571429
16
SQLReference Manual
SQL Data Types
Command
Result
2009-052915:21:00.456789-04
2009-05-2800:00:0004
1 15:21:00.456789
1 15:21:00.456789
1 15:21:00.457
141660.456789
28
2-4
141660.457
2361
2361
2361:00.457
2361:00.456789
SQLReference Manual
SQL Data Types
Note: TIME ZONE is a synonym for TIMEZONE. Both are allowed in HP Vertica syntax.
Syntax
timestamp AT TIME ZONE zone
Parameters
timestamp
TIMESTAMP
zone
TIME
Examples
If you indicate a TIME interval timezone (such as America/Chicago in the following example), the
interval function converts the interval to the timezone you specify and includes the UTC offset
value (-05 here):
=> select time '10:00' at time zone 'America/Chicago';
?column?
--------------------09:00:00-05
(1 row)
Casting a TIMESTAMPTZ interval to a TIMESTAMP without a zone depends on the local time
zone.
SQLReference Manual
SQL Data Types
Note: For a complete list of valid time zone definitions, see Wikipedia - tz database time
zones.
Casting a TIME (or TIMETZ) interval to a TIMESTAMP returns the local date and time, without the
UTC offset:
=> select (time '3:01am')::timestamp;
?column?
--------------------2012-08-30 03:01:00
(1 row)
=> select (timetz '3:01am')::timestamp;
?column?
--------------------2012-08-22 03:01:00
(1 row)
Casting the same interval (TIME or TIMETZ) to a TIMESTAMPTZ returns the local date and time
appended with the UTC offset (-04 here):
=> select (time '3:01am')::timestamptz;
?column?
--------------------2012-08-30 03:01:00-04
(1 row)
LONG VARBINARYVariable-length raw-byte data, such as spatial data. LONG VARBINARY values
are not extended to the full width of the column.
LONG VARCHARVariable-length strings, such as log files and unstructured data. LONG VARCHAR
values are not extended to the full width of the column.
The maximum size for the LONG data types is 32,000,000 bytes. Use the LONG data types only when
you need to store data greater than 65,000 bytes, which is the maximum size for VARBINARY and
SQLReference Manual
SQL Data Types
VARCHAR data types. Such data might include unstructured data, online comments or posts, or small
log files.
Default length is 1048576.
Flex tables have a default LONG VARBINARY __raw__ column, with a NOT NULLconstraint.
Syntax
LONG VARBINARY ( max_length )
LONG VARCHAR ( octet_length )
Parameters
max_length
Specifies the length of the byte string (column width, declared in bytes (octets)), in
CREATE TABLE statements). Maximum value: 32,000,000.
octet_length
Specifies the length of the string (column width, declared in bytes (octets)), in
CREATE TABLE statements). Maximum value: 32,000,000.
Notes
For optimal performance of LONG data types, HP Vertica recommends that you:
l
Use the LONG data types as storage only containers; HP Vertica does not support operations on
their content.
Use the VARBINARY and VARCHAR data types, instead of their LONG counterparts, whenever
possible. The VARBINARY and VARCHAR data types are more flexible and have a wider range of
operations.
Do not add constraints, such as primary key, to any LONG VARBINARY or LONG VARCHAR
columns.
Example
The following example creates a table user_comments with a LONG VARCHAR column and inserts
data into it:
SQLReference Manual
SQL Data Types
SQLReference Manual
SQL Data Types
Exact numeric types, values where the precision and scale need to be preserved. The exact
numeric types are INTEGER, BIGINT, DECIMAL, NUMERIC, NUMBER, and MONEY.
Approximate numeric types, values where the precision needs to be preserved and the scale
can be floating. The approximate numeric types are DOUBLE PRECISION, FLOAT, and REAL.
Implicit casts from INTEGER, FLOAT, and NUMERIC to VARCHAR are not supported. If you need that
functionality, write an explicit cast using one of the following forms:
CAST(x AS data-type-name) or x::data-type-name
String-to-numeric data type conversions accept formats of quoted constants for scientific notation,
binary scaling, hexadecimal, and combinations of numeric-type literals:
l
Scientific notation:
=> SELECT FLOAT '1e10';
?column?
------------10000000000
(1 row)
BINARY scaling:
=> SELECT NUMERIC '1p10';
?column?
---------1024
(1 row)
Hexadecimal:
SQLReference Manual
SQL Data Types
Syntax
[ DOUBLE PRECISION | FLOAT | FLOAT(n) | FLOAT8 | REAL ]
Parameters
Note: On a machine whose floating-point arithmetic does not follow IEEE-754, these values
probably do not work as expected.
Double precision is an inexact, variable-precision numeric type. In other words, some values
cannot be represented exactly and are stored as approximations. Thus, input and output operations
involving double precision might show slight discrepancies.
l
All of the DOUBLE PRECISION data types are synonyms for 64-bit IEEE FLOAT.
The n in FLOAT(n) must be between 1 and 53, inclusive, but a 53-bit fraction is always used.
See the IEEE-754 standard for details.
For exact numeric storage and calculations (money for example), use NUMERIC.
Floating point calculations depend on the behavior of the underlying processor, operating
system, and compiler.
Comparing two floating-point values for equality might not work as expected.
Values
COPY accepts floating-point data in the following format:
SQLReference Manual
SQL Data Types
A decimal number consists of a non-empty sequence of decimal digits possibly containing a radix
character (decimal point "."), optionally followed by a decimal exponent. A decimal exponent
consists of an "E" or "e", followed by an optional plus or minus sign, followed by a non-empty
sequence of decimal digits, and indicates multiplication by a power of 10.
A hexadecimal number consists of a "0x" or "0X" followed by a non-empty sequence of
hexadecimal digits possibly containing a radix character, optionally followed by a binary exponent.
A binary exponent consists of a "P" or "p", followed by an optional plus or minus sign, followed by a
non-empty sequence of decimal digits, and indicates multiplication by a power of 2. At least one of
radix character and binary exponent must be present.
An infinity is either INF or INFINITY, disregarding case.
A NaN (Not A Number) is NAN (disregarding case) optionally followed by a sequence of characters
enclosed in parentheses. The character string specifies the value of NAN in an implementationdependent manner. (The HP Vertica internal representation of NAN is 0xfff8000000000000LL on
x86 machines.)
When writing infinity or NAN values as constants in a SQL statement, enclose them in single
quotes. For example:
=> UPDATE table SET x = 'Infinity'
Note: HP Vertica follows the IEEE definition of NaNs (IEEE 754). The SQL standards do not
specify how floating point works in detail.
IEEE defines NaNs as a set of floating point values where each one is not equal to anything,
even to itself. A NaN is not greater than and at the same time not less than anything, even
itself. In other words, comparisons always return false whenever a NaN is involved.
However, for the purpose of sorting data, NaN values must be placed somewhere in the result.
The value generated 'NaN' appears in the context of a floating point number matches the NaN
value generated by the hardware. For example, Intel hardware generates
(0xfff8000000000000LL), which is technically a Negative, Quiet, Non-signaling NaN.
HP Vertica uses a different NaN value to represent floating point NULL (0x7ffffffffffffffeLL).
This is a Positive, Quiet, Non-signaling NaN and is reserved by HP Vertica
SQLReference Manual
SQL Data Types
The load file format of a null value is user defined, as described in the COPY command. The HP
Vertica internal representation of a null value is 0x7fffffffffffffffLL. The interactive format is
controlled by the vsql printing option null. For example:
\pset null '(null)'
Rules
l
-0 == +0
1/0 = Infinity
0/0 == Nan
NaN
-Inf
numbers
+Inf
NULL
Notes
l
All overflows in floats generate +/-infinity or NaN, per the IEEE floating point standard.
SQLReference Manual
SQL Data Types
INTEGER
A signed 8-byte (64-bit) data type.
Syntax
[ INTEGER | INT | BIGINT | INT8 | SMALLINT | TINYINT ]
Parameters
INT, INTEGER, INT8, SMALLINT, TINYINT, and BIGINT are all synonyms for the same signed 64-bit
integer data type.Automatic compression techniques are used to conserve disk space in cases
where the full 64 bits are not required.
Notes
l
HP Vertica does not have an explicit 4-byte (32-bit integer) or smaller types. HP Vertica's
encoding and compression automatically eliminate the storage overhead of values that fit in less
than 64 bits.
Restrictions
l
The JDBC type INTEGER is 4 bytes and is not supported by HP Vertica. Use BIGINT instead.
HP Vertica does not support the SQL/JDBC types NUMERIC, SMALLINT, or TINYINT.
HP Vertica does not check for overflow (positive or negative) except in the aggregate function
SUM(). If you encounter overflow when using SUM, use SUM_FLOAT(), which converts to floating
point.
See Also
Data Type Coercion Chart
SQLReference Manual
SQL Data Types
NUMERIC
Numeric data types store numeric data. For example, a money value of $123.45 can be stored in a
NUMERIC(5,2) field.
Syntax
NUMERIC | DECIMAL | NUMBER | MONEY [ ( precision [ , scale ] ) ]
Parameters
precision
The total number of significant digits that the data type stores. precision must be
positive and <= 1024. If you assign a value that exceeds the precision value, an error
occurs.
scale
The maximum number of digits to the right of the decimal point that the data type
stores. scale must be non-negative and less than or equal to precision. If you omit the
scale parameter, the scale value is set to 0. If you assign a value with more decimal
digits than scale, the value is rounded to scale digits.
Notes
l
NUMERIC, DECIMAL, NUMBER, and MONEY are all synonyms that return NUMERIC data. The four
NUMERIC data types differ in their default precision and scale values:
Type
Precision
Scale
NUMERIC
37
15
DECIMAL
37
15
NUMBER
38
MONEY
18
NUMERIC data types are exact data types that store values of a specified precision and scale,
expressed with a number of digits before and after a decimal point. This contrasts slightly with
existing HP Vertica data types:
n
DOUBLE PRECISION (FLOAT) types support ~15 digits, variable exponent, and represent
numeric values approximately.
INTEGER (and similar) types support ~18 digits, whole numbers only.
SQLReference Manual
SQL Data Types
The approximate numeric data types, such as DOUBLE PRECISION, use floating points and are
less precise than NUMERIC data types.
Basic math: +, , *, /
NUMERIC divide operates directly on numeric values, without converting to floating point. The
result has at least 18 decimal places and is rounded.
NUMERIC mod (including %) operates directly on numeric values, without converting to floating
point. The result has the same scale as the numerator and never needs rounding.
COPY accepts a DECIMAL data type with a decimal point ('.'), prefixed by or +(optional).
Valid encoding types for numeric columns with precision <= 18 are:
AUTO
BLOCK_DICT
BLOCKDICT_COMP
COMMONDELTA_COMP
DELTARANGE_COMP
DELTAVAL
GCDDELTA
RLE
Valid encoding types for numeric columns with precision >18 are:
n
AUTO
BLOCK_DICT
SQLReference Manual
SQL Data Types
BLOCKDICT_COMP
RLE
The NUMERIC data type is preferred for non-integer constants, because it is always exact. For
example:
=> SELECT 1.1 + 2.2 = 3.3;
?column?
---------t
(1 row)
=> SELECT 1.1::float + 2.2::float = 3.3::float;
?column?
---------f
(1 row)
Performance of the NUMERIC data type has been fine tuned for the common case of 18 digits of
precision.
Some of the more complex operations used with NUMERIC data types result in an implicit cast to
FLOAT. When using SQRT, STDDEV, transcendental functions such as LOG, and TO_CHAR/TO_
NUMBER formatting, the result is always FLOAT.
Examples
The following series of commands creates a table that contains a NUMERIC data type and then
performs some mathematical operations on the data:
=> CREATE TABLE num1 (id INTEGER, amount NUMERIC(8,2));
SQLReference Manual
SQL Data Types
(1 row)
The following example returns the NUMERIC column, amount, from table num1:
=> SELECT amount FROM num1;
amount
----------123456.78
(1 row)
The following syntax returns a negative number for the amount column:
=> SELECT -amount FROM num1;
?column?
------------123456.78
(1 row)
The following syntax returns the absolute value of the amount argument:
=> SELECT ABS(amount) FROM num1;
ABS
----------123456.78
(1 row)
The following syntax casts the NUMERIC amount as a FLOAT data type:
=> SELECT amount::float FROM num1;
amount
----------123456.78
SQLReference Manual
SQL Data Types
(1 row)
See Also
Mathematical Functions
SQLReference Manual
SQL Data Types
zero
zero
zero
zero
Add, subtract, and multiply operations ignore overflow. Sum and average operations use 128-bit
arithmetic internally. SUM() reports an error if the final result overflows, suggesting the use of SUM_
FLOAT(INT), which converts the 128-bit sum to a FLOAT8. For example:
=>
=>
=>
=>
=>
=>
=>
Implicit castingOccurs when the expression automatically converts the data from one type to
another.
Explicit castingOccurs when you write a SQL statement that specifies the target data type for
the conversion.
The ANSI SQL-92 standard supports implicit casting between similar data types:
l
Number types
SQLReference Manual
SQL Data Types
From CHAR to FLOAT, to match the one from VARCHAR to FLOAT. The following example
converts the CHAR '3' to a FLOAT so it can add the number 4.33 to the FLOAT result of the
second expression:
=> SELECT '3'::CHAR + 4.33::FLOAT;
?column?
---------7.33
(1 row)
Between DATE and TIMESTAMP. The following example DATE to a TIMESTAMP and
calculates the time 6 hours, 6 minutes, and 6 seconds back from 12:00 AM:
=> SELECT DATE('now') - INTERVAL '6:6:6';
?column?
--------------------2013-07-30 17:53:54
(1 row)
When there is no ambiguity about the data type of an expression value, it is implicitly coerced to
match the expected data type. In the following command, the quoted string constant '2' is implicitly
coerced into an INTEGER value so that it can be the operand of an arithmetic operator (addition):
=> SELECT 2 + '2';
?column?
---------4
(1 row)
A concatenate operation explicitly takes arguments of any data type. In the following example, the
concatenate operation implicitly coerces the arithmetic expression 2 + 2 and the INTEGER
constant 2 to VARCHAR values so that they can be concatenated.
=> SELECT 2 + 2 || 2;
?column?
---------42
(1 row)
SQLReference Manual
SQL Data Types
The following command converts DATE to a TIMESTAMP and adds a day and a half to the results
by using INTERVAL:
=> SELECT DATE 'now' + INTERVAL '1 12:00:00';
?column?
--------------------2013-07-31 12:00:00
(1 row)
Most implicit casts stay within their relational family and go in one direction, from less detailed to
more detailed. For example:
l
DATE to TIMESTAMP/TZ
CHAR to FLOAT
CHAR to VARCHAR
BINARY to VARBINARY
Direction Type
Notes
INT8
>
FLOAT8
FLOAT8
>
INT8
Explicit, rounds
VARCHAR
<->
CHAR
BINARY
VARBINARY <->
SQLReference Manual
SQL Data Types
Type
Direction Type
Notes
VARCHAR
>
VARBINARY >
LONG VARCHAR
No other types cast to or from LONGVARBINARY, VARBINARY, or BINARY. In the following list,
<any> means one these types: INT8, FLOAT8, DATE, TIME, TIMETZ, TIMESTAMP,
TIMESTAMPTZ, INTERVAL.
l
Important: Implicit casts from INTEGER, FLOAT, and NUMERIC to VARCHAR are not
supported. If you need that functionality, write an explicit cast:
SQLReference Manual
SQL Data Types
CAST(x AS data-type-name)
or
x::data-type-name
String-to-numeric data type conversions accept formats of quoted constants for scientific notation,
binary scaling, hexadecimal, and combinations of numeric-type literals:
l
Scientific notation:
=> SELECT FLOAT '1e10';
?column?
------------10000000000
(1 row)
BINARY scaling:
=> SELECT NUMERIC '1p10';
?column?
---------1024
(1 row)
Hexadecimal:
=> SELECT NUMERIC '0x0abc';
?column?
---------2748
(1 row)
Examples
The following example casts three strings as NUMERICs:
=> SELECT NUMERIC '12.3e3', '12.3p10'::NUMERIC, CAST('0x12.3p-10e3' AS NUMERIC);
SQLReference Manual
SQL Data Types
?column? | ?column? |
?column?
----------+----------+------------------12300 | 12595.2 | 17.76123046875000
(1 row)
This example casts a VARBINARY string into a LONG VARBINARY data type:
=> SELECT B'101111000'::LONG VARBINARY;
?column?
---------\001x
(1 row)
The following example concatenates a CHAR with a LONG VARCHAR, resulting in a LONG
VARCHAR:
=> \set s ''''`cat longfile.txt`''''
=> SELECT length ('a' || :s ::LONG VARCHAR);
length
---------65002
(1 row)
The following example casts a combination of NUMERIC and INTEGER data into a NUMERIC
result:
=> SELECT (18. + 3./16)/1024*1000;
?column?
----------------------------------------17.761230468750000000000000000000000000
(1 row)
Note: In SQL expressions, pure numbers between (2^631) and (2^631) are INTEGERs.
Numbers with decimal points are NUMERIC.
See Also
l
SQLReference Manual
SQL Data Types
Data Types
Implicit
Explicit
BOOLEAN
Assignment
Assignment
without numeric
meaning
INTEGER
LONG VARCHAR
VARCHAR
CHAR
INTEGER
BOOLEAN
NUMERIC
FLOAT
INTERVAL
DAY/SECOND
INTERVAL
YEAR/MONTH
LONG VARCHAR
VARCHAR
CHAR
NUMERIC
FLOAT
INTEGER
LONG VARCHAR
VARCHAR
CHAR
INTEGER
NUMERIC
LONG VARCHAR
VARCHAR
CHAR
FLOAT
LONG VARCHAR
Conversion
without explicit
casting
FLOAT
CHAR
BOOLEAN
INTEGER
NUMERIC
VARCHAR
TIMESTAMP
TIMESTAMP
WITH TIME
ZONE
DATE
TIME
TIME WITH
TIME ZONE
INTERVAL
DAY/SECOND
INTERVAL
YEAR/MONTH
LONG
VARBINARY
NUMERIC
LONG VARCHAR
SQLReference Manual
SQL Data Types
Conversion Types
Conversion
without explicit
casting
Data Types
Implicit
Explicit
VARCHAR
FLOAT
LONG VARCHAR
CHAR
BOOLEAN
INTEGER
NUMERIC
TIMESTAMP
TIMESTAMP
WITH TIME
ZONE
DATE
TIME
TIME WITH
TIME ZONE
INTERVAL
DAY/SECOND
INTERVAL
YEAR/MONTH
VARCHAR
CHAR
FLOAT
LONG VARCHAR
VARCHAR
BOOLEAN
INTEGER
NUMERIC
TIMESTAMP
TIMESTAMP
WITH TIME
ZONE
DATE
TIME
TIME WITH
TIME ZONE
INTERVAL
DAY/SECOND
INTERVAL
YEAR/MONTH
CHAR
TIMESTAMP
TIMESTAMP
WITH TIME
ZONE
LONG CHAR
VARCHAR
CHAR
DATE
TIME
TIMESTAMP
TIMESTAMP
WITH TIME
ZONE
TIMESTAMP
LONG CHAR
VARCHAR
CHAR
DATE
TIME
TIME WITH
TIME ZONE
TIMESTAMP WITH
TIME ZONE
DATE
TIMESTAMP
LONG CHAR
VARCHAR
CHAR
TIMESTAMP
WITH TIME
ZONE
Assignment
Assignment
without numeric
meaning
SQLReference Manual
SQL Data Types
Conversion Types
Assignment
without numeric
meaning
Conversion
without explicit
casting
Data Types
Implicit
Explicit
Assignment
TIME
TIME WITH
TIME ZONE
TIMESTAMP
TIMESTAMP
WITH TIME
ZONE
INTERVAL
DAY/SECOND
LONG CHAR
VARCHAR
CHAR
TIME
TIME WITH
TIME ZONE
TIMESTAMP
TIMESTAMP
WITH TIME
ZONE
LONG CHAR
VARCHAR
CHAR
TIME
INTERVAL
DAY/SECOND
TIME
INTEGER
LONG CHAR
VARCHAR
CHAR
INTERVAL
DAY/SECOND
INTEGER
LONG CHAR
VARCHAR
CHAR
INTERVAL
YEAR/MONTH
INTERVAL
YEAR/MONTH
LONG
VARBINARY
VARBINARY
LONG VARBINARY
VARBINARY
LONG
VARBINARY
BINARY
VARBINARY
BINARY
VARBINARY
BINARY
SQLReference Manual
SQL Data Types
Assignment Conversion
In data assignment conversion, coercion implicitly occurs when values are assigned to database
columns in an INSERT or UPDATE..SET statement. For example, in a statement that includes
INSERT ... VALUES('2.5'), where the target column data type is NUMERIC(18,5), a cast from
VARCHAR to the column data type is inferred.
In an assignment without numeric meaning, the value is subject to CHAR/VARCHAR/LONG
VARCHAR comparisons.
See Also
l
SQLReference Manual
SQL Functions
SQL Functions
Functions return information from the database.You can use a function anywhere an expression is
allowed. The exception is HP Vertica-specific functions, which are not allowed everywhere.
Each function is documented with its specific behavior type, describing its return values, which are
as follows:
Some functions return different results on different invocations with the same set of arguments. The
following three categories of functions are defined based on their behavior:
Immutable (invariant):
When run with a given set of arguments, immutable functions always produce the same result. The
function is independent of any environment or session settings, such as locale. For example, 2+2
always equals 4. Another immutable function is AVG(). Some immutable functions can take an
optional stable argument; in this case they are treated as stable functions.
Stable:
When run with a given set of arguments, stable functions produce the same result within a single
query or scan operation. However, a stable function could produce different results when issued
under a different environment, such as a change of locale and time zone. Expressions that could
give different results in the future are also stable, for example SYSDATE() or 'today'.
Volatile:
Regardless of the arguments or environment, volatile functions can return different results on
multiple invocations. RANDOM() is one example.
This chapter describes the functions that HP Vertica supports.
l
All HP Vertica-specific functions can be assumed to be volatile and are not annotated
individually.
SQLReference Manual
SQL Functions
Aggregate Functions
Note: All functions in this section that have an analytic function counterpart are appended with
[Aggregate] to avoid confusion between the two.
Aggregate functions summarize data over groups of rows from a query result set. The groups are
specified using the GROUP BY clause. They are allowed only in the select list and in the HAVING
and ORDER BY clauses of a SELECT statement (as described in Aggregate Expressions).
Notes
l
Except for COUNT, these functions return a null value when no rows are selected. In particular,
SUM of no rows returns NULL, not zero.
In some cases you can replace an expression that includes multiple aggregates with an single
aggregate of an expression. For example SUM(x) + SUM(y) can be expressed as as SUM(x+y)
(where x and y are NOT NULL).
You can also use some of the simple aggregate functions as analytic (window) functions. See
Analytic Functions for details. See also Using SQL Analytics in the Analyzing Data Guide.
APPROXIMATE_COUNT_DISTINCT
Returns the number of rows in the data set that have distinct non-NULLvalues.
Behavior Type
Immutable
Syntax
APPROXIMATE_COUNT_DISTINCT ( expr [, error_tolerance ] )
Parameters
expr
Value to be evaluated using any data type that supports equality comparison.
SQLReference Manual
SQL Functions
error_tolerance
For detailed information about the error tolerance, see the following Notes
section.
Notes
l
The maximum number of distinct values is in the range of 0 to approximately 2^47, or 1.4*10^14.
SQLReference Manual
SQL Functions
Examples
The following query counts total number of distinct values in the product_key column of the
store.store_sales_fact table:
=> \timing
Timing is on.
=> SELECT COUNT(DISTINCT product_key) FROM store.store_sales_fact;
COUNT
------19982
(1 row)
Time: First fetch (1 row): 16.839 ms. All rows formatted: 16.866 ms
The next query counts the approximate number of distinct values in the product_key column with
various error tolerances. The smaller the error_tolerance, the closer the approximation.
=> \timing
Timing is on.
=> SELECT APPROXIMATE_COUNT_DISTINCT(product_key,5) AS five_pct_accuracy,
APPROXIMATE_COUNT_DISTINCT(product_key,1) AS one_pct_accuracy,
APPROXIMATE_COUNT_DISTINCT(product_key,.1) AS point_one_pct_accuracy
FROM store.store_sales_fact;
five_pct_accuracy | one_pct_accuracy | point_one_pct_accuracy
-------------------+------------------+-----------------------19431 |
19921 |
19980
(1 row)
Time: First fetch (1 row): 262.580 ms. All rows formatted: 262.616 ms
The following query counts the distinct values in the date_key and product_key columns.
=> \timing
Timing is on.
=> SELECT COUNT (DISTINCT date_key),
COUNT (DISTINCT product_key)
FROM store.store_sales_fact;
count | count
-------+------1826 | 19982
(1 row)
Time: First fetch (1 row): 207.431 ms. All rows formatted: 207.468 ms
SQLReference Manual
SQL Functions
See Also
l
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS
APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS
COUNT [Aggregate]
APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS
Returns the number of rows in the synopsis object created by APPROXIMATE_COUNT_
DISTINCT_SYNOPSIS that have distinct non-NULLvalues.
Behavior Type
Immutable
Syntax
APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS ( expr [, maximum_error_percent ] )
Parameters
expr
error_
SQLReference Manual
SQL Functions
Notes
l
The maximum number of distinct values is in the range of 0 to approximately 2^47, or 1.4*10^14.
Examples
The following example creates the synopsis and then calculates an approximate count of distinct
values in the synopsis.
=> \timing
Timing is on.
=> SELECT product_version,
APPROXIMATE_COUNT_DISTINCT(product_key)
FROM store.store_sales_fact
GROUP BY product_version;
product_version | ApproxCountDistinct
-----------------+--------------------1
|
19921
2
|
15958
SQLReference Manual
SQL Functions
3
4
5
(5 rows)
|
|
|
11895
7935
3993
Time: First fetch (5 rows): 2826.318 ms. All rows formatted: 2826.358 ms
=> CREATE TABLE my_summary AS
SELECT product_version,
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS (product_key) syn
FROM store.store_sales_fact
GROUP BY product_version;
CREATE TABLE
=> SELECT APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS(syn)
FROM my_summary;
ApproxCountDistinctOfSynopsis
------------------------------19963
(1 row)
Time: First fetch (1 row): 42.994 ms. All rows formatted: 43.021 ms
=>
See Also
l
APPROXIMATE_COUNT_DISTINCT
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS
COUNT [Aggregate]
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS
Returns a subset of the data set, known as a synopsis, as a VARBINARYor LONGVARBINARY.
Save the synopsis as an HP Vertica table for use by APPROXIMATE_COUNT_DISTINCT_OF_
SYNOPSIS.
Behavior Type
Immutable
Syntax
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS ( expr )
SQLReference Manual
SQL Functions
Parameters
expr
Notes
l
The maximum number of distinct values is in the range of 0 to approximately 2^47, or 1.4*10^14.
Example
In the following example, the query creates a table that contains the synopsis of the product_key
data. The my_summary table is used in the example for APPROXIMATE_COUNT_DISTINCT_OF_
SYNOPSIS.
=> CREATE TABLE my_summary AS
SELECT tender_type,
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS(product_key) syn
FROM store.store_sales_fact
GROUP BY tender_type;
CREATE TABLE
Time: First fetch (0 rows): 3216.056 ms. All rows formatted: 3216.069 ms
See Also
l
APPROXIMATE_COUNT_DISTINCT
APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS
COUNT [Aggregate]
AVG [Aggregate]
Computes the average (arithmetic mean) of an expression over a group of rows. AVGalways
returns a DOUBLE PRECISION value.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
AVG ( [ ALL | DISTINCT ] expression )
Parameters
ALL
Invokes the aggregate function for all rows in the group (default).
DISTINCT
Invokes the aggregate function for all distinct non-null values of the expression
found in the group.
expression
The value whose average is calculated over a set of rows. This can be any
expression that can have a DOUBLE PRECISION result.
Notes
The AVG() aggregate function is different from the AVG() analytic function, which computes an
average of an expression over a group of rows within a window.
Examples
The following example returns the average income from the customer table:
=> SELECT AVG(annual_income) FROM customer_dimension;
avg
-------------2104270.6485
(1 row)
See Also
l
AVG [Analytic]
COUNT [Aggregate]
SUM [Aggregate]
BIT_AND
Takes the bitwise AND of all non-null input values. If the input parameter is NULL, the return value is
also NULL.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
BIT_AND ( expression )
Parameters
expression
Notes
l
The function returns the same value as the argument data type.
For each bit compared, if all bits are 1, the function returns 1; otherwise it returns 0.
If the columns are different lengths, the return values are treated as though they are all equal in
length and are right-extended with zero bytes. For example, given a group containing the hex
values 'ff', null, and 'f', the function ignores the null value and extends the value 'f' to
'f0'..
Example
This example uses the following schema, which creates table t with a single column of VARBINARY
data type:
=>
=>
=>
=>
CREATE
INSERT
INSERT
INSERT
TABLE t ( c VARBINARY(2) );
INTO t values(HEX_TO_BINARY('0xFF00'));
INTO t values(HEX_TO_BINARY('0xFFFF'));
INTO t values(HEX_TO_BINARY('0xF00F'));
SQLReference Manual
SQL Functions
The function is applied pairwise to all values in the group, resulting in f000, which is determined as
follows:
1. ff00 (record 1) is compared with ffff (record 2), which results in ff00.
2. The result from the previous comparison is compared with f00f (record 3), which results in
f000.
See Also
l
BIT_OR
Takes the bitwise OR of all non-null input values. If the input parameter is NULL, the return value is
also NULL.
Behavior Type
Immutable
Syntax
BIT_OR ( expression )
Parameters
expression
Notes
l
The function returns the same value as the argument data type.
For each bit compared, if any bit is 1, the function returns 1; otherwise it returns 0.
SQLReference Manual
SQL Functions
If the columns are different lengths, the return values are treated as though they are all equal in
length and are right-extended with zero bytes. For example, given a group containing the hex
values 'ff', null, and 'f', the function ignores the null value and extends the value 'f' to
'f0'.
Example
This example uses the following schema, which creates table t with a single column of VARBINARY
data type:
=>
=>
=>
=>
CREATE
INSERT
INSERT
INSERT
TABLE t ( c VARBINARY(2) );
INTO t values(HEX_TO_BINARY('0xFF00'));
INTO t values(HEX_TO_BINARY('0xFFFF'));
INTO t values(HEX_TO_BINARY('0xF00F'));
The function is applied pairwise to all values in the group, resulting in ffff, which is determined as
follows:
1. ff00 (record 1) is compared with ffff, which results in ffff.
2. The ff00 result from the previous comparison is compared with f00f (record 3), which results
in ffff.
See Also
l
SQLReference Manual
SQL Functions
BIT_XOR
Takes the bitwise XOR of all non-null input values. If the input parameter is NULL, the return value is
also NULL.
Behavior Type
Immutable
Syntax
BIT_XOR ( expression )
Parameters
expression
Notes
l
The function returns the same value as the argument data type.
For each bit compared, if there are an odd number of arguments with set bits, the function
returns 1; otherwise it returns 0.
If the columns are different lengths, the return values are treated as though they are all equal in
length and are right-extended with zero bytes. For example, given a group containing the hex
values 'ff', null, and 'f', the function ignores the null value and extends the value 'f' to
'f0'.
Example
First create a sample table and projections with binary columns:
This example uses the following schema, which creates table t with a single column of VARBINARY
data type:
=>
=>
=>
=>
CREATE
INSERT
INSERT
INSERT
TABLE t ( c VARBINARY(2) );
INTO t values(HEX_TO_BINARY('0xFF00'));
INTO t values(HEX_TO_BINARY('0xFFFF'));
INTO t values(HEX_TO_BINARY('0xF00F'));
SQLReference Manual
SQL Functions
See Also
l
CORR
Returns the coefficient of correlation of a set of expression pairs (expression1 and expression2).
The return value is of type DOUBLE PRECISION. The function eliminates expression pairs where
either expression in the pair is NULL. If no rows remain, the function returns NULL.Syntax
SELECT CORR (expression1, expression2)
Parameters
expression1
expression2
Example
=> SELECT CORR (Annual_salary, Employee_age) FROM employee_dimension;
CORR
----------------------0.00719153413192422
(1 row)
SQLReference Manual
SQL Functions
COUNT [Aggregate]
Returns the number of rows in each group of the result set for which the expression is not NULL. The
return value is a BIGINT.
The COUNT() aggregate function is different from the COUNT() analytic function. The COUNT()
analytic function returns the number over a group of rows within a window.
When an approximate count of the number of distinct values is sufficient, use the
APPROXIMATE_COUNT_DISTINCT function. If you want to combine the data in different ways,
use APPROXIMATE_COUNT_DISTINCT_SYNOPSIS together with APPROXIMATE_COUNT_
DISTINCT_OF_SYNOPSIS.
Behavior Type
Immutable
Syntax
COUNT ( [ * ] [ ALL | DISTINCT ] expression )
Parameters
*
Indicates that the count does not apply to any specific column or expression in the
select list. Requires a FROM Clause.
ALL
Invokes the aggregate function for all rows in the group (default).
DISTINCT
Invokes the aggregate function for all distinct non-null values of the expression
found in the group.
expression
Returns the number of rows in each group for which the expression is not null. Can
be any expression resulting in BIGINT.
Examples
The following query returns the number of distinct values in the primary_key column of the date_
dimension table:
=> SELECT COUNT (DISTINCT date_key) FROM date_dimension;
COUNT
-------
SQLReference Manual
SQL Functions
1826
(1 row)
This example returns all distinct values of evaluating the expression x+y for all records of fact.
=> SELECT COUNT (DISTINCT date_key + product_key)
FROM inventory_fact;
COUNT
------21560
(1 row)
You can create an equivalent query using the LIMIT keyword to restrict the number of rows
returned:
=> SELECT COUNT(date_key + product_key) FROM inventory_fact
GROUP BY date_key LIMIT 10;
COUNT
------173
31
321
113
286
84
244
238
145
202
(10 rows)
This query returns the number of distinct values of date_key in all records with the specific distinct
product_key value.
=> SELECT product_key, COUNT (DISTINCT date_key)
FROM inventory_fact GROUP BY product_key LIMIT 10;
product_key | count
-------------+------1 |
12
2 |
18
3 |
13
4 |
17
5 |
11
6 |
14
7 |
13
8 |
17
9 |
15
10 |
12
(10 rows)
This query counts each distinct product_key value in inventory_fact table with the constant 1.
SQLReference Manual
SQL Functions
This query selects each distinct date_key value and counts the number of distinct product_key
values for all records with the specific product_key value. It then sums the qty_in_stock values
in all records with the specific product_key value and groups the results by date_key.
=> SELECT date_key, COUNT (DISTINCT product_key),
SUM(qty_in_stock) FROM inventory_fact
GROUP BY date_key LIMIT 10;
date_key | count | sum
----------+-------+-------1 |
173 | 88953
2 |
31 | 16315
3 |
318 | 156003
4 |
113 | 53341
5 |
285 | 148380
6 |
84 | 42421
7 |
241 | 119315
8 |
238 | 122380
9 |
142 | 70151
10 |
202 | 95274
(10 rows)
This query selects each distinct product_key value and then counts the number of distinct date_
key values for all records with the specific product_key value. It also counts the number of distinct
warehouse_key values in all records with the specific product_key value.
=> SELECT product_key, COUNT (DISTINCT date_key),
COUNT (DISTINCT warehouse_key) FROM inventory_fact
GROUP BY product_key LIMIT 15;
product_key | count | count
-------------+-------+------1 |
12 |
12
2 |
18 |
18
3 |
13 |
12
4 |
17 |
18
5 |
11 |
9
SQLReference Manual
SQL Functions
6
7
8
9
10
11
12
13
14
15
|
|
|
|
|
|
|
|
|
|
14
13
17
15
12
11
13
9
13
18
|
|
|
|
|
|
|
|
|
|
13
13
15
14
12
11
12
7
13
17
(15 rows)
This query selects each distinct product_key value, counts the number of distinct date_key and
warehouse_key values for all records with the specific product_key value, and then sums all qty_
in_stock values in records with the specific product_key value. It then returns the number of
product_version values in records with the specific product_key value.
=> SELECT product_key, COUNT (DISTINCT date_key),
COUNT (DISTINCT warehouse_key),
SUM (qty_in_stock),
COUNT (product_version)
FROM inventory_fact GROUP BY product_key
LIMIT 15;
product_key | count | count | sum | count
-------------+-------+-------+-------+------1 |
12 |
12 | 5530 |
12
2 |
18 |
18 | 9605 |
18
3 |
13 |
12 | 8404 |
13
4 |
17 |
18 | 10006 |
18
5 |
11 |
9 | 4794 |
11
6 |
14 |
13 | 7359 |
14
7 |
13 |
13 | 7828 |
13
8 |
17 |
15 | 9074 |
17
9 |
15 |
14 | 7032 |
15
10 |
12 |
12 | 5359 |
12
11 |
11 |
11 | 6049 |
11
12 |
13 |
12 | 6075 |
13
13 |
9 |
7 | 3470 |
9
14 |
13 |
13 | 5125 |
13
15 |
18 |
17 | 9277 |
18
(15 rows)
The following example returns the number of warehouses from the warehouse dimension table:
=> SELECT COUNT(warehouse_name) FROM warehouse_dimension;
COUNT
------100
(1 row)
SQLReference Manual
SQL Functions
See Also
l
Analytic Functions
AVG [Aggregate]
SUM [Aggregate]
APPROXIMATE_COUNT_DISTINCT
APPROXIMATE_COUNT_DISTINCT_SYNOPSIS
APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS
COVAR_POP
Returns the population covariance for a set of expression pairs (expression1 and expression2). The
return value is of type DOUBLE PRECISION. The function eliminates expression pairs where
either expression in the pair is NULL. If no rows remain, the function returns NULL.
Syntax
SELECT COVAR_POP (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT COVAR_POP (Annual_salary, Employee_age)
FROM employee_dimension;
SQLReference Manual
SQL Functions
COVAR_POP
-------------------9032.34810730019
(1 row)
COVAR_SAMP
Returns the sample covariance for a set of expression pairs (expression1 and expression2). The
return value is of type DOUBLE PRECISION. The function eliminates expression pairs where
either expression in the pair is NULL. If no rows remain, the function returns NULL.
Syntax
COVAR_SAMP (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT COVAR_SAMP (Annual_salary, Employee_age)
FROM employee_dimension;
COVAR_SAMP
-------------------9033.25143244343
(1 row)
GROUP_ID
Uniquely identifies duplicate sets for GROUP BY queries that return duplicate grouping sets. This
function returns one or more integers, starting with zero (0), as identifiers.
For the number of duplicates n for a particular grouping, GROUP_ID returns a range of sequential
numbers, 0 to n1. For the first each unique group it encounters, GROUP_ID returns the value 0. If
GROUP_IDfinds the same grouping again, the function returns 1, then returns 2 for the next found
grouping, and so on.
Note: GROUP_IDis applicable only in SELECT statements that contain a multi-level GROUP
BY extension: CUBE, GROUPINGSETS, and ROLLUP.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
GROUP_ID ()
Examples
This example shows how GROUP_ID creates unique identifiers when a query produces duplicate
groupings. For an expenses table, the following query groups the results by category of expense
and year and rolls up the sum for those two columns. The results have duplicate groupings for
category and NULL. The first grouping has a GROUP_ID of 0, and the second grouping has a
GROUP_IDof 1.
=> SELECT Category, Year, SUM(Amount), GROUPING_ID(Category, Year),
GROUP_ID() FROM expenses GROUP BY Category, ROLLUP(Category,Year)
ORDER BY Category, Year, GROUPING_ID();
Category
| Year | SUM
| GROUPING_ID | GROUP_ID
-------------+------+--------+-------------+---------Books
| 2005 | 39.98 |
0 |
0
Books
| 2007 | 29.99 |
0 |
0
Books
| 2008 | 29.99 |
0 |
0
Books
|
| 99.96 |
1 |
0
Books
|
| 99.96 |
1 |
1
Electricity | 2005 | 109.99 |
0 |
0
Electricity | 2006 | 109.99 |
0 |
0
Electricity | 2007 | 229.98 |
0 |
0
Electricity |
| 449.96 |
1 |
1
Electricity |
| 449.96 |
1 |
0
See Also
l
CUBE Aggregate
GROUPING
GROUPING_ID
GROUP BY Clause
ROLLUP Aggregate
SQLReference Manual
SQL Functions
GROUPING
Disambiguates the use of NULL values when GROUP BY queries with multi-level aggregates
generate NULL values to identify subtotals in grouping columns. Such NULL values from the
original data can also occur in rows. GROUPING returns 1, if the value of expression is:
l
Note: You can use GROUPING only in SELECT statements that contain a GROUP BY
aggregate: CUBE, GROUPINGSETS, or ROLLUP.
Behavior Type
Immutable
Syntax
GROUPING (expression)
Parameters
expression
Examples
This example shows a query that uses the GROUPING function. This query takes one of the
GROUP BY expressions as an argument. For each row, the function returns either:
l
The 1 in the GROUPING(Year) column for electricity and books indicates that these values are
subtotals. The right-most column values for both GROUPING(Category) and GROUPING(Year)
are 1. This value indicates that neither column contributed to the GROUP BY. The final row
represents the total sales.
=> SELECT Category, Year, SUM(Amount),
SQLReference Manual
SQL Functions
See Also
l
CUBE Aggregate
GROUP_ID
GROUPING_ID
GROUP BY Clause
ROLLUP Aggregate
GROUPING_ID
Concatenates the set of Boolean values generated by the GROUPING function into a bit vector.
The GROUPING_ID function treats the bit vector as a binary number and returns it as a base-10
value that identifies the grouping set combination.
By using GROUPING_ID you avoid the need for multiple, individual GROUPING functions.
GROUPING_ID simplifies row-filtering conditions, because the rows of interest are identified using
a single return from GROUPING_ID = n. Use GROUPING_ID to identify grouping combinations.
Note: GROUPING_ID is applicable only in SELECT statements that contains a GROUP BY
aggregate:CUBE, GROUPINGSETS, or ROLLUP.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
GROUPING_ID (expression[, expression]...) | GROUPING_ID()
Parameters
expression
Examples
This example shows how calling GROUPING_ID without an expression returns the GROUPING
bit vector associated with a full set of multi-level aggregate expressions. The GROUPING_ID
value is comparable to GROUPING_ID(a,b) because GROUPING_ID()includes all columns in the
GROUPBYROLLUP:
=> SELECT a,b,COUNT(*), GROUPING_ID() FROM T GROUP BY ROLLUP(a,b);
In the following query, the GROUPING(Category) and GROUPING(Year) columns have three
combinations:
l
0,0
0,1
1,1
=> SELECT Category, Year, SUM(Amount),
GROUPING(Category), GROUPING(Year) FROM expenses
GROUP BY ROLLUP(Category, Year) ORDER BY Category, Year, GROUPING_ID();
Category
| Year | SUM
| GROUPING | GROUPING
-------------+------+--------+----------+---------Books
| 2005 | 39.98 |
0 |
0
Books
| 2007 | 29.99 |
0 |
0
Books
| 2008 | 29.99 |
0 |
0
Books
|
| 99.96 |
0 |
1
Electricity | 2005 | 109.99 |
0 |
0
Electricity | 2006 | 109.99 |
0 |
0
Electricity | 2007 | 229.98 |
0 |
0
Electricity |
| 449.96 |
0 |
1
|
| 549.92 |
1 |
1
SQLReference Manual
SQL Functions
Decimal Equivalents
00
01
11
Category, Year
The following query returns the single number for each GROUP BY level that appears in the gr_id
column:
=> SELECT Category, Year, SUM(Amount),
GROUPING(Category),GROUPING(Year),GROUPING_ID(Category,Year) AS gr_id
FROM expenses GROUP BY ROLLUP(Category, Year);
Category
| Year | SUM
| GROUPING | GROUPING | gr_id
-------------+------+--------+----------+----------+------Books
| 2008 | 29.99 |
0 |
0 |
0
Books
| 2005 | 39.98 |
0 |
0 |
0
Electricity | 2007 | 229.98 |
0 |
0 |
0
Books
| 2007 | 29.99 |
0 |
0 |
0
Electricity | 2005 | 109.99 |
0 |
0 |
0
Electricity |
| 449.96 |
0 |
1 |
1
|
| 549.92 |
1 |
1 |
3
Electricity | 2006 | 109.99 |
0 |
0 |
0
Books
|
| 99.96 |
0 |
1 |
1
The gr_id value determines the GROUP BY level for each row:
GROUPBYLevel
GROUPBYRow Level
Total sum
Category
Category, year
You can also use the DECODE function to give the values more meaning by comparing each
search value individually:
=> SELECT Category, Year, SUM(AMOUNT), DECODE(GROUPING_ID(Category, Year),
3, 'Total',
1, 'Category',
0, 'Category,Year')
AS GROUP_NAME FROM expenses GROUP BY ROLLUP(Category, Year);
Category
| Year | SUM
| GROUP_NAME
-------------+------+--------+--------------Electricity | 2006 | 109.99 | Category,Year
Books
|
| 99.96 | Category
SQLReference Manual
SQL Functions
Electricity
Books
Electricity
Electricity
Books
Books
|
|
|
|
|
|
|
2007 | 229.98
2007 | 29.99
2005 | 109.99
| 449.96
| 549.92
2005 | 39.98
2008 | 29.99
|
|
|
|
|
|
|
Category,Year
Category,Year
Category,Year
Category
Total
Category,Year
Category,Year
See Also
l
CUBE Aggregate
GROUP_ID
GROUPING
GROUP BY Clause
ROLLUP Aggregate
MAX [Aggregate]
Returns the greatest value of an expression over a group of rows. The return value is the same as
the expression data type.
Behavior Type
Immutable
Syntax
MAX ( [ ALL | DISTINCT ] expression )
Parameters
ALL | DISTINCT
expression
Any expression for which the maximum value is calculated, typically a column
reference.
SQLReference Manual
SQL Functions
Notes
The MAX() aggregate function is different from the MAX() analytic function, which returns the
maximum value of an expression over a group of rows within a window.
Example
This example returns the largest value (dollar amount) of the sales_dollar_amount column.
=> SELECT MAX(sales_dollar_amount) AS highest_sale FROM store.store_sales_fact;
highest_sale
-------------600
(1 row)
See Also
l
Analytic Functions
MIN [Aggregate]
MIN [Aggregate]
Returns the smallest value of an expression over a group of rows. The return value is the same as
the expression data type.
Behavior Type
Immutable
Syntax
MIN ( [ ALL | DISTINCT ] expression )
Parameters
ALL | DISTINCT
expression
Any expression for which the minimum value is calculated, typically a column
reference.
SQLReference Manual
SQL Functions
Notes
The MIN() aggregate function is different from the MIN() analytic function, which returns the
minimum value of an expression over a group of rows within a window.
Example
This example returns the lowest salary from the employee dimension table.
=> SELECT MIN(annual_salary) AS lowest_paid FROM employee_dimension;
lowest_paid
------------1200
(1 row)
See Also
l
Analytic Functions
MAX [Aggregate]
REGR_AVGX
Returns the average of the independent expression in an expression pair (expression1 and
expression2). The return value is of type DOUBLE PRECISION. The function eliminates
expression pairs where either expression in the pair is NULL. If no rows remain, the function returns
NULL.
Syntax
SELECT REGR_AVGX (expression1,expression2)
Parameters
expression1
expression2
SQLReference Manual
SQL Functions
Example
=> SELECT REGR_AVGX (Annual_salary, Employee_age)
FROM employee_dimension;
REGR_AVGX
----------39.321
(1 row)
REGR_AVGY
Returns the average of the dependent expression in an expression pair (expression1 and
expression2). The return value is of type DOUBLE PRECISION. The function eliminates
expression pairs where either expression in the pair is NULL. If no rows remain, the function returns
NULL.
Syntax
REGR_AVGY (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT REGR_AVGY (Annual_salary, Employee_age)
FROM employee_dimension;
REGR_AVGY
-----------58354.4913
(1 row)
REGR_COUNT
Returns the number of expression pairs (expression1 and expression2). The return value is of type
INTEGER. The function eliminates expression pairs where either expression in the pair is NULL. If
no rows remain, the function returns 0.
SQLReference Manual
SQL Functions
Syntax
SELECT REGR_COUNT (expression1, expression2)
Parameters
expression1
expression2
Example
=> SELECT REGR_COUNT (Annual_salary, Employee_age) FROM employee_dimension;
REGR_COUNT
-----------10000
(1 row)
REGR_INTERCEPT
Returns the y-intercept of the regression line determined by a set of expression pairs (expression1
and expression2). The return value is of type DOUBLE PRECISION. The function eliminates
expression pairs where either expression in the pair is NULL. If no rows remain, the function returns
NULL.
Syntax
SELECT REGR_INTERCEPT (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT REGR_INTERCEPT (Annual_salary, Employee_age) FROM employee_dimension;
REGR_INTERCEPT
-----------------59929.5490163437
SQLReference Manual
SQL Functions
(1 row)
REGR_R2
Returns the square of the correlation coefficient of a set of expression pairs (expression1 and
expression2). The return value is of type DOUBLE PRECISION. The function eliminates
expression pairs where either expression in the pair is NULL. If no rows remain, the function returns
NULL.
Syntax
SELECT REGR_R2 (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT REGR_R2 (Annual_salary, Employee_age) FROM employee_dimension;
REGR_R2
---------------------5.17181631706311e-05
(1 row)
REGR_SLOPE
Returns the slope of the regression line, determined by a set of expression pairs (expression1 and
expression2). The return value is of type DOUBLE PRECISION. The function eliminates
expression pairs where either expression in the pair is NULL. If no rows remain, the function returns
NULL.
Syntax
SELECT REGR_SLOPE (expression1,expression2)
Parameters
expression1
SQLReference Manual
SQL Functions
expression2
Example
=> SELECT REGR_SLOPE (Annual_salary, Employee_age) FROM employee_dimension;
REGR_SLOPE
------------------40.056400303749
(1 row)
REGR_SXX
Returns the sum of squares of the independent expression in an expression pair (expression1 and
expression2). The return value is of type DOUBLE PRECISION. The function eliminates
expression pairs where either expression in the pair is NULL. If no rows remain, the function returns
NULL.
Syntax
SELECT REGR_SXX (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT REGR_SXX (Annual_salary, Employee_age) FROM employee_dimension;
REGR_SXX
-----------2254907.59
(1 row)
REGR_SXY
Returns the sum of products of the independent expression multiplied by the dependent expression
in an expression pair (expression1 and expression2). The return value is of type DOUBLE
PRECISION. The function eliminates expression pairs where either expression in the pair is NULL.
If no rows remain, the function returns NULL.
SQLReference Manual
SQL Functions
Syntax
SELECT REGR_SXY (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT REGR_SXY (Annual_salary, Employee_age) FROM employee_dimension;
REGR_SXY
-------------------90323481.0730019
(1 row)
REGR_SYY
Returns the sum of squares of the dependent expression in an expression pair (expression1 and
expression2). The return value is of type DOUBLE PRECISION. The function eliminates
expression pairs where either expression in the pair is NULL. If no rows remain, the function returns
NULL.
Syntax
SELECT REGR_SYY (expression1,expression2)
Parameters
expression1
expression2
Example
=> SELECT REGR_SYY (Annual_salary, Employee_age) FROM employee_dimension;
REGR_SYY
-----------------69956728794707.2
SQLReference Manual
SQL Functions
(1 row)
STDDEV [Aggregate]
Note: The non-standard function STDDEV() is provided for compatibility with other databases.
It is semantically identical to STDDEV_SAMP().
Evaluates the statistical sample standard deviation for each member of the group. The STDDEV()
return value is the same as the square root of the VAR_SAMP() function:
STDDEV(expression) = SQRT(VAR_SAMP(expression))
Behavior Type
Immutable
Syntax
STDDEV ( expression )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
Notes
The STDDEV() aggregate function is different from the STDDEV() analytic function, which computes
the statistical sample standard deviation of the current row with respect to the group of rows within
a window.
Examples
The following example returns the statistical sample standard deviation for each household ID from
the customer_dimension table of the VMart example database:
SQLReference Manual
SQL Functions
See Also
l
Analytic Functions
STDDEV_SAMP [Aggregate]
STDDEV_POP [Aggregate]
Evaluates the statistical population standard deviation for each member of the group. The STDDEV_
POP() return value is the same as the square root of the VAR_POP() function
STDDEV_POP(expression) = SQRT(VAR_POP(expression))
Behavior Type
Immutable
Syntax
STDDEV_POP ( expression )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
Notes
The STDDEV_POP() aggregate function is different from the STDDEV_POP() analytic function, which
evaluates the statistical population standard deviation for each member of the group of rows within
a window.
SQLReference Manual
SQL Functions
Examples
The following example returns the statistical population standard deviation for each household ID in
the customer table.
=> SELECT STDDEV_POP(household_id) FROM customer_dimension;
STDDEV_POP
-----------------8651.41895973367
(1 row)
See Also
l
Analytic Functions
STDDEV_SAMP [Aggregate]
Evaluates the statistical sample standard deviation for each member of the group. The STDDEV_
SAMP() return value is the same as the square root of the VAR_SAMP() function:
STDDEV_SAMP(expression) = SQRT(VAR_SAMP(expression))
Behavior Type
Immutable
Syntax
STDDEV_SAMP ( expression )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
SQLReference Manual
SQL Functions
Notes
l
The STDDEV_SAMP() aggregate function is different from the STDDEV_SAMP() analytic function,
which computes the statistical sample standard deviation of the current row with respect to the
group of rows within a window.
Examples
The following example returns the statistical sample standard deviation for each household ID from
the customer dimension table.
=> SELECT STDDEV_SAMP(household_id) FROM customer_dimension;
stddev_samp
-----------------8651.50842400771
(1 row)
See Also
l
Analytic Functions
STDDEV [Aggregate]
SUM [Aggregate]
Computes the sum of an expression over a group of rows. It returns a DOUBLE PRECISION value for
a floating-point expression. Otherwise, the return value is the same as the expression data type.
Behavior Type
Immutable
Syntax
SUM ( [ ALL | DISTINCT ] expression )
SQLReference Manual
SQL Functions
Parameters
ALL
Invokes the aggregate function for all rows in the group (default)
DISTINCT
Invokes the aggregate function for all distinct non-null values of the expression
found in the group
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
Notes
l
The SUM() aggregate function is different from the SUM() analytic function, which computes the
sum of an expression over a group of rows within a window.
If you encounter data overflow when using SUM(), use SUM_FLOAT() which converts the data to
a floating point.
Example
This example returns the total sum of the product_cost column.
=> SELECT SUM(product_cost) AS cost FROM product_dimension;
cost
--------9042850
(1 row)
See Also
l
AVG [Aggregate]
COUNT [Aggregate]
SQLReference Manual
SQL Functions
SUM_FLOAT [Aggregate]
Computes the sum of an expression over a group of rows. It returns a DOUBLE PRECISION value for
the expression, regardless of the expression type.
Behavior Type
Immutable
Syntax
SUM_FLOAT ( [ ALL | DISTINCT ] expression )
Parameters
ALL
Invokes the aggregate function for all rows in the group (default).
DISTINCT
Invokes the aggregate function for all distinct non-null values of the expression
found in the group.
expression
Example
The following example returns the floating-point sum of the average price from the product table:
=> SELECT SUM_FLOAT(average_competitor_price) AS cost FROM product_dimension;
cost
---------18181102
(1 row)
VAR_POP [Aggregate]
Evaluates the population variance for each member of the group. This is defined as the sum of
squares of the difference of expression from the mean of expression, divided by the number of rows
remaining.
(SUM(expression*expression) - SUM(expression)*SUM(expression) /COUNT(expression)) / COUNT
(expression)
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
VAR_POP ( expression )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
Notes
The VAR_POP() aggregate function is different from the VAR_POP() analytic function, which
computes the population variance of the current row with respect to the group of rows within a
window.
Examples
The following example returns the population variance for each household ID in the customer table.
=> SELECT VAR_POP(household_id) FROM customer_dimension;
var_pop
-----------------74847050.0168393
(1 row)
VAR_SAMP [Aggregate]
Evaluates the sample variance for each row of the group. This is defined as the sum of squares of
the difference of expression from the mean of expression, divided by the number of rows remaining
minus 1 (one).
(SUM(expression*expression) - SUM(expression) *SUM(expression) /COUNT(expression)) /
(COUNT(expression) -1)
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
VAR_SAMP ( expression )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
Notes
l
The VAR_SAMP() aggregate function is different from the VAR_SAMP() analytic function, which
computes the sample variance of the current row with respect to the group of rows within a
window.
Examples
The following example returns the sample variance for each household ID in the customer table.
=> SELECT VAR_SAMP(household_id) FROM customer_dimension;
var_samp
-----------------74848598.0106764
(1 row)
See Also
l
Analytic Functions
VARIANCE [Aggregate]
VARIANCE [Aggregate]
Note: The non-standard function VARIANCE() is provided for compatibility with other
databases. It is semantically identical to VAR_SAMP().
SQLReference Manual
SQL Functions
Evaluates the sample variance for each row of the group. This is defined as the sum of squares of
the difference of expression from the mean of expression, divided by the number of rows remaining
minus 1 (one).
(SUM(expression*expression) - SUM(expression) *SUM(expression) /COUNT(expression)) /
(COUNT(expression) -1)
Behavior Type
Immutable
Syntax
VARIANCE ( expression )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
Notes
The VARIANCE() aggregate function is different from the VARIANCE() analytic function, which
computes the sample variance of the current row with respect to the group of rows within a
window.
Examples
The following example returns the sample variance for each household ID in the customer table.
=> SELECT VARIANCE(household_id) FROM customer_dimension;
variance
-----------------74848598.0106764
(1 row)
See Also
l
Analytic Functions
VAR_SAMP [Aggregate]
SQLReference Manual
SQL Functions
SQLReference Manual
SQL Functions
Analytic Functions
Note: All analytic functions in this section that have an aggregate counterpart are appended
with [Analytics] in the heading to avoid confusion between the two.
HP Vertica analytics are SQL functions based on the ANSI 99 standard. These functions handle
complex analysis and reporting tasks such as:
l
Find the highest score among all students in the same grade
Compare the current sales bonus each salesperson received against his or her previous bonus
Analytic functions return aggregate results but they do not group the result set. They return the
group value multiple times, once per record.
You can sort these group values, or partitions, using a window ORDER BY clause, but the order
affects only the function result set, not the entire query result set. This ordering concept is
described more fully later.
OVER(...)
SQLReference Manual
SQL Functions
window_partition_clause
window_order_clause
Sorts the rows specified by the OVER() operator and supplies the
ordered set of rows to the analytic function. If the partition clause is
present, the window_order_clause applies within each partition.
The order clause is optional. If you do not use it, the selection set is
not sorted. See window_order_clause.
window_frame_clause
Used by only some analytic functions. If you include the frame clause
in the OVER() statement, which specifies the beginning and end of the
window relative to the current row, the analytic function applies only to
a subset of the rows defined by the partition clause. This subset
changes as the rows in the partition change (called a moving window).
See window_frame_clause.
Notes
Analytic functions:
l
Require the OVER() clause. However, depending on the function, the window_frame_clause
and window_order_clause might not apply. For example, when used with analytic aggregate
functions like SUM(x), you can use the OVER() clause without supplying any of the windowing
clauses; in this case, the aggregate returns the same aggregated value for each row of the result
set.
Can be used in a subquery or in the parent query but cannot be nested; for example, the
following query is not allowed:
=> SELECT MEDIAN(RANK() OVER(ORDER BY sal) OVER()).
WHERE, GROUP BY and HAVING operators are technically not part of the analytic function;
however, they determine on which rows the analytic functions operate.
SQLReference Manual
SQL Functions
See Also
l
window_partition_clause
When specified, the window_partition_clause divides the rows in the input based on userprovided expressions, such as aggregation functions like SUM(x), or it provides query performance
improvements by using parallelism when no expression is provided.
Window partitioning is similar to the GROUP BY clause except that it returns only one result row
per input row. If you omit the window_partition_clause, all input rows are treated as a single
partition.
When used with analytic functions, results are computed per partition and start over again (reset) at
the beginning of each subsequent partition.
The window_partition_clause is specified within the OVER() clause.
Syntax
OVER ( [ PARTITION BY expression
Parameters
empty
PARTITION BY
expression
SQLReference Manual
SQL Functions
PARTITION BEST
PARTITION NODES
Examples
The following example uses the VMart sample database to show how to use the analytic window_
partition_clause to calculate median annual income within each occupation. The analytic function is
computed per partition and starts over again at the beginning of the next partition.
=> SELECT customer_name, occupation, annual_income, MEDIAN(annual_income)
OVER (PARTITION BY occupation) AS MEDIAN FROM customer_dimension;
Partial output for this example shows the results are grouped into partitions for Accountant
(515392.5) and Acrobat (513514.5) under the median column.
customer_name
| occupation | annual_income | median
-------------------+------------+---------------+--------Jose I. Brown
| Accountant |
11371 | 515392.5
Jessica O. Nguyen | Accountant |
12374 | 515392.5
Robert H. Kramer
| Accountant |
999129 | 515392.5
Ruth C. Lewis
| Acrobat
|
10715 | 513514.5
Sarah S. Greenwood | Acrobat
|
11016 | 513514.5
Mary Z. Jones
| Acrobat
|
12140 | 513514.5
window_order_clause
Sorts the rows specified by the OVER() clause and specifies whether data is sorted in ascending or
descending order as well as the placement of null values. For example:
SQLReference Manual
SQL Functions
Null placement
ORDER BY column1
Because the window_order_clause is different from a query's final ORDER BY clause, window
ordering might not guarantee the final result order; it specifies only the order within a window result
set, supplying the ordered set of rows to the window_frame_clause (if present), to the analytic
function, or to both. Use the SQL ORDER BY clause to guarantee ordering of the final result set.
Syntax
OVER ( ORDER BY expression [ { ASC | DESC } ]
... [ NULLS { FIRST | LAST | AUTO } ] [, expression ...] )
Parameters
expression
ASC | DESC
SQLReference Manual
SQL Functions
RANK() / DENSE_RANK()
LEAD() / LAG()
PERCENT_RANK() / CUME_DIST()
NTILE()
You can also use the window_order_clause with aggregation functions, such as SUM(x).
The ORDER BY clause is optional for the ROW_NUMBER() function.
The ORDER BY clause is not allowed with the following functions:
l
PERCENTILE_CONT() / PERCENTILE_DISC()
MEDIAN()
Examples
The following example uses the VMart sample database to show how to use the analytic window_
order_clause to order the annual_income inside each occupation partition.
SQLReference Manual
SQL Functions
window_frame_clause
Allowed for some analytic functions in the analytic OVER() clause, window framing represents a
unique construct, called a moving window. It defines which values in the partition are evaluated
relative to the current row. You specify a window frame in terms of either logical intervals (such as
time) using the RANGE keyword or on a physical number of rows before and/or after the current row
using the ROWS keyword. The CURRENT ROW is the next row for which the analytic function
computes results.
As the current row advances, the window boundaries are recomputed (move) along with it,
determining which rows fall into the current window.
An analytic function with a window frame specification is computed for each row based on the rows
that fall into the window relative to that row.
An analytic function with a window frame specification is computed for each row based on the rows
that fall into the window relative to that row. If you omit the window_frame_clause, the default
window is RANGE UNBOUNDED PRECEDING AND CURRENT ROW.
Syntax
{ ROWS | RANGE }
{
{
BETWEEN
{ UNBOUNDED PRECEDING
| CURRENT ROW
| constant-value { PRECEDING | FOLLOWING }
}
SQLReference Manual
SQL Functions
AND
{ UNBOUNDED FOLLOWING
| CURRENT ROW
| constant-value { PRECEDING | FOLLOWING }
}
}
|
{
{ UNBOUNDED PRECEDING
| CURRENT ROW
| constant-value PRECEDING
}
}
}
Parameters
ROWS | RANGE
SQLReference Manual
SQL Functions
UNBOUNDED PRECEDING
UNBOUNDED FOLLOWING
CURRENT ROW
SQLReference Manual
SQL Functions
SQLReference Manual
SQL Functions
Window Aggregates
Analytic functions that take the window_frame_clause are called window aggregates, and they
return information such as moving averages and cumulative results. To use the following functions
as window (analytic) aggregates, instead of basic aggregates, specify both an ORDER BY clause
(window_order_clause) and a moving window (window_frame_clause) in the OVER() clause.
Used by only some analytic functions. If you include the frame clause in the OVER() statement,
which specifies the beginning and end of the window relative to the current row, the analytic
function applies only to a subset of the rows defined by the partition clause. This subset changes as
the rows in the partition change (called a moving window). See window_frame_clause.
Sorts the rows specified by the window_partition_clause and supplies an ordered set of rows to
the window_frame_clause (if present), to the analytic function, or to both. The window_order_
clause specifies whether data is returned in ascending or descending order and specifies where
null values appear in the sorted result as either first or last. The ordering of the data affects the
results.
Note: The window_order_clause does not guarantee the order of the SQL result. Use the SQL
ORDER BY clause to guarantee the ordering of the final result set.
Within a partition, UNBOUNDED PRECEDING/FOLLOWING means beginning/end of partition. If
you omit the window_frame_clause but you specify the window_order_clause, the system
provides the default window of RANGE BETWEEN UNBOUNDED PRECEDING AND
CURRENT ROW.
The following analytic functions take the window_frame_clause:
l
AVG()
COUNT()
SUM()
SQLReference Manual
SQL Functions
clause.
If you use a window aggregate with an empty OVER() clause, there is no moving window, and the
function is used as a reporting function, where the entire input is treated as one partition.
The value returned by an analytic function with a logical offset is always deterministic. However,
the value returned by an analytic function with a physical offset could produce nondeterministic
results unless the ordering expression results in a unique ordering. You might have to specify
multiple columns in the window_order_clause to achieve this unique ordering.
Examples
This example uses the VMart sample database to show how to use the ROWS-based window for
the COUNT() analytic function to return the customer name, occupation, and annual income with a
count. The window_frame_clause specifies the rows between the current row and two preceding.
Using ROWS in the window_frame_clause specifies the window as a physical offset and defines
the start- and end-point of a window by the number of rows before and after the current row.
=>Select customer_name, occupation, annual_income,
COUNT(*) OVER (PARTITION BY occupation ORDER BY
annual_income ROWS BETWEEN 2 PRECEDING AND CURRENT ROW)
AS COUNT FROM customer_dimension;
customer_name
| occupation | annual_income | COUNT
------------------+------------+---------------+-----Jose I. Brown
| Accountant |
11371 |
1
Jose I. Brown
| Accountant |
11371 |
2
Jose I. Brown
| Accountant |
11371 |
3
Jessica O. Nguyen | Accountant |
12374 |
3
Jessica O. Nguyen | Accountant |
12374 |
3
Jessica O. Nguyen | Accountant |
12374 |
3
...
Ruth C. Lewis
| Acrobat
|
10715 |
1
Ruth C. Lewis
| Acrobat
|
10715 |
2
Ruth C. Lewis
| Acrobat
|
10715 |
3
Sarah S. Greenwood | Acrobat
|
11016 |
3
Sarah S. Greenwood | Acrobat
|
11016 |
3
Sarah S. Greenwood | Acrobat
|
11016 |
3
SQLReference Manual
SQL Functions
named_windows
You can use the WINDOW clause to name your windows and avoid typing long OVER() clause
syntax.
The window_partition_clause is defined in the named window specification, not in the OVER()
clause, and a window definition cannot contain a window_frame_clause.
Each window defined in the window_definition_clause must have a unique name.
Syntax
WINDOW window_name AS ( window_definition_clause );
Parameters
window_name
window_definition_clause
[window_partition_clause ] [window_order_clause ]
Examples
In the following example, RANK() and DENSE_RANK() use the partitioning and ordering specifications
in the window definition for a window named w:
=> SELECT RANK() OVER w , DENSE_RANK() OVER w
FROM employee_dimension
WINDOW w AS (PARTITION BY employee_region ORDER by annual_salary);
Though analytic functions can reference a named window to inherit the window_partition_clause,
you can use OVER() to define your own window_order_clause, but only if the window_definition_
clause did not already define it. Because ORDER by annual_salary was already defined in the
WINDOW clause in the previous example, the following query would return an error.
=> SELECT RANK() OVER(w ORDER BY annual_salary ASC),
DENSE_RANK() OVER(w ORDER BY annual_salary DESC)
FROM employee_dimension
WINDOW w AS (PARTITION BY employee_region);
ERROR: cannot override ORDER BY clause of window "w"
You can reference window names within their scope only. For example, because named window w1
in the following query is defined before w2, w2 is within the scope of w1:
SQLReference Manual
SQL Functions
AVG [Analytic]
Computes an average of an expression in a group within a window.
Behavior Type
Immutable
Syntax
AVG
...
...
...
(
[
[
[
expression ) OVER (
window_partition_clause ]
window_order_clause ]
window_frame_clause ] )
Parameters
expression
The value whose average is calculated over a set of rows. Can be any expression
resulting in DOUBLE PRECISION.
OVER(...)
Notes
AVG() takes as an argument any numeric data type or any non-numeric data type that can be
implicitly converted to a numeric data type. The function returns the same data type as the
argument's numeric data type.
Examples
The following query finds the sales for that calendar month and returns a running/cumulative
average (sometimes called a moving average) using the default window of RANGE UNBOUNDED
PRECEDING AND CURRENT ROW:
=> SELECT calendar_month_number_in_year, SUM(product_price) AS sales,
AVG(SUM(product_price)) OVER (ORDER BY calendar_month_number_in_year)
FROM product_dimension, date_dimension, inventory_fact
WHERE date_dimension.date_key = inventory_fact.date_key
AND product_dimension.product_key = inventory_fact.product_key
SQLReference Manual
SQL Functions
GROUP BY calendar_month_number_in_year;
calendar_month_number_in_year | sales
|
?column?
-------------------------------+----------+-----------------1 | 23869547 |
23869547
2 | 19604661 |
21737104
3 | 22877913 | 22117373.6666667
4 | 22901263 |
22313346
5 | 23670676 |
22584812
6 | 22507600 | 22571943.3333333
7 | 21514089 | 22420821.2857143
8 | 24860684 |
22725804.125
9 | 21687795 | 22610469.7777778
10 | 23648921 |
22714314.9
11 | 21115910 | 22569005.3636364
12 | 24708317 | 22747281.3333333
(12 rows)
To return a moving average that is not a running (cumulative) average, the window should specify
ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING:
=> SELECT calendar_month_number_in_year, SUM(product_price) AS sales,
AVG(SUM(product_price)) OVER (ORDER BY calendar_month_number_in_year
ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
FROM product_dimension, date_dimension, inventory_fact
WHERE date_dimension.date_key = inventory_fact.date_key
AND product_dimension.product_key = inventory_fact.product_key
GROUP BY calendar_month_number_in_year;
See Also
l
AVG [Aggregate]
COUNT [Analytic]
SUM [Analytic]
CONDITIONAL_CHANGE_EVENT [Analytic]
Assigns an event window number to each row, starting from 0, and increments by 1 when the result
of evaluating the argument expression on the current row differs from that on the previous row.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
CONDITIONAL_CHANGE_EVENT ( expression ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
expression
SQL scalar expression that is evaluated on an input record. The result of expression
can be of any data type.
OVER(...)
Notes
The analytic window_order_clause is required but the window_partition_clause is optional.
Example
=> SELECT CONDITIONAL_CHANGE_EVENT(bid)
OVER (PARTITION BY symbol ORDER BY ts) AS cce
FROM TickStore;
For more examples, see Event-Based Windows in the Analyzing Data Guide.
See Also
l
CONDITIONAL_TRUE_EVENT [Analytic]
ROW_NUMBER [Analytic]
Event-Based Windows
SQLReference Manual
SQL Functions
CONDITIONAL_TRUE_EVENT [Analytic]
Assigns an event window number to each row, starting from 0, and increments the number by 1
when the result of the boolean argument expression evaluates true. For example, given a sequence
of values for column a, as follows:
( 1, 2, 3, 4, 5, 6 )
Behavior Type:
Immutable
Syntax
CONDITIONAL_TRUE_EVENT ( boolean-expression ) OVER
... ( [ window_partition_clause ]
... window_order_clause )
Parameters
boolean-expression
OVER(...)
Notes
The analytic window_order_clause is required but the window_partition_clause is optional.
Example
> SELECT CONDITIONAL_TRUE_EVENT(bid > 10.6)
OVER(PARTITION BY bid ORDER BY ts) AS cte
FROM Tickstore;
SQLReference Manual
SQL Functions
For more examples, see Event-Based Windows in the Analyzing Data Guide.
See Also
l
CONDITIONAL_CHANGE_EVENT [Analytic]
Event-Based Windows
COUNT [Analytic]
Counts occurrences within a group within a window. If you specify * or some non-null constant,
COUNT() counts all rows.
Behavior Type
Immutable
Syntax
COUNT
... [
... [
... [
( expression ) OVER (
window_partition_clause ]
window_order_clause ]
window_frame_clause ] )
Parameters
expression
Returns the number of rows in each group for which the expression is not null. Can
be any expression resulting in BIGINT.
OVER(...)
Example
Using the schema defined in Window Framing in the Analyzing Data Guide, the following COUNT
function does not specify an order_clause or a frame_clause; otherwise it would be treated as a
window aggregate. Think of the window of reporting aggregates as UNBOUNDED PRECEDING
and UNBOUNDED FOLLOWING.
SQLReference Manual
SQL Functions
Using ORDER BY sal creates a moving window query with default window: RANGE BETWEEN
UNBOUNDED PRECEDING AND CURRENT ROW.
=> SELECT deptno, sal, empno, COUNT(sal)
OVER (PARTITION BY deptno ORDER BY sal) AS count
FROM emp;
deptno | sal | empno | count
--------+-----+-------+------10 | 101 |
1 |
1
10 | 104 |
4 |
2
20 | 100 |
11 |
1
20 | 109 |
7 |
4
20 | 109 |
6 |
4
20 | 109 |
8 |
4
20 | 110 |
10 |
6
20 | 110 |
9 |
6
30 | 102 |
2 |
1
30 | 103 |
3 |
2
30 | 105 |
5 |
3
Using the VMart schema, the following query finds the number of employees who make less than or
equivalent to the hourly rate of the current employee. The query returns a running/cumulative
average (sometimes called a moving average) using the default window of RANGE UNBOUNDED
PRECEDING AND CURRENT ROW:
=> SELECT employee_last_name AS "last_name", hourly_rate, COUNT(*)
OVER (ORDER BY hourly_rate) AS moving_count from employee_dimension;
last_name | hourly_rate | moving_count
------------+-------------+-------------Gauthier
|
6 |
4
Taylor
|
6 |
4
Jefferson |
6 |
4
Nielson
|
6 |
4
McNulty
|
6.01 |
11
Robinson
|
6.01 |
11
SQLReference Manual
SQL Functions
Dobisz
Williams
Kramer
Miller
Wilson
Vogel
Moore
Vogel
Carcetti
...
|
|
|
|
|
|
|
|
|
6.01
6.01
6.01
6.01
6.01
6.02
6.02
6.02
6.03
|
|
|
|
|
|
|
|
|
11
11
11
11
11
14
14
14
19
To return a moving average that is not also a running (cumulative) average, the window should
specify ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING:
=> SELECT employee_last_name AS "last_name", hourly_rate, COUNT(*)
OVER (ORDER BY hourly_rate ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
AS moving_count from employee_dimension;
See Also
l
COUNT [Aggregate]
AVG [Analytic]
SUM [Analytic]
CUME_DIST [Analytic]
Calculates the cumulative distribution, or relative rank, of the current row with regard to other rows
in the same partition within a window.
CUME_DIST() returns a number greater then 0 and less then or equal to 1, where the number
represents the relative position of the specified row within a group of N rows. For a row x (assuming
ASC ordering), the CUME_DIST of x is the number of rows with values lower than or equal to the value
of x, divided by the number of rows in the partition. In a group of three rows, for example, the
cumulative distribution values returned would be 1/3, 2/3, and 3/3.
Note: Because the result for a given row depends on the number of rows preceding that row in
the same partition, HP recommends that you always specify a window_order_clause when
you call this function.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
CUME_DIST ( ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
OVER(...)
Notes
The analytic window_order_clause is required but the window_partition_clause is optional.
Examples
The following example returns the cumulative distribution of sales for different transaction types
within each month of the first quarter.
=> SELECT calendar_month_name AS month, tender_type, SUM(sales_quantity),
CUME_DIST()
OVER (PARTITION BY calendar_month_name ORDER BY SUM(sales_quantity)) AS
CUME_DIST
FROM store.store_sales_fact JOIN date_dimension
USING(date_key) WHERE calendar_month_name IN ('January','February','March')
AND tender_type NOT LIKE 'Other'
GROUP BY calendar_month_name, tender_type;
month
| tender_type | SUM
| CUME_DIST
----------+-------------+--------+----------March
| Credit
| 469858 |
0.25
March
| Cash
| 470449 |
0.5
March
| Check
| 473033 |
0.75
March
| Debit
| 475103 |
1
January | Cash
| 441730 |
0.25
January | Debit
| 443922 |
0.5
January | Check
| 446297 |
0.75
January | Credit
| 450994 |
1
February | Check
| 425665 |
0.25
February | Debit
| 426726 |
0.5
February | Credit
| 430010 |
0.75
February | Cash
| 430767 |
1
(12 rows)
SQLReference Manual
SQL Functions
See Also
l
PERCENT_RANK [Analytic]
PERCENTILE_DISC [Analytic]
DENSE_RANK [Analytic]
Computes the relative rank of each row returned from a query with respect to the other rows, based
on the values of the expressions in the window ORDER BY clause.
The data within a group is sorted by the ORDER BY clause and then a numeric ranking is assigned to
each row in turn starting with 1 and continuing from there. The rank is incremented every time the
values of the ORDER BY expressions change. Rows with equal values receive the same rank (nulls
are considered equal in this comparison). A DENSE_RANK() function returns a ranking number
without any gaps, which is why it is called "DENSE."
Behavior Type
Immutable
Syntax
DENSE_RANK ( ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
OVER(...)
Notes
l
The ranks are consecutive integers beginning with 1. The largest rank value is the number of
unique values returned by the query.
The primary difference between DENSE_RANK() and RANK() is that RANK leaves gaps when
SQLReference Manual
SQL Functions
ranking records whereas DENSE_RANK leaves no gaps. For example, N records occupy a
particular position (say, a tie for rank X), RANK assigns all those records with rank X and skips
the next N ranks, therefore the next assigned rank is X+N. DENSE_RANK places all the records in
that position onlyit does not skip any ranks.
If there is a tie at the third position with two records having the same value, RANK and DENSE_
RANK place both the records in the third position, but RANK places the next record at the fifth
position, while DENSE_RANK places the next record at the fourth position.
l
If you omit NULLS FIRST | LAST | AUTO, the ordering of the NULL values depends on the ASC or
DESC arguments. NULL values are considered larger than any other value. If the ordering
sequence is ASC, then nulls appear last; nulls appear first otherwise. Nulls are considered equal
to other nulls and, therefore, the order in which nulls are presented is non-deterministic.
Example
The following example shows the difference between RANK and DENSE_RANK when ranking
customers by their annual income. Notice that RANK has a tie at 10 and skips 11, while DENSE_RANK
leaves no gaps in the ranking sequence:
=> SELECT customer_name, SUM(annual_income),
RANK () OVER (ORDER BY TO_CHAR(SUM(annual_income),'100000') DESC) rank,
DENSE_RANK () OVER (ORDER BY TO_CHAR(SUM(annual_income),'100000') DESC) dense_rank
FROM customer_dimension GROUP BY customer_name LIMIT 15;
customer_name
| sum | rank | dense_rank
---------------------+-------+------+-----------Brian M. Garnett
| 99838 |
1 |
1
Tanya A. Brown
| 99834 |
2 |
2
Tiffany P. Farmer
| 99826 |
3 |
3
Jose V. Sanchez
| 99673 |
4 |
4
Marcus D. Rodriguez | 99631 |
5 |
5
Alexander T. Nguyen | 99604 |
6 |
6
Sarah G. Lewis
| 99556 |
7 |
7
Ruth Q. Vu
| 99542 |
8 |
8
Theodore T. Farmer | 99532 |
9 |
9
Daniel P. Li
| 99497 |
10 |
10
Seth E. Brown
| 99497 |
10 |
10
Matt X. Gauthier
| 99402 |
12 |
11
Rebecca W. Lewis
| 99296 |
13 |
12
Dean L. Wilson
| 99276 |
14 |
13
Tiffany A. Smith
| 99257 |
15 |
14
(15 rows)
SQLReference Manual
SQL Functions
See Also
l
RANK [Analytic]
EXPONENTIAL_MOVING_AVERAGE [Analytic]
Calculates the exponential moving average of expression E with smoothing factor X.
The exponential moving average (EMA) is calculated by adding the previous EMA value to the
current data point scaled by the smoothing factor, as in the following formula, where:
l
Behavior Type
Immutable
Syntax
EXPONENTIAL_MOVING_AVERAGE ( E , X ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
E
The value whose average is calculated over a set of rows. Can be INTEGER, FLOAT or
NUMERIC type and must be a constant.
A positive FLOAT value between 0 and 1 that is used as the smoothing factor.
OVER(...)
SQLReference Manual
SQL Functions
Notes
l
The EXPONENTIAL_MOVING_AVERAGE() function also works at the row level; for example, EMA
assumes the data in a given column is sampled at uniform intervals. If the users' data points are
sampled at non-uniform intervals, they should run the time series gap filling and interpolation
(GFI) operations before EMA().
Examples
The following example uses time series gap filling and interpolation (GFI) first in a subquery, and
then performs an EXPONENTIAL_MOVING_AVERAGE operation on the subquery result.
Create a simple four-column table:
=> CREATE TABLE ticker(
time TIMESTAMP,
symbol VARCHAR(8),
bid1 FLOAT,
bid2 FLOAT );
Insert some data, including nulls, so GFI can do its interpolation and gap filling:
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
COMMIT;
ticker
ticker
ticker
ticker
ticker
ticker
ticker
ticker
ticker
ticker
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
VALUES
('2009-07-12
('2009-07-12
('2009-07-12
('2009-07-12
('2009-07-12
('2009-07-12
('2009-07-12
('2009-07-12
('2009-07-12
('2009-07-12
03:00:00',
03:00:01',
03:00:02',
03:00:03',
03:00:04',
03:00:00',
03:00:01',
03:00:02',
03:00:03',
03:00:04',
'ABC',
'ABC',
'ABC',
'ABC',
'ABC',
'XYZ',
'XYZ',
'XYZ',
'XYZ',
'XYZ',
60.45, 60.44);
60.49, 65.12);
57.78, 59.25);
null, 65.12);
67.88, null);
47.55, 40.15);
44.35, 46.78);
71.56, 75.78);
85.55, 70.21);
45.55, 58.65);
Note: During gap filling and interpolation, HP Vertica takes the closest non null value on either
side of the time slice and uses that value. For example, if you use a linear interpolation scheme
and you do not specify IGNORE NULLS, and your data has one real value and one null, the result
is null. If the value on either side is null, the result is null. See When Time Series Data Contains
Nulls in the Analyzing Data Guide for details.
Query the table that you just created to you can see the output:
SQLReference Manual
SQL Functions
The following query processes the first and last values that belong to each 2-second time slice in
table trades' column a. The query then calculates the exponential moving average of expression fv
and lv with a smoothing factor of 50%:
=> SELECT symbol, slice_time, fv, lv,
EXPONENTIAL_MOVING_AVERAGE(fv, 0.5)
OVER (PARTITION BY symbol ORDER BY slice_time) AS ema_first,
EXPONENTIAL_MOVING_AVERAGE(lv, 0.5)
OVER (PARTITION BY symbol ORDER BY slice_time) AS ema_last
FROM (
SELECT symbol, slice_time,
TS_FIRST_VALUE(bid1 IGNORE NULLS) as fv,
TS_LAST_VALUE(bid2 IGNORE NULLS) AS lv
FROM ticker TIMESERIES slice_time AS '2 seconds'
OVER (PARTITION BY symbol ORDER BY time) ) AS sq;
symbol |
slice_time
| fv
| lv
| ema_first | ema_last
--------+---------------------+-------+-------+-----------+---------ABC
| 2009-07-12 03:00:00 | 60.45 | 65.12 |
60.45 |
65.12
ABC
| 2009-07-12 03:00:02 | 57.78 | 65.12 |
59.115 |
65.12
ABC
| 2009-07-12 03:00:04 | 67.88 | 65.12 |
63.4975 |
65.12
XYZ
| 2009-07-12 03:00:00 | 47.55 | 46.78 |
47.55 |
46.78
XYZ
| 2009-07-12 03:00:02 | 71.56 | 70.21 |
59.555 |
58.495
XYZ
| 2009-07-12 03:00:04 | 45.55 | 58.65 |
52.5525 | 58.5725
(6 rows)
See Also
l
TIMESERIES Clause
SQLReference Manual
SQL Functions
FIRST_VALUE [Analytic]
Allows the selection of the first value of a table or partition without having to use a self-join. If no
window is specified for the current row, the default window is UNBOUNDED PRECEDING AND
CURRENT ROW.
Behavior Type
Immutable
Syntax
FIRST_VALUE ( expression [ IGNORE NULLS ] ) OVER (
... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
Parameters
expression
IGNORE NULLS
Specifies to return the first non-null value in the set, or NULL if all values are NULL.
OVER(...)
Notes
l
The FIRST_VALUE() function lets you select a table's first value (determined by the window_
order_clause) without having to use a self join. This function is useful when you want to use
the first value as a baseline in calculations.
If the first value in the set is null, then the function returns NULL unless you specify IGNORE
NULLS. If you specify IGNORE NULLS, FIRST_VALUE returns the first non-null value in the set, or
NULL if all values are null.
Examples
The following query, which asks for the first value in the partitioned day of week, illustrates the
potential nondeterministic nature of the FIRST_VALUE function:
SQLReference Manual
SQL Functions
The first value returned is January 31, 2003; however, the next time the same query is run, the first
value could be January 24 or January 3, or the 10th or 17th. The reason is because the analytic
ORDER BY column (day_of_week) returns rows that contain ties (multiple Fridays). These repeated
values make the ORDER BY evaluation result nondeterministic, because rows that contain ties can
be ordered in any way, and any one of those rows qualifies as being the first value of day_of_week.
calendar_year | date_key | day_of_week | full_date_description |first_value
--------------+----------+-------------+-----------------------+----------2003 |
31 | Friday
| January 31, 2003
| January 31,
2003 |
24 | Friday
| January 24, 2003
| January 31,
2003 |
3 | Friday
| January 3, 2003
| January 31,
2003 |
10 | Friday
| January 10, 2003
| January 31,
2003 |
17 | Friday
| January 17, 2003
| January 31,
2003 |
6 | Monday
| January 6, 2003
| January 31,
2003 |
27 | Monday
| January 27, 2003
| January 31,
2003 |
13 | Monday
| January 13, 2003
| January 31,
2003 |
20 | Monday
| January 20, 2003
| January 31,
2003 |
11 | Saturday
| January 11, 2003
| January 31,
2003 |
18 | Saturday
| January 18, 2003
| January 31,
2003 |
25 | Saturday
| January 25, 2003
| January 31,
2003 |
4 | Saturday
| January 4, 2003
| January 31,
2003 |
12 | Sunday
| January 12, 2003
| January 31,
2003 |
26 | Sunday
| January 26, 2003
| January 31,
2003 |
5 | Sunday
| January 5, 2003
| January 31,
2003 |
19 | Sunday
| January 19, 2003
| January 31,
2003 |
23 | Thursday
| January 23, 2003
| January 31,
2003 |
2 | Thursday
| January 2, 2003
| January 31,
2003 |
9 | Thursday
| January 9, 2003
| January 31,
2003 |
16 | Thursday
| January 16, 2003
| January 31,
2003 |
30 | Thursday
| January 30, 2003
| January 31,
2003 |
21 | Tuesday
| January 21, 2003
| January 31,
2003 |
14 | Tuesday
| January 14, 2003
| January 31,
2003 |
7 | Tuesday
| January 7, 2003
| January 31,
2003 |
28 | Tuesday
| January 28, 2003
| January 31,
2003 |
22 | Wednesday
| January 22, 2003
| January 31,
2003 |
29 | Wednesday
| January 29, 2003
| January 31,
2003 |
15 | Wednesday
| January 15, 2003
| January 31,
2003 |
1 | Wednesday
| January 1, 2003
| January 31,
2003 |
8 | Wednesday
| January 8, 2003
| January 31,
(31 rows)
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
2003
Note: The day_of_week results are returned in alphabetical order because of lexical rules. The
fact that each day does not appear ordered by the 7-day week cycle (for example, starting with
Sunday followed by Monday, Tuesday, and so on) has no affect on results.
SQLReference Manual
SQL Functions
To return deterministic results, modify the query so that it performs its analytic ORDER BY operations
on a unique field, such as date_key:
=> SELECT calendar_year, date_key, day_of_week, full_date_description,
FIRST_VALUE(full_date_description) OVER
(PARTITION BY calendar_month_number_in_year ORDER BY date_key) AS "first_value"
FROM date_dimension WHERE calendar_year=2003;
Notice that the results return a first value of January 1 for the January partition and the first value of
February 1 for the February partition. Also, there are no ties in the full_date_description
column:
calendar_year | date_key | day_of_week | full_date_description | first_value
---------------+----------+-------------+-----------------------+-----------2003 |
1 | Wednesday
| January 1, 2003
| January 1, 2003
2003 |
2 | Thursday
| January 2, 2003
| January 1, 2003
2003 |
3 | Friday
| January 3, 2003
| January 1, 2003
2003 |
4 | Saturday
| January 4, 2003
| January 1, 2003
2003 |
5 | Sunday
| January 5, 2003
| January 1, 2003
2003 |
6 | Monday
| January 6, 2003
| January 1, 2003
2003 |
7 | Tuesday
| January 7, 2003
| January 1, 2003
2003 |
8 | Wednesday
| January 8, 2003
| January 1, 2003
2003 |
9 | Thursday
| January 9, 2003
| January 1, 2003
2003 |
10 | Friday
| January 10, 2003
| January 1, 2003
2003 |
11 | Saturday
| January 11, 2003
| January 1, 2003
2003 |
12 | Sunday
| January 12, 2003
| January 1, 2003
2003 |
13 | Monday
| January 13, 2003
| January 1, 2003
2003 |
14 | Tuesday
| January 14, 2003
| January 1, 2003
2003 |
15 | Wednesday
| January 15, 2003
| January 1, 2003
2003 |
16 | Thursday
| January 16, 2003
| January 1, 2003
2003 |
17 | Friday
| January 17, 2003
| January 1, 2003
2003 |
18 | Saturday
| January 18, 2003
| January 1, 2003
2003 |
19 | Sunday
| January 19, 2003
| January 1, 2003
2003 |
20 | Monday
| January 20, 2003
| January 1, 2003
2003 |
21 | Tuesday
| January 21, 2003
| January 1, 2003
2003 |
22 | Wednesday
| January 22, 2003
| January 1, 2003
2003 |
23 | Thursday
| January 23, 2003
| January 1, 2003
2003 |
24 | Friday
| January 24, 2003
| January 1, 2003
2003 |
25 | Saturday
| January 25, 2003
| January 1, 2003
2003 |
26 | Sunday
| January 26, 2003
| January 1, 2003
2003 |
27 | Monday
| January 27, 2003
| January 1, 2003
2003 |
28 | Tuesday
| January 28, 2003
| January 1, 2003
2003 |
29 | Wednesday
| January 29, 2003
| January 1, 2003
2003 |
30 | Thursday
| January 30, 2003
| January 1, 2003
2003 |
31 | Friday
| January 31, 2003
| January 1, 2003
2003 |
32 | Saturday
| February 1, 2003
| February 1, 2003
2003 |
33 | Sunday
| February 2, 2003
| February 1,2003
...
(365 rows)
SQLReference Manual
SQL Functions
See Also
l
LAST_VALUE [Analytic]
TIME_SLICE
LAG [Analytic]
Returns the value of the input expression at the given offset before the current row within a
window.
Behavior Type
Immutable
Syntax
LAG ( expression [, offset ] [, default ] ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
expression
offset
[Optional] Indicates how great is the lag. The default value is 1 (the previous row).
The offset parameter must be (or can be evaluated to) a constant positive integer.
default
NULL. This optional parameter is the value returned if offset falls outside the bounds
of the table or partition.
Note: The default input argument must be a constant value or an expression
that can be evaluated to a constant; its data type is coercible to that of the first
argument.
OVER(...)
SQLReference Manual
SQL Functions
Notes
l
The LAG() function returns values from the row before the current row, letting you access more
than one row in a table at the same time. This is useful for comparing values when the relative
positions of rows can be reliably known. It also lets you avoid the more costly self join, which
enhances query processing speed.
Examples
This example sums the current balance by date in a table and also sums the previous balance from
the last day. Given the inputs that follow, the data satisfies the following conditions:
l
For each some_id, there is exactly 1 row for each date represented by month_date.
For each some_id, the set of dates is consecutive; that is, if there is a row for February 24 and a
row for February 26, there would also be a row for February 25.
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
balances
balances
balances
balances
balances
balances
balances
balances
balances
values
values
values
values
values
values
values
values
values
('2009-02-24',
('2009-02-25',
('2009-02-26',
('2009-02-24',
('2009-02-25',
('2009-02-26',
('2009-02-24',
('2009-02-25',
('2009-02-26',
10,
10,
10,
20,
20,
20,
30,
20,
30,
1);
1);
1);
2);
2);
2);
3);
3);
3);
Now run the LAG() function to sum the current balance for each date and sum the previous balance
from the last day:
=> SELECT month_date,
SUM(current_bal) as current_bal_sum,
SUM(previous_bal) as previous_bal_sum FROM
SQLReference Manual
SQL Functions
Using the same example data, the following query would not be allowed because LAG() is nested
inside an aggregate function:
=> SELECT month_date,
SUM(current_bal) as current_bal_sum,
SUM(LAG(current_bal, 1, 0) OVER
(PARTITION BY some_id ORDER BY month_date)) AS previous_bal_sum
FROM some_table GROUP BY month_date ORDER BY month_date;
In the next example, which uses the VMart example database (see Introducing the VMart Example
Database), the LAG() function first returns the annual income from the previous row, and then it
calculates the difference between the income in the current row from the income in the previous
row. Note: The vmart example database returns over 50,000 rows, so we'll limit the results to 20
records:
=> SELECT occupation, customer_key, customer_name, annual_income,
LAG(annual_income, 1, 0) OVER (PARTITION BY occupation
ORDER BY annual_income) AS prev_income, annual_income LAG(annual_income, 1, 0) OVER (PARTITION BY occupation
ORDER BY annual_income) AS difference
FROM customer_dimension ORDER BY occupation, customer_key LIMIT 20;
occupation | customer_key |
customer_name
| annual_income | prev_income |
difference
------------+--------------+----------------------+---------------+-------------+----------Accountant |
15 | Midori V. Peterson
|
692610 |
692535 |
75
Accountant |
43 | Midori S. Rodriguez |
282359 |
280976 |
1383
Accountant |
93 | Robert P. Campbell
|
471722 |
471355 |
367
Accountant |
102 | Sam T. McNulty
|
901636 |
901561 |
75
Accountant |
134 | Martha B. Overstreet |
705146 |
704335 |
811
Accountant |
165 | James C. Kramer
|
376841 |
376474 |
367
Accountant |
225 | Ben W. Farmer
|
70574 |
70449 |
125
Accountant |
270 | Jessica S. Lang
|
684204 |
682274 |
SQLReference Manual
SQL Functions
1930
Accountant
557
Accountant
621
Accountant
1301
Accountant
277
Accountant
2914
Accountant
1226
Accountant
244
Accountant
620
Accountant
1707
Accountant
383
Accountant
336
Accountant
662
(20 rows)
723294 |
722737 |
29033 |
28412 |
816858 |
815557 |
915149 |
914872 |
147396 |
144482 |
126023 |
124797 |
810528 |
810284 |
639649 |
639029 |
187246 |
185539 |
677433 |
677050 |
735691 |
735355 |
577 | Robert U. Vu
616101 |
615439 |
Continuing with the Vmart database, the next example uses both LEAD() and LAG() to return the
third row after the salary in the current row and fifth salary before the salary in the current row.
=> SELECT hire_date, employee_key, employee_last_name,
LEAD(hire_date, 1) OVER (ORDER BY hire_date) AS "next_hired" ,
LAG(hire_date, 1) OVER (ORDER BY hire_date) AS "last_hired"
FROM employee_dimension ORDER BY hire_date, employee_key;
hire_date | employee_key | employee_last_name | next_hired | last_hired
------------+--------------+--------------------+------------+-----------1956-04-11 |
2694 | Farmer
| 1956-05-12 |
1956-05-12 |
5486 | Winkler
| 1956-09-18 | 1956-04-11
1956-09-18 |
5525 | McCabe
| 1957-01-15 | 1956-05-12
1957-01-15 |
560 | Greenwood
| 1957-02-06 | 1956-09-18
1957-02-06 |
9781 | Bauer
| 1957-05-25 | 1957-01-15
1957-05-25 |
9506 | Webber
| 1957-07-04 | 1957-02-06
1957-07-04 |
6723 | Kramer
| 1957-07-07 | 1957-05-25
1957-07-07 |
5827 | Garnett
| 1957-11-11 | 1957-07-04
1957-11-11 |
373 | Reyes
| 1957-11-21 | 1957-07-07
1957-11-21 |
3874 | Martin
| 1958-02-06 | 1957-11-11
(10 rows)
The following example specifies arguments that use different data types; for example annual_
income(INT) and occupation(VARCHAR). The query returns an error:
=> SELECT customer_key, customer_name, occupation, annual_income,
LAG (annual_income, 1, occupation) OVER
SQLReference Manual
SQL Functions
See Also
l
LEAD [Analytic]
LAST_VALUE [Analytic]
Returns values of the expression from the last row of a window for the current row. If no window is
specified for the current row, the default window is UNBOUNDED PRECEDING AND CURRENT ROW.
Behavior Type
Immutable
Syntax
LAST_VALUE ( expression [ IGNORE NULLS ] ) OVER ( ... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
Parameters
expression
IGNORE NULLS
Returns the last non-null value in the set, or NULL if all values are NULL.
OVER(...)
Notes
l
The LAST_VALUE() function lets you select a window's last value (determined by the window_
order_clause), without having to use a self join. This function is useful when you want to use the
last value as a baseline in calculations.
SQLReference Manual
SQL Functions
LAST_VALUE() takes the last record from the partition after the analytic window_order_clause.
The expression is then computed against the last record, and results are returned.
Tip: Due to default window semantics, LAST_VALUE does not always return the last value
of a partition. If you omit the window_frame_clause from the analytic clause, LAST_VALUE
operates on this default window. Although results can seem non-intuitive by not returning
the bottom of the current partition, it returns the bottom of the window, which continues to
change along with the current input row being processed. If you want to return the last value
of a partition, use UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. See
examples below.
If the last value in the set is null, then the function returns NULL unless you specify IGNORE
NULLS. If you specify IGNORE NULLS, LAST_VALUE returns the fist non-null value in the set,
or NULL if all values are null.
Example
Using the schema defined in Window Framing in the Analyzing Data Guide, the following query
does not show the highest salary value by department; instead it shows the highest salary value by
department by salary.
=> SELECT deptno, sal, empno, LAST_VALUE(sal)
OVER (PARTITION BY deptno ORDER BY sal) AS lv
FROM emp;
deptno | sal | empno |
lv
--------+-----+-------+-------10 | 101 |
1 |
101
10 | 104 |
4 |
104
20 | 100 |
11 |
100
20 | 109 |
7 |
109
20 | 109 |
6 |
109
20 | 109 |
8 |
109
20 | 110 |
10 |
110
20 | 110 |
9 |
110
30 | 102 |
2 |
102
30 | 103 |
3 |
103
30 | 105 |
5 |
105
If you include the window_frame clause ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING, the LAST_VALUE() function will return the highest salary by department, an accurate
representation of the information.
SQLReference Manual
SQL Functions
See Also
FIRST_VALUE [Analytic]
TIME_SLICE
l
l
LEAD [Analytic]
Returns the value of the input expression at the given offset after the current row within a window.
Behavior Type
Immutable
Syntax
LEAD ( expression [, offset ] [, default ] ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
expression
SQLReference Manual
SQL Functions
offset
Is an optional parameter that defaults to 1 (the next row). The offset parameter must
be (or can be evaluated to) a constant positive integer.
default
Is NULL. This optional parameter is the value returned if offset falls outside the
bounds of the table or partition.
Note: The third input argument must be a constant value or an expression that
can be evaluated to a constant; its data type is coercible to that of the first
argument.
OVER(...)
Notes
l
The LEAD() function returns values from the row after the current row, letting you access more
than one row in a table at the same time. This is useful for comparing values when the relative
positions of rows can be reliably known. It also lets you avoid the more costly self join, which
enhances query processing speed.
Examples
In this example, the LEAD() function finds the hire date of the employee hired just after the current
row:
=> SELECT employee_region, hire_date, employee_key, employee_last_name,
LEAD(hire_date, 1) OVER (PARTITION BY employee_region ORDER BY hire_date) AS "next_
hired"
FROM employee_dimension ORDER BY employee_region, hire_date, employee_key;
employee_region | hire_date | employee_key | employee_last_name | next_hired
-------------------+------------+--------------+--------------------+-----------East
| 1956-04-08 |
9218 | Harris
| 1957-02-06
East
| 1957-02-06 |
7799 | Stein
| 1957-05-25
East
| 1957-05-25 |
3687 | Farmer
| 1957-06-26
East
| 1957-06-26 |
9474 | Bauer
| 1957-08-18
East
| 1957-08-18 |
570 | Jefferson
| 1957-08-24
East
| 1957-08-24 |
4363 | Wilson
| 1958-02-17
East
| 1958-02-17 |
6457 | McCabe
| 1958-06-26
East
| 1958-06-26 |
6196 | Li
| 1958-07-16
East
| 1958-07-16 |
7749 | Harris
| 1958-09-18
East
| 1958-09-18 |
9678 | Sanchez
| 1958-11-10
(10 rows)
SQLReference Manual
SQL Functions
The next example uses both LEAD() and LAG() to return the third row after the salary in the current
row and fifth salary before the salary in the current row.
=> SELECT hire_date, employee_key, employee_last_name,
LEAD(hire_date, 1) OVER (ORDER BY hire_date) AS "next_hired" ,
LAG(hire_date, 1) OVER (ORDER BY hire_date) AS "last_hired"
FROM employee_dimension ORDER BY hire_date, employee_key;
hire_date | employee_key | employee_last_name | next_hired | last_hired
------------+--------------+--------------------+------------+-----------1956-04-11 |
2694 | Farmer
| 1956-05-12 |
1956-05-12 |
5486 | Winkler
| 1956-09-18 | 1956-04-11
1956-09-18 |
5525 | McCabe
| 1957-01-15 | 1956-05-12
1957-01-15 |
560 | Greenwood
| 1957-02-06 | 1956-09-18
1957-02-06 |
9781 | Bauer
| 1957-05-25 | 1957-01-15
1957-05-25 |
9506 | Webber
| 1957-07-04 | 1957-02-06
1957-07-04 |
6723 | Kramer
| 1957-07-07 | 1957-05-25
1957-07-07 |
5827 | Garnett
| 1957-11-11 | 1957-07-04
1957-11-11 |
373 | Reyes
| 1957-11-21 | 1957-07-07
1957-11-21 |
3874 | Martin
| 1958-02-06 | 1957-11-11
(10 rows)
The following example returns employee name and salary, along with the next highest and lowest
salaries.
=> SELECT employee_last_name, annual_salary,
NVL(LEAD(annual_salary) OVER (ORDER BY annual_salary),
MIN(annual_salary) OVER()) "Next Highest",
NVL(LAG(annual_salary) OVER (ORDER BY annual_salary),
MAX(annual_salary) OVER()) "Next Lowest"
FROM employee_dimension;
employee_last_name | annual_salary | Next Highest | Next Lowest
--------------------+---------------+--------------+------------Nielson
|
1200 |
1200 |
995533
Lewis
|
1200 |
1200 |
1200
Harris
|
1200 |
1202 |
1200
Robinson
|
1202 |
1202 |
1200
Garnett
|
1202 |
1202 |
1202
Weaver
|
1202 |
1202 |
1202
Nielson
|
1202 |
1202 |
1202
McNulty
|
1202 |
1204 |
1202
Farmer
|
1204 |
1204 |
1202
Martin
|
1204 |
1204 |
1204
(10 rows)
The next example returns, for each assistant director in the employees table, the hire date of the
director hired just after the director on the current row. For example, Jackson was hired on 2007-1228, and the next director hired was Bauer:
=> SELECT employee_last_name, hire_date,
LEAD(hire_date, 1) OVER (ORDER BY hire_date DESC) as "NextHired"
FROM employee_dimension WHERE job_title = 'Assistant Director';
employee_last_name | hire_date | NextHired
--------------------+------------+------------
SQLReference Manual
SQL Functions
Jackson
Bauer
Miller
Fortin
Harris
Goldberg
(5 rows)
|
|
|
|
|
|
2007-12-28
2007-12-26
2007-12-11
2007-12-07
2007-11-27
2007-11-15
|
|
|
|
|
|
2007-12-26
2007-12-11
2007-12-07
2007-11-27
2007-11-15
See Also
l
LAG [Analytic]
MAX [Analytic]
Returns the maximum value of an expression within a window. The return value is the same as the
expression data type.
Behavior Type
Immutable
Syntax
MAX
...
...
...
(
[
[
[
Parameters
DISTINCT
expression
Any expression for which the maximum value is calculated, typically a column
reference .
OVER(...)
Example
The following query computes the deviation between the employees' annual salary and the
maximum annual salary in Massachusetts:
SQLReference Manual
SQL Functions
See Also
l
MAX [Aggregate]
MIN [Analytic]
MEDIAN [Analytic]
A numerical value of an expression in a result set within a window, which separates the higher half
of a sample from the lower half. For example, a query can retrieve the median of a finite list of
numbers by arranging all observations from lowest value to highest value and then picking the
middle one.
If there is an even number of observations, then there is no single middle value; thus, the median is
defined to be the mean (average) of the two middle values
MEDIAN() is an alias for 50% PERCENTILE(); for example:
PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY expression)
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
MEDIAN ( expression ) OVER ( [ window_partition_clause ] )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the middle value or an
interpolated value that would be the middle value once the values are sorted. Null
values are ignored in the calculation.
OVER(...)
Notes
l
For each row, MEDIAN() returns the value that would fall in the middle of a value set within each
partition.
HP Vertica determines the argument with the highest numeric precedence, implicitly converts
the remaining arguments to that data type, and returns that data type.
Examples
The following query computes the median annual income for first 500 customers in Wisconsin and
in the District of Columbia. The median is reported for every row in each partitioned result set:
=> SELECT customer_state, annual_income,
MEDIAN(annual_income) OVER (PARTITION BY customer_state) AS MEDIAN
FROM customer_dimension
WHERE customer_state IN ('DC','WI')
ORDER BY customer_state;
customer_state | customer_key | annual_income | MEDIAN
----------------+--------------+---------------+---------DC
|
120 |
299768 |
535413
DC
|
113 |
535413 |
535413
DC
|
130 |
848360 |
535413
---------------------------------------------------------WI
|
372 |
34962 |
668147
WI
|
437 |
47128 |
668147
WI
|
435 |
67770 |
668147
WI
|
282 |
638054 |
668147
WI
|
314 |
668147 |
668147
WI
|
128 |
675608 |
668147
WI
|
179 |
825304 |
668147
SQLReference Manual
SQL Functions
WI
WI
(12 rows)
|
|
302 |
29 |
827618 |
922760 |
668147
668147
See Also
l
PERCENTILE_CONT [Analytic]
MIN [Analytic]
Returns the minimum value of an expression within a window. The return value is the same as the
expression data type.
Behavior Type
Immutable
Syntax
MIN
...
...
...
(
[
[
[
Parameters
DISTINCT
expression
Any expression for which the minimum value is calculated, typically a column
reference.
OVER(...)
Examples
The following query computes the deviation between the employees' annual salary and the
minimum annual salary in Massachusetts:
=> SELECT employee_state, annual_salary,
MIN(annual_salary)
OVER(PARTITION BY employee_state ORDER BY employee_key) min,
SQLReference Manual
SQL Functions
annual_salary- MIN(annual_salary)
OVER(PARTITION BY employee_state ORDER BY employee_key) diff
FROM employee_dimension
WHERE employee_state = 'MA';
employee_state | annual_salary | min | diff
----------------+---------------+------+-----MA
|
1918 | 1204 | 714
MA
|
2058 | 1204 | 854
MA
|
2586 | 1204 | 1382
MA
|
2500 | 1204 | 1296
MA
|
1318 | 1204 | 114
MA
|
2072 | 1204 | 868
MA
|
2656 | 1204 | 1452
MA
|
2148 | 1204 | 944
MA
|
2366 | 1204 | 1162
MA
|
2664 | 1204 | 1460
(10 rows)
See Also
l
MIN [Aggregate]
MAX [Analytic]
NTILE [Analytic]
Equally divides an ordered data set (partition) into a {value} number of subsets within a window,
with buckets (subsets) numbered 1 through constant-value. For example, if constant-value = 4,
then each row in the partition is assigned a number from 1 to 4. If the partition contains 20 rows, the
first 5 would be assigned 1, the next 5 would be assigned 2, and so on.
Behavior Type
Immutable
Syntax
NTILE ( constant-value ) OVER (
... [ window_partition_clause ]
... window_order_clause )
SQLReference Manual
SQL Functions
Parameters
constant-value
Represents the number of subsets and must resolve to a positive constant for
each partition.
OVER(...)
Notes
l
If the number of subsets is greater than the number of rows, then a number of subsets equal to
the number of rows is filled, and the remaining subsets are empty.
In the event the cardinality of the partition is not evenly divisible by the number of subsets, the
rows are distributed so no subset has more than 1 row more then any other subset, and the
lowest subsets are the ones that have extra rows. For example, using constant-value = 4 again
and the number of rows = 21, subset = 1 has 6 rows, subset = 2 has 5, and so on.
Examples
The following query assigns each month's sales total into one of four subsets:
=> SELECT calendar_month_name AS MONTH, SUM(sales_quantity),
NTILE(4) OVER (ORDER BY SUM(sales_quantity)) AS NTILE
FROM store.store_sales_fact JOIN date_dimension
USING(date_key)
GROUP BY calendar_month_name
ORDER BY NTILE;
MONTH
| SUM | NTILE
-----------+------+------February | 755 |
1
June
| 842 |
1
September | 849 |
1
January
| 881 |
2
May
| 882 |
2
July
| 894 |
2
August
| 921 |
3
April
| 952 |
3
March
| 987 |
3
October
| 1010 |
4
November | 1026 |
4
December | 1094 |
4
(12 rows)
SQLReference Manual
SQL Functions
See Also
l
PERCENTILE_CONT [Analytic]
WIDTH_BUCKET
PERCENT_RANK [Analytic]
Calculates the relative rank of a row for a given row in a group within a window by dividing that
rows rank less 1 by the number of rows in the partition, also less 1. This function always returns
values from 0 to 1 inclusive. The first row in any set has a PERCENT_RANK() of 0. The return value is
NUMBER.
( rank - 1 ) / ( [ rows ] - 1 )
In the preceding formula, rank is the rank position of a row in the group and rows is the total number
of rows in the partition defined by the OVER() clause.
Behavior Type
Immutable
Syntax
PERCENT_RANK ( ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
OVER(...)
Notes
The window_order_clause is required but the window_partition_clause is optional.
Examples
The following example finds the percent rank of gross profit for different states within each month of
the first quarter:
SQLReference Manual
SQL Functions
The following example calculates, for each employee, the percent rank of the employee's salary by
their job title:
=> SELECT job_title, employee_last_name, annual_salary,
PERCENT_RANK()
OVER (PARTITION BY job_title ORDER BY annual_salary DESC) AS percent_rank
FROM employee_dimension
ORDER BY percent_rank, annual_salary;
job_title
| employee_last_name | annual_salary |
PERCENT_RANK
--------------------+--------------------+---------------+--------------------CEO
| Campbell
|
963914 |
0
Co-Founder
| Nguyen
|
968625 |
0
Founder
| Overstreet
|
995533 |
0
Greeter
| Peterson
|
3192 | 0.00113895216400911
Greeter
| Greenwood
|
3192 | 0.00113895216400911
Customer Service
| Peterson
|
3190 | 0.00121065375302663
Delivery Person
| Rodriguez
|
3192 | 0.00121065375302663
Shelf Stocker
| Martin
|
3194 | 0.00125786163522013
Shelf Stocker
| Vu
|
3194 | 0.00125786163522013
Marketing
| Li
|
99711 | 0.00190114068441065
Assistant Director | Sanchez
|
99913 | 0.00190839694656489
Branch Manager
| Perkins
|
99901 | 0.00192307692307692
Advertising
| Lampert
|
99809 | 0.00204918032786885
Sales
| Miller
|
99727 | 0.00211416490486258
Shift Manager
| King
|
99904 | 0.00215982721382289
Custodian
| Bauer
|
3196 | 0.00235849056603774
Custodian
| Goldberg
|
3196 | 0.00235849056603774
Customer Service
| Fortin
|
3184 | 0.00242130750605327
SQLReference Manual
SQL Functions
Delivery Person
Cashier
Regional Manager
VP of Sales
Director of HR
Head of Marketing
VP of Advertising
Head of PR
Customer Service
Delivery Person
Cashier
Cashier
Marketing
Branch Manager
Branch Manager
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Greenwood
Overstreet
McCabe
Li
Goldberg
Stein
Goldberg
Stein
Rodriguez
King
Dobisz
Miller
Dobisz
Gauthier
Moore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3186
3178
199688
199309
199592
199941
199036
199767
3180
3184
3174
3174
99655
99082
98415
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0.00242130750605327
0.00243605359317905
0.00306748466257669
0.00313479623824451
0.00316455696202532
0.00317460317460317
0.00323624595469256
0.00323624595469256
0.0036319612590799
0.0036319612590799
0.00365408038976857
0.00365408038976857
0.00380228136882129
0.025
0.05
See Also
l
CUME_DIST [Analytic]
PERCENTILE_CONT [Analytic]
An inverse distribution function where, for each row, PERCENTILE_CONT() returns the value that
would fall into the specified percentile among a set of values in each partition within a window. For
example, if the argument to the function is 0.5, the result of the function is the median of the data
set (the 50th percentile). PERCENTILE_CONT() assumes a continuous distribution data model. Nulls
are ignored.
Behavior Type
Immutable
Syntax
PERCENTILE_CONT ( %_number ) WITHIN GROUP (
... ORDER BY expression [ ASC | DESC ] ) OVER (
... [ window_partition_clause ] )
Parameters
%_number
SQLReference Manual
SQL Functions
ASC | DESC
OVER(...)
Notes
l
HP Vertica computes the percentile by first computing the row number where the percentile row
would exist, for example:
ROW_NUMBER = 1 + PERCENTILE_VALUE * (NUMBER_OF_ROWS_IN_PARTITION -1)
If ROW_NUMBER is a whole number (within an error of 0.00001), the percentile is the value of the
(ROW_NUMBER)'th row.
Otherwise, Vertica interpolates the percentile value between the value of the CEILING(ROW_
NUMBER)'th row and the value of the FLOOR(ROW_NUMBER)'th row, i.e. the percentile =
(CEILING(ROW_NUMBER) - ROW_NUMBER) * (Value of the FLOOR(ROW_NUMBER)'th row) +
(ROW_NUMBER - FLOOR(ROW_NUMBER)) * (Value of the CEILING(ROW_NUMBER)'th row)
l
Specifying ASC or DESC in the WITHIN GROUP clause affects results as long as the percentile
parameter is not .5.
Examples
This query computes the median annual income per group for the first 500 customers in Wisconsin
and the District of Columbia.
=> SELECT customer_state, customer_key, annual_income,
PERCENTILE_CONT(.5) WITHIN GROUP(ORDER BY annual_income)
SQLReference Manual
SQL Functions
The median value for DC is 65838, and the median value for WI is 458607. With a %_number of 0.5
in the above query, PERCENTILE_CONT() returns the same result as MEDIAN() in the following
query:
=> SELECT customer_state, customer_key, annual_income,
MEDIAN(annual_income)
OVER (PARTITION BY customer_state) AS MEDIAN
FROM customer_dimension
WHERE customer_state IN ('DC','WI')
AND customer_key < 300
ORDER BY customer_state, customer_key;
customer_state | customer_key | annual_income | MEDIAN
----------------+--------------+---------------+-------DC
|
104 |
658383 | 658383
DC
|
168 |
417092 | 658383
DC
|
245 |
670205 | 658383
WI
|
106 |
227279 | 458607
WI
|
127 |
703889 | 458607
WI
|
209 |
458607 | 458607
(6 rows)
See Also
l
MEDIAN [Analytic]
PERCENTILE_DISC [Analytic]
An inverse distribution function where, for each row, PERCENTILE_DISC() returns the value that
would fall into the specified percentile among a set of values in each partition within a window.
PERCENTILE_DISC() assumes a discrete distribution data model. Nulls are ignored.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
PERCENTILE_DISC ( %_number ) WITHIN GROUP (
... ORDER BY expression [ ASC | DESC ] ) OVER (
... [ window_partition_clause ] )
Parameters
%_number
ASC | DESC
OVER(...)
Notes
l
HP Vertica computes the percentile where, for each row, PERCENTILE_DISC outputs the first
value of the WITHIN GROUP(ORDER BY) column whose CUME_DIST (cumulative distribution)
value is >= the argument FLOAT value (for example, 0.4). Specifically:
PERCENTILE_DIST(.4) WITHIN GROUP (ORDER BY salary) OVER(PARTITION By deptno) ...
SQLReference Manual
SQL Functions
The smallest CUME_DIST value that is greater than 0.4 is also the PERCENTILE_DISC.
Example
This query computes the 20th percentile annual income by group for first 500 customers in
Wisconsin and the District of Columbia.
=> SELECT customer_state, customer_key, annual_income,
PERCENTILE_DISC(.2) WITHIN GROUP(ORDER BY annual_income)
OVER (PARTITION BY customer_state) AS PERCENTILE_DISC
FROM customer_dimension
WHERE customer_state IN ('DC','WI')
AND customer_key < 300
ORDER BY customer_state, customer_key;
customer_state | customer_key | annual_income | PERCENTILE_DISC
----------------+--------------+---------------+----------------DC
|
104 |
658383 |
417092
DC
|
168 |
417092 |
417092
DC
|
245 |
670205 |
417092
WI
|
106 |
227279 |
227279
WI
|
127 |
703889 |
227279
WI
|
209 |
458607 |
227279
(6 rows)
See Also
l
CUME_DIST [Analytic]
PERCENTILE_CONT [Analytic]
RANK [Analytic]
Assigns a rank to each row returned from a query with respect to the other ordered rows, based on
the values of the expressions in the window ORDER BY clause. The data within a group is sorted by
the ORDER BY clause and then a numeric ranking is assigned to each row in turn, starting with 1, and
continuing up. Rows with the same values of the ORDER BY expressions receive the same rank;
however, if two rows receive the same rank (a tie), RANK() skips the ties. If, for example, two rows
are numbered 1, RANK() skips number 2 and assigns 3 to the next row in the group. This is in
contrast to DENSE_RANK(), which does not skip values.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
RANK ( ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
OVER(...)
Notes
l
Ranking functions return a rank value for each row in a result set based on the order specified in
the query. For example, a territory sales manager might want to identify the top or bottom
ranking sales associates in a department or the highest/lowest-performing sales offices by
region.
In ranking functions, OVER() specifies the measures expression on which ranking is done and
defines the order in which rows are sorted in each group (or partition). Once the data is sorted
within each partition, ranks are given to each row starting from 1.
The primary difference between RANK and DENSE_RANK is that RANK leaves gaps when ranking
records; DENSE_RANK leaves no gaps. For example, if more than one record occupies a particular
position (a tie), RANK places all those records in that position and it places the next record after a
gap of the additional records (it skips one). DENSE_RANK places all the records in that position
onlyit does not leave a gap for the next rank.
If there is a tie at the third position with two records having the same value, RANK and DENSE_
RANK place both the records in the third position only, but RANK has the next record at the fifth
positionleaving a gap of 1 positionwhile DENSE_RANK places the next record at the forth
position (no gap).
If you omit NULLS FIRST | LAST | AUTO, the ordering of the null values depends on the ASC or
DESC arguments. Null values are considered larger than any other values. If the ordering
sequence is ASC, then nulls appear last; nulls appear first otherwise. Nulls are considered equal
to other nulls and, therefore, the order in which nulls are presented is non-deterministic.
SQLReference Manual
SQL Functions
Examples
This example ranks the longest standing customers in Massachusetts. The query first computes
the customer_since column by region, and then partitions the results by customers with
businesses in MA. Then within each region, the query ranks customers over the age of 70.
=> SELECT customer_type, customer_name,
RANK() OVER (PARTITION BY customer_region
ORDER BY customer_since) as rank
FROM customer_dimension
WHERE customer_state = 'MA'
AND customer_age > '70';
The following example shows the difference between RANK and DENSE_RANK when ranking
customers by their annual income. RANK has a tie at 10 and skips 11, while DENSE_RANK leaves no
gaps in the ranking sequence:
=> SELECT customer_name, SUM(annual_income),
RANK () OVER (ORDER BY TO_CHAR(SUM(annual_income),'100000') DESC) rank,
DENSE_RANK () OVER (ORDER BY TO_CHAR(SUM(annual_income),'100000') DESC) dense_rank
FROM customer_dimension
GROUP BY customer_name
LIMIT 15;
customer_name
| sum | rank | dense_rank
---------------------+-------+------+-----------Brian M. Garnett
| 99838 |
1 |
1
Tanya A. Brown
| 99834 |
2 |
2
Tiffany P. Farmer
| 99826 |
3 |
3
Jose V. Sanchez
| 99673 |
4 |
4
Marcus D. Rodriguez | 99631 |
5 |
5
Alexander T. Nguyen | 99604 |
6 |
6
Sarah G. Lewis
| 99556 |
7 |
7
Ruth Q. Vu
| 99542 |
8 |
8
Theodore T. Farmer | 99532 |
9 |
9
SQLReference Manual
SQL Functions
Daniel P. Li
Seth E. Brown
Matt X. Gauthier
Rebecca W. Lewis
Dean L. Wilson
Tiffany A. Smith
(15 rows)
|
|
|
|
|
|
99497
99497
99402
99296
99276
99257
|
|
|
|
|
|
10
10
12
13
14
15
|
|
|
|
|
|
10
10
11
12
13
14
See Also
l
DENSE_RANK [Analytic]
ROW_NUMBER [Analytic]
Assigns a unique number, sequentially, starting from 1, to each row in a partition within a window.
Behavior Type
Immutable
Syntax
ROW_NUMBER ( ) OVER (
... [ window_partition_clause ]
... window_order_clause )
Parameters
OVER(...)
Notes
l
ROW_NUMBER() is an HP Vertica extension, not part of the SQL-99 standard. It requires an OVER
() clause. The window_partition_clause is optional.
You can use the optional partition clause to group data into partitions before operating on it; for
example:
SUM OVER (PARTITION BY col1, col2, ...)
SQLReference Manual
SQL Functions
You can substitute any RANK() example for ROW_NUMBER(). The difference is that ROW_
NUMBERassigns a unique ordinal number, starting with 1, to each row in the ordered set.
Examples
The following query first partitions customers in the customer_dimension table by occupation and
then ranks those customers based on the ordered set specified by the analytic partition_clause.
=> SELECT occupation, customer_key, customer_since, annual_income,
ROW_NUMBER() OVER (PARTITION BY occupation) AS customer_since_row_num
FROM public.customer_dimension
ORDER BY occupation, customer_since_row_num;
occupation
| customer_key | customer_since | annual_income | customer_since_row_
num
--------------------+--------------+----------------+---------------+----------------------Accountant
|
19453 | 1973-11-06
|
602460 |
1
Accountant
|
42989 | 1967-07-09
|
850814 |
2
Accountant
|
24587 | 1995-05-18
|
180295 |
3
Accountant
|
26421 | 2001-10-08
|
126490 |
4
Accountant
|
37783 | 1993-03-16
|
790282 |
5
Accountant
|
39170 | 1980-12-21
|
823917 |
6
Banker
|
13882 | 1998-04-10
|
15134 |
1
Banker
|
14054 | 1989-03-16
|
961850 |
2
Banker
|
15850 | 1996-01-19
|
262267 |
3
Banker
|
29611 | 2004-07-14
|
739016 |
4
Doctor
|
261 | 1969-05-11
|
933692 |
1
Doctor
|
1264 | 1981-07-19
|
593656 |
2
Psychologist
|
5189 | 1999-05-04
|
397431 |
1
Psychologist
|
5729 | 1965-03-26
|
339319 |
2
Software Developer |
2513 | 1996-09-22
|
920003 |
1
Software Developer |
5927 | 2001-03-12
|
633294 |
2
Software Developer |
9125 | 1971-10-06
|
198953 |
3
Software Developer |
16097 | 1968-09-02
|
748371 |
4
Software Developer |
23137 | 1988-12-07
|
92578 |
SQLReference Manual
SQL Functions
5
Software Developer
6
Software Developer
7
Software Developer
8
Software Developer
9
Software Developer
10
Software Developer
11
Stock Broker
1
Stock Broker
2
Stock Broker
3
Stock Broker
4
Stock Broker
5
Writer
1
Writer
2
Writer
3
Writer
4
Writer
5
Writer
6
(39 rows)
24495 | 1989-04-16
149371 |
24548 | 1994-09-21
743788 |
33744 | 2005-12-07
735003 |
9684 | 1970-05-20
246000 |
24278 | 2001-11-14
122882 |
27122 | 1994-02-05
810044 |
5950 | 1965-01-20
752120 |
12517 | 2003-06-13
380102 |
33010 | 1984-05-07
384463 |
46196 | 1972-11-28
497049 |
8710 | 2005-02-11
79387 |
3149 | 1998-11-17
643972 |
17124 | 1965-01-18
444747 |
20100 | 1994-08-13
106097 |
23317 | 2003-05-27
511750 |
42845 | 1967-10-23
433483 |
47560 | 1997-04-23
515647 |
See Also
l
RANK [Analytic]
STDDEV [Analytic]
Note: The non-standard function STDDEV() is provided for compatibility with other databases.
It is semantically identical to STDDEV_SAMP().
SQLReference Manual
SQL Functions
Computes the statistical sample standard deviation of the current row with respect to the group
within a window. The STDDEV_SAMP() return value is the same as the square root of the variance
defined for the VAR_SAMP() function:
STDDEV(expression) = SQRT(VAR_SAMP(expression))
Behavior Type
Immutable
Syntax
STDDEV ( expression ) OVER (
... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
OVER(...)
Example
The following example returns the standard deviations of salaries in the employee dimension table
by job title Assistant Director:
=> SELECT employee_last_name, annual_salary,
STDDEV(annual_salary) OVER (ORDER BY hire_date) as "stddev"
FROM employee_dimension
WHERE job_title = 'Assistant Director';
employee_last_name | annual_salary |
stddev
--------------------+---------------+-----------------Goldberg
|
61859 |
NaN
Miller
|
79582 | 12532.0534829692
Goldberg
|
74236 | 9090.97147357388
Campbell
|
66426 | 7909.9541665339
Moore
|
66630 | 7068.30282316761
Nguyen
|
53530 | 9154.14713486005
Harris
|
74115 | 8773.54346886142
Lang
|
59981 | 8609.60471031374
Farmer
|
60597 | 8335.41158418579
SQLReference Manual
SQL Functions
Nguyen
Smith
...
|
|
78941 | 8812.87941405456
55018 | 9179.7672390773
See Also
l
STDDEV [Aggregate]
STDDEV_SAMP [Aggregate]
STDDEV_SAMP [Analytic]
STDDEV_POP [Analytic]
Computes the statistical population standard deviation and returns the square root of the population
variance within a window. The STDDEV_POP() return value is the same as the square root of the
VAR_POP() function:
STDDEV_POP(expression) = SQRT(VAR_POP(expression))
Behavior Type
Immutable
Syntax
STDDEV_POP ( expression ) OVER (
... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
OVER(...)
SQLReference Manual
SQL Functions
Examples
The following example returns the population standard deviations of salaries in the employee
dimension table by job title Assistant Director:
=> SELECT employee_last_name, annual_salary,
STDDEV_POP(annual_salary) OVER (ORDER BY hire_date) as "stddev_pop"
FROM employee_dimension WHERE job_title = 'Assistant Director';
employee_last_name | annual_salary |
stddev_pop
--------------------+---------------+-----------------Goldberg
|
61859 |
0
Miller
|
79582 |
8861.5
Goldberg
|
74236 | 7422.74712548456
Campbell
|
66426 | 6850.22125098891
Moore
|
66630 | 6322.08223926257
Nguyen
|
53530 | 8356.55480080699
Harris
|
74115 | 8122.72288970008
Lang
|
59981 | 8053.54776538731
Farmer
|
60597 | 7858.70140687825
Nguyen
|
78941 | 8360.63150784682
See Also
l
STDDEV_POP [Aggregate]
STDDEV_SAMP [Analytic]
Computes the statistical sample standard deviation of the current row with respect to the group
within a window. The STDDEV_SAMP() return value is the same as the square root of the variance
defined for the VAR_SAMP() function:
STDDEV(expression) = SQRT(VAR_SAMP(expression))
Behavior Type
Immutable
Syntax
STDDEV_SAMP ( expression ) OVER (
... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
SQLReference Manual
SQL Functions
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument..
OVER(...)
Notes
STDDEV_SAMP() is semantically identical to the non-standard function, STDDEV().
Examples
The following example returns the sample standard deviations of salaries in the employee
dimension table by job title Assistant Director:
=> SELECT employee_last_name, annual_salary,
STDDEV(annual_salary) OVER (ORDER BY hire_date) as "stddev_samp"
FROM employee_dimension WHERE job_title = 'Assistant Director';
employee_last_name | annual_salary |
stddev_samp
--------------------+---------------+-----------------Goldberg
|
61859 |
NaN
Miller
|
79582 | 12532.0534829692
Goldberg
|
74236 | 9090.97147357388
Campbell
|
66426 | 7909.9541665339
Moore
|
66630 | 7068.30282316761
Nguyen
|
53530 | 9154.14713486005
Harris
|
74115 | 8773.54346886142
Lang
|
59981 | 8609.60471031374
Farmer
|
60597 | 8335.41158418579
Nguyen
|
78941 | 8812.87941405456
...
See Also
l
Analytic Functions
STDDEV [Analytic]
STDDEV [Aggregate]
STDDEV_SAMP [Aggregate]
SQLReference Manual
SQL Functions
SUM [Analytic]
Computes the sum of an expression over a group of rows within a window. It returns a DOUBLE
PRECISION value for a floating-point expression. Otherwise, the return value is the same as the
expression data type.
Behavior Type
Immutable
Syntax
SUM
...
...
...
(
[
[
[
expression ) OVER (
window_partition_clause ]
window_order_clause ]
window_frame_clause ] )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
OVER(...)
Notes
l
If you encounter data overflow when using SUM(), use SUM_FLOAT() which converts data to a
floating point.
Examples
The following query returns the cumulative sum all of the returns made to stores in January:
=> SELECT calendar_month_name AS month, transaction_type, sales_quantity,
SUM(sales_quantity)
OVER (PARTITION BY calendar_month_name ORDER BY date_dimension.date_key) AS SUM
FROM store.store_sales_fact JOIN date_dimension
USING(date_key) WHERE calendar_month_name IN ('January')
AND transaction_type= 'return';
month | transaction_type | sales_quantity | SUM
---------+------------------+----------------+------
SQLReference Manual
SQL Functions
January |
January |
January |
January |
January |
January |
January |
January |
January |
January |
(10 rows)
return
return
return
return
return
return
return
return
return
return
|
|
|
|
|
|
|
|
|
|
4
3
1
5
8
3
5
10
9
10
|
|
|
|
|
|
|
|
|
|
2338
2338
2338
2338
2338
2338
2338
2338
2338
2338
See Also
l
SUM [Aggregate]
VAR_POP [Analytic]
Returns the statistical population variance of a non-null set of numbers (nulls are ignored) in a group
within a window. Results are calculated by the sum of squares of the difference of expression from
the mean of expression, divided by the number of rows remaining:
(SUM(expression*expression) - SUM(expression)*SUM(expression) /
COUNT(expression)
COUNT(expression)) /
Behavior Type
Immutable
Syntax
VAR_POP ( expression ) OVER (
... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
SQLReference Manual
SQL Functions
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument
OVER(...)
Examples
The following example calculates the cumulative population in the store orders fact table of sales in
December 2007:
=> SELECT date_ordered,
VAR_POP(SUM(total_order_cost))
OVER (ORDER BY date_ordered) "var_pop"
FROM store.store_orders_fact s
WHERE date_ordered BETWEEN '2007-12-01' AND '2007-12-31'
GROUP BY s.date_ordered;
date_ordered |
var_pop
--------------+-----------------2007-12-01
|
0
2007-12-02
|
1129564881
2007-12-03
| 1206008121.55542
2007-12-04
| 26353624176.1875
2007-12-05
| 21315288023.4402
2007-12-06
| 21619271028.3333
2007-12-07
| 19867030477.6328
2007-12-08
|
19197735288.5
2007-12-09
| 19100157155.2097
2007-12-10
| 19369222968.0896
(10 rows)
See Also
l
VAR_POP [Aggregate]
VAR_SAMP [Analytic]
Returns the sample variance of a non-null set of numbers (nulls in the set are ignored) for each row
of the group within a window. Results are calculated by the sum of squares of the difference of
expression from the mean of expression, divided by the number of rows remaining minus 1:
SQLReference Manual
SQL Functions
(SUM(expression*expression) - SUM(expression)*SUM(expression) /
COUNT(expression)) / (COUNT(expression) - 1)
Behavior Type
Immutable
Syntax
VAR_SAMP ( expression ) OVER (
... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument
OVER(...)
Notes
l
VAR_SAMP() returns the sample variance of a set of numbers after it discards the nulls in the set.
This function is similar to VARIANCE(), except that given an input set of one element, VARIANCE
() returns 0 and VAR_SAMP() returns null.
Examples
The following example calculates the sample variance in the store orders fact table of sales in
December 2007:
=> SELECT date_ordered,
VAR_SAMP(SUM(total_order_cost))
OVER (ORDER BY date_ordered) "var_samp"
FROM store.store_orders_fact s
WHERE date_ordered BETWEEN '2007-12-01' AND '2007-12-31'
GROUP BY s.date_ordered;
date_ordered |
var_samp
--------------+------------------
SQLReference Manual
SQL Functions
2007-12-01
2007-12-02
2007-12-03
2007-12-04
2007-12-05
2007-12-06
2007-12-07
2007-12-08
2007-12-09
2007-12-10
(10 rows)
|
|
|
|
|
|
|
|
|
|
NaN
2259129762
1809012182.33301
35138165568.25
26644110029.3003
25943125234
23178202223.9048
21940268901.1431
21487676799.6108
21521358853.4331
See Also
l
VARIANCE [Analytic]
VAR_SAMP [Aggregate]
VARIANCE [Analytic]
Note: The non-standard function VARIANCE() is provided for compatibility with other
databases. It is semantically identical to VAR_SAMP().
Returns the sample variance of a non-null set of numbers (nulls in the set are ignored) for each row
of the group within a window. Results are calculated by the sum of squares of the difference of
expression from the mean of expression, divided by the number of rows remaining minus 1:
(SUM(expression*expression) - SUM(expression)*SUM(expression) /
(COUNT(expression) - 1)
COUNT(expression)) /
Behavior Type
Immutable
Syntax
VAR_SAMP ( expression ) OVER (
... [ window_partition_clause ]
... [ window_order_clause ]
... [ window_frame_clause ] )
SQLReference Manual
SQL Functions
Parameters
expression
Any NUMERIC data type or any non-numeric data type that can be implicitly
converted to a numeric data type. The function returns the same data type as the
numeric data type of the argument.
OVER(...)
Notes
l
Examples
The following example calculates the cumulative variance in the store orders fact table of sales in
December 2007:
=> SELECT date_ordered,
VARIANCE(SUM(total_order_cost))
OVER (ORDER BY date_ordered) "variance"
FROM store.store_orders_fact s
WHERE date_ordered BETWEEN '2007-12-01' AND '2007-12-31'
GROUP BY s.date_ordered;
date_ordered |
variance
--------------+-----------------2007-12-01
|
NaN
2007-12-02
|
2259129762
2007-12-03
| 1809012182.33301
2007-12-04
|
35138165568.25
2007-12-05
| 26644110029.3003
2007-12-06
|
25943125234
2007-12-07
| 23178202223.9048
2007-12-08
| 21940268901.1431
2007-12-09
| 21487676799.6108
2007-12-10
| 21521358853.4331
(10 rows)
SQLReference Manual
SQL Functions
See Also
l
VAR_SAMP [Analytic]
VARIANCE [Aggregate]
VAR_SAMP [Aggregate]
CURRENT_LOAD_SOURCE
Returns the file name used during the COPYstatement.
Behavior Type
Stable
Syntax
CURRENT_LOAD_SOURCE()
Behavior
l
If the function is called by a UDL that does not set the source, it returns the string <unknown>.
Examples
This example creates a table and populates column c3 with the names of the two separate files
being loaded.
=> CREATE TABLE t (c1 integer, c2 varchar(50), c3 varchar(200));
CREATE TABLE
=> COPY t (c1, c2, c3 AS CURRENT_LOAD_SOURCE()) FROM '/home/load_file_1' ON exampledb_
node02, '/home/load_file_2' ON exampledb_node03 DELIMITER ',';
SQLReference Manual
SQL Functions
Rows Loaded
------------5
(1 row)
=> SELECT * FROM t;
c1 |
c2
|
c3
----+--------------+----------------------2
| dogs
| load_file_1
1
| cats
| load_file_1
4
| superheroes | load_file_2
3
| birds
| load_file_1
5
| whales
| load_file_2
(5 rows)
See Also
l
COPY
SQLReference Manual
SQL Functions
Date/Time Functions
Date and time functions perform conversion, extraction, or manipulation operations on date and
time data types and can return date and time information.
Usage
Functions that take TIME or TIMESTAMP inputs come in two variants:
l
produces
TIMESTAMP WITH TIME ZONE '2005-04-03 12:00-06'
Adding INTERVAL '24 hours' to the same initial TIMESTAMP WITH TIME ZONE produces
TIMESTAMP WITH TIME ZONE '2005-04-03 13:00-06',
This result occurs because there is a change in daylight saving time at 2005-04-03 02:00 in time
zone CST7CDT.
SQLReference Manual
SQL Functions
See Also
Template Patterns for Date/Time Formatting
ADD_MONTHS
Takes a DATE, TIMESTAMP, or TIMESTAMPTZ argument and a number of months and returns a
date. TIMESTAMPTZ arguments are implicitly cast to TIMESTAMP.
Behavior Type
Immutable if called with DATE or TIMESTAMP but stable with TIMESTAMPTZ in that its results
can change based on TIMEZONE settings
Syntax
ADD_MONTHS ( d , n );
Parameters
d
The incoming DATE, TIMESTAMP, or TIMESTAMPTZ. If the start date falls on the last day
of the month, or if the resulting month has fewer days than the given day of the month, then
the result is the last day of the resulting month. Otherwise, the result has the same start day.
Any INTEGER.
Examples
The following example's results include a leap year:
SELECT ADD_MONTHS('31-Jan-08', 1) "Months";
Months
SQLReference Manual
SQL Functions
-----------2008-02-29
(1 row)
The next example adds four months to January and returns a date in May:
SELECT ADD_MONTHS('31-Jan-08', 4) "Months";
Months
-----------2008-05-31
(1 row)
This example subtracts four months from January, returning a date in September:
SELECT ADD_MONTHS('31-Jan-08', -4) "Months";
Months
-----------2007-09-30
(1 row)
Because the following example specifies NULL, the result set is empty:
SELECT ADD_MONTHS('31-Jan-03', NULL) "Months";
Months
-------(1 row)
This example provides no date argument, so even though the number of months specified is 1, the
result set is empty:
SELECT ADD_MONTHS(NULL, 1) "Months";
Months
-------(1 row)
In this example, the date field defaults to a timestamp, so the PST is ignored. Even though it is
already the next day in Pacific time, the result falls on the same date in New York (two years later):
SET TIME ZONE 'America/New_York';
SELECT ADD_MONTHS('2008-02-29 23:30 PST', 24);
add_months
-----------2010-02-28
(1 row)
The next example specifies a timestamp with time zone, so the PST is taken into account:
SQLReference Manual
SQL Functions
AGE_IN_MONTHS
Returns an INTEGER value representing the difference in months between two TIMESTAMP,
DATE or TIMESTAMPTZ values.
Behavior Type
Stable if second argument is omitted or if either argument is TIMESTAMPTZ. Immutable
otherwise.
Syntax
AGE_IN_MONTHS ( expression1 [ , expression2 ] )
Parameters
expression1
expression2
Notes
The inputs can be TIMESTAMP, TIMESTAMPTZ, or DATE.
Examples
The following example returns the age in months of a person born on March 2, 1972 on the date
June 21, 1990, with a time elapse of 18 years, 3 months, and 19 days:
SELECT AGE_IN_MONTHS(TIMESTAMP '1990-06-21', TIMESTAMP '1972-03-02');
AGE_IN_MONTHS
--------------219
(1 row)
The next example shows the age in months of the same person (born March 2, 1972) as of March
16, 2010:
SQLReference Manual
SQL Functions
This example returns the age in months of a person born on November 21, 1939:
SELECT AGE_IN_MONTHS(TIMESTAMP '1939-11-21');
AGE_IN_MONTHS
--------------844
(1 row)
See Also
l
AGE_IN_YEARS
INTERVAL
AGE_IN_YEARS
Returns an INTEGER value representing the difference in years between two TIMESTAMP, DATE
or TIMESTAMPTZ values.
Behavior Type
Stable if second argument is omitted or if either argument is TIMESTAMPTZ. Immutable
otherwise.
Syntax
AGE_IN_YEARS ( expression1 [ , expression2 ] )
Parameters
expression1
expression2
SQLReference Manual
SQL Functions
Notes
l
The AGE_IN_YEARS() function was previously called AGE. AGE() is not supported.
Examples
The following example returns the age in years of a person born on March 2, 1972 on the date June
21, 1990, with a time elapse of 18 years, 3 months, and 19 days:
SELECT AGE_IN_YEARS(TIMESTAMP '1990-06-21', TIMESTAMP '1972-03-02');
AGE_IN_YEARS
-------------18
(1 row)
The next example shows the age in years of the same person (born March 2, 1972) as of February
24, 2009:
SELECT AGE_IN_YEARS(TIMESTAMP '2009-02-24', TIMESTAMP '1972-03-02');
AGE_IN_YEARS
-------------36
(1 row)
This example returns the age in years of a person born on November 21, 1939:
SELECT AGE_IN_YEARS(TIMESTAMP '1939-11-21');
AGE_IN_YEARS
-------------70
(1 row)
See Also
l
AGE_IN_MONTHS
INTERVAL
CLOCK_TIMESTAMP
Returns a value of type TIMESTAMP WITH TIMEZONE representing the current system-clock
time.
SQLReference Manual
SQL Functions
Behavior Type
Volatile
Syntax
CLOCK_TIMESTAMP()
Notes
This function uses the date and time supplied by the operating system on the server to which you
are connected, which should be the same across all servers. The value changes each time you call
it.
Examples
The following command returns the current time on your system:
SELECT CLOCK_TIMESTAMP() "Current Time";
Current Time
-----------------------------2010-09-23 11:41:23.33772-04
(1 row)
Each time you call the function, you get a different result. The difference in this example is in
microseconds:
SELECT CLOCK_TIMESTAMP() "Time 1", CLOCK_TIMESTAMP() "Time 2";
Time 1
|
Time 2
-------------------------------+------------------------------2010-09-23 11:41:55.369201-04 | 2010-09-23 11:41:55.369202-04
(1 row)
See Also
l
STATEMENT_TIMESTAMP
TRANSACTION_TIMESTAMP
CURRENT_DATE
Returns the date (date-type value) on which the current transaction started.
SQLReference Manual
SQL Functions
Behavior Type
Stable
Syntax
CURRENT_DATE
Notes
The CURRENT_DATE function does not require parentheses.
Examples
SELECT CURRENT_DATE;
?column?
-----------2010-09-23
(1 row)
CURRENT_TIME
Returns a value of type TIME WITH TIMEZONE representing the time of day.
Behavior Type
Stable
Syntax
CURRENT_TIME [ ( precision ) ]
Parameters
precision
Notes
l
This function returns the start time of the current transaction; the value does not change during
the transaction. The intent is to allow a single transaction to have a consistent notion of the
SQLReference Manual
SQL Functions
current time, so that multiple modifications within the same transaction bear the same
timestamp.
l
Examples
SELECT CURRENT_TIME "Current Time";
Current Time
-------------------12:45:12.186089-05
(1 row)
CURRENT_TIMESTAMP
Returns a value of type TIMESTAMP WITH TIME ZONE representing the start of the current
transaction.
Behavior Type
Stable
Syntax
CURRENT_TIMESTAMP [ ( precision ) ]
Parameters
precision
Notes
This function returns the start time of the current transaction; the value does not change during the
transaction. The intent is to allow a single transaction to have a consistent notion of the "current"
time, so that multiple modifications within the same transaction bear the same timestamp.
Examples
SELECT CURRENT_TIMESTAMP;
SQLReference Manual
SQL Functions
?column?
------------------------------2010-09-23 11:37:22.354823-04
(1 row)
SELECT CURRENT_TIMESTAMP(2);
?column?
--------------------------2010-09-23 11:37:22.35-04
(1 row)
DATE_PART
Is modeled on the traditional Ingres equivalent to the SQL-standard function EXTRACT. Internally
DATE_PART is used by the EXTRACT function.
Behavior Type
Stable when source is of type TIMESTAMPTZ, Immutable otherwise.
Syntax
DATE_PART ( field , source )
CENTURY
The first century starts at 0001-01-01 00:00:00 AD. This definition applies to all
Gregorian calendar countries. There is no century number 0, you go from 1 to
1.
DAY
DECADE
SQLReference Manual
SQL Functions
DOQ
The result is calculated as follows: Current date = June 28, current quarter = 2
(April, May, June). 30 (April) + 31 (May) + 28 (June current day) = 89.
DOQ recognizes leap year days.
DOW
EXTRACT's day of the week numbering is different from that of the TO_CHAR
function.
DOY
EPOCH
For DATE and TIMESTAMP values, the number of seconds since 1970-01-01
00:00:00-00 (can be negative); for INTERVAL values, the total number of
seconds in the interval.
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:4008');
Result: 982384720
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800
SQLReference Manual
SQL Functions
ISODOW
ISOWEEK
The ISO week, which consists of 7 days starting on Monday and ending on
Sunday. The first week of the year is the week that contains January 4.
ISOYEAR
MICROSECONDS
MILLENNIUM
Years in the 1900s are in the second millennium. The third millennium starts
January 1, 2001.
MILLISECONDS
The seconds field, including fractional parts, multiplied by 1000. This includes
full seconds.
SELECT EXTRACT(MILLISECONDS FROM TIME '17:12:28.5');
Result: 28500
MINUTE
SQLReference Manual
SQL Functions
MONTH
For timestamp values, the number of the month within the year (1 - 12) ; for
interval values the number of months, modulo 12 (0 - 11).
SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 3 months');
Result: 3
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 13 months');
Result: 1
QUARTER
The quarter of the year (14) that the day is in (for timestamp values only).
SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 1
SECOND
The seconds field, including fractional parts (059) (60 if leap seconds are
implemented by the operating system).
SELECT EXTRACT(SECOND FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 40
SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
Result: 28.5
TIME ZONE
The time zone offset from UTC, measured in seconds. Positive values
correspond to time zones east of UTC, negative values to zones west of UTC.
TIMEZONE_HOUR
TIMEZONE_
MINUTE
WEEK
The number of the week of the calendar year that the day is in.
SELECT EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 7
SELECT EXTRACT(WEEK FROM DATE '2001-02-16');
Result: 7
YEAR
The year field. Keep in mind there is no 0 AD, so subtract BC years from AD
years with care.
SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2001
Parameters
SQLReference Manual
SQL Functions
field
Single-quoted string value that specifies the field to extract. You must enter the constant
field values (for example, CENTURY, DAY, etc). when specifying the field.
Note: The field parameter values are the same for the EXTRACT function.
source
A date/time expression
Field Values
CENTURY
The first century starts at 0001-01-01 00:00:00 AD. This definition applies to all
Gregorian calendar countries. There is no century number 0, you go from 1 to
1.
DAY
DECADE
DOQ
The result is calculated as follows: Current date = June 28, current quarter = 2
(April, May, June). 30 (April) + 31 (May) + 28 (June current day) = 89.
DOQ recognizes leap year days.
SQLReference Manual
SQL Functions
DOW
EXTRACT's day of the week numbering is different from that of the TO_CHAR
function.
DOY
EPOCH
For DATE and TIMESTAMP values, the number of seconds since 1970-01-01
00:00:00-00 (can be negative); for INTERVAL values, the total number of
seconds in the interval.
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:4008');
Result: 982384720
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800
ISODOW
ISOWEEK
The ISO week, which consists of 7 days starting on Monday and ending on
Sunday. The first week of the year is the week that contains January 4.
SQLReference Manual
SQL Functions
ISOYEAR
MICROSECONDS
MILLENNIUM
Years in the 1900s are in the second millennium. The third millennium starts
January 1, 2001.
MILLISECONDS
The seconds field, including fractional parts, multiplied by 1000. This includes
full seconds.
SELECT EXTRACT(MILLISECONDS FROM TIME '17:12:28.5');
Result: 28500
MINUTE
MONTH
For timestamp values, the number of the month within the year (1 - 12) ; for
interval values the number of months, modulo 12 (0 - 11).
SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 3 months');
Result: 3
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 13 months');
Result: 1
QUARTER
The quarter of the year (14) that the day is in (for timestamp values only).
SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 1
SQLReference Manual
SQL Functions
SECOND
The seconds field, including fractional parts (059) (60 if leap seconds are
implemented by the operating system).
SELECT EXTRACT(SECOND FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 40
SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
Result: 28.5
TIME ZONE
The time zone offset from UTC, measured in seconds. Positive values
correspond to time zones east of UTC, negative values to zones west of UTC.
TIMEZONE_HOUR
TIMEZONE_
MINUTE
WEEK
The number of the week of the calendar year that the day is in.
SELECT EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 7
SELECT EXTRACT(WEEK FROM DATE '2001-02-16');
Result: 7
YEAR
The year field. Keep in mind there is no 0 AD, so subtract BC years from AD
years with care.
SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2001
Examples
The following example extracts the day value from the input parameters:
SELECT DATE_PART('day', TIMESTAMP '2009-02-24 20:38:40') "Day";
Day
----24
(1 row)
The following example extracts the month value from the input parameters:
SELECT DATE_PART('month', TIMESTAMP '2009-02-24 20:38:40') "Month";
Month
------2
(1 row)
The following example extracts the year value from the input parameters:
SELECT DATE_PART('year', TIMESTAMP '2009-02-24 20:38:40') "Year";
SQLReference Manual
SQL Functions
Year
-----2009
(1 row)
The following example extracts the hours from the input parameters:
SELECT DATE_PART('hour', TIMESTAMP '2009-02-24 20:38:40') "Hour";
Hour
-----20
(1 row)
The following example extracts the minutes from the input parameters:
SELECT DATE_PART('minutes', TIMESTAMP '2009-02-24 20:38:40') "Minutes";
Minutes
--------38
(1 row)
The following example extracts the seconds from the input parameters:
SELECT DATE_PART('seconds', TIMESTAMP '2009-02-24 20:38:40') "Seconds";
Seconds
--------40
(1 row)
The following example extracts the day of quarter (DOQ) from the input parameters:
SELECT DATE_PART('DOQ', TIMESTAMP '2009-02-24 20:38:40') "DOQ";
DOQ
----55
(1 row)
SQLReference Manual
SQL Functions
(1 row)
See Also
EXTRACT
DATE
Converts a TIMESTAMP, TIMESTAMPTZ, DATE, or VARCHAR to a DATE. You can also use
this function to convert an INTEGER to a DATE. In this case, the resulting date reflects the int
number of days after 0001 AD. (Day 1 is January 1, 0001.)
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
DATE ( d | n )
Parameters
d
Examples
=> SELECT DATE (1);
DATE
-----------0001-01-01
(1 row)
=> SELECT DATE (734260);
DATE
SQLReference Manual
SQL Functions
-----------2011-05-03
(1 row)
=> SELECT DATE ('TODAY');
DATE
-----------2011-05-31
(1 row)
See Also
l
TO_DATE
TO_TIMESTAMP
TO_TIMESTAMP_TZ
DATE_TRUNC
Truncates date and time values as indicated. The return value is of type TIME or TIMETZ with all
fields that are less significant than the selected one set to zero (or one, for day and month).
Behavior Type
Stable.
Syntax
DATE_TRUNC ( field , source )
Parameters
field
String constant that selects the precision to which truncate the input value.
source
Field Values
CENTURY
SQLReference Manual
SQL Functions
DAY
DECADE
HOUR
MICROSECONDS
MILLENNIUM
MILLISECONDS
The seconds field, including fractional parts, multiplied by 1000. Note that this
includes full seconds.
MINUTE
MONTH
For timestamp values, the number of the month within the year (112) ; for
interval values the number of months, modulo 12 (011).
SECOND
The seconds field, including fractional parts (059) (60 if leap seconds are
implemented by the operating system).
WEEK
By definition, the ISO-8601 week starts on Monday, and the first week of a year
contains January 4 of that year. In other words, the first Thursday of a year is in
week 1 of that year.
Because of this, it is possible for early January dates to be part of the 52nd or 53rd
week of the previous year. For example, 2005-01-01 is part of the 53rd week of
year 2004, and 2006-01-01 is part of the 52nd week of year 2005.
The number of the week of the year that the day is in.
YEAR
The year field. Keep in mind there is no 0 AD, so subtract BC years from AD years
with care.
Examples
The following example sets the field value as hour and returns the hour, truncating the minutes and
seconds:
VMart=> select date_trunc('hour', timestamp '2012-02-24 13:38:40') as hour;
hour
SQLReference Manual
SQL Functions
--------------------2012-02-24 13:00:00
(1 row)
The following example returns the year from the input timestamptz '2012-02-24 13:38:40'. The
function also defaults the month and day to January 1, truncates the hour:minute:second of the
timestamp, and appends the time zone (-05):
VMart=> select date_trunc('year', timestamptz '2012-02-24 13:38:40') as year;
year
-----------------------2012-01-01 00:00:00-05
(1 row)
The following example returns the year and month and defaults day of month to 1, truncating the
rest of the string:
VMart=> select date_trunc('month', timestamp '2012-02-24 13:38:40') as year;
year
--------------------2012-02-01 00:00:00
(1 row)
DATEDIFF
Returns the difference between two date or time values, based on the specified start and end
arguments.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax 1
DATEDIFF ( datepart , startdate , enddate);
Syntax 2
DATEDIFF ( datepart , starttime , endtime);
Parameters
SQLReference Manual
SQL Functions
datepart
startdate
datepart
Abbreviation
year
yy, yyyy
quarter
qq, q
month
mm, m
day
week
wk, ww
hour
hh
minute
mi, n
second
ss, s
millisecond
ms
microsecond
mcs, us
Start date for the calculation and is an expression that returns a TIMESTAMP,
DATE, or TIMESTAMPTZ value.
The startdate value is not included in the count.
enddate
End date for the calculation and is an expression that returns a TIMESTAMP, DATE,
or TIMESTAMPTZ value.
The enddate value is included in the count.
starttime
Start time for the calculation and is an expression that returns an INTERVAL or TIME
data type.
l
SQLReference Manual
SQL Functions
endtime
End time for the calculation and is an expression that returns an INTERVAL or TIME
data type.
l
Notes
l
DATEDIFF() is an immutable function with a default type of TIMESTAMP. It also takes DATE.
If TIMESTAMPTZ is specified, the function is stable.
Starting arguments are not included in the count, but end arguments are included.
The previous example specified a datepart of year, a startdate of January 1, 2005 and an
enddate of December 31, 2008. DATEDIFF returns 3 by counting the year intervals as follows:
[1] January 1, 2006 + [2] January 1, 2007 + [3] January 1, 2008 = 3
SQLReference Manual
SQL Functions
The function returns 3, and not 4, because startdate (January 1, 2005) is not counted in the
calculation. DATEDIFF also ignores the months between January 1, 2008 and December 31, 2008
because the datepart specified is year and only the start of each year is counted.
Sometimes the enddate occurs earlier in the ending year than the startdate in the starting year.
For example, assume a datepart of year, a startdate of August 15, 2005, and an enddate of
January 1, 2009. In this scenario, less than three years have elapsed, but DATEDIFF counts the
same way it did in the previous example, returning 3 because it returns the number of January 1s
between the limits:
[1] January 1, 2006 + [2] January 1, 2007 + [3] January 1, 2008 = 3
In the following query, HP Vertica recognizes the full year 2005 as the starting year and 2009 as the
ending year.
SELECT DATEDIFF('year', TO_DATE('08-15-2005','MM-DD-YYYY'), TO_DATE('01-01-2009','MM-DDYYYY'));
Even though August 15 has not yet occurred in the enddate, the function counts the entire enddate
year as one tick or boundary because of the year datepart.
Examples
Year: In this example, the startdateand enddateare adjacent. The difference between the dates
is one time boundary (second) of its datepart, so the result set is 1.
SELECT DATEDIFF('year', TIMESTAMP '2008-12-31 23:59:59',
'2009-01-01 00:00:00');
datediff
---------1
(1 row)
SQLReference Manual
SQL Functions
datediff
---------0
(1 row)
The next example, however, returns eight quarters because the difference spans two full years. The
extra month is ignored:
SELECT DATEDIFF('quarter', TO_DATE('01-01-1993','MM-DD-YYYY'),
TO_DATE('02-02-1995','MM-DD-YYYY'));
datediff
---------8
(1 row)
And this third example returns 23 because there are 23 months difference between
SELECT DATEDIFF('m', TO_DATE('02-02-1993','MM-DD-YYYY'),
TO_DATE('01-01-1995','MM-DD-YYYY'));
datediff
---------23
(1 row)
SQLReference Manual
SQL Functions
In the next example, DATEDIFF() counts the weeks between January 1, 1995 and February 2,
1995 and returns 4 (weeks):
SELECT DATEDIFF('wk', TO_DATE('01-01-1995','MM-DD-YYYY'),
TO_DATE('02-02-1995','MM-DD-YYYY'));
datediff
---------4
(1 row)
SQLReference Manual
SQL Functions
datediff
---------762
(1 row)
In the following example, the query counts the difference in seconds, beginning at a start time of
4:44 and ending at 5:55 with an interval of two days:
SELECT DATEDIFF('ss', TIME '04:44:42.315786',
INTERVAL '2 05:55:52.963558');
datediff
SQLReference Manual
SQL Functions
---------177070
(1 row)
See Also
Date/Time Expressions
DAY
Extracts the day of the month from a TIMESTAMP, TIMESTAMPTZ, INTEGER, VARCHAR, or
INTERVAL input value. The return value is of type INTEGER.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
DAY (d )
Parameters
d
Examples
=> SELECT
DAY
----6
(1 row)
=> SELECT
DAY
----22
(1 row)
=> SELECT
DAY
----22
(1 row)
=> SELECT
DAY
-----
DAY (6);
SQLReference Manual
SQL Functions
35
(1 row)
DAYOFMONTH
Returns an integer representing the day of the month based on a VARCHAR, DATE, TIMESTAMP,
OR TIMESTAMPTZ input value.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
DAYOFMONTH ( d )
Parameters
d
Example
=> SELECT DAYOFMONTH (TIMESTAMP 'sep 22, 2011 12:34');
DAYOFMONTH
-----------22
(1 row)
DAYOFWEEK
Returns an INTEGER representing the day of the week based on a TIMESTAMP, TIMESTAMPTZ,
VARCHAR, or DATE input value. Valid return values are:
Integer Week Day
1
Sunday
Monday
Tuesday
Wednesday
SQLReference Manual
SQL Functions
Thursday
Friday
Saturday
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
DAYOFWEEK ( d )
Parameters
d
Example
=> SELECT DAYOFWEEK (TIMESTAMP 'sep 17, 2011 12:34');
DAYOFWEEK
----------7
(1 row)
DAYOFWEEK_ISO
Returns an INTEGER representing the ISO 8061 day of the week based on a VARCHAR, DATE,
TIMESTAMP, or TIMESTAMPTZ input value. Valid return values are:
Integer Week Day
1
Monday
Tuesday
Wednesday
Thursday
Friday
SQLReference Manual
SQL Functions
Saturday
Sunday
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
DAYOFWEEK_ISO ( d )
Parameters
d
Examples
=> SELECT DAYOFWEEK_ISO(TIMESTAMP 'Sep 22, 2011 12:34');
DAYOFWEEK_ISO
--------------4
(1 row)
The following example shows how to combine the DAYOFWEEK_ISO, WEEK_ISO, and YEAR_
ISO functions to find the ISO day of the week, week, and year:
=> SELECT DAYOFWEEK_ISO('Jan 1, 2000'), WEEK_ISO('Jan 1, 2000'),YEAR_ISO('Jan1,2000');
DAYOFWEEK_ISO | WEEK_ISO | YEAR_ISO
---------------+----------+---------6 |
52 |
1999
(1 row)
See Also
l
WEEK_ISO
DAYOFWEEK_ISO
http://en.wikipedia.org/wiki/ISO_8601
SQLReference Manual
SQL Functions
DAYOFYEAR
Returns an INTEGER representing the day of the year based on a TIMESTAMP, TIMESTAMPTZ ,
VARCHAR, or DATE input value. (January 1 is day 1.)
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
DAYOFYEAR ( d )
Parameters
d
Example
=> SELECT DAYOFYEAR (TIMESTAMP 'SEPT 22,2011 12:34');
DAYOFYEAR
----------265
(1 row)
DAYS
Converts a DATE, VARCHAR, TIMESTAMP, or TIMESTAMPTZ to an INTEGER, reflecting the
number of days after 0001 AD.
Behavior Type
Immutable
Syntax
DAYS( DATE d )
Parameters
DATE d
SQLReference Manual
SQL Functions
Example
=> SELECT DAYS (DATE '2011-01-22');
DAYS
-------734159
(1 row)
=> SELECT DAYS ('1999-12-31');
DAYS
-------730119
(1 row)
EXTRACT
Retrieves subfields such as year or hour from date/time values and returns values of type
NUMERIC. EXTRACT is primarily intended for computational processing, rather than for
formatting date/time values for display.
Internally EXTRACT uses the DATE_PART function.
Behavior Type
Stable when source is of type TIMESTAMPTZ, Immutable otherwise.
Syntax
EXTRACT ( field FROM source )
CENTURY
The first century starts at 0001-01-01 00:00:00 AD. This definition applies to all
Gregorian calendar countries. There is no century number 0, you go from 1 to
1.
DAY
SQLReference Manual
SQL Functions
DECADE
DOQ
The result is calculated as follows: Current date = June 28, current quarter = 2
(April, May, June). 30 (April) + 31 (May) + 28 (June current day) = 89.
DOQ recognizes leap year days.
DOW
EXTRACT's day of the week numbering is different from that of the TO_CHAR
function.
DOY
EPOCH
For DATE and TIMESTAMP values, the number of seconds since 1970-01-01
00:00:00-00 (can be negative); for INTERVAL values, the total number of
seconds in the interval.
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:4008');
Result: 982384720
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800
SQLReference Manual
SQL Functions
ISODOW
ISOWEEK
The ISO week, which consists of 7 days starting on Monday and ending on
Sunday. The first week of the year is the week that contains January 4.
ISOYEAR
MICROSECONDS
MILLENNIUM
Years in the 1900s are in the second millennium. The third millennium starts
January 1, 2001.
MILLISECONDS
The seconds field, including fractional parts, multiplied by 1000. This includes
full seconds.
SELECT EXTRACT(MILLISECONDS FROM TIME '17:12:28.5');
Result: 28500
MINUTE
SQLReference Manual
SQL Functions
MONTH
For timestamp values, the number of the month within the year (1 - 12) ; for
interval values the number of months, modulo 12 (0 - 11).
SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 3 months');
Result: 3
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 13 months');
Result: 1
QUARTER
The quarter of the year (14) that the day is in (for timestamp values only).
SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 1
SECOND
The seconds field, including fractional parts (059) (60 if leap seconds are
implemented by the operating system).
SELECT EXTRACT(SECOND FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 40
SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
Result: 28.5
TIME ZONE
The time zone offset from UTC, measured in seconds. Positive values
correspond to time zones east of UTC, negative values to zones west of UTC.
TIMEZONE_HOUR
TIMEZONE_
MINUTE
WEEK
The number of the week of the calendar year that the day is in.
SELECT EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 7
SELECT EXTRACT(WEEK FROM DATE '2001-02-16');
Result: 7
YEAR
The year field. Keep in mind there is no 0 AD, so subtract BC years from AD
years with care.
SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2001
Parameters
field
Identifier or string that selects what field to extract from the source value. You must
enter the constant field values (i.e. CENTURY, DAY, etc). when specifying the field.
Note: The field parameter is the same for the DATE_PART() function.
SQLReference Manual
SQL Functions
source
Field Values
CENTURY
The first century starts at 0001-01-01 00:00:00 AD. This definition applies to all
Gregorian calendar countries. There is no century number 0, you go from 1 to
1.
DAY
DECADE
DOQ
The result is calculated as follows: Current date = June 28, current quarter = 2
(April, May, June). 30 (April) + 31 (May) + 28 (June current day) = 89.
DOQ recognizes leap year days.
DOW
EXTRACT's day of the week numbering is different from that of the TO_CHAR
function.
SQLReference Manual
SQL Functions
DOY
EPOCH
For DATE and TIMESTAMP values, the number of seconds since 1970-01-01
00:00:00-00 (can be negative); for INTERVAL values, the total number of
seconds in the interval.
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:4008');
Result: 982384720
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800
ISODOW
ISOWEEK
The ISO week, which consists of 7 days starting on Monday and ending on
Sunday. The first week of the year is the week that contains January 4.
ISOYEAR
SQLReference Manual
SQL Functions
MICROSECONDS
MILLENNIUM
Years in the 1900s are in the second millennium. The third millennium starts
January 1, 2001.
MILLISECONDS
The seconds field, including fractional parts, multiplied by 1000. This includes
full seconds.
SELECT EXTRACT(MILLISECONDS FROM TIME '17:12:28.5');
Result: 28500
MINUTE
MONTH
For timestamp values, the number of the month within the year (1 - 12) ; for
interval values the number of months, modulo 12 (0 - 11).
SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 3 months');
Result: 3
SELECT EXTRACT(MONTH FROM INTERVAL '2 years 13 months');
Result: 1
QUARTER
The quarter of the year (14) that the day is in (for timestamp values only).
SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 1
SECOND
The seconds field, including fractional parts (059) (60 if leap seconds are
implemented by the operating system).
SELECT EXTRACT(SECOND FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 40
SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
Result: 28.5
TIME ZONE
The time zone offset from UTC, measured in seconds. Positive values
correspond to time zones east of UTC, negative values to zones west of UTC.
SQLReference Manual
SQL Functions
TIMEZONE_HOUR
TIMEZONE_
MINUTE
WEEK
The number of the week of the calendar year that the day is in.
SELECT EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 7
SELECT EXTRACT(WEEK FROM DATE '2001-02-16');
Result: 7
YEAR
The year field. Keep in mind there is no 0 AD, so subtract BC years from AD
years with care.
SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 2001
Examples
=> SELECT EXTRACT (DAY FROM DATE '2008-12-25');
date_part
----------25
(1 row)
=> SELECT EXTRACT (MONTH FROM DATE '2008-12-25');
date_part
----------12
(1 row
SELECT EXTRACT(DOQ FROM CURRENT_DATE);
date_part
----------89
(1 row)
TIMESTAMP '1972-03-
In the above example, AGE_IN_YEARS is 36. The UNIX epoch uses 365.25 days per year:
=> SELECT 1136073600.0/36/(24*60*60);
?column?
----------
SQLReference Manual
SQL Functions
365.25
(1 row)
See Also
l
DATE_PART
GETDATE
Returns the current system date and time as a TIMESTAMP value.
Behavior Type
Stable
Syntax
GETDATE();
Notes
l
This function uses the date and time supplied by the operating system on the server to which
you are connected, which is the same across all servers.
Example
=> SELECT GETDATE();
GETDATE
SQLReference Manual
SQL Functions
---------------------------2011-03-07 13:21:29.497742
(1 row)
See Also
l
Date/Time Expressions
GETUTCDATE
Returns the current system date and time as a TIMESTAMP value relative to UTC.
Behavior Type
Stable
Syntax
GETUTCDATE();
Notes
l
This function uses the date and time supplied by the operating system on the server to which
you are connected, which is the same across all servers.
Example
=> SELECT GETUTCDATE();
GETUTCDATE
---------------------------2011-03-07 20:20:26.193052
(1 row)
See Also
l
Date/Time Expressions
SQLReference Manual
SQL Functions
HOUR
Extracts the hour from a DATE, TIMESTAMP, TIMESTAMPTZ, VARCHAR, or INTERVAL value.
The return value is of type INTEGER. (Hour 0 is midnight to 1 a.m.)
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
HOUR ( d )
Parameters
d
Examples
=> SELECT HOUR (TIMESTAMP 'sep 22, 2011 12:34');
HOUR
-----12
(1 row)
=> SELECT HOUR (INTERVAL '35 12:34');
HOUR
-----12
(1 row)
=> SELECT HOUR ('12:34');
HOUR
-----12
(1 row)
ISFINITE
Tests for the special TIMESTAMP constant INFINITY and returns a value of type BOOLEAN.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
ISFINITE ( timestamp )
Parameters
timestamp
Examples
SELECT ISFINITE(TIMESTAMP '2009-02-16 21:28:30');
isfinite
---------t
(1 row)
SELECT ISFINITE(TIMESTAMP 'INFINITY');
isfinite
---------f
(1 row)
JULIAN_DAY
Returns an INTEGER representing the Julian day based on an input TIMESTAMP,
TIMESTAMPTZ, VARCHAR, or DATE value.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
JULIAN_DAY ( d )
Parameters
d
Example
=> SELECT JULIAN_DAY(TIMESTAMP 'sep 22, 2011 12:34');
SQLReference Manual
SQL Functions
JULIAN_DAY
-----------2455827
(1 row)
LAST_DAY
Returns the last day of the month based on a TIMESTAMP. The TIMESTAMP can be supplied as a
DATE or a TIMESTAMPTZ data type.
Behavior Type
Immutable, unless called with TIMESTAMPTZ, in which case it is Stable.
Syntax
LAST_DAY ( date );
Examples
The following example returns the last day of the month, February, as 29 because 2008 was a leap
year:
SELECT LAST_DAY('2008-02-28 23:30 PST') "Last";
Last
-----------2008-02-29
(1 row)
The following example returns the last day of the month in March, after converting the string value
to the specified DATE type:
SELECT LAST_DAY('2003/03/15') "Last";
Last
-----------2003-03-31
(1 row)
The following example returns the last day of February in the specified year (not a leap year):
SELECT LAST_DAY('2003/02/03') "Last";
Last
-----------2003-02-28
(1 row)
SQLReference Manual
SQL Functions
LOCALTIME
Returns a value of type TIME representing the time of day.
Behavior Type
Stable
Syntax
LOCALTIME [ ( precision ) ]
Parameters
precision
Causes the result to be rounded to the specified number of fractional digits in the
seconds field.
Notes
This function returns the start time of the current transaction; the value does not change during the
transaction. The intent is to allow a single transaction to have a consistent notion of the "current"
time, so that multiple modifications within the same transaction bear the same timestamp.
Example
SELECT LOCALTIME;
time
----------------16:16:06.790771
(1 row)
LOCALTIMESTAMP
Returns a value of type TIMESTAMP that represents today's date and time of day.
Behavior Type
Stable
Syntax
LOCALTIMESTAMP [ ( precision ) ]
SQLReference Manual
SQL Functions
Parameters
precision
Causes the result to be rounded to the specified number of fractional digits in the
seconds field.
Notes
This function returns the start time of the current transaction; the value does not change during the
transaction. The intent is to allow a single transaction to have a consistent notion of the "current"
time, so that multiple modifications within the same transaction bear the same timestamp.
Example
SELECT LOCALTIMESTAMP;
timestamp
-------------------------2009-02-24 14:47:48.5951
(1 row)
MICROSECOND
Returns an INTEGER representing the microsecond portion of an input DATE, VARCHAR,
TIMESTAMP, TIMESTAMPTZ, or INTERVAL value.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
MICROSECOND ( d )
Parameters
d
Example
=> SELECT MICROSECOND (TIMESTAMP 'Sep 22, 2011 12:34:01.123456');
MICROSECOND
SQLReference Manual
SQL Functions
------------123456
(1 row)
MIDNIGHT_SECONDS
Returns an INTEGER that represents the number of seconds between midnight and the input
value. The input value can be of type VARCHAR, TIME, TIMESTAMP, or TIMESTAMPTZ.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
MIDNIGHT_SECONDS ( d )
Parameters
d
Example
=> SELECT MIDNIGHT_SECONDS('12:34:00.987654');
MIDNIGHT_SECONDS
-----------------45240
(1 row)
=> SELECT MIDNIGHT_SECONDS(TIME '12:34:00.987654');
MIDNIGHT_SECONDS
-----------------45240
(1 row)
=> SELECT MIDNIGHT_SECONDS (TIMESTAMP 'sep 22, 2011 12:34');
MIDNIGHT_SECONDS
-----------------45240
(1 row)
MINUTE
Returns an INTEGER that represents the minute value of the input value. The input value can be of
type VARCHAR, DATE, TIMESTAMP, TIMESTAMPTZ, or INTERVAL.
SQLReference Manual
SQL Functions
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
MINUTE ( d )
Parameters
d
Example
=> SELECT MINUTE('12:34:03.456789');
MINUTE
-------34
(1 row)
=>SELECT MINUTE (TIMESTAMP 'sep 22, 2011 12:34');
MINUTE
-------34
(1 row)
=> SELECT MINUTE(INTERVAL '35 12:34:03.456789');
MINUTE
-------34
(1 row)
MONTH
Returns an INTEGER that represents the month portion of the input value. The input value can be
of type VARCHAR, DATE, TIMESTAMP, TIMESTAMPTZ, or INTERVAL.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
MONTH( d )
SQLReference Manual
SQL Functions
Parameters
d
Examples
=> SELECT MONTH('6-9');
MONTH
------9
(1 row)
=> SELECT MONTH (TIMESTAMP 'sep 22, 2011 12:34');
MONTH
------9
(1 row)
=> SELECT MONTH(INTERVAL '2-35' year to month);
MONTH
------11
(1 row)
MONTHS_BETWEEN
Returns the number of months between date1 and date2 as a FLOAT8, where the input arguments
can be of TIMESTAMP, DATE, or TIMESTAMPTZ type.
Behavior Type
Immutable for TIMESTAMP and DATE, Stable for TIMESTAMPTZ
Syntax
MONTHS_BETWEEN ( date1 , date2 );
Parameters
date1, date2
If date1 is later than date2, the result is positive. If date1 is earlier than date2,
then the result is negative.
If date1 and date2 are either the same days of the month or both are the last days
of their respective month, then the result is always an integer. Otherwise
MONTHS_BETWEEN returns a FLOAT8 result based on a 31-day month, which
considers the difference between date1 and date2.
SQLReference Manual
SQL Functions
Examples
The following result is an integral number of days because the dates are on the same day of the
month:
=> SELECT MONTHS_BETWEEN('2009-03-07 16:00'::TIMESTAMP,
'2009-04-07 15:00'::TIMESTAMP);
MONTHS_BETWEEN
----------------1
(1 row)
The result from the next example returns an integral number of days because the days fall on the
last day of their respective months:
=> SELECT MONTHS_BETWEEN('29Feb2000', '30Sep2000') "Months";
MONTHS
----------------7
(1 row)
In the next example, and in the example that immediately follows it, MONTHS_BETWEEN() returns the
number of months between date1 and date2 as a fraction because the days do not fall on the same
day or on the last day of their respective months:
=> SELECT MONTHS_BETWEEN(TO_DATE('02-02-1995','MM-DD-YYYY'),
TO_DATE('01-01-1995','MM-DD-YYYY') ) "Months";
Months
-----------------1.03225806451613
(1 row)
=> SELECT MONTHS_BETWEEN(TO_DATE ('2003/01/01', 'yyyy/mm/dd'),
TO_DATE ('2003/03/14', 'yyyy/mm/dd') ) "Months";
Months
-------------------2.41935483870968
(1 row)
The following two examples use the same date1 and date2 strings, but they are cast to a different
data types (TIMESTAMP and TIMESTAMPTZ). The result is the same for both statements:
SELECT MONTHS_BETWEEN('2008-04-01'::timestamp, '2008-02-29'::timestamp);
months_between
-----------------1.09677419354839
(1 row)
SQLReference Manual
SQL Functions
NEW_TIME
Converts a TIMESTAMP value between time zones. Intervals are not permitted.
Behavior Type
Immutable
Syntax
NEW_TIME( 'timestamp' , 'timezone1' , 'timezone2')
Returns
TIMESTAMP
Parameters
timestamp
SQLReference Manual
SQL Functions
timezone1
timezone2
Notes
The timezone arguments are character strings of the form required by the TIMESTAMP AT
TIMEZONE 'zone' clause; for example:
AST, ADT
BST, BDT
CST, CDT
EST, EDT
GMT
HST
MST, MDT
NST
PST, PDT
Examples
The following command converts the specified time from Eastern Standard Time to Pacific
Standard Time:
=> SELECT NEW_TIME('05-24-12 13:48:00', 'EST', 'PST');
NEW_TIME
--------------------2012-05-24 10:48:00
(1 row)
This command converts the time on January 1 from Eastern Standard Time to Pacific Standard
Time. Notice how the time rolls back to the previous year:
SQLReference Manual
SQL Functions
The following example returns the year 45 before the Common Era in Greenwich Mean Time and
converts it to Newfoundland Standard Time:
=>
NEXT_DAY
Returns the date of the first instance of a particular day of the week that follows the specified date.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
NEXT_DAY( 'date', 'DOW')
SQLReference Manual
SQL Functions
Parameters
date
DOW
Day of week, type CHAR/VARCHAR string or character constant. DOW is not case
sensitive and trailing spaces are ignored.
Examples
The following example returns the date of the next Friday following the specified date. All are
variations on the same query, and all return the same result:
=> SELECT NEXT_DAY('28-MAR-2011','FRIDAY') "NEXT DAY" FROM DUAL;
NEXT DAY
-----------2011-04-01
(1 row)
=> SELECT NEXT_DAY('March 28 2011','FRI') "NEXT DAY" FROM DUAL;
NEXT DAY
-----------2011-04-01
(1 row)
=> SELECT NEXT_DAY('3-29-11','FRI') "NEXT DAY" FROM DUAL;
NEXT DAY
-----------2011-04-01
(1 row)
NOW [Date/Time]
Returns a value of type TIMESTAMP WITH TIME ZONE representing the start of the current
transaction. NOW is equivalent to CURRENT_TIMESTAMP except that it does not accept a
precision parameter.
Behavior Type
Stable
Syntax
NOW()
SQLReference Manual
SQL Functions
Notes
This function returns the start time of the current transaction; the value does not change during the
transaction. The intent is to allow a single transaction to have a consistent notion of the "current"
time, so that multiple modifications within the same transaction bear the same timestamp.
Example
SELECT NOW();
NOW
------------------------------2010-04-01 15:31:12.144584-04
(1 row)
See Also
l
CURRENT_TIMESTAMP
OVERLAPS
Returns true when two time periods overlap, false when they do not overlap.
Behavior Type
Stable when TIMESTAMP and TIMESTAMPTZ are both used, or when TIMESTAMPTZ is used
with INTERVAL, Immutable otherwise.
Syntax
( start, end ) OVERLAPS ( start, end )
( start, interval ) OVERLAPS ( start, interval )
Parameters
start
DATE, TIME, or TIME STAMP value that specifies the beginning of a time period.
end
DATE, TIME, or TIME STAMP value that specifies the end of a time period.
interval
SQLReference Manual
SQL Functions
Examples
The first command returns true for an overlap in date range of 2007-02-16 through 2007-12-21 with
2007-10-30 through 2008-10-30.
SELECT (DATE '2007-02-16', DATE '2007-12-21')
OVERLAPS (DATE '2007-10-30', DATE '2008-10-30');
OVERLAPS
---------t
(1 row)
The next command returns false for an overlap in date range of 2007-02-16 through 2007-12-21 with
2008-10-30 through 2008-10-30.
SELECT (DATE '2007-02-16', DATE '2007-12-21')
OVERLAPS (DATE '2008-10-30', DATE '2008-10-30');
OVERLAPS
---------f
(1 row)
The next command returns false for an overlap in date range of 2007-02-16, 22 hours ago with 200710-30, 22 hours ago.
SELECT (DATE '2007-02-16', INTERVAL '1 12:59:10')
OVERLAPS (DATE '2007-10-30', INTERVAL '1 12:59:10');
overlaps
---------f
(1 row)
QUARTER
Returns an INTEGER representing calendar quarter into which the input value falls. The input value
can be of type VARCHAR, DATE, TIMESTAMP or TIMESTAMPTZ.
Syntax
QUARTER( d )
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
SQLReference Manual
SQL Functions
Parameters
d
Example
=> SELECT QUARTER (TIMESTAMP 'sep 22, 2011 12:34');
QUARTER
--------3
(1 row)
ROUND [Date/Time]
Rounds a TIMESTAMP, TIMESTAMPTZ, or DATE. The return value is of type TIMESTAMP.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
ROUND([TIMESTAMP | DATE] , format )
Parameters
TIMESTAMP | DATE
SQLReference Manual
SQL Functions
format
Valid values
Century
CC, SCC
Year
ISO Year
Quarter
Month
WW
of the year
Same day of the week as the first day
IW
of the month
Day
DDD, DD, J
DAY, DY, D
Hour
Minute
MI
Second
SS
Example
=> SELECT ROUND(TIMESTAMP 'sep 22, 2011 12:34:00', 'dy');
ROUND
--------------------2011-09-18 00:00:00
(1 row)
SQLReference Manual
SQL Functions
SECOND
Returns an INTEGER representing the second portion of the input value. The input value can be of
type VARCHAR, TIMESTAMP, TIMESTAMPTZ, or INTERVAL.
Syntax
SECOND( d )
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Parameters
d
Examples
=> SELECT SECOND ('23:34:03.456789');
SECOND
-------3
(1 row)
=> SELECT SECOND (TIMESTAMP 'sep 22, 2011 12:34');
SECOND
-------0
(1 row)
=> SELECT SECOND (INTERVAL '35 12:34:03.456789');
SECOND
-------3
(1 row)
STATEMENT_TIMESTAMP
Is similar to TRANSACTION_TIMESTAMP. It returns a value of type TIMESTAMP WITH TIME
ZONE representing the start of the current statement.
Behavior Type
Stable
SQLReference Manual
SQL Functions
Syntax
STATEMENT_TIMESTAMP()
Notes
This function returns the start time of the current statement; the value does not change during the
statement. The intent is to allow a single statement to have a consistent notion of the "current"
time, so that multiple modifications within the same statement bear the same timestamp.
Example
SELECT STATEMENT_TIMESTAMP();
STATEMENT_TIMESTAMP
------------------------------2010-04-01 15:40:42.223736-04
(1 row)
See Also
l
CLOCK_TIMESTAMP
TRANSACTION_TIMESTAMP
SYSDATE
Returns the current system date and time as a TIMESTAMP value.
Behavior Type
Stable
Syntax
SYSDATE();
Notes
l
SYSDATE is a stable function (called once per statement) that requires no arguments.
Parentheses are optional.
SQLReference Manual
SQL Functions
This function uses the date and time supplied by the operating system on the server to which
you are connected, which must be the same across all servers.
Example
=> SELECT SYSDATE();
sysdate
---------------------------2011-03-07 13:22:28.295802
(1 row)
See Also
l
Date/Time Expressions
TIME_SLICE
Aggregates data by different fixed-time intervals and returns a rounded-up input TIMESTAMP value
to a value that corresponds with the start or end of the time slice interval.
Given an input TIMESTAMP value, such as '2000-10-28 00:00:01', the start time of a 3-second time
slice interval is '2000-10-28 00:00:00', and the end time of the same time slice is '2000-10-28
00:00:03'.
Behavior Type
Immutable
Syntax
TIME_SLICE(expression, slice_length,
[ time_unit = 'SECOND' ],
[ start_or_end = 'START' ] )
SQLReference Manual
SQL Functions
Parameters
expression
slice_length
time_unit
start_or_end
Indicates whether the returned value corresponds to the start or end time of the
time slice interval. The default is START.
Domain of possible values: {START, END }.
Notes
l
The corresponding SQL data type for TIMESTAMP is TIMESTAMP WITHOUT TIME ZONE.
HP Vertica supports TIMESTAMP for TIME_SLICE instead of DATE and TIME data types.
The system returns an error when any one of slice_length, time_unit, or start_or_end
parameters is null.
When slice_length, time_unit, and start_or_end contain legal values, and expression is null,
the system returns a NULL value, instead of an error.
Usage
The following command returns the (default) start time of a 3-second time slice:
SELECT TIME_SLICE('2009-09-19 00:00:01', 3);
time_slice
--------------------2009-09-19 00:00:00
(1 row)
The following command returns the end time of a 3-second time slice:
SQLReference Manual
SQL Functions
The next example uses a 3-second interval with an input value of '00:00:01'. To focus specifically
on seconds, the example omits date, though all values are implied as being part of the timestamp
with a given input of '00:00:01':
l
'00:00:03' is also the start of the second 3-second time slice. In time slice boundaries, the end
value of a time slice does not belong to that time slice; it starts the next one.
When the time slice interval is not a factor of 60 seconds, such as a given slice length of 9 in the
following example, the slice does not always start or end on 00 seconds:
SELECT TIME_SLICE('2009-02-14 20:13:01', 9);
SQLReference Manual
SQL Functions
time_slice
--------------------2009-02-14 20:12:54
(1 row)
This is expected behavior, as the following properties are true for all time slices:
l
Equal in length
Non-overlapping
To force the above example ('2009-02-14 20:13:01') to start at '2009-02-14 20:13:00', adjust the
output timestamp values so that the remainder of 54 counts up to 60:
SELECT TIME_SLICE('2009-02-14 20:13:01', 9 )+'6 seconds'::INTERVAL AS time;
time
--------------------2009-02-14 20:13:00
(1 row)
Alternatively, you could use a different slice length, which is divisible by 60, such as 5:
SELECT TIME_SLICE('2009-02-14 20:13:01', 5);
time_slice
--------------------2009-02-14 20:13:00
(1 row)
A TIMESTAMPTZ value is implicitly cast to TIMESTAMP. For example, the following two
statements have the same effect.
SELECT TIME_SLICE('2009-09-23 11:12:01'::timestamptz, 3);
TIME_SLICE
--------------------2009-09-23 11:12:00
(1 row)
SQLReference Manual
SQL Functions
Examples
You can use the SQL analytic functions FIRST_VALUE and LAST_VALUE to find the first/last
price within each time slice group (set of rows belonging to the same time slice). This structure
could be useful if you want to sample input data by choosing one row from each time slice group.
SELECT date_key, transaction_time, sales_dollar_amount,TIME_SLICE(DATE '2000-01-01' +
date_key + transaction_time, 3),
FIRST_VALUE(sales_dollar_amount)
OVER (PARTITION BY TIME_SLICE(DATE '2000-01-01' + date_key + transaction_time, 3)
ORDER BY DATE '2000-01-01' + date_key + transaction_time) AS first_value
FROM store.store_sales_fact
LIMIT 20;
date_key | transaction_time | sales_dollar_amount |
time_slice
| first_value
----------+------------------+---------------------+---------------------+------------1 | 00:41:16
|
164 | 2000-01-02 00:41:15 |
164
1 | 00:41:33
|
310 | 2000-01-02 00:41:33 |
310
1 | 15:32:51
|
271 | 2000-01-02 15:32:51 |
271
1 | 15:33:15
|
419 | 2000-01-02 15:33:15 |
419
1 | 15:33:44
|
193 | 2000-01-02 15:33:42 |
193
1 | 16:36:29
|
466 | 2000-01-02 16:36:27 |
466
1 | 16:36:44
|
250 | 2000-01-02 16:36:42 |
250
2 | 03:11:28
|
39 | 2000-01-03 03:11:27 |
39
3 | 03:55:15
|
375 | 2000-01-04 03:55:15 |
375
3 | 11:58:05
|
369 | 2000-01-04 11:58:03 |
369
3 | 11:58:24
|
174 | 2000-01-04 11:58:24 |
174
3 | 11:58:52
|
449 | 2000-01-04 11:58:51 |
449
3 | 19:01:21
|
201 | 2000-01-04 19:01:21 |
201
3 | 22:15:05
|
156 | 2000-01-04 22:15:03 |
156
4 | 13:36:57
|
-125 | 2000-01-05 13:36:57 |
-125
4 | 13:37:24
|
-251 | 2000-01-05 13:37:24 |
-251
4 | 13:37:54
|
353 | 2000-01-05 13:37:54 |
353
4 | 13:38:04
|
426 | 2000-01-05 13:38:03 |
426
4 | 13:38:31
|
209 | 2000-01-05 13:38:30 |
209
5 | 10:21:24
|
488 | 2000-01-06 10:21:24 |
488
(20 rows)
SQLReference Manual
SQL Functions
(TickTime, 3)
ORDER BY TickTime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING);
Note: If you omit the windowing clause from an analytic clause, LAST_VALUE defaults to
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. Results can
seem non-intuitive, because instead of returning the value from the bottom of the current
partition, the function returns the bottom of the window, which continues to change along with
the current input row that is being processed. For more information, see Using Time Series
Analytics and Using SQL Analytics in the Analyzing Data Guide.
In the next example, FIRST_VALUE is evaluated once for each input record and the data is sorted
by ascending values. Use SELECT DISTINCT to remove the duplicates and return only one output
record per TIME_SLICE:
SELECT DISTINCT TIME_SLICE(TickTime, 3), FIRST_VALUE(price)OVER (PARTITION BY TIME_SLICE
(TickTime, 3)
ORDER BY TickTime ASC)
FROM tick_store;
TIME_SLICE
| ?column?
---------------------+---------2009-09-21 00:00:06 |
20.00
2009-09-21 00:00:09 |
30.00
2009-09-21 00:00:00 |
10.00
(3 rows)
The information output by the above query can also return MIN, MAX, and AVG of the trading prices
within each time slice.
SELECT DISTINCT TIME_SLICE(TickTime, 3),FIRST_VALUE(Price) OVER (PARTITION BY TIME_SLICE
(TickTime, 3)
ORDER BY TickTime ASC),
MIN(price) OVER (PARTITION BY TIME_SLICE(TickTime, 3)),
MAX(price) OVER (PARTITION BY TIME_SLICE(TickTime, 3)),
AVG(price) OVER (PARTITION BY TIME_SLICE(TickTime, 3))
FROM tick_store;
See Also
l
Aggregate Functions
FIRST_VALUE [Analytic]
LAST_VALUE [Analytic]
TIMESERIES Clause
SQLReference Manual
SQL Functions
TS_FIRST_VALUE
TS_LAST_VALUE
TIMEOFDAY
Returns a text string representing the time of day.
Behavior Type
Volatile
Syntax
TIMEOFDAY()
Notes
TIMEOFDAY() returns the wall-clock time and advances during transactions.
Example
SELECT TIMEOFDAY();
TIMEOFDAY
------------------------------------Thu Apr 01 15:42:04.483766 2010 EDT
(1 row)
TIMESTAMPADD
Adds a specified number of intervals to a TIMESTAMP or TIMESTAMPTZ. The return value
depends on the input, as follows:
l
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
SQLReference Manual
SQL Functions
Syntax
TIMESTAMPADD ( datepart ,interval, starttimestamp );
Parameters
datepart
Abbreviation
YEAR
yy, yyyy
QUARTER
qq, q
MONTH
mm, m
DAY
WEEK
wk, ww
HOUR
hh
MINUTE
mi, n
SECOND
ss, s
MILLISECOND
ms
MICROSECOND
mcs, us
Notes
l
SQLReference Manual
SQL Functions
TIMESTAMPDIFF(year, s, e);
TIMESTAMPDIFF('year', s, e);
Starting arguments are not included in the count, but end arguments are included.
Example
=> SELECT TIMESTAMPADD (SQL_TSI_MONTH, 2, ('jan 1, 2006'));
TIMESTAMPADD
-----------------------2006-03-01 00:00:00-05
(1 row)
See Also
l
Date/Time Expressions
TIMESTAMPDIFF
Returns the difference between two TIMESTAMP or TIMESTAMPTZ values, based on the
specified start and end arguments.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
TIMESTAMPDIFF ( datepart , starttimestamp , endtimestamp );
Parameters
SQLReference Manual
SQL Functions
datepart
Abbreviation
year
yy, yyyy
quarter
qq, q
month
mm, m
day
week
wk, ww
hour
hh
minute
mi, n
second
ss, s
millisecond
ms
microsecond
mcs, us
starttimestamp
endtimestamp
Notes
l
SQLReference Manual
SQL Functions
TIMESTAMPDIFF((expression), s, e);
Starting arguments are not included in the count, but end arguments are included.
Example
=> SELECT TIMESTAMPDIFF ('YEAR',('jan 1, 2006 12:34:00'), ('jan 1, 2008 12:34:00'));
TIMESTAMPDIFF
--------------2
(1 row)
See Also
l
Date/Time Expressions
TIMESTAMP_ROUND
Rounds a TIMESTAMP to a specified format. The return value is of type TIMESTAMP.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
TIMESTAMP_ROUND ( timestamp, format )
Parameters
timestamp
SQLReference Manual
SQL Functions
format
String constant that selects the precision to which truncate the input value. Valid
values for format are:
Precision
Valid values
Century
CC, SCC
Year
ISO Year
Quarter
Month
IW
year
Same day of the week as the first day of the
month
Day
DDD, DD, J
DAY, DY, D
Hour
Minute
MI
Second
SS
Examples
b=> SELECT TIMESTAMP_ROUND('sep 22, 2011 12:34:00', 'dy');
TIMESTAMP_ROUND
--------------------2011-09-18 00:00:00
(1 row)
TIMESTAMP_TRUNC
Truncates a TIMESTAMP. The return value is of type TIMESTAMP.
SQLReference Manual
SQL Functions
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
TIMESTAMP_TRUNC ( timestamp, format )
Parameters
timestamp
format
String constant that selects the precision to which truncate the input value. Valid
values for format are:
Precision
Valid values
Century
CC, SCC
Year
ISO Year
Quarter
Month
IW
year
Same day of the week as the first day of the
month
Day
DDD, DD, J
DAY, DY, D
Hour
Minute
MI
Second
SS
SQLReference Manual
SQL Functions
Examples
=> SELECT TIMESTAMP_TRUNC('sep 22, 2011 12:34:00');
TIMESTAMP_TRUNC
--------------------2011-09-22 00:00:00
(1 row)
=> SELECT TIMESTAMP_TRUNC('sep 22, 2011 12:34:00', 'dy');
TIMESTAMP_TRUNC
--------------------2011-09-18 00:00:00
(1 row)
TRANSACTION_TIMESTAMP
Returns a value of type TIMESTAMP WITH TIME ZONE representing the start of the current
transaction. TRANSACTION_TIMESTAMP is equivalent to CURRENT_TIMESTAMP except that
it does not accept a precision parameter.
Behavior Type
Stable
Syntax
TRANSACTION_TIMESTAMP()
Notes
This function returns the start time of the current transaction; the value does not change during the
transaction. The intent is to allow a single transaction to have a consistent notion of the "current"
time, so that multiple modifications within the same transaction bear the same timestamp.
Example
SELECT TRANSACTION_TIMESTAMP();
TRANSACTION_TIMESTAMP
------------------------------2010-04-01 15:31:12.144584-04
(1 row)
SQLReference Manual
SQL Functions
See Also
l
CLOCK_TIMESTAMP
STATEMENT_TIMESTAMP
TRUNC [Date/Time]
Truncates a TIMESTAMP, TIMESTAMPTZ, or DATE. The return value is of type TIMESTAMP.
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Syntax
TRUNC ([TIMESTAMP | DATE] , format )
Parameters
TIMESTAMP | DATE
SQLReference Manual
SQL Functions
format
A string constant that selects the precision to which truncate the input value.
Valid values for format are:
Precision
Valid values
Century
CC, SCC
Year
ISO Year
Quarter
Month
DDD, DD, J
DAY, DY, D
Hour
Minute
MI
Second
SS
Examples
=> SELECT TRUNC(TIMESTAMP 'sep 22, 2011 12:34:00', 'dy');
TRUNC
--------------------2011-09-18 00:00:00
(1 row)
SQLReference Manual
SQL Functions
WEEK
Returns an INTEGER representing the week of the year into which the input value falls. A week
starts on Sunday. January 1 is always in the first week of the year.
Syntax
WEEK ( d )
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Parameters
d
Example
=> SELECT WEEK (TIMESTAMP 'sep 22, 2011 12:34');
WEEK
-----39
(1 row)
WEEK_ISO
Returns an INTEGER from 153 that represents the week of the year into which the input value
falls. The return value is based on the ISO 8061 standard.
The ISO week consists of 7 days starting on Monday and ending on Sunday. The first week of the
year is the week that contains January 4.
Syntax
WEEK_ISO ( d )
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
SQLReference Manual
SQL Functions
Parameters
d
Examples
The following examples illustrate the different results returned by WEEK_ISO. The first shows that
December 28, 2011 falls within week 52 of the ISO calendar:
=> SELECT WEEK_ISO (TIMESTAMP 'Dec 28, 2011 10:00:00');
WEEK_ISO
---------52
(1 row)
The second example shows WEEK_ISO results for January 1, 2012. Note that, since this date falls
on a Sunday, it falls within week 52 of the ISO year:
=> SELECT WEEK_ISO (TIMESTAMP 'Jan 1, 2012 10:00:00');
WEEK_ISO
---------52
(1 row)
The third example shows WEEK_ISO results for January 2, 2012, which occurs on a Monday. This
is the first week of the year that contains a Thursday and contains January 4. The function returns
week 1.
=> SELECT WEEK_ISO (TIMESTAMP 'Jan 2, 2012 10:00:00');
WEEK_ISO
---------1
The last example shows how to combine the DAYOFWEEK_ISO, WEEK_ISO, and YEAR_ISO
functions to find the ISO day of the week, week, and year:
=> SELECT DAYOFWEEK_ISO('Jan 1, 2000'), WEEK_ISO('Jan 1, 2000'),YEAR_ISO('Jan1,2000');
DAYOFWEEK_ISO | WEEK_ISO | YEAR_ISO
---------------+----------+---------6 |
52 |
1999
(1 row)
SQLReference Manual
SQL Functions
See Also
l
YEAR_ISO
DAYOFWEEK_ISO
http://en.wikipedia.org/wiki/ISO_8601
YEAR
Returns an INTEGER representing the year portion of the input value.
Syntax
YEAR( d )
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Parameters
d
Examples
=> SELECT YEAR ('6-9');
YEAR
-----6
(1 row)
=> SELECT YEAR (TIMESTAMP 'sep 22, 2011 12:34');
YEAR
-----2011
(1 row)
=> SELECT YEAR (INTERVAL '2-35' year to month);
YEAR
-----4
(1 row)
SQLReference Manual
SQL Functions
YEAR_ISO
Returns an INTEGER representing the year portion of the input value. The return value is based on
the ISO 8061 standard.
The first week of the ISO year is the week that contains January 4.
Syntax
YEAR_ISO( d )
Behavior Type
Immutable, except for TIMESTAMPTZ arguments where it is Stable.
Parameters
d
Examples
=> SELECT YEAR_ISO (TIMESTAMP 'sep 22, 2011 12:34');
YEAR_ISO
---------2011
(1 row)
The following example shows how to combine the DAYOFWEEK_ISO, WEEK_ISO, and YEAR_
ISO functions to find the ISO day of the week, week, and year:
=> SELECT DAYOFWEEK_ISO('Jan 1, 2000'), WEEK_ISO('Jan 1, 2000'),YEAR_ISO('Jan1,2000');
DAYOFWEEK_ISO | WEEK_ISO | YEAR_ISO
---------------+----------+---------6 |
52 |
1999
(1 row)
See Also
l
WEEK_ISO
DAYOFWEEK_ISO
SQLReference Manual
SQL Functions
http://en.wikipedia.org/wiki/ISO_8601
SQLReference Manual
SQL Functions
Formatting Functions
Formatting functions provide a powerful tool set for converting various data types (DATE/TIME,
INTEGER, FLOATING POINT) to formatted strings and for converting from formatted strings to
specific data types.
These functions all use a common calling convention:
l
The second argument is a template that defines the output or input format.
Note: The TO_TIMESTAMP function can take a single double precision argument.
TO_BITSTRING
Returns a VARCHAR that represents the given VARBINARY value in bitstring format.
Behavior Type
Immutable
Syntax
TO_BITSTRING ( expression )
Parameters
expression
Notes
VARCHAR TO_BITSTRING(VARBINARY) converts data from binary type to character type
(where the character representation is the bitstring format). This function is the inverse of
BITSTRING_TO_BINARY:
TO_BITSTRING(BITSTRING_TO_BINARY(x)) = x)
BITSTRING_TO_BINARY(TO_BITSTRING(x)) = x)
SQLReference Manual
SQL Functions
Examples
SELECT TO_BITSTRING('ab'::BINARY(2));
to_bitstring
-----------------0110000101100010
(1 row)
SELECT TO_BITSTRING(HEX_TO_BINARY('0x10'));
to_bitstring
-------------00010000
(1 row)
SELECT TO_BITSTRING(HEX_TO_BINARY('0xF0'));
to_bitstring
-------------11110000
(1 row)
See Also
l
BITCOUNT
BITSTRING_TO_BINARY
TO_CHAR
Converts various date/time and numeric values into text strings.
Behavior Type
Stable
Syntax
TO_CHAR ( expression [, pattern ] )
Parameters
expression
SQLReference Manual
SQL Functions
pattern
Notes
l
TO_CHAR accepts TIME and TIMETZ data types as inputs if you explicitly cast TIME to
TIMESTAMP and TIMETZ to TIMESTAMPTZ.
=> SELECT TO_CHAR(TIME '14:34:06.4','HH12:MI am');
=> SELECT TO_CHAR(TIMETZ '14:34:06.4+6','HH12:MI am');
Ordinary text is allowed in to_char templates and is output literally. You can put a substring in
double quotes to force it to be interpreted as literal text even if it contains pattern key words. For
example, in '"Hello Year "YYYY', the YYYY is replaced by the year data, but the single Y in
Year is not.
The TO_CHAR function's day-of-the-week numbering (see the 'D' template pattern) is different
from that of the EXTRACT function.
Given an INTERVAL type, TO_CHAR formats HH and HH12 as hours in a single day, while
HH24 can output hours exceeding a single day, for example, >24.
To use a double quote character in the output, precede it with a double backslash. This is
necessary because the backslash already has a special meaning in a string constant. For
example: '\\"YYYY Month\\"'
SQLReference Manual
SQL Functions
TO_CHAR does not support the use of V combined with a decimal point. For example: 99.9V99
is not allowed.
Examples
Result
Expression
SELECT TO_CHAR(CURRENT_TIMESTAMP, 'Day, DD
HH12:MI:SS');
HH12:MI:SS');
'Tuesday , 06
'Tuesday, 6
05:39:18'
04:34 am
'
'-.1'
' 0.1'
'
'0012.'
' 485'
'-485'
' 4 8 5'
' 1,485'
' 1 485'
' 148.500'
'148.5'
'148.500'
' 148,500'
' 3 148,500'
'485-'
'485-'
'485 '
'485'
'+485'
'+485'
'-485'
'4-85'
05:39:18'
-.10'
0012.0'
SQLReference Manual
SQL Functions
'<485>'
'DM 485
'
'CDLXXXV'
'V'
' 482nd'
' 12000'
' 12400'
' 125'
SELECT TO_CHAR(-1234.567);
-1234.567
SELECT TO_CHAR('1999-12-25'::DATE);
CDLXXXV'
1999-12-25
1999-12-25 11:31:00
1999-12-25 11:31:00-05
3 days 00:16:40.333
TO_DATE
Converts a string value to a DATE type.
Behavior Type
Stable
Syntax
TO_DATE ( expression , pattern )
Parameters
expression
pattern
SQLReference Manual
SQL Functions
Notes
l
To use a double quote character in the output, precede it with a double backslash. This is
necessary because the backslash already has a special meaning in a string constant. For
example: '\\"YYYY Month\\"'
n
TO_TIMESTAMP('2000
TO_TIMESTAMP('2000
The YYYY conversion from string to TIMESTAMP or DATE has a restriction if you use a year
with more than four digits. You must use a non-digit character or template after YYYY,
otherwise the year is always interpreted as four digits. For example (with the year 20000):
TO_DATE('200001131', 'YYYYMMDD') is interpreted as a four-digit year
Instead, use a non-digit separator after the year, such as TO_DATE('20000-1131', 'YYYYMMDD') or TO_DATE('20000Nov31', 'YYYYMonDD').
In conversions from string to TIMESTAMP or DATE, the CC field is ignored if there is a YYY,
YYYY or Y,YYY field. If CC is used with YY or Y then the year is computed as (CC1)
*100+YY.
Examples
SELECT TO_DATE('13 Feb 2000', 'DD Mon YYYY');
to_date
-----------2000-02-13
(1 row)
SQLReference Manual
SQL Functions
See Also
l
Date/Time Functions
DATE
TO_HEX
Returns a VARCHAR or VARBINARY representing the hexadecimal equivalent of a number.
Behavior Type
Immutable
Syntax
TO_HEX ( number )
Parameters
number
Notes
VARCHAR TO_HEX(INTEGER) and VARCHAR TO_HEX(VARBINARY) are similar. The
function converts data from binary type to character type (where the character representation is in
hexadecimal format). This function is the inverse of HEX_TO_BINARY.
TO_HEX(HEX_TO_BINARY(x)) = x);
HEX_TO_BINARY(TO_HEX(x)) = x);
Examples
SELECT TO_HEX(123456789);
TO_HEX
--------75bcd15
(1 row)
For VARBINARY inputs, the returned value is not preceded by "0x". For example:
SQLReference Manual
SQL Functions
SELECT TO_HEX('ab'::binary(2));
TO_HEX
-------6162
(1 row)
TO_TIMESTAMP
Converts a string value or a UNIX/POSIX epoch value to a TIMESTAMP type.
Behavior Type
Stable
Syntax
TO_TIMESTAMP ( expression, pattern )TO_TIMESTAMP ( unix-epoch )
Parameters
expression
pattern
unix-epoch
Notes
l
Millisecond (MS) and microsecond (US) values in a conversion from string to TIMESTAMP are
used as part of the seconds after the decimal point. For example TO_TIMESTAMP('12:3',
'SS:MS') is not 3 milliseconds, but 300, because the conversion counts it as 12 + 0.3 seconds.
This means for the format SS:MS, the input values 12:3, 12:30, and 12:300 specify the same
number of milliseconds. To get three milliseconds, use 12:003, which the conversion counts as
12 + 0.003 = 12.003 seconds.
SQLReference Manual
SQL Functions
To use a double quote character in the output, precede it with a double backslash. This is
necessary because the backslash already has a special meaning in a string constant. For
example: '\\"YYYY Month\\"'
TO_TIMESTAMP, TO_TIMESTAMP_TZ, and TO_DATE skip multiple blank spaces in the input
string if the FX option is not used. FX must be specified as the first item in the template. For
example:
n
TO_TIMESTAMP('2000
TO_TIMESTAMP('2000
The YYYY conversion from string to TIMESTAMP or DATE has a restriction if you use a year
with more than four digits. You must use a non-digit character or template after YYYY, otherwise
the year is always interpreted as four digits. For example (with the year 20000):
TO_DATE('200001131', 'YYYYMMDD') is interpreted as a four-digit year
Instead, use a non-digit separator after the year, such as TO_DATE('20000-1131', 'YYYYMMDD') or TO_DATE('20000Nov31', 'YYYYMonDD').
In conversions from string to TIMESTAMP or DATE, the CC field is ignored if there is a YYY,
YYYY or Y,YYY field. If CC is used with YY or Y then the year is computed as (CC1)*100+YY.
Examples
=> SELECT TO_TIMESTAMP('13 Feb 2009', 'DD Mon YYYY');
TO_TIMESTAMP
--------------------1200-02-13 00:00:00
(1 row)
=> SELECT TO_TIMESTAMP(200120400);
TO_TIMESTAMP
--------------------1976-05-05 01:00:00
(1 row)
SQLReference Manual
SQL Functions
See Also
l
Date/Time Functions
TO_TIMESTAMP_TZ
Converts a string value or a UNIX/POSIX epoch value to a TIMESTAMP WITH TIME ZONE type.
Behavior Type
Immutable if single argument form, Stable otherwise.
Syntax
TO_TIMESTAMP_TZ ( expression, pattern )TO_TIMESTAMP ( unix-epoch )
Parameters
expression
pattern
unix-epoch
Notes
l
Millisecond (MS) and microsecond (US) values in a conversion from string to TIMESTAMP are
used as part of the seconds after the decimal point. For example TO_TIMESTAMP('12:3',
'SS:MS') is not 3 milliseconds, but 300, because the conversion counts it as 12 + 0.3 seconds.
This means for the format SS:MS, the input values 12:3, 12:30, and 12:300 specify the same
number of milliseconds. To get three milliseconds, use 12:003, which the conversion counts as
SQLReference Manual
SQL Functions
To use a double quote character in the output, precede it with a double backslash. This is
necessary because the backslash already has a special meaning in a string constant. For
example: '\\"YYYY Month\\"'
n
TO_TIMESTAMP('2000
TO_TIMESTAMP('2000
The YYYY conversion from string to TIMESTAMP or DATE has a restriction if you use a year
with more than four digits. You must use a non-digit character or template after YYYY,
otherwise the year is always interpreted as four digits. For example (with the year 20000):
TO_DATE('200001131', 'YYYYMMDD') is interpreted as a four-digit year
Instead, use a non-digit separator after the year, such as TO_DATE('20000-1131', 'YYYYMMDD') or TO_DATE('20000Nov31', 'YYYYMonDD').
In conversions from string to TIMESTAMP or DATE, the CC field is ignored if there is a YYY,
YYYY or Y,YYY field. If CC is used with YY or Y then the year is computed as (CC1)
*100+YY.
Examples
=> SELECT TO_TIMESTAMP_TZ('13 Feb 2009', 'DD Mon YYY');
TO_TIMESTAMP_TZ
-----------------------1200-02-13 00:00:00-05
(1 row)
=> SELECT TO_TIMESTAMP_TZ(200120400);
TO_TIMESTAMP_TZ
-----------------------1976-05-05 01:00:00-04
(1 row)
SQLReference Manual
SQL Functions
See Also
l
Date/Time Functions
TO_NUMBER
Converts a string value to DOUBLE PRECISION.
Behavior Type
Stable
Syntax
TO_NUMBER ( expression, [ pattern ] )
Parameters
expression
pattern
(CHAR or VARCHAR) Optionally specifies an output pattern string using one of the
supported Template Patterns for Numeric Formatting. If omitted, function returns a
floating point.
Notes
To use a double quote character in the output, precede it with a double backslash. This is
necessary because the backslash already has a special meaning in a string constant. For example:
'\\"YYYY Month\\"'
Note: To convert a date string to a numeric value, use the appropriate date/time function, such
as EXTRACT.
Examples
SELECT TO_NUMBER('MCML', 'rn');
SQLReference Manual
SQL Functions
TO_NUMBER
----------1950
(1 row)
It the pattern parameter is omitted, the function returns a floating point. For example:
SELECT TO_NUMBER('-123.456e-01');
TO_NUMBER
-----------12.3456
SQLReference Manual
SQL Functions
Description
HH
HH12
HH24
MI
Minute (00-59)
SS
Second (00-59)
MS
Millisecond (000-999)
US
Microsecond (000000-999999)
SSSS
AM or A.M. or PM or P.M.
am or a.m. or pm or p.m.
Y,YYY
YYYY
YYY
YY
SQLReference Manual
SQL Functions
Pattern
Description
IYYY
IYY
IY
BC or B.C. or AD or A.D.
bc or b.c. or ad or a.d.
MONTH
Month
month
MON
Mon
mon
MM
DAY
Day
day
DY
Dy
dy
DDD
SQLReference Manual
SQL Functions
Pattern
Description
DD
Week of month (1-5) (The first week starts on the first day of the
month.)
WW
Week number of year (1-53) (The first week starts on the first day of
the year.)
IW
ISO week number of year (The first Thursday of the new year is in
week 1.)
CC
Century (2 digits)
Quarter
RM
rm
TZ
tz
Description
AM
AT
Ignored
JULIAN, JD, J
SQLReference Manual
SQL Functions
Modifier
Description
FM prefix
FX prefix
ON
Ignored
PM
TH suffix
th suffix
TM prefix
Translation mode (print localized day and month names based on lc_messages).
For example: TMMonth
Description
. (period)
Decimal point
SQLReference Manual
SQL Functions
Pattern
Description
MI
PL
SG
RN
TH or th
EEEE
Usage
l
A sign formatted using SG, PL, or MI is not anchored to the number; for example:
n
9 results in a value with the same number of digits as there are 9s. If a digit is not available it
outputs a space.
TH does not convert values less than zero and does not convert fractional numbers.
V effectively multiplies the input values by 10^n, where n is the number of digits following V.
TO_CHAR does not support the use of V combined with a decimal point. For example: 99.9V99
is not allowed.
SQLReference Manual
SQL Functions
Important: The Geospatial Package SQL Functions are being deprecated in HP Vertica 7.1.
These functions will be removed in the next major or minor release. We encourage you use the
new HP Vertica Place SQL functions for geospatial functionality. If the deprecated geospatial
functions are important to your business, then please contact HP Vertica.
geospatial.sqlThis file contains all the functions that are installed with the
package. The file describes the calculations used for each function, and
provides examples. This file also contains links to helpful sites that provide more
information about standards and calculations.
SQLReference Manual
SQL Functions
DEGREES
DISTANCE
DISTANCEV
RADIANS
These functions are not part of the Vertica Geospatial Package; they are installed with HP Vertica.
SQLReference Manual
SQL Functions
WGS84_a()
WGS84_b()
WGS84_e2()
WGS84_f()
WGS84_if()
RADIUS_r(lat)
WGS84_r1()
RADIUS_SI()
RADIUS_M(lat)
RADIUS_N (lat)
RADIUS_Ra (lat)
RADIUS_Rv (lat)
RADIUS_Rc (lat,bearing)
BEARING (lat1,lon1,lat2,lon2)
RADIUS_LON (lat)
SQLReference Manual
SQL Functions
toward latitude 0, longitude 0; y is toward latitude 0, longitude 90 degrees; and z is toward the North
Pole. The height above mean sea level (h) is also in meters.
l
ECEF_x (lat,lon,h)
ECEF_y (lat,lon,h)
ECEF_z (lat,lon,h)
ECEF_chord (lat1,lon1,h1,lat2,lon2,h2)
CHORD_TO_ARC (chord)
BB_WITHIN (lat,lon,llat,llon,ulat,rlon)
LAT_WITHIN (lat,lat0,d)
LON_WITHIN (lon,lat0,lon0,d)
LL_WITHIN (lat,lon,lat0,lon0,d)
DWITHIN (lat,lon,lat0,lon0,d)
LLD_WITHIN (lat,lon,lat0,lon0,d)
ISLEFT (x0,y0,x1,y1,x2,y2)
RAYCROSSING (x0,y0,x1,y1,x2,y2)
MILES2KM (miles)
KM2MILES (km)
SQLReference Manual
SQL Functions
BB_WITHIN
Determines whether a point (lat, lon) falls within a bounding box defined by its lower-left and upperright corners. The return value has the type BOOLEAN.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
BB_WITHIN (lat,lon,llat,llon,ulat,rlon)
Parameters
lat
lon
llat
A value of type DOUBLE PRECISION indicating the latitude used to define the lower-left
corner of the bounding box.
llon
A value of type DOUBLE PRECISION indicating the longitude used to define the lowerleft corner of the bounding box.
ulat
A value of type DOUBLE PRECISION indicating the latitude used to define the upper-right
corner of the bounding box.
rlon
A value of type DOUBLE PRECISION indicating the longitude used in defining the upperright corner of the bounding box.
Example
The following example determines that the point (14,30) is not contained in the bounding box
defined by (23.0,45) and (13,37):
=> SELECT BB_WITHIN(14,30,23.0,45,13,37);
BB_WITHIN
----------f
SQLReference Manual
SQL Functions
(1 row)
The following example determines that the point (14,30) is contained in the bounding box defined by
(13.0,45) and (23,37).
=> SELECT BB_WITHIN(14,30,13.0,45,23,37);
BB_WITHIN
----------t
(1 row)
BEARING
Returns the approximate bearing from a starting point to an ending point, in degrees. It assumes a
flat earth and is useful only for short distances. The return value has the type DOUBLE
PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
BEARING (lat1,lon1,lat2,lon2)
Parameters
lat1
lon1
lat2
lon2
Example
The following examples calculate the bearing, in degrees, from point (45,13) to (33,3) and from point
(33,3) to (45,13):
SQLReference Manual
SQL Functions
CHORD_TO_ARC
Converts a chord (the straight line between two points) in meters to a geodesic arc length, also in
meters. The return value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
CHORD_TO_ARC (chord)
Parameters
chord
Example
The following examples convert the length of a chord to the length of its geodesic arc:
=> SELECT CHORD_TO_ARC(120);
CHORD_TO_ARC
-----------------120.000000001774
(1 row)
=> SELECT CHORD_TO_ARC(12000);
CHORD_TO_ARC
-----------------12000.0017738474
(1 row)
=> SELECT CHORD_TO_ARC(1200000);
SQLReference Manual
SQL Functions
CHORD_TO_ARC
-----------------1201780.96402514
(1 row)
DWITHIN
Determines whether a point (lat,lon) is within a circle of radius d kilometers centered at a given point
(lat0,lon0). The return value has the type BOOLEAN.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
DWITHIN (lat,lon,lat0,lon0,d)
Parameters
lat
lon
lat0
A value of type DOUBLE PRECISION indicating the latitude of the center point of a circle.
lon0
A value of type DOUBLE PRECISION indicating the longitude of the center point of a
circle.
A value of type DOUBLE PRECISION indicating the radius of the circle (in kilometers).
Example
The following examples determine that the point (13.6,43.5) is within 38803890 kilometers of the
radius of a circle centered at (48.5,45.5):
=> SELECT DWITHIN(13.6,43.5,48.5,45.5,3880);
DWITHIN
--------f
(1 row)
SQLReference Manual
SQL Functions
ECEF_CHORD
Calculates the distance in meters between two ECEF coordinates. The return value has the type
DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
ECEF_CHORD (lat1,lon1,h1,lat2,lon2,h2)
Parameters
lat
A value of type DOUBLE PRECISION indicating the latitude of one end point of the line.
lon1
A value of type DOUBLE PRECISION indicating the longitude of one end point of the line.
h1
A value of type DOUBLE PRECISION indicating the height above sea level (in meters) of
one end point of the line.
lat2
A value of type DOUBLE PRECISION indicating the latitude of one end point of the line.
lon2
A value of type DOUBLE PRECISION indicating the longitude of one end point of the line.
h2
A value of type DOUBLE PRECISION indicating the height of one end point of the line.
Example
The following example calculates the distance in meters between the ECEF coordinates (12,10.0,14) and (12,-10,17):
=> SELECT ECEF_chord (-12,10.0,14,12,-10,17);
ECEF_chord
SQLReference Manual
SQL Functions
-----------------3411479.93992789
(1 row)
ECEF_x
Converts a given latitude, longitude, and height into the ECEF x coordinate in meters. The return
value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
ECEF_x (lat,lon,h)
Parameters
lat
lon
Example
The following example calculates the ECEF x coordinate in meters for the point (-12,13.2,0):
=> SELECT ECEF_x(-12,13.2,0);
ECEF_x
-----------------6074803.56179976
(1 row)
ECEF_y
Converts a given latitude, longitude, and height into the ECEF y coordinate in meters. The return
value has the type DOUBLE PRECISION.
SQLReference Manual
SQL Functions
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
ECEF_y (lat,lon,h)
Parameters
lat
lon
Example
The following example calculates the ECEF y coordinate in meters for the point (12.0,-14.2,12):
=> SELECT ECEF_y(12.0,-14.2,12);
ECEF_y
-------------------1530638.12327962
(1 row)
ECEF_z
Converts a given latitude, longitude, and height into the ECEF z coordinate in meters. The return
value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
ECEF_Z (lat,lon,h)
SQLReference Manual
SQL Functions
Parameters
lat
lon
Example
The following example calculates the ECEF z coordinate in meters for the point (12.0,-14.2,12):
=> SELECT ECEF_z(12.0,-14.2,12);
ECEF_z
-----------------1317405.02616989
(1 row)
ISLEFT
Determines whether a given point is anywhere to the left of a directed line that goes though two
specified points. The return value has the type FLOAT and has the following possible values:
l
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
ISLEFT (x0,y0,x1,y1,x2,y2)
SQLReference Manual
SQL Functions
Parameters
x0
A value of type DOUBLE PRECISION indicating the latitude of the first point through which
the directed line passes.
y0
A value of type DOUBLE PRECISION indicating the longitude of the first point through
which the directed line passes.
x1
A value of type DOUBLE PRECISION indicating the latitude of the second point through
which the directed line passes.
y1
A value of type DOUBLE PRECISION indicating the longitude of the second point through
which the directed line passes.
x2
A value of type DOUBLE PRECISION indicating the latitude of the point whose position you
are evaluating.
y2
A value of type DOUBLE PRECISION indicating the longitude of a whose position you are
evaluating.
Example
The following example determines that (0,0) is to the left of the line that passes through (1,1) and
(2,3):
=> SELECT ISLEFT(1,1,2,3,0,0);
ISLEFT
-------1
(1 row)
KM2MILES
Converts a value from kilometers to miles. The return value is of type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
KM2MILES (km)
Parameters
km
A value of type DOUBLE PRECISION indicating the number of kilometers you want to
convert.
Example
The following example converts 1.0 kilometers to miles:
=> SELECT KM2MILES(1.0);
KM2MILES
------------------0.621371192237334
(1 row)
LAT_WITHIN
Determines whether a certain latitude (lat) is within d kilometers of another latitude point (lat0),
independent of longitude. The return value has the type BOOLEAN.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
LAT_WITHIN (lat,lat0,d)
Parameters
lat
lat0
A value of type DOUBLE PRECISION indicating the latitude of the point to which you are
comparing the first latitude.
SQLReference Manual
SQL Functions
Example
The following examples determine that latitude 12 is between 220 and 230 kilometers of latitude
14.0:
=> SELECT LAT_WITHIN(12,14.0,220);
LAT_WITHIN
-----------f
(1 row)
=> SELECT LAT_WITHIN(12,14.0,230);
LAT_WITHIN
-----------t
(1 row)
LL_WITHIN
Determines whether a point (lat, lon) is within a bounding box whose sides are 2d kilometers long,
centered at a given point (lat0, lon0). The return value has the type BOOLEAN.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
LL_WITHIN (lat,lon,lat0,lon0,d);
Parameters
lat
lon
lat0
A value of type DOUBLE PRECISION indicating the latitude of the center point of the
bounding box.
SQLReference Manual
SQL Functions
lon0
A value of type DOUBLE PRECISION indicating the longitude of the center point of the
bounding box.
A value of type DOUBLE PRECISION indicating the length of half the side of the box.
Example
The following examples determine that the point (16,15) is within a bounding box centered at (12,13)
whose sides are between 880 and 890 kilometers long:
=> SELECT LL_WITHIN(16,15,12,13.0,440);
LL_WITHIN
----------f
(1 row)
=> SELECT LL_WITHIN(16,15,12,13.0,445);
LL_WITHIN
----------t
(1 row)
LLD_WITHIN
Determines whether a point (lat,lon) is within a circle of radius d kilometers centered at a given point
(lat0,lon0). LLD_WITHIN is a faster, but less accurate version of DWITHIN. The return value has
the type BOOLEAN.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
LLD_WITHIN (lat,lon,lat0,lon0,d)
Parameters
lat
lon
SQLReference Manual
SQL Functions
lat0
A value of type DOUBLE PRECISION indicating the latitude of the center point of a circle.
lon0
A value of type DOUBLE PRECISION indicating the longitude of the center point of a
circle.
A value of type DOUBLE PRECISION indicating the radius of the circle (in kilometers).
Example
The following examples determine that the point (13.6,43.5) is within a circle centered at (48.5,45.5)
whose radius is between 3800 and 3900 kilometers long:
=> SELECT LLD_WITHIN(13.6,43.5,48.5,45.5,3800);
LLD_WITHIN
-----------f
(1 row)
=> SELECT LLD_WITHIN(13.6,43.5,48.5,45.5,3900);
LLD_WITHIN
-----------t
(1 row)
LON_WITHIN
Determines whether a longitude (lon) is within d kilometers of a given point (lat0, lon0). The return
value has the type BOOLEAN.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
LON_WITHIN (lon,lat0,lon0,d)
Parameters
lon
SQLReference Manual
SQL Functions
lat0
A value of type DOUBLE PRECISION indicating the latitude of the point to which you
want to compare the lon value.
lon0
A value of type DOUBLE PRECISION indicating the longitude of the point to which you
want to compare the lon value.
A value of type DOUBLE PRECISION indicating the distance, in kilometers, that defines
your range.
Example
The following examples determine that the longitude 15 is between 1600 and 1700 kilometers from
the point (16,0):
=> SELECT LON_WITHIN(15,16,0,1600);
LON_WITHIN
-----------f
(1 row)
=> SELECT LON_WITHIN(15,16,0,1700);
LON_WITHIN
-----------t
(1 row)
MILES2KM
Converts a value from miles to kilometers. The return value is of type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
MILES2KM (miles)
Parameters
miles
A value of type DOUBLE PRECISION indicating the number of miles you want to
convert.
SQLReference Manual
SQL Functions
Example
The following example converts 1.0 miles to kilometers:
=> SELECT MILES2KM(1.0);
MILES2KM
---------1.609344
(1 row)
RADIUS_LON
Returns the radius of the circle of longitude in kilometers at a given latitude. The return value has
the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
RADIUS_LON (lat)
Parameters
lat
A value of type DOUBLE PRECISION indicating latitude at which you want to measure the
radius.
Example
The following example calculates the circle of longitude in kilometers at a latitude of 45:
=> SELECT RADIUS_LON(45);
RADIUS_LON
--------------------4517.59087884893
(1 row)
SQLReference Manual
SQL Functions
RADIUS_M
Returns the earth's radius of curvature in kilometers along the meridian at the given latitude. The
return value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
RADIUS_M (lat)
Parameters
lat
A value of type DOUBLE PRECISION indicating latitude at which you want to measure the
radius of curvature.
Example
The following example calculates the earth's radius of curvature in kilometers along the meridian at
latitude 90 (the South Pole):
=> SELECT RADIUS_M(-90);
RADIUS_M
----------------6399.5936257585
(1 row)
RADIUS_N
Returns the earth's radius of curvature in kilometer normal to the meridian at a given latitude. The
return value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
RADIUS_N (lat)
Parameters
lat
A value of type DOUBLE PRECISION indicating latitude at which you want to measure the
radius of curvature.
Example
The following example calculates the earth's radius of curvature in kilometers normal to the
meridian at latitude 90 (the South Pole):
=> SELECT RADIUS_N(-90);
RADIUS_N
-----------------6399.59362575849
(1 row)
RADIUS_R
Returns the WGS-84 radius of the earth (to the center of mass) in kilometers at a given latitude. The
return value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
RADIUS_R (lat)
Parameters
lat
A value of type DOUBLE PRECISION indicating latitude at which you want to measure the
earth's radius.
SQLReference Manual
SQL Functions
Example
The following example calculates the WGS-84 radius of the earth in kilometers at latitude 90 (the
South Pole):
=> SELECT RADIUS_R(-90);
RADIUS_R
-----------------6356.75231424518
(1 row)
RADIUS_Ra
Returns the earth's average radius of curvature in kilometers at a given latitude. This function is the
geometric mean of RADIUS_M and RADIUS_N. (RADIUS_Rv is a faster approximation of this
function.)
The return value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
RADIUS_Ra (lat)
Parameters
lat
A value of type DOUBLE PRECISION indicating latitude at which you want to measure the
radius of curvature.
Example
The following example calculates the earth's average radius of curvature in kilometers at latitude
90 (the South Pole):
=> SELECT RADIUS_Ra(-90);
RADIUS_Ra
SQLReference Manual
SQL Functions
-----------------6399.59362575849
(1 row)
RADIUS_Rc
Returns the earth's radius of curvature in kilometers at a given bearing measured clockwise from
north. The return value has the type DOUBLE PRECISION.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
RADIUS_Rc (lat, bearing)
Parameters
lat
bearing
Example
The following example measures the earth's radius of curvature in kilometers at latitude 45, with a
bearing of 45 measured clockwise from north:
=> SELECT RADIUS_Rc(45,45);
RADIUS_Rc
-----------------6378.09200754445
(1 row)
RADIUS_Rv
Returns the earth's average radius of curvature in kilometers at a given latitude. This value is the
geometric mean of RADIUS_M and RADIUS_N. This function is a fast approximation of RADIUS_
Ra. The return value has the type DOUBLE PRECISION.
SQLReference Manual
SQL Functions
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
RADIUS_Rv (lat)
Parameters
lat
A value of type DOUBLE PRECISION indicating latitude at which you want to measure the
radius of curvature.
Example
The following example calculates the earth's average radius of curvature in kilometers at latitude
90 (the South Pole):
=> SELECT RADIUS_Rv(-90);
RADIUS_Rv
-----------------6399.59362575849
(1 row)
RADIUS_SI
Returns the International System of Units (SI) radius based on the nautical mile. (A nautical mile is
a unit of length about one minute of arc of latitude measured along any meridian, or about one
minute of arc of longitude measured at the equator.) The return value has the type NUMERIC.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
RADIUS_SI ()
SQLReference Manual
SQL Functions
Example
The following example calculates the SI radius based on the nautical mile:
=> SELECT RADIUS_SI();
RADIUS_SI
--------------------6366.70701949370750
(1 row)
RAYCROSSING
Determines whether a ray traveling to the right from point (x2,y2), in the direction of increasing x,
intersects a directed line segment that starts at point (x0,y0) and ends at point (x1,y1).
This function returns:
l
Behavior Type
Immutable
Syntax
RAYCROSSING (x0,y0,x1,y1,x2,y2)
Parameters
x0
A value of type DOUBLE PRECISION indicating the latitude of the starting point of the line
segment.
y0
A value of type DOUBLE PRECISION indicating the longitude of the starting point of the
line segment
SQLReference Manual
SQL Functions
x1
A value of type DOUBLE PRECISION indicating the latitude of the ending point of the line
segment.
y1
A value of type DOUBLE PRECISION indicating the longitude of the ending point of the line
segment.
x2
A value of type DOUBLE PRECISION indicating the latitude of the point from which the ray
starts.
y2 A value of type DOUBLE PRECISION indicating the longitude of the point from which the
ray starts.
Example
The following example checks if a line traveling to the right from the point (0,0) intersects the line
from (1,1) to (2,3):
=> SELECT RAYCROSSING(1,1,2,3,0,0);
RAYCROSSING
------------0
(1 row)
The following example checks if a line traveling to the right from the point (0,2) intersects the line
from (1,1) to (2,3):
=> SELECT RAYCROSSING(1,1,2,3,0,2);
RAYCROSSING
------------1
(1 row)
The following example checks if a line traveling to the right from the point (0,2) intersects the line
from (1,3) to (2,1):
=> SELECT RAYCROSSING(1,3,2,1,0,2);
RAYCROSSING
-------------1
(1 row)
SQLReference Manual
SQL Functions
WGS84_a
Returns the length, in kilometers, of the earth's semi-major axis. The return value is of type
NUMERIC.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
WGS84_a ()
Example
=> SELECT WGS84_a();
wgs84_a
------------6378.137000
(1 row)
WGS84_b
Returns the WGS-84 semi-minor axis length value in kilometers. The return value is of type
NUMERIC.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
WGS84_b ()
Example
=> SELECT WGS84_b();
SQLReference Manual
SQL Functions
WGS84_b
--------------------6356.75231424517950
(1 row)
WGS84_e2
Returns the WGS-84 eccentricity squared value. The return value is of type NUMERIC.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
WGS84_e2 ()
Example
=> SELECT WGS84_e2();
WGS84_e2
----------------------.00669437999014131700
(1 row)
WGS84_f
Returns the WGS-84 flattening value. The return value is of type NUMERIC.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
WGS84_f ()
SQLReference Manual
SQL Functions
Example
=> SELECT WGS84_f();
WGS84_f
----------------------.00335281066474748072
(1 row)
WGS84_if
Returns the WGS-84 inverse flattening value. The return value is of type NUMERIC.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
Syntax
WGS84_if ()
Example
=> SELECT WGS84_if();
WGS84_if
--------------298.257223563
(1 row)
WGS84_r1
Returns the International Union of Geodesy and Geophysics (IUGG) mean radius of the earth, in
kilometers. The return value is of type NUMERIC.
This function is available only if you install the HP Vertica Geospatial Package. See Geospatial
Package SQL Functions for information on installing the package.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
WGS84_r1 ()
Example
=> SELECT WGS84_r1();
WGS84_r1
--------------------6371.00877141505983
(1 row)
SQLReference Manual
SQL Functions
IP Conversion Functions
IP functions perform conversion, calculation, and manipulation operations on IP, network, and
subnet addresses.
INET_ATON
Returns an integer that represents the value of the address in host byte order, given the dotted-quad
representation of a network address as a string.
Behavior Type
Immutable
Syntax
INET_ATON ( expression )
Parameters
expression
Notes
The following syntax converts an IPv4 address represented as the string A to an integer I. INET_
ATON trims any spaces from the right of A, calls the Linux function inet_pton, and converts the result
from network byte order to host byte order using ntohl.
INET_ATON(VARCHAR A) -> INT8 I
Examples
The generated number is always in host byte order. In the following example, the number is
calculated as 209256^3 + 207256^2 + 224256 + 40.
> SELECT INET_ATON('209.207.224.40');
inet_aton
-----------3520061480
SQLReference Manual
SQL Functions
(1 row)
> SELECT INET_ATON('1.2.3.4');
inet_aton
----------16909060
(1 row)
> SELECT TO_HEX(INET_ATON('1.2.3.4'));
to_hex
--------1020304
(1 row)
See Also
l
INET_NTOA
INET_NTOA
Returns the dotted-quad representation of the address as a VARCHAR, given a network address as
an integer in network byte order.
Behavior Type
Immutable
Syntax
INET_NTOA ( expression )
Parameters
expression
Notes
The following syntax converts an IPv4 address represented as integer I to a string A.
INET_NTOA converts I from host byte order to network byte order using htonl, and calls the Linux
function inet_ntop.
INET_NTOA(INT8 I) -> VARCHAR A
SQLReference Manual
SQL Functions
Examples
> SELECT INET_NTOA(16909060);
inet_ntoa
----------1.2.3.4
(1 row)
> SELECT INET_NTOA(03021962);
inet_ntoa
------------0.46.28.138
(1 row)
See Also
l
INET_ATON
V6_ATON
Converts an IPv6 address represented as a character string to a binary string.
Behavior Type
Immutable
Syntax
V6_ATON ( expression )
Parameters
expression
Notes
The following syntax converts an IPv6 address represented as the character string A to a binary
string B.
V6_ATON trims any spaces from the right of A and calls the Linux function inet_pton.
V6_ATON(VARCHAR A) -> VARBINARY(16) B
SQLReference Manual
SQL Functions
If A has no colons it is prepended with '::ffff:'. If A is NULL, too long, or if inet_pton returns an error,
the result is NULL.
Examples
SELECT V6_ATON('2001:DB8::8:800:200C:417A');
v6_aton
-----------------------------------------------------\001\015\270\000\000\000\000\000\010\010\000 \014Az
(1 row)
SELECT V6_ATON('1.2.3.4');
v6_aton
-----------------------------------------------------------------\000\000\000\000\000\000\000\000\000\000\377\377\001\002\003\004
(1 row)
SELECT TO_HEX(V6_ATON('2001:DB8::8:800:200C:417A'));
to_hex
---------------------------------20010db80000000000080800200c417a
(1 row)
SELECT V6_ATON('::1.2.3.4');
v6_aton
-----------------------------------------------------------------\000\000\000\000\000\000\000\000\000\000\000\000\001\002\003\004
(1 row)
See Also
l
V6_NTOA
V6_NTOA
Converts an IPv6 address represented as varbinary to a character string.
Behavior Type
Immutable
Syntax
V6_NTOA ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
The following syntax converts an IPv6 address represented as VARBINARY B to a string A.
V6_NTOA right-pads B to 16 bytes with zeros, if necessary, and calls the Linux function inet_ntop.
V6_NTOA(VARBINARY B) -> VARCHAR A
Examples
> SELECT V6_NTOA(' \001\015\270\000\000\000\000\000\010\010\000 \014Az');
v6_ntoa
--------------------------2001:db8::8:800:200c:417a
(1 row)
> SELECT V6_NTOA(V6_ATON('1.2.3.4'));
v6_ntoa
--------1.2.3.4
(1 row)
> SELECT V6_NTOA(V6_ATON('::1.2.3.4'));
v6_ntoa
----------::1.2.3.4
(1 row)
See Also
l
V6_ATON
V6_SUBNETA
Calculates a subnet address in CIDR (Classless Inter-Domain Routing) format from a binary or
alphanumeric IPv6 address.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
V6_SUBNETA ( expression1, expression2 )
Parameters
expression1
expression2
Notes
The following syntax calculates a subnet address in CIDR format from a binary or varchar IPv6
address.
V6_SUBNETA masks a binary IPv6 address B so that the N leftmost bits form a subnet address,
while the remaining rightmost bits are cleared. It then converts to an alphanumeric IPv6 address,
appending a slash and N.
V6_SUBNETA(BINARY B, INT8 N) -> VARCHAR C
The following syntax calculates a subnet address in CIDR format from an alphanumeric IPv6
address.
V6_SUBNETA(VARCHAR A, INT8 N) -> V6_SUBNETA(V6_ATON(A), N) -> VARCHAR C
Examples
> SELECT V6_SUBNETA(V6_ATON('2001:db8::8:800:200c:417a'), 28);
v6_subneta
--------------2001:db0::/28
(1 row)
See Also
l
V6_SUBNETN
SQLReference Manual
SQL Functions
V6_SUBNETN
Calculates a subnet address in CIDR (Classless Inter-Domain Routing) format from a varbinary or
alphanumeric IPv6 address.
Behavior Type
Immutable
Syntax
V6_SUBNETN ( expression1, expression2 )
Parameters
expression1
expression2
Notes
The following syntax masks a BINARY IPv6 address B so that the N left-most bits of S form a
subnet address, while the remaining right-most bits are cleared.
V6_SUBNETN right-pads B to 16 bytes with zeros, if necessary and masks B, preserving its N-bit
subnet prefix.
V6_SUBNETN(VARBINARY B, INT8 N) -> VARBINARY(16) S
If B is NULL or longer than 16 bytes, or if N is not between 0 and 128 inclusive, the result is NULL.
S = [B]/N in Classless Inter-Domain Routing notation (CIDR notation).
The following syntax masks an alphanumeric IPv6 address A so that the N leftmost bits form a
subnet address, while the remaining rightmost bits are cleared.
SQLReference Manual
SQL Functions
Example
This example returns VARBINARY, after using V6_ATON to convert the VARCHAR string to VARBINARY:
> SELECT V6_SUBNETN(V6_ATON('2001:db8::8:800:200c:417a'), 28);
v6_subnetn
--------------------------------------------------------------\001\015\260\000\000\000\000\000\000\000\000\000\000\000\000
See Also
l
V6_ATON
V6_SUBNETA
V6_TYPE
Characterizes a binary or alphanumeric IPv6 address B as an integer type.
Behavior Type
Immutable
Syntax
V6_TYPE ( expression )
Parameters
expression
Notes
V6_TYPE(VARBINARY B) returns INT8 T.
V6_TYPE(VARCHAR A) -> V6_TYPE(V6_ATON(A)) -> INT8 T
The IPv6 types are defined in the Network Working Group's IP Version 6 Addressing Architecture
memo.
SQLReference Manual
SQL Functions
GLOBAL = 0
LINKLOCAL = 1
LOOPBACK = 2
UNSPECIFIED = 3
MULTICAST = 4
IPv4-mapped and IPv4-compatible IPv6 addresses are also interpreted, as specified in IPv4 Global
Unicast Address Assignments.
l
Details
IPv4 (either kind):
0.0.0.0/8
127.0.0.0/8
169.254.0.0/16
172.16.0.0/12
192.168.0.0/16
224.0.0.0/4
others
UNSPECIFIED
LOOPBACK
LINKLOCAL
LINKLOCAL
LINKLOCAL
MULTICAST
GLOBAL
10.0.0.0/8
::0/128
fe80::/10
ff00::/8
others
UNSPECIFIED
LINKLOCAL
MULTICAST
GLOBAL
::1/128
LINKLOCAL
IPv6:
LOOPBACK
Examples
> SELECT V6_TYPE(V6_ATON('192.168.2.10'));
v6_type
--------1
(1 row)
> SELECT V6_TYPE(V6_ATON('2001:db8::8:800:200c:417a'));
v6_type
--------0
(1 row)
SQLReference Manual
SQL Functions
See Also
l
INET_ATON
SQLReference Manual
SQL Functions
Mathematical Functions
Some of these functions are provided in multiple forms with different argument types. Except where
noted, any given form of a function returns the same data type as its argument. The functions
working with DOUBLE PRECISION data could vary in accuracy and behavior in boundary cases
depending on the host system.
See Also
l
ABS
Returns the absolute value of the argument. The return value has the same data type as the
argument..
Behavior Type
Immutable
Syntax
ABS ( expression )
Parameters
expression
Examples
SELECT ABS(-28.7);
abs
-----28.7
(1 row)
SQLReference Manual
SQL Functions
ACOS
Returns a DOUBLE PRECISION value representing the trigonometric inverse cosine of the
argument.
Behavior Type
Immutable
Syntax
ACOS ( expression )
Parameters
expression
Example
SELECT ACOS (1);
acos
-----0
(1 row)
ASIN
Returns a DOUBLE PRECISION value representing the trigonometric inverse sine of the
argument.
Behavior Type
Immutable
Syntax
ASIN ( expression )
Parameters
SQLReference Manual
SQL Functions
expression
Example
SELECT ASIN(1);
asin
----------------1.5707963267949
(1 row)
ATAN
Returns a DOUBLE PRECISION value representing the trigonometric inverse tangent of the
argument.
Behavior Type
Immutable
Syntax
ATAN ( expression )
Parameters
expression
Example
SELECT ATAN(1);
atan
------------------0.785398163397448
(1 row)
ATAN2
Returns a DOUBLE PRECISION value representing the trigonometric inverse tangent of the
arithmetic dividend of the arguments.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
ATAN2 ( quotient, divisor )
Parameters
quotient
divisor
Example
SELECT ATAN2(2,1);
ATAN2
-----------------1.10714871779409
(1 row)
CBRT
Returns the cube root of the argument. The return value has the type DOUBLE PRECISION.
Behavior Type
Immutable
Syntax
CBRT ( expression )
Parameters
expression
Examples
SELECT CBRT(27.0);
SQLReference Manual
SQL Functions
cbrt
-----3
(1 row)
CEILING (CEIL)
Rounds the returned value up to the next whole number. Any expression that contains even a slight
decimal is rounded up.
Behavior Type
Immutable
Syntax
CEILING ( expression )CEIL ( expression )
Parameters
expression
Notes
CEILING is the opposite of FLOOR, which rounds the returned value down:
=> SELECT CEIL(48.01) AS ceiling, FLOOR(48.01) AS floor;
ceiling | floor
---------+------49 |
48
(1 row)
Examples
=> SELECT CEIL(-42.8);
CEIL
------42
(1 row)
SELECT CEIL(48.01);
CEIL
-----49
(1 row)
SQLReference Manual
SQL Functions
COS
Returns a DOUBLE PRECISION value representing the trigonometric cosine of the argument.
Behavior Type
Immutable
Syntax
COS ( expression )
Parameters
expression
Example
SELECT COS(-1);
cos
-----------------0.54030230586814
(1 row)
COT
Returns a DOUBLE PRECISION value representing the trigonometric cotangent of the argument.
Behavior Type
Immutable
Syntax
COT ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Example
SELECT COT(1);
cot
------------------0.642092615934331
(1 row)
DEGREES
Converts an expression from RADIANS to fractional degrees, or from degrees, minutes, and
seconds to fractional degrees. The return value has the type DOUBLE PRECISION.
Behavior Type
Immutable
Syntax 1
DEGREES (radians)
Syntax 2
DEGREES (degrees, minutes, seconds)
Parameters
radians
degrees
minutes
seconds
Examples
SELECT DEGREES(0.5);
DEGREES
-----------------28.6478897565412
(1 row)
SQLReference Manual
SQL Functions
SELECT DEGREES(1,2,3);
DEGREES
-----------------1.03416666666667
(1 row)
DISTANCE
Returns the distance (in kilometers) between two points. You specify the latitude and longitude of
both the starting point and the ending point. You can also specify the radius of curvature for greater
accuracy when using an ellipsoidal model.
Behavior Type
Immutable
Syntax
DISTANCE ( lat0, lon0, lat1, lon1, radius_of_curvature )
Parameters
lat0
lon0
lat1
lon1
radius_of_curvature
Specifies the radius of the curvature of the earth at the midpoint between
the starting and ending points. This parameter allows for greater accuracy
when using an ellipsoidal earth model. If you do not specify this parameter,
it defaults to the WGS-84 average r1 radius, about 6371.009 km.
Example
This example finds the distance in kilometers for 1 degree of longitude at latitude 45 degrees,
assuming earth is spherical.
SELECT DISTANCE(45,0, 45,1);
DISTANCE
----------------------
SQLReference Manual
SQL Functions
78.6262959272162
(1 row)
DISTANCEV
Returns the distance (in kilometers) between two points using the Vincenty formula. Because the
Vincenty formula includes the parameters of the WGS-84 ellipsoid model, you need not specify a
radius of curvature. You specify the latitude and longitude of both the starting point and the ending
point. This function is more accurate, but will be slower, than the DISTANCE function.
Behavior Type
Immutable
Syntax
DISTANCEV (lat0, lon0, lat1, lon1);
Parameters
lat0
Example
This example finds the distance in kilometers for 1 degree of longitude at latitude 45 degrees,
assuming earth is ellipsoidal.
SELECT DISTANCEV(45,0, 45,1);
distanceV
-----------------78.8463347095916
(1 row)
EXP
Returns the exponential function, e to the power of a number. The return value has the same data
type as the argument.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
EXP ( exponent )
Parameters
exponent
Example
SELECT EXP(1.0);
exp
-----------------2.71828182845905
(1 row)
FLOOR
Rounds the returned value down to the next whole number. For example, each of these functions
evaluates to 5:
floor(5.01)
floor(5.5)
floor(5.99)
Behavior Type
Immutable
Syntax
FLOOR ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
FLOOR is the opposite of CEILING, which rounds the returned value up:
=> SELECT FLOOR(48.01) AS floor, CEIL(48.01) AS ceiling;
floor | ceiling
-------+--------48 |
49
(1 row)
Examples
=> SELECT FLOOR((TIMESTAMP '2005-01-17 10:00' - TIMESTAMP '2005-01-01') / INTERVAL '7');
FLOOR
------2
(1 row)
=> SELECT FLOOR(-42.8);
FLOOR
-------43
(1 row)
=> SELECT FLOOR(42.8);
FLOOR
------42
(1 row)
Although the following example looks like an INTEGER, the number on the left is 2^49 as an
INTEGER, but the number on the right is a FLOAT:
=> SELECT 1<<49, FLOOR(1 << 49);
?column?
|
floor
-----------------+----------------562949953421312 | 562949953421312
(1 row)
SQLReference Manual
SQL Functions
HASH
Calculates a hash value over its arguments, producing a value in the range 0 <= x < 263 (two to the
sixty-third power or 2^63).
Behavior Type
Immutable
Syntax
HASH ( expression [ ,... ] )
Parameters
expression
Is an expression of any data type. For the purpose of hash segmentation, each
expression is a column reference .
Notes
l
The HASH() function is used to provide projection segmentation over a set of nodes in a cluster
and takes up to 32 arguments, usually column names, and selects a specific node for each row
based on the values of the columns for that row. HASH (Col1, Col2).
If your data is fairly regular and you want more even distribution than you get with HASH,
consider using MODULARHASH() for project segmentation.
Examples
SELECT HASH(product_price, product_cost) FROM product_dimension
WHERE product_price = '11';
hash
--------------------4157497907121511878
1799398249227328285
3250220637492749639
(3 rows)
See Also
l
MODULARHASH
SQLReference Manual
SQL Functions
LN
Returns the natural logarithm of the argument. The return data type is the same as the argument.
Behavior Type
Immutable
Syntax
LN ( expression )
Parameters
expression
Example
SELECT LN(2);
ln
------------------0.693147180559945
(1 row)
LOG
Returns the logarithm to the specified base of the argument. The return data type is the same as the
argument.
Behavior Type
Immutable
Syntax
LOG ( [ base, ] expression )
Parameters
base
expression
SQLReference Manual
SQL Functions
Examples
SELECT LOG(2.0, 64);
log
----6
(1 row)
SELECT LOG(100);
log
----2
(1 row)
MOD
Returns the remainder of a division operation. MOD is also called modulo.
Behavior Type
Immutable
Syntax
MOD( expression1, expression2 )
Parameters
expression1
expression2
Notes
When computing mod(N,M), the following rules apply:
l
If either N or M is the null value, then the result is the null value.
Otherwise, the result is the unique exact numeric value R with scale 0 (zero) such that all of the
following are true:
SQLReference Manual
SQL Functions
Examples
SELECT MOD(9,4);
mod
----1
(1 row)
SELECT MOD(10,3);
mod
----1
(1 row)
SELECT MOD(-10,3);
mod
-----1
(1 row)
SELECT MOD(-10,-3);
mod
-----1
(1 row)
SELECT MOD(10,-3);
mod
----1
(1 row)
MODULARHASH
Calculates a hash value over its arguments for the purpose of projection segmentation. In all other
uses, returns 0.
If you can hash segment your data using a column with a regular pattern, such as a sequential
unique identifier, MODULARHASH distributes the data more evenly than HASH, which distributes
data using a normal statistical distribution.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
MODULARHASH ( expression [ ,... ] )
Parameters
expression
Notes
The MODULARHASH() function takes up to 32 arguments, usually column names, and selects a
specific node for each row based on the values of the columns for that row.
Example
CREATE PROJECTION fact_ts_2 (f_price, f_cid, f_tid, f_cost, f_date)
AS (SELECT price, cid, tid, cost, dwdate
FROM fact)
SEGMENTED BY MODULARHASH(dwdate)
ALL NODES OFFSET 2;
See Also
l
HASH
PI
Returns the constant pi (), the ratio of any circle's circumference to its diameter in Euclidean
geometry The return type is DOUBLE PRECISION.
Behavior Type
Immutable
Syntax
PI()
SQLReference Manual
SQL Functions
Examples
SELECT PI();
pi
-----------------3.14159265358979
(1 row)
Behavior Type
Immutable
Syntax
POWER ( expression1, expression2 )
Parameters
expression1
expression2
Example
SELECT POWER(9.0, 3.0);
power
------729
(1 row)
RADIANS
Returns a DOUBLE PRECISION value representing an angle expressed in radians. You can
express the input angle in DEGREES, and optionally include minutes and seconds.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
RADIANS (degrees [, minutes, seconds])
Parameters
degrees
minutes
seconds
Examples
SELECT RADIANS(45);
RADIANS
------------------0.785398163397448
(1 row)
SELECT RADIANS (1,2,3);
RADIANS
------------------0.018049613347708
(1 row)
RANDOM
Returns a uniformly-distributed random number x, where 0 <= x < 1.
Behavior Type
Volatile
Syntax
RANDOM()
Parameters
RANDOM has no arguments. Its result is a FLOAT8 data type (also called DOUBLE PRECISION).
SQLReference Manual
SQL Functions
Notes
Typical pseudo-random generators accept a seed, which is set to generate a reproducible pseudorandom sequence. HP Vertica, however, distributes SQL processing over a cluster of nodes, where
each node generates its own independent random sequence.
Results depending on RANDOM are not reproducible because the work might be divided differently
across nodes. Therefore, HP Vertica automatically generates truly random seeds for each node
each time a request is executed and does not provide a mechanism for forcing a specific seed.
Examples
In the following example, the result is a float, which is >= 0 and < 1.0:
SELECT RANDOM();
random
------------------0.211625560652465
(1 row)
RANDOMINT
Returns an INT8 value, and accepts a positive integer (n). RANDOMINT(n) returns one of the n
integers from 0 through n 1.
Behavior Type
Volatile
Syntax
RANDOMINT ( n )
Example
In the following example, the result is an INT8, which is >= 0 and < n, randomly chosen from the set
{0,1,2,3,4}.
SELECT RANDOMINT(5);
RANDOMINT
---------3
(1 row)
SQLReference Manual
SQL Functions
ROUND
Rounds a value to a specified number of decimal places, retaining the original scale and precision.
Fractions greater than or equal to .5 are rounded up. Fractions less than .5 are rounded down
(truncated).
Behavior Type
Immutable
Syntax
ROUND ( expression [ , decimal-places ] )
Parameters
expression
decimal-places
If positive, specifies the number of decimal places to display to the right of the
decimal point; if negative, specifies the number of decimal places to display to
the left of the decimal point.
Notes
NUMERIC ROUND() returns NUMERIC, retaining the original scale and precision:
=> SELECT ROUND(3.5);
ROUND
-------
SQLReference Manual
SQL Functions
4.0
(1 row)
The internal floating-point representation used to compute the ROUND function causes the fraction
to be evaluated as 3.5, which is rounded up.
Examples
SELECT ROUND(2.0, 1.0 ) FROM dual;
round
------2
(1 row)
SELECT ROUND(12.345, 2.0 );
round
------12.35
(1 row)
SELECT ROUND(3.444444444444444);
ROUND
------------------3.000000000000000
(1 row)
SELECT ROUND(3.14159, 3);
ROUND
--------3.14200
(1 row)
SELECT ROUND(1234567, -3);
round
--------1235000
(1 row)
SELECT ROUND(3.4999, -1);
ROUND
------.0000
(1 row)
SELECT employee_last_name, ROUND(annual_salary,4) FROM employee_dimension;
employee_last_name | ROUND
--------------------+-------Li
|
1880
Rodriguez
|
1704
Goldberg
|
2282
Meyer
|
1628
Pavlov
|
3168
McNulty
|
1516
Dobisz
|
3006
Pavlov
|
2142
Goldberg
|
2268
SQLReference Manual
SQL Functions
Pavlov
Robinson
...
|
|
1918
2366
SIGN
Returns a DOUBLE PRECISION value of -1, 0, or 1 representing the arithmetic sign of the
argument.
Behavior Type
Immutable
Syntax
SIGN ( expression )
Parameters
expression
Examples
SELECT SIGN(-8.4);
sign
------1
(1 row)
SIN
Returns a DOUBLE PRECISION value representing the trigonometric sine of the argument.
Behavior Type
Immutable
Syntax
SIN ( expression )
SQLReference Manual
SQL Functions
Parameters
expression
Example
SELECT SIN(30 * 2 * 3.14159 / 360);
sin
------------------0.499999616987256
(1 row)
SQRT
Returns a DOUBLE PRECISION value representing the arithmetic square root of the argument.
Behavior Type
Immutable
Syntax
SQRT ( expression )
Parameters
expression
Examples
SELECT SQRT(2);
sqrt
----------------1.4142135623731
(1 row)
TAN
Returns a DOUBLE PRECISION value representing the trigonometric tangent of the argument.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
TAN ( expression )
Parameters
expression
Example
SELECT TAN(30);
tan
-------------------6.40533119664628
(1 row)
TRUNC
Returns a value representing the argument fully truncated (toward zero) or truncated to a specific
number of decimal places, retaining the original scale and precision.
Behavior Type
Immutable
Syntax
TRUNC ( expression [ , places ]
Parameters
expression
places
SQLReference Manual
SQL Functions
Notes
NUMERIC TRUNC() returns NUMERIC, retaining the original scale and precision:
=> SELECT TRUNC(3.5);
TRUNC
------3.0
(1 row)
Examples
=> SELECT TRUNC(42.8);
TRUNC
------42.0
(1 row)
=> SELECT TRUNC(42.4382, 2);
TRUNC
--------42.4300
(1 row)
WIDTH_BUCKET
Constructs equiwidth histograms, in which the histogram range is divided into intervals (buckets)
of identical sizes. In addition, values below the low bucket return 0, and values above the high
bucket return bucket_count +1. Returns an integer value.
Behavior Type
Immutable
Syntax
WIDTH_BUCKET ( expression, hist_min, hist_max, bucket_count )
Parameters
expression
The expression for which the histogram is created. This expression must evaluate
to a numeric or datetime value or to a value that can be implicitly converted to a
numeric or datetime value. If expression evaluates to null, then the expression
returns null.
SQLReference Manual
SQL Functions
hist_min
An expression that resolves to the low boundary of bucket 1. Must also evaluate
to numeric or datetime values and cannot evaluate to null.
hist_max
bucket_count
Notes
l
WIDTH_BUCKET divides a data set into buckets of equal width. For example, Age = 020, 20
40, 4060, 6080. This is known as an equiwidth histogram.
When using WIDTH_BUCKET pay attention to the minimum and maximum boundary values.
Each bucket contains values equal to or greater than the base value of that bucket, so that age
ranges of 020, 2040, and so on, are actually 019.99 and 2039.999.
WIDTH_BUCKET accepts the following data types: (FLOAT and/or INT), (TIMESTAMP and/or
DATE and/or TIMESTAMPTZ), or (INTERVAL and/or TIME).
Examples
The following example returns five possible values and has three buckets: 0 [Up to 100), 1 [100
300), 2 [300500), 3 [500700), and 4 [700 and up):
SELECT product_description, product_cost, WIDTH_BUCKET(product_cost, 100, 700, 3);
The following example creates a nine-bucket histogram on the annual_income column for
customers in Connecticut who are female doctors. The results return the bucket number to an
Income column, divided into eleven buckets, including an underflow and an overflow. Note that if
customers had an annual incomes greater than the maximum value, they would be assigned to an
overflow bucket, 10:
SELECT customer_name, annual_income, WIDTH_BUCKET (annual_income, 100000, 1000000, 9) AS
"Income"
FROM public.customer_dimension WHERE customer_state='CT'
AND title='Dr.' AND customer_gender='Female' AND household_id < '1000'
ORDER BY "Income";
In the following result set, the reason there is a bucket 0 is because buckets are numbered from 1 to
bucket_count. Anything less than the given value of hist_min goes in bucket 0, and anything
greater than the given value of hist_max goes in the bucket bucket_count+1. In this example,
SQLReference Manual
SQL Functions
bucket 9 is empty, and there is no overflow. The value 12,283 is less than 100,000, so it goes into
the underflow bucket.
customer_name
| annual_income | Income
--------------------+---------------+-------Joanna A. Nguyen
|
12283 |
0
Amy I. Nguyen
|
109806 |
1
Juanita L. Taylor |
219002 |
2
Carla E. Brown
|
240872 |
2
Kim U. Overstreet |
284011 |
2
Tiffany N. Reyes
|
323213 |
3
Rebecca V. Martin |
324493 |
3
Betty . Roy
|
476055 |
4
Midori B. Young
|
462587 |
4
Martha T. Brown
|
687810 |
6
Julie D. Miller
|
616509 |
6
Julie Y. Nielson
|
894910 |
8
Sarah B. Weaver
|
896260 |
8
Jessica C. Nielson |
861066 |
8
(14 rows)
See Also
l
NTILE [Analytic]
SQLReference Manual
SQL Functions
NULL-handling Functions
NULL-handling functions take arguments of any type, and their return type is based on their
argument types.
COALESCE
Returns the value of the first non-null expression in the list. If all expressions evaluate to null, then
the COALESCE function returns null.
Behavior Type
Immutable
Syntax
COALESCE ( expression1, expression2 );
COALESCE ( expression1, expression2, ...
expression-n );
Parameters
l
Notes
COALESCE is an ANSI standard function (SQL-92).
Example
SELECT product_description,
SQLReference Manual
SQL Functions
COALESCE(lowest_competitor_price,
highest_competitor_price,
average_competitor_price) AS price
FROM product_dimension;
product_description
| price
------------------------------------+------Brand #54109 kidney beans
|
264
Brand #53364 veal
|
139
Brand #50720 ice cream sandwiches |
127
Brand #48820 coffee cake
|
174
Brand #48151 halibut
|
353
Brand #47165 canned olives
|
250
Brand #39509 lamb
|
306
Brand #36228 tuna
|
245
Brand #34156 blueberry muffins
|
183
Brand #31207 clams
|
163
(10 rows)
See Also
l
CASE Expressions
ISNULL
IFNULL
Returns the value of the first non-null expression in the list.
IFNULL is an alias of NVL.
Behavior Type
Immutable
Syntax
IFNULL ( expression1 , expression2 );
Parameters
l
SQLReference Manual
SQL Functions
Notes
l
IFNULL is equivalent to COALESCE except that IFNULL is called with only two arguments.
Examples
=> SELECT IFNULL (SCORE, 0.0) FROM TESTING;
IFNULL
-------100.0
87.0
.0
.0
.0
(5 rows)
See Also
l
CASE Expressions
COALESCE
SQLReference Manual
SQL Functions
NVL
ISNULL
ISNULL
Returns the value of the first non-null expression in the list.
ISNULL is an alias of NVL.
Behavior Type
Immutable
Syntax
ISNULL ( expression1 , expression2 );
Parameters
l
Notes
l
ISNULL is equivalent to COALESCE except that ISNULL is called with only two arguments.
SQLReference Manual
SQL Functions
Examples
SELECT product_description, product_price,
ISNULL(product_cost, 0.0) AS cost
FROM product_dimension;
product_description
| product_price | cost
--------------------------------+---------------+-----Brand #59957 wheat bread
|
405 | 207
Brand #59052 blueberry muffins |
211 | 140
Brand #59004 english muffins
|
399 | 240
Brand #53222 wheat bread
|
323 |
94
Brand #52951 croissants
|
367 | 121
Brand #50658 croissants
|
100 |
94
Brand #49398 white bread
|
318 |
25
Brand #46099 wheat bread
|
242 |
3
Brand #45283 wheat bread
|
111 | 105
Brand #43503 jelly donuts
|
259 |
19
(10 rows)
See Also
l
CASE Expressions
COALESCE
NVL
NULLIF
Compares two expressions. If the expressions are not equal, the function returns the first
expression (expression1). If the expressions are equal, the function returns null.
Behavior Type
Immutable
Syntax
NULLIF( expression1, expression2 )
SQLReference Manual
SQL Functions
Parameters
expression1
expression2
Must have the same data type as expr1 or a type that can be implicitly cast to
match expression1. The result has the same type as expression1.
Examples
The following series of statements illustrates one simple use of the NULLIF function.
Creates a single-column table t and insert some values:
CREATE TABLE t (x TIMESTAMPTZ);
INSERT INTO t VALUES('2009-09-04 09:14:00-04');
INSERT INTO t VALUES('2010-09-04 09:14:00-04');
NULLIFZERO
Evaluates to NULL if the value in the column is 0.
Syntax
NULLIFZERO(expression)
SQLReference Manual
SQL Functions
Parameters
expression
Example
The TESTING table below shows the test scores for 5 students. Note that test scores are missing
for S. Robinson and K. Johnson (NULL values appear in the Score column.)
=> SELECT * FROM TESTING;
Name
| Score
-------------+------J. Doe
|
100
R. Smith
|
87
L. White
|
0
S. Robinson |
K. Johnson |
(5 rows)
The SELECT statement below specifies that HP Vertica should return any 0 values in the Score
column as Null. In the results, you can see that HP Vertica returns L. White's 0 score as Null.
=> SELECT Name, NULLIFZERO(Score) FROM TESTING;
Name
| NULLIFZERO
-------------+-----------J. Doe
|
100
R. Smith
|
87
L. White
|
S. Robinson |
K. Johnson |
(5 rows)
NVL
Returns the value of the first non-null expression in the list.
Behavior Type
Immutable
Syntax
NVL ( expression1 , expression2 );
SQLReference Manual
SQL Functions
Parameters
l
Notes
l
NVL is equivalent to COALESCE except that NVL is called with only two arguments.
Examples
expression1 is not null, so NVL returns expression1:
SELECT NVL('fast', 'database');
nvl
-----fast
(1 row)
SQLReference Manual
SQL Functions
In the following example, expression1 (title) contains nulls, so NVL returns expression2 and
substitutes 'Withheld' for the unknown values:
SELECT customer_name, NVL(title, 'Withheld') as title
FROM customer_dimension
ORDER BY title;
customer_name
| title
------------------------+------Alexander I. Lang
| Dr.
Steve S. Harris
| Dr.
Daniel R. King
| Dr.
Luigi I. Sanchez
| Dr.
Duncan U. Carcetti
| Dr.
Meghan K. Li
| Dr.
Laura B. Perkins
| Dr.
Samantha V. Robinson
| Dr.
Joseph P. Wilson
| Mr.
Kevin R. Miller
| Mr.
Lauren D. Nguyen
| Mrs.
Emily E. Goldberg
| Mrs.
Darlene K. Harris
| Ms.
Meghan J. Farmer
| Ms.
Bettercare
| Withheld
Ameristar
| Withheld
Initech
| Withheld
(17 rows)
See Also
l
CASE Expressions
COALESCE
ISNULL
NVL2
NVL2
Takes three arguments. If the first argument is not NULL, it returns the second argument, otherwise
it returns the third argument. The data types of the second and third arguments are implicitly cast to
a common type if they don't agree, similar to COALESCE.
Behavior Type
Immutable
Syntax
NVL2 ( expression1 , expression2 , expression3 );
SQLReference Manual
SQL Functions
Parameters
l
Notes
Arguments two and three can have any data type supported by HP Vertica.
Implementation is equivalent to the CASE expression:
CASE WHEN expression1 IS NOT NULL THEN expression2 ELSE expression3 END;
Examples
In this example, expression1 is not null, so NVL2 returns expression2:
SELECT NVL2('very', 'fast', 'database');
nvl2
-----fast
(1 row)
In the following example, expression1 (title) contains nulls, so NVL2 returns expression3
('Withheld') and also substitutes the non-null values with the expression 'Known':
SELECT customer_name, NVL2(title, 'Known', 'Withheld')
as title
FROM customer_dimension
ORDER BY title;
customer_name
| title
------------------------+------Alexander I. Lang
| Known
Steve S. Harris
| Known
Daniel R. King
| Known
Luigi I. Sanchez
| Known
Duncan U. Carcetti
| Known
Meghan K. Li
| Known
Laura B. Perkins
| Known
SQLReference Manual
SQL Functions
Samantha V. Robinson
Joseph P. Wilson
Kevin R. Miller
Lauren D. Nguyen
Emily E. Goldberg
Darlene K. Harris
Meghan J. Farmer
Bettercare
Ameristar
Initech
(17 rows)
|
|
|
|
|
|
|
|
|
|
Known
Known
Known
Known
Known
Known
Known
Withheld
Withheld
Withheld
See Also
l
CASE Expressions
COALESCE
COALESCE
ZEROIFNULL
Evaluates to 0 if the column is NULL.
Syntax
ZEROIFNULL(expression)
Parameters
expression
Example
The TESTING table below shows the test scores for 5 students. Note that L. White's score is 0,
and that scores are missing for S. Robinson and K. Johnson.
=> SELECT * FROM TESTING;
Name
| Score
-------------+------J. Doe
|
100
R. Smith
|
87
L. White
|
0
S. Robinson |
SQLReference Manual
SQL Functions
K. Johnson
(5 rows)
The next SELECT statement specifies that HP Vertica should return any Null values in the Score
column as 0s. In the results, you can see that HP Vertica returns a 0 score for S. Robinson and K.
Johnson.
=> SELECT Name, ZEROIFNULL (Score) FROM TESTING;
Name
| ZEROIFNULL
-------------+-----------J. Doe
|
100
R. Smith
|
87
L. White
|
0
S. Robinson |
0
K. Johnson |
0
(5 rows)
SQLReference Manual
SQL Functions
Ran a search.
Made a purchase.
For examples that use this clickstream model, see Event Series Pattern Matching in the Analyzing
Data Guide.
See Also
MATCH Clause
l
l
EVENT_NAME
Returns a VARCHAR value representing the name of the event that matched the row.
Syntax
EVENT_NAME()
SQLReference Manual
SQL Functions
Notes
Pattern matching functions must be used in MATCH Clause syntax; for example, if you call
EVENT_NAME() on its own, HP Vertica returns the following error message:
=> SELECT event_name();
ERROR: query with pattern matching function event_name must include a MATCH clause
Example
Note: This example uses the schema defined in Event Series Pattern Matching in the
Analyzing Data Guide. For a more detailed example, see that topic.
The following statement analyzes users' browsing history on website2.com and identifies patterns
where the user landed on website2.com from another Web site (Entry) and browsed to any number
of other pages (Onsite) before making a purchase (Purchase). The query also outputs the values for
EVENT_NAME(), which is the name of the event that matched the row.
SELECT uid,
sid,
ts,
refurl,
pageurl,
action,
event_name()
FROM clickstream_log
MATCH
(PARTITION BY uid, sid ORDER BY ts
DEFINE
Entry
AS RefURL NOT ILIKE '%website2.com%' AND PageURL ILIKE '%website2.com%',
Onsite
AS PageURL ILIKE
'%website2.com%' AND Action='V',
Purchase AS PageURL ILIKE
'%website2.com%' AND Action = 'P'
PATTERN
P AS (Entry Onsite* Purchase)
ROWS MATCH FIRST EVENT);
uid | sid |
ts
|
refurl
|
pageurl
| action | event_name
-----+-----+----------+----------------------+----------------------+--------+----------1 | 100 | 12:00:00 | website1.com
| website2.com/home
| V
| Entry
1 | 100 | 12:01:00 | website2.com/home
| website2.com/floby
| V
| Onsite
1 | 100 | 12:02:00 | website2.com/floby
| website2.com/shamwow | V
| Onsite
1 | 100 | 12:03:00 | website2.com/shamwow | website2.com/buy
| P
| Purchase
2 | 100 | 12:10:00 | website1.com
| website2.com/home
| V
| Entry
2 | 100 | 12:11:00 | website2.com/home
| website2.com/forks
| V
| Onsite
2 | 100 | 12:13:00 | website2.com/forks
| website2.com/buy
| P
| Purchase
(7 rows)
SQLReference Manual
SQL Functions
See Also
l
MATCH Clause
MATCH_ID
PATTERN_ID
l
l
MATCH_ID
Returns a successful pattern match as an INTEGER value. The returned value is the ordinal
position of a match within a partition.
Syntax
MATCH_ID()
Notes
Pattern matching functions must be used in MATCH Clause syntax; for example, if you call
MATCH_ID() on its own, HP Vertica returns the following error message:
=> SELECT match_id();
ERROR: query with pattern matching function match_id must include a MATCH clause
Example
Note: This example uses the schema defined in Event Series Pattern Matching in the
Analyzing Data Guide. For a more detailed example, see that topic.
The following statement analyzes users' browsing history on a site called website2.com and
identifies patterns where the user reached website2.com from another Web site (Entry in the
MATCH clause) and browsed to any number of other pages (Onsite) before making a purchase
(Purchase). The query also outputs values for the MATCH_ID(), which represents a sequential
number of the match.
SELECT uid,
sid,
SQLReference Manual
SQL Functions
ts,
refurl,
pageurl,
action,
match_id()
FROM clickstream_log
MATCH
(PARTITION BY uid, sid ORDER BY ts
DEFINE
Entry
AS RefURL NOT ILIKE '%website2.com%' AND PageURL ILIKE '%website2.com%',
Onsite
AS PageURL ILIKE
'%website2.com%' AND Action='V',
Purchase AS PageURL ILIKE
'%website2.com%' AND Action = 'P'
PATTERN
P AS (Entry Onsite* Purchase)
ROWS MATCH FIRST EVENT);
uid | sid | ts | refurl | pageurl | action | match_id
----+-----+----+--------+---------+--------+---------1 | 100 | 12:00:00 | website1.com | website2.com/home | V | 1
1 | 100 | 12:01:00 | website2.com/home | website2.com/floby | V | 2
1 | 100 | 12:02:00 | website2.com/floby | website2.com/shamwow | V | 3
1 | 100 | 12:03:00 | website2.com/shamwow | website2.com/buy | P | 4
2 | 100 | 12:10:00 | website1.com | website2.com/home | V | 1
2 | 100 | 12:11:00 | website2.com/home | website2.com/forks | V | 2
2 | 100 | 12:13:00 | website2.com/forks | website2.com/buy | P | 3
(7 rows)
See Also
l
MATCH Clause
EVENT_NAME
PATTERN_ID
l
l
PATTERN_ID
Returns an integer value that is a partition-wide unique identifier for the instance of the pattern that
matched.
Syntax
PATTERN_ID()
SQLReference Manual
SQL Functions
Notes
Pattern matching functions must be used in MATCH Clause syntax; for example, if call
PATTERN_ID() on its own, HP Vertica returns the following error message:
=> SELECT pattern_id();
ERROR: query with pattern matching function pattern_id must include a MATCH clause
Example
Note: This example uses the schema defined in Event Series Pattern Matching in the
Analyzing Data Guide. For a more detailed example, see that topic.
The following statement analyzes users' browsing history on website2.com and identifies patterns
where the user landed on website2.com from another Web site (Entry) and browsed to any number
of other pages (Onsite) before making a purchase (Purchase). The query also outputs values for
PATTERN_ID(), which represents the partition-wide identifier for the instance of the pattern that
matched.
SELECT uid,
sid,
ts,
refurl,
pageurl,
action,
pattern_id()
FROM clickstream_log
MATCH
(PARTITION BY uid, sid ORDER BY ts
DEFINE
Entry
AS RefURL NOT ILIKE '%website2.com%' AND PageURL ILIKE '%website2.com%',
Onsite
AS PageURL ILIKE
'%website2.com%' AND Action='V',
Purchase AS PageURL ILIKE
'%website2.com%' AND Action = 'P'
PATTERN
P AS (Entry Onsite* Purchase)
ROWS MATCH FIRST EVENT);
SQLReference Manual
SQL Functions
See Also
l
MATCH Clause
EVENT_NAME
MATCH_ID
l
l
SQLReference Manual
SQL Functions
ISUTF8
Tests whether a string is a valid UTF-8 string. Returns true if the string conforms to UTF-8
standards, and false otherwise. This function is useful to test strings for UTF-8 compliance before
passing them to one of the regular expression functions, such as REGEXP_LIKE, which expect
UTF-8 characters by default.
ISUTF8 checks for invalid UTF8 byte sequences, according to UTF-8 rules:
l
invalid bytes
an Overload Encoding
The presence of an invalid UTF8 byte sequence results in a return value of false.
SQLReference Manual
SQL Functions
Syntax
ISUTF8( string );
Parameters
string
Examples
=> SELECT ISUTF8(E'\xC2\xBF'); -- UTF-8 INVERTED QUESTION MARK ISUTF8
-------t
(1 row)
=> SELECT ISUTF8(E'\xC2\xC0'); -- UNDEFINED UTF-8 CHARACTER
ISUTF8
-------f
(1 row)
REGEXP_COUNT
Returns the number times a regular expression matches a string.
Syntax
REGEXP_COUNT( string, pattern [, position [, regexp_modifier ] ] )
Parameters
string
pattern
The regular expression to search for within the string. The syntax of the regular
expression is compatible with the Perl 5 regular expression syntax. See the
Perl Regular Expressions Documentation for details.
position
The number of characters from the start of the string where the function should
start searching for matches. The default value, 1, means to start searching for
a match at the first (leftmost) character. Setting this parameter to a value
greater than 1 starts searching for a match to the pattern that many characters
into the string.
SQLReference Manual
SQL Functions
regexp_modifier
A string containing one or more single-character flags that change how the
regular expression is matched against the string:
b
Treats the string being matched as multiple lines. With this modifier, the
start of line (^) and end of line ($) regular expression operators match line
breaks (\n) within the string. Ordinarily, these operators only match the
start and end of the string.
Notes
This function operates on UTF-8 strings using the default locale, even if the locale has been set to
something else.
If you are porting a regular expression query from an Oracle database, remember that Oracle
considers a zero-length string to be equivalent to NULL, while HP Vertica does not.
Examples
Count the number of occurrences of the substring "an" in the string "A man, a plan, a canal,
Panama."
=> SELECT REGEXP_COUNT('a man, a plan, a canal: Panama', 'an');
REGEXP_COUNT
-------------4
(1 row)
SQLReference Manual
SQL Functions
Find the number of occurrences of the substring "an" in the string "a man, a plan, a canal: Panama"
starting with the fifth character.
=> SELECT REGEXP_COUNT('a man, a plan, a canal: Panama', 'an',5);
REGEXP_COUNT
-------------3
(1 row)
Find the number of occurrences of a substring containing a lower-case character followed by "an."
In the first example, the query does not have a modifier. In the second example, the "i" query
modifier is used to force the regular expression to ignore case.
=> SELECT REGEXP_COUNT('a man, a plan, a canal: Panama', '[a-z]an');
REGEXP_COUNT
-------------3
(1 row)
=> SELECT REGEXP_COUNT('a man, a plan, a canal: Panama', '[a-z]an', 1, 'i');
REGEXP_COUNT
-------------4
REGEXP_INSTR
Returns the starting or ending position in a string where a regular expression matches. This function
returns 0 if no match for the regular expression is found in the string.
Syntax
REGEXP_INSTR( string, pattern [, position [, occurrence ... [, return_position [, regexp_
modifier ]
... [, captured_subexp ] ] ] ] )
Parameters
string
pattern
The regular expression to search for within the string. The syntax of the regular
expression is compatible with the Perl 5 regular expression syntax. See the
Perl Regular Expressions Documentation for details.
SQLReference Manual
SQL Functions
position
The number of characters from the start of the string where the function should
start searching for matches. The default value, 1, means to start searching for
a match at the first (leftmost) character. Setting this parameter to a value
greater than 1 starts searching for a match to the pattern that many characters
into the string.
occurrence
Controls which occurrence of a match between the string and the pattern is
returned. With the default value (1), the function returns the position of the first
substring that matches the pattern. You can use this parameter to find the
position of additional matches between the string and the pattern. For example,
set this parameter to 3 to find the position of the third substring that matched
the pattern.
return_position
Sets the position within the string that is returned. When set to the default
value (0), this function returns the position in the string of the first character of
the substring that matched the pattern. If you set this value to 1, the function
returns the position of the first character after the end of the matching
substring.
regexp_modifier
A string containing one or more single-character flags that change how the
regular expression is matched against the string:
b
Treats the string being matched as multiple lines. With this modifier, the
start of line (^) and end of line ($) regular expression operators match line
breaks (\n) within the string. Ordinarily, these operators only match the
start and end of the string.
SQLReference Manual
SQL Functions
captured_subexp
Notes
This function operates on UTF-8 strings using the default locale, even if the locale has been set to
something else.
If you are porting a regular expression query from an Oracle database, remember that Oracle
considers a zero-length string to be equivalent to NULL, while HP Vertica does not.
Examples
Find the first occurrence of a sequence of letters starting with the letter e and ending with the letter y
in the phrase "easy come, easy go."
=> SELECT REGEXP_INSTR('easy come, easy go','e\w*y'); REGEXP_INSTR
-------------1
(1 row)
Find the first occurrence of a sequence of letters starting with the letter e and ending with the letter y
starting at the second character in the string "easy come, easy go."
=> SELECT REGEXP_INSTR('easy come, easy go','e\w*y',2); REGEXP_INSTR
-------------12
(1 row)
Find the second sequence of letters starting with the letter e and ending with the letter y in the string
"easy come, easy go" starting at the first character.
=> SELECT REGEXP_INSTR('easy come, easy go','e\w*y',1,2); REGEXP_INSTR
SQLReference Manual
SQL Functions
-------------12
(1 row)
Find the position of the first character after the first whitespace in the string "easy come, easy go."
=> SELECT REGEXP_INSTR('easy come, easy go','\s',1,1,1); REGEXP_INSTR
-------------6
(1 row)
Find the position of the start of the third word in a string by capturing each word as a subexpression,
and returning the third subexpression's start position.
=> SELECT REGEXP_INSTR('one two three','(\w+)\s+(\w+)\s+(\w+)', 1,1,0,'',3); REGEXP_INSTR
-------------9
(1 row)
REGEXP_LIKE
Returns true if the string matches the regular expression. This function is similar to the LIKEpredicate, except that it uses regular expressions rather than simple wildcard character matching.
Syntax
REGEXP_LIKE( string, pattern [, modifiers ] )
Parameters
string
pattern
A string containing the regular expression to match against the string. The syntax of
the regular expression is compatible with the Perl 5 regular expression syntax. See
the Perl Regular Expressions Documentation for details.
SQLReference Manual
SQL Functions
modifiers
A string containing one or more single-character flags that change how the regular
expression is matched against the string:
b
Treats the string being matched as multiple lines. With this modifier, the start of
line (^) and end of line ($) regular expression operators match line breaks (\n)
within the string. Ordinarily, these operators only match the start and end of the
string.
Allows the single character regular expression operator (.) to match a newline
(\n). Normally, the . operator will match any character except a newline.
Notes
This function operates on UTF-8 strings using the default locale, even if the locale has been set to
something else.
If you are porting a regular expression query from an Oracle database, remember that Oracle
considers a zero-length string to be equivalent to NULL, while HP Vertica does not.
Examples
This example creates a table containing several strings to demonstrate regular expressions.
=> CREATE TABLE t (v VARCHAR);
CREATE TABLE
=> CREATE PROJECTION t1 AS SELECT * FROM t;
CREATE PROJECTION
=> COPY t FROM stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> aaa
>> Aaa
SQLReference Manual
SQL Functions
>>
>>
>>
>>
=>
abc
abc1
123
\.
SELECT * FROM t;
v
------aaa
Aaa
abc
abc1
123
(5 rows)
Select all records in the table that contain the letter "a."
=> SELECT v FROM t WHERE REGEXP_LIKE(v,'a');
v
-----Aaa
aaa
abc
abc1
(4 rows)
Select all of the rows in the table that start with the letter "a."
=> SELECT v FROM t WHERE REGEXP_LIKE(v,'^a');
v
-----aaa
abc
abc1
(3 rows)
SQLReference Manual
SQL Functions
(2 rows)
Select all rows that contain the substring "aaa" using case insensitive matching.
=> SELECT v FROM t WHERE REGEXP_LIKE(v,'aaa', 'i');
v
----Aaa
aaa
(2 rows)
Select rows that contain the substring "a b c" ignoring space within the regular expression.
=> SELECT v FROM t WHERE REGEXP_LIKE(v,'a b c','x');
v
-----abc
abc1
(2 rows)
Select rows that start with the substring "Record" and end with the substring "line 2."
SQLReference Manual
SQL Functions
Select rows that start with the substring "Record" and end with the substring "line 2," treating
multiple lines as separate strings.
=> SELECT v from t WHERE REGEXP_LIKE(v,'^Record.*line 2$','m');
v
-------------------------------------------------Record 2
Record 2
Record 2
Record 1
Record 1
Record 1
(2 rows)
line
line
line
line
line
line
1
2
3
1
2
3
REGEXP_REPLACE
Replace all occurrences of a substring that match a regular expression with another substring. It is
similar to the REPLACE function, except it uses a regular expression to select the substring to be
replaced.
Syntax
REGEXP_REPLACE( string, target [, replacement [, position [, occurrence ... [, regexp_
modifiers ] ] ] ] )
Parameters
string
target
The regular expression to search for within the string. The syntax of the regular
expression is compatible with the Perl 5 regular expression syntax. See the
Perl Regular Expressions Documentation for details.
replacement
SQLReference Manual
SQL Functions
position
The number of characters from the start of the string where the function should
start searching for matches. The default value, 1, means to start searching for
a match at the first (leftmost) character. Setting this parameter to a value
greater than 1 starts searching for a match to the pattern that many characters
into the string.
occurrence
Controls which occurrence of a match between the string and the pattern is
replaced. With the default value (0), the function replaces all matching
substrings with the replacement string. For any value above zero, the function
replaces just a single occurrence. For example, set this parameter to 3 to
replace the third substring that matched the pattern.
regexp_modifier
A string containing one or more single-character flags that change how the
regular expression is matched against the string:
b
Treats the string being matched as multiple lines. With this modifier, the
start of line (^) and end of line ($) regular expression operators match line
breaks (\n) within the string. Ordinarily, these operators only match the
start and end of the string.
Notes
This function operates on UTF-8 strings using the default locale, even if the locale has been set to
something else.
SQLReference Manual
SQL Functions
If you are porting a regular expression query from an Oracle database, remember that Oracle
considers a zero-length string to be equivalent to NULL, while HP Vertica does not.
Another key difference between Oracle and HP Vertica is that HP Vertica can handle an unlimited
number of captured subexpressions where Oracle is limited to nine. In HP Vertica, you are able to
use \10 in the replacement pattern to access the substring captured by the tenth set of parentheses
in the regular expression. In Oracle, \10 is treated as the substring captured by the first set of
parentheses followed by a zero. To force the same behavior in HP Vertica, use the \g
backreference with the number of the captured subexpression enclosed in curly braces. For
example, \g{1}0 is the substring captured by the first set of parentheses followed by a zero. You
can also name your captured subexpressions, to make your regular expressions less ambiguous.
See the PCRE documentation for details.
Examples
Find groups of "word characters" (letters, numbers and underscore) ending with "thy" in the string
"healthy, wealthy, and wise" and replace them with nothing.
=> SELECT REGEXP_REPLACE('healthy, wealthy, and wise','\w+thy');
REGEXP_REPLACE
---------------, , and wise
(1 row)
Find groups of word characters ending with "thy" and replace with the string "something."
=> SELECT REGEXP_REPLACE('healthy, wealthy, and wise','\w+thy', 'something');
REGEXP_REPLACE
-------------------------------something, something, and wise
(1 row)
Find groups of word characters ending with "thy" and replace with the string "something" starting at
the third character in the string.
=> SELECT REGEXP_REPLACE('healthy, wealthy, and wise','\w+thy', 'something', 3);
REGEXP_REPLACE
---------------------------------hesomething, something, and wise
(1 row)
Replace the second group of word characters ending with "thy" with the string "something."
=> SELECT REGEXP_REPLACE('healthy, wealthy, and wise','\w+thy', 'something', 1, 2);
REGEXP_REPLACE
------------------------------
SQLReference Manual
SQL Functions
Find groups of word characters ending with "thy" capturing the letters before the "thy", and replace
with the captured letters plus the letters "ish."
=> SELECT REGEXP_REPLACE('healthy, wealthy, and wise','(\w+)thy', '\1ish');
REGEXP_REPLACE
---------------------------healish, wealish, and wise
(1 row)
REGEXP_SUBSTR
Returns the substring that matches a regular expression within a string. If no matches are found,
this function returns NULL. This is different than an empty string, which can be returned by this
function if the regular expression matches a zero-length string.
Syntax
REGEXP_SUBSTR( string, pattern [, position [,
captured_subexp ] ] ] )
SQLReference Manual
SQL Functions
Parameters
string
pattern
The regular expression to find the substring to be extracted. The syntax of the
regular expression is compatible with the Perl 5 regular expression syntax. See
the Perl Regular Expressions Documentation for details.
position
The character in the string where the search for a match should start. The
default value, 1, starts the search at the beginning of the string. If you supply a
value larger than 1 for this parameter, the function will start searching that
many characters into the string.
occurrence
Controls which matching substring is returned by the function. When given the
default value (1), the function will return the first matching substring it finds in
the string. By setting this value to a number greater than 1, this function will
return subsequent matching substrings. For example, setting this parameter to
3 will return the third substring that matches the regular expression within the
string.
SQLReference Manual
SQL Functions
regexp_modifier
A string containing one or more single-character flags that change how the
regular expression is matched against the string:
b
Treats the string being matched as multiple lines. With this modifier, the
start of line (^) and end of line ($) regular expression operators match line
breaks (\n) within the string. Ordinarily, these operators only match the
start and end of the string.
captured_subexp
Notes
This function operates on UTF-8 strings using the default locale, even if the locale has been set to
something else.
SQLReference Manual
SQL Functions
If you are porting a regular expression query from an Oracle database, remember that Oracle
considers a zero-length string to be equivalent to NULL, while HP Vertica does not.
Examples
Select the first substring of letters that end with "thy."
=> SELECT REGEXP_SUBSTR('healthy, wealthy, and wise','\w+thy');
REGEXP_SUBSTR
--------------healthy
(1 row)
Select the first substring of letters that ends with "thy" starting at the second character in the string.
=> SELECT REGEXP_SUBSTR('healthy, wealthy, and wise','\w+thy',2);
REGEXP_SUBSTR
--------------ealthy
(1 row)
Return the contents of the third captured subexpression, which captures the third word in the string.
=> SELECT REGEXP_SUBSTR('one two three', '(\w+)\s+(\w+)\s+(\w+)', 1, 1, '', 3);
REGEXP_SUBSTR
--------------three
(1 row)
SQLReference Manual
SQL Functions
Sequence Functions
The sequence functions provide simple, multiuser-safe methods for obtaining successive
sequence values from sequence objects.
NEXTVAL
Returns the next value in a sequence. Calling NEXTVAL after creating a sequence initializes the
sequence with its default value, incrementing a positive value for ascending sequences, and
decrementing a negative value for descending sequences. Thereafter, calling NEXTVAL
increments the sequence value. NEXTVAL is used in INSERT, COPY, and SELECT statements
to create unique values.
Behavior Type
Volatile
Syntax
[[db-name.]schema.]sequence_name.NEXTVAL('[[db-name.]schema.]sequence_name')
Parameters
[[db-name.]schema.]
sequence_name
SQLReference Manual
SQL Functions
Permissions
l
Examples
The following example creates an ascending sequence called my_seq, starting at 101:
CREATE SEQUENCE my_seq START 101;
The following command illustrates how NEXTVAL is evaluated on a per-row basis, so in this
example, both calls to NEXTVAL yield the same result:
SELECT NEXTVAL('my_seq'), NEXTVAL('my_seq');
nextval | nextval
---------+--------103 |
103
(1 row)
The following example illustrates how the NEXTVAL is always evaluated first (and here, increments
the my_seq sequence from its previous value), even when CURRVAL precedes NEXTVAL:
SELECT CURRVAL('my_seq'), NEXTVAL('my_seq');
currval | nextval
---------+--------104 |
104
(1 row)
SQLReference Manual
SQL Functions
The following example shows how to use NEXTVAL in a table SELECT statement. Notice that the
nextval column is incremented by 1 again:
SELECT NEXTVAL('my_seq'), product_description FROM product_dimension LIMIT 10;
nextval |
product_description
---------+-----------------------------105 | Brand #2 bagels
106 | Brand #1 butter
107 | Brand #6 chicken noodle soup
108 | Brand #5 golf clubs
109 | Brand #4 brandy
110 | Brand #3 lamb
111 | Brand #11 vanilla ice cream
112 | Brand #10 ground beef
113 | Brand #9 camera case
114 | Brand #8 halibut
(10 rows)
See Also
l
ALTER SEQUENCE
CREATE SEQUENCE
CURRVAL
DROP SEQUENCE
Sequence Privileges
CURRVAL
For a sequence generator, returns the LAST value across all nodes returned by a previous
invocation of NEXTVAL in the same session. If there were no calls to NEXTVAL after the
sequence was created, an error is returned.
Behavior Type
Volatile
Syntax
[[db-name.]schema.]sequence_name.CURRVALCURRVAL('[[db-name.]schema.]sequence_name')
SQLReference Manual
SQL Functions
Parameters
[[db-name.]schema.]
sequence_name
Permissions
l
Examples
The following example creates an ascending sequence called sequential, starting at 101:
CREATE SEQUENCE seq2 START 101;
You cannot call CURRVAL until after you have initiated the sequence with NEXTVAL or the
system returns an error:
SELECT CURRVAL('seq2');
ERROR: Sequence seq2 has not been accessed in the session
Use the NEXTVAL function to generate the first number for this sequence:
SELECT NEXTVAL('seq2');
nextval
--------101
(1 row)
Now you can use CURRVAL to return the current number from this sequence:
SQLReference Manual
SQL Functions
SELECT CURRVAL('seq2');
currval
--------101
(1 row)
The following example illustrates how the NEXTVAL is always evaluated first (and here,
increments the my_seq sequence from its previous value), even when CURRVAL precedes
NEXTVAL:
SELECT CURRVAL('my_seq'), NEXTVAL('my_seq');
currval | nextval
---------+--------102 |
102
(1 row)
See Also
l
ALTER SEQUENCE
CREATE SEQUENCE
DROP SEQUENCE
NEXTVAL
l
l
SQLReference Manual
SQL Functions
LAST_INSERT_ID
Returns the last value of a column whose value is automatically incremented through the AUTO_
INCREMENT or IDENTITY Column-Constraint. If multiple sessions concurrently load the same
table, the returned value is the last value generated for an AUTO_INCREMENT column by an
insert in that session.
Behavior Type
Volatile
Syntax
LAST_INSERT_ID()
Privileges
l
Table owner
Notes
l
This function works only with AUTO_INCREMENT and IDENTITY columns. See columnconstraints for the CREATE TABLE statement.
LAST_INSERT_ID does not work with sequence generators created through the CREATE
SEQUENCE statement.
Examples
Create a sample table called customer4.
=> CREATE TABLE customer4(
ID IDENTITY(2,2),
lname VARCHAR(25),
fname VARCHAR(25),
membership_card INTEGER
);
=> INSERT INTO customer4(lname, fname, membership_card)
VALUES ('Gupta', 'Saleem', 475987);
SQLReference Manual
SQL Functions
Notice that the IDENTITY column has a seed of 2, which specifies the value for the first row loaded
into the table, and an increment of 2, which specifies the value that is added to the IDENTITY value
of the previous row.
Query the table you just created:
=> SELECT * FROM customer4;
ID | lname | fname | membership_card
----+-------+--------+----------------2 | Gupta | Saleem |
475987
(1 row)
SQLReference Manual
SQL Functions
| membership_card
See Also
l
ALTER SEQUENCE
CREATE SEQUENCE
DROP SEQUENCE
SEQUENCES
Sequence Privileges
SQLReference Manual
SQL Functions
String Functions
String functions perform conversion, extraction, or manipulation operations on strings, or return
information about strings.
This section describes functions and operators for examining and manipulating string values.
Strings in this context include values of the types CHAR, VARCHAR, BINARY, and
VARBINARY.
Unless otherwise noted, all of the functions listed in this section work on all four data types. As
opposed to some other SQL implementations, HP Vertica keeps CHAR strings unpadded
internally, padding them only on final output. So converting a CHAR(3) 'ab' to VARCHAR(5)
results in a VARCHAR of length 2, not one with length 3 including a trailing space.
Some of the functions described here also work on data of non-string types by converting that data
to a string representation first. Some functions work only on character strings, while others work
only on binary strings. Many work for both.BINARY and VARBINARY functions ignore multibyte
UTF-8 character boundaries.
Non-binary character string functions handle normalized multibyte UTF-8 characters, as specified
by the Unicode Consortium. Unless otherwise specified, those character string functions for which
it matters can optionally specify whether VARCHAR arguments should be interpreted as octet
(byte) sequences, or as (locale-aware) sequences of UTF-8 characters. This is accomplished by
adding "USING OCTETS" or "USING CHARACTERS" (default) as a parameter to the function.
Some character string functions are stable because in general UTF-8 case-conversion, searching
and sorting can be locale dependent. Thus, LOWER is stable, while LOWERB is immutable. The
USING OCTETS clause converts these functions into their "B" forms, so they become immutable.
If the locale is set to collation=binary, which is the default, all string functionsexcept CHAR_
LENGTH/CHARACTER_LENGTH, LENGTH, SUBSTR, and OVERLAYare converted to their
"B" forms and so are immutable.
BINARY implicitly converts to VARBINARY, so functions that take VARBINARY arguments work
with BINARY.
ASCII
Converts the first octet of a VARCHAR to an INTEGER.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
ASCII ( expression )
Parameters
expression
Notes
l
ASCII operates on UTF-8 characters, not only on single-byte ASCII characters. It continues to
get the same results for the ASCII subset of UTF-8.
Examples
Expression
Result
SELECT ASCII('A');
65
SELECT ASCII('ab');
97
SELECT ASCII(null);
SELECT ASCII('');
BIT_LENGTH
Returns the length of the string expression in bits (bytes * 8) as an INTEGER.
Behavior Type
Immutable
Syntax
BIT_LENGTH ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
BIT_LENGTH applies to the contents of VARCHAR and VARBINARY fields.
Examples
Expression
Result
SELECT BIT_LENGTH('abc'::varbinary);
24
SELECT BIT_LENGTH('abc'::binary);
SELECT BIT_LENGTH(''::varbinary);
SELECT BIT_LENGTH(''::binary);
SELECT BIT_LENGTH(null::varbinary);
SELECT BIT_LENGTH(null::binary);
SELECT BIT_LENGTH(VARCHAR 'abc');
24
24
48
24
48
24
24
24
See Also
l
CHARACTER_LENGTH
LENGTH
OCTET_LENGTH
BITCOUNT
Returns the number of one-bits (sometimes referred to as set-bits) in the given VARBINARY value.
This is also referred to as the population count.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
BITCOUNT ( expression )
Parameters
expression
Examples
SELECT BITCOUNT(HEX_TO_BINARY('0x10'));
bitcount
---------1
(1 row)
SELECT BITCOUNT(HEX_TO_BINARY('0xF0'));
bitcount
---------4
(1 row)
SELECT BITCOUNT(HEX_TO_BINARY('0xAB'))
bitcount
---------5
(1 row)
BITSTRING_TO_BINARY
Translates the given VARCHAR bitstring representation into a VARBINARY value.
Behavior Type
Immutable
Syntax
BITSTRING_TO_BINARY ( expression )
SQLReference Manual
SQL Functions
Parameters
expression
Notes
VARBINARY BITSTRING_TO_BINARY(VARCHAR) converts data from character type (in
bitstring format) to binary type. This function is the inverse of TO_BITSTRING.
BITSTRING_TO_BINARY(TO_BITSTRING(x)) = x
TO_BITSTRING(BITSTRING_TO_BINARY(x)) = x
Examples
If there are an odd number of characters in the hex value, the first character is treated as the low
nibble of the first (furthest to the left) byte.
SELECT BITSTRING_TO_BINARY('0110000101100010');
bitstring_to_binary
--------------------ab
(1 row)
BTRIM
Removes the longest string consisting only of specified characters from the start and end of a
string.
Behavior Type
Immutable
Syntax
BTRIM ( expression [ , characters-to-remove ] )
SQLReference Manual
SQL Functions
Parameters
expression
characters-to-remove
Example
SELECT BTRIM('xyxtrimyyx', 'xy');
btrim
------trim
(1 row)
See Also
l
LTRIM
RTRIM
TRIM
CHARACTER_LENGTH
The CHARACTER_LENGTH() function:
l
Returns the string length in UTF-8 characters for CHAR and VARCHAR columns
Returns the string length in bytes (octets) for BINARY and VARBINARY columns
Strips the padding from CHAR expressions but not from VARCHAR expressions
Is identical to LENGTH() for CHAR and VARCHAR. For binary types, CHARACTER_LENGTH
() is identical to OCTET_LENGTH().
Behavior Type
Immutable if USING OCTETS, stable otherwise.
Syntax
[ CHAR_LENGTH | CHARACTER_LENGTH ] ( expression , ... [ USING { CHARACTERS | OCTETS } ] )
SQLReference Manual
SQL Functions
Parameters
expression
Examples
SELECT CHAR_LENGTH('1234
char_length
------------4
(1 row)
SELECT CHAR_LENGTH('1234
char_length
------------6
(1 row)
'::VARCHAR(10));
See Also
l
BIT_LENGTH
CHR
Converts the first octet of an INTEGER to a VARCHAR.
Behavior Type
Immutable
Syntax
CHR ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
l
CHR operates on UTF-8 characters, not only on single-byte ASCII characters. It continues to
get the same results for the ASCII subset of UTF-8.
Examples
Expression
Result
SELECT CHR(65);
SELECT CHR(65+32);
SELECT CHR(null);
COLLATION
Applies a collation to two or more strings. Use theCOLLATIONfunction with ORDERBY,
GROUPBY, and equality clauses.
Syntax
COLLATION ( 'expression' [ , 'locale_or_collation_name' ] )
Parameters
'expression'
SQLReference Manual
SQL Functions
'locale_or_collation_name'
Locales
The locale used for the COLLATIONfunction can be one of the following:
l
A session locale
A locale that you specify when you call the COLLATIONfunction. If you specify the locale, HP
Vertica applies the collation associated with that locale to the data. The COLLATIONfunction
does not modify the collation for any other columns in the table.
SQLReference Manual
SQL Functions
you request a GROUPBY on string data. In this case,HP Vertica calls the COLLATION
function,whether or not you specify the function in your query.
For information about collation naming, see Collator Naming Scheme.
Examples
Collating GROUPBYResults
The following examples are based on a Premium_Customer table that contains the following data:
=> SELECT * FROM Premium_Customer;
ID | LName | FName
----+--------+--------1 | Mc Coy | Bob
2 | Mc Coy | Janice
3 | McCoy | Jody
4 | McCoy | Peter
5 | McCoy | Brendon
6 | Mccoy | Cameron
7 | Mccoy | Lisa
The first statement shows how the COLLATION function applies the collation for the EN_USlocale
to theLName column for the locale EN_US . HP Verticasorts the GROUPBY output according to the
following order:
l
The next statement shows how the COLLATION function collates theLName column for the locale
LEN_AS:
SQLReference Manual
SQL Functions
AS (Alternate Shifted) instructs the collation function that lowercase letters come before
uppercase (shifted)letters.
In the results, the last names in which "coy" starts with a lowercase letter precede the last names
where "Coy" starts with an uppercase letter.
=> SELECT * FROM Premium_Customer ORDER BY COLLATION(LName, 'LEN_AS'), FName;
ID | LName | FName
----+--------+--------6 | Mccoy | Cameron
7 | Mccoy | Lisa
1 | Mc Coy | Bob
5 | McCoy | Brendon
2 | Mc Coy | Janice
3 | McCoy | Jody
4 | McCoy | Peter
SQLReference Manual
SQL Functions
S1 indicates the strength (S) of 1 (primary). This value indicates that the collation does not need
to consider accents and case.
CONCAT
Used to concatenate two or more VARBINARY strings. The return value is of type VARBINARY.
Syntax
CONCAT ('string1','string2')
Behavior Type
Immutable
Parameters
'string1'
'string2'
Example
=> SELECT CONCAT ('ABC','DEF');
CONCAT
-------ABCDEF
(1 row)
SQLReference Manual
SQL Functions
DECODE
Compares expression to each search value one by one. If expression is equal to a search, the
function returns the corresponding result. If no match is found, the function returns default. If default
is omitted, the function returns null.
Behavior Type
Immutable
Syntax
DECODE ( expression, search, result [ , search, result ]...[, default ] );
Parameters
expression
search
result
default
Notes
DECODE is similar to the IF-THEN-ELSE and CASE expression:
CASE expressionWHEN search THEN result
[WHEN search THEN result]
[ELSE default];
The arguments can have any data type supported by HP Vertica. The result types of individual
results are promoted to the least common type that can be used to represent all of them. This leads
to a character string type, an exact numeric type, an approximate numeric type, or a DATETIME
type, where all the various result arguments must be of the same type grouping.
Example
The following example converts numeric values in the weight column from the product_dimension
table to descriptive values in the output.
SQLReference Manual
SQL Functions
SELECT
2,
50,
71,
99,
product_description, DECODE(weight,
'Light',
'Medium',
'Heavy',
'Call for help',
'N/A')
FROM product_dimension
WHERE category_description = 'Food'
AND department_description = 'Canned Goods'
AND sku_number BETWEEN 'SKU-#49750' AND 'SKU-#49999'
LIMIT 15;
product_description
|
case
-----------------------------------+--------------Brand #499 canned corn
| N/A
Brand #49900 fruit cocktail
| Medium
Brand #49837 canned tomatoes
| Heavy
Brand #49782 canned peaches
| N/A
Brand #49805 chicken noodle soup | N/A
Brand #49944 canned chicken broth | N/A
Brand #49819 canned chili
| N/A
Brand #49848 baked beans
| N/A
Brand #49989 minestrone soup
| N/A
Brand #49778 canned peaches
| N/A
Brand #49770 canned peaches
| N/A
Brand #4977 fruit cocktail
| N/A
Brand #49933 canned olives
| N/A
Brand #49750 canned olives
| Call for help
Brand #49777 canned tomatoes
| N/A
(15 rows)
GREATEST
Returns the largest value in a list of expressions.
Behavior Type
Stable
Syntax
GREATEST ( expression1, expression2, ... expression-n );
Parameters
expression1, expression2, and expression-n are the expressions to be evaluated.
SQLReference Manual
SQL Functions
Notes
l
Works for all data types, and implicitly casts similar types. See Examples.
Examples
This example returns 9 as the greatest in the list of expressions:
Note that putting quotes around the integer expressions returns the same result as the first
example:
SELECT GREATEST('7', '5', '9');
greatest
---------9
(1 row)
The next example returns FLOAT 1.5 as the greatest because the integer is implicitly cast to float:
SELECT GREATEST(1, 1.5);
greatest
---------1.5
(1 row)
SQLReference Manual
SQL Functions
See Also
l
LEAST
GREATESTB
Returns its greatest argument, using binary ordering, not UTF-8 character ordering.
Behavior Type
Immutable
Syntax
GREATESTB ( expression1, expression2, ... expression-n );
Parameters
expression1, expression2, and expression-n are the expressions to be evaluated.
Notes
l
Works for all data types, and implicitly casts similar types. See Examples.
Examples
The following command selects strae as the greatest in the series of inputs:
SQLReference Manual
SQL Functions
Note that putting quotes around the integer expressions returns the same result as the first
example:
GREATESTB
----------9
(1 row)
The next example returns FLOAT 1.5 as the greatest because the integer is implicitly cast to float:
SELECT GREATESTB(1, 1.5);
GREATESTB
----------1.5
(1 row)
SQLReference Manual
SQL Functions
GREATESTB
----------site
(1 row)
See Also
l
LEASTB
HEX_TO_BINARY
Translates the given VARCHAR hexadecimal representation into a VARBINARY value.
Behavior Type
Immutable
Syntax
HEX_TO_BINARY ( [ 0x ] expression )
Parameters
expression
0x
Optional prefix.
Notes
VARBINARY HEX_TO_BINARY(VARCHAR) converts data from character type in hexadecimal
format to binary type. This function is the inverse of TO_HEX.
HEX_TO_BINARY(TO_HEX(x)) = x)
TO_HEX(HEX_TO_BINARY(x)) = x)
If there are an odd number of characters in the hexadecimal value, the first character is treated as
the low nibble of the first (furthest to the left) byte.
Examples
If the given string begins with "0x" the prefix is ignored. For example:
SQLReference Manual
SQL Functions
If an invalid hex value is given, HP Vertica returns an invalid binary representation" error; for
example:
=> SELECT HEX_TO_BINARY('0xffgf');
ERROR: invalid hex string "0xffgf"
See Also
l
TO_HEX
HEX_TO_INTEGER
Translates the given VARCHAR hexadecimal representation into an INTEGER value.
HP Vertica completes this conversion as follows:
l
Behavior Type
Immutable
Syntax
HEX_TO_INTEGER ( [ 0x ] expression )
Parameters
expression
0x
SQLReference Manual
SQL Functions
Examples
You can enter the string with or without the Ox prefix. For example:
=> SELECT HEX_TO_INTEGER ('0aedc')
AS hex1,HEX_TO_INTEGER ('aedc') AS hex2;
hex1 | hex2
-------+------44764 | 44764
(1 row)
If you pass the function an invalid hex value, HP Vertica returns an invalid input syntax error;
for example:
=> SELECT HEX_TO_INTEGER ('0xffgf');
ERROR 3691: Invalid input syntax for numeric: "0xffgf"
See Also
l
TO_HEX
HEX_TO_BINARY
INET_ATON
Returns an integer that represents the value of the address in host byte order, given the dotted-quad
representation of a network address as a string.
Behavior Type
Immutable
Syntax
INET_ATON ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
The following syntax converts an IPv4 address represented as the string A to an integer I. INET_
ATON trims any spaces from the right of A, calls the Linux function inet_pton, and converts the result
from network byte order to host byte order using ntohl.
INET_ATON(VARCHAR A) -> INT8 I
Examples
The generated number is always in host byte order. In the following example, the number is
calculated as 209256^3 + 207256^2 + 224256 + 40.
> SELECT INET_ATON('209.207.224.40');
inet_aton
-----------3520061480
(1 row)
> SELECT INET_ATON('1.2.3.4');
inet_aton
----------16909060
(1 row)
> SELECT TO_HEX(INET_ATON('1.2.3.4'));
to_hex
--------1020304
(1 row)
See Also
l
INET_NTOA
INET_NTOA
Returns the dotted-quad representation of the address as a VARCHAR, given a network address as
an integer in network byte order.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
INET_NTOA ( expression )
Parameters
expression
Notes
The following syntax converts an IPv4 address represented as integer I to a string A.
INET_NTOA converts I from host byte order to network byte order using htonl, and calls the Linux
function inet_ntop.
INET_NTOA(INT8 I) -> VARCHAR A
Examples
> SELECT INET_NTOA(16909060);
inet_ntoa
----------1.2.3.4
(1 row)
> SELECT INET_NTOA(03021962);
inet_ntoa
------------0.46.28.138
(1 row)
See Also
l
INET_ATON
INITCAP
Starting in Release 5.1, this function treats the string argument as a UTF-8 encoded string, rather
than depending on the collation setting of the locale (for example, collation=binary) to identify the
encoding. Prior to Release 5.1, the behavior type of this function was stable.
Capitalizes first letter of each alphanumeric word and puts the rest in lowercase.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
INITCAP ( expression )
Parameters
expression
Notes
l
INITCAP is restricted to 32750 octet inputs, since it is possible for the UTF-8 representation of
result to double in size.
Examples
Expression
Result
Linux Tutorial
SELECT INITCAP('');
SELECT INITCAP(null);
INITCAPB
Capitalizes first letter of each alphanumeric word and puts the rest in lowercase. Multibyte
characters are not converted and are skipped.
Behavior Type
Immutable
Syntax
INITCAPB ( expression )
SQLReference Manual
SQL Functions
Parameters
expression
Notes
Depends on collation setting of the locale.
Examples
Expression
Result
SELECT INITCAPB('tudiant');
Tudiant
Linux Tutorial
SELECT INITCAPB('');
SELECT INITCAPB(null);
INSERT
Inserts a character string into a specified location in another character string.
Syntax
INSERT( 'string1', n, m, 'string2');
Behavior Type
Immutable
Parameters
string1
A character of type INTEGER that represents the starting point for the insertion within
string1. You specify the number of characters from the first character in string1 as the
starting point for the insertion. For example, to insert characters before "c", in the string
"abcdef," enter 3.
SQLReference Manual
SQL Functions
A character of type INTEGER that represents the number of characters in string1 (if
any) that should be replaced by the insertion. For example,if you want the insertion to
replace the letters "cd" in the string "abcdef, " enter 2.
string2
Example
The following example changes the string Warehouse to Storehouse using the INSERT function:
=> SELECT INSERT ('Warehouse',1,3,'Stor');
INSERT
-----------Storehouse
(1 row)
INSTR
Starting in Release 5.1, this function treats the string argument as a UTF-8 encoded string, rather
than depending on the collation setting of the locale (for example, collation=binary) to identify the
encoding. Prior to Release 5.1, the behavior type of this function was stable.
Searches string for substring and returns an integer indicating the position of the character in string
that is the first character of this occurrence. The return value is based on the character position of
the identified character.
Behavior Type
Immutable
Syntax
INSTR ( string , substring [, position [, occurrence ] ] )
Parameters
string
substring
SQLReference Manual
SQL Functions
position
Nonzero integer indicating the character of string where HP Vertica begins the
search. If position is negative, then HP Vertica counts backward from the end of
string and then searches backward from the resulting position. The first character
of string occupies the default position 1, and position cannot be 0.
occurrence
Notes
Both position and occurrence must be of types that can resolve to an integer. The default values of
both parameters are 1, meaning HP Vertica begins searching at the first character of string for the
first occurrence of substring. The return value is relative to the beginning of string, regardless of the
value of position, and is expressed in characters.
If the search is unsuccessful (that is, if substring does not appear occurrence times after the
position character of string, the return value is 0.
Examples
The first example searches forward in string abc for substring b. The search returns the position in
abc where b occurs, or position 2. Because no position parameters are given, the default search
starts at a, position 1.
SELECT INSTR('abc', 'b');
INSTR
------2
(1 row)
The following three examples use character position to search backward to find the position of a
substring.
Note: Although it might seem intuitive that the function returns a negative integer, the position
of n occurrence is read left to right in the sting, even though the search happens in reverse
(from the endor right sideof the string).
In the first example, the function counts backward one character from the end of the string, starting
with character c. The function then searches backward for the first occurrence of a, which it finds
it in the first position in the search string.
SELECT INSTR('abc', 'a', -1);
SQLReference Manual
SQL Functions
INSTR
------1
(1 row)
In the second example, the function counts backward one byte from the end of the string, starting
with character c. The function then searches backward for the first occurrence of a, which it finds
it in the first position in the search string.
SELECT INSTR(VARBINARY 'abc', VARBINARY 'a', -1);
INSTR
------1
(1 row)
In the third example, the function counts backward one character from the end of the string, starting
with character b, and searches backward for substring bc, which it finds in the second position of
the search string.
SELECT INSTR('abcb', 'bc', -1);
INSTR
------2
(1 row)
In the fourth example, the function counts backward one character from the end of the string,
starting with character b, and searches backward for substring bcef, which it does not find. The
result is 0.
SELECT INSTR('abcb', 'bcef', -1);
INSTR
------0
(1 row)
In the fifth example, the function counts backward one byte from the end of the string, starting with
character b, and searches backward for substring bcef, which it does not find. The result is 0.
SELECT INSTR(VARBINARY 'abcb', VARBINARY 'bcef', -1);
INSTR
------0
(1 row)
SQLReference Manual
SQL Functions
INSTR
------3
(1 row)
INSTRB
Searches string for substring and returns an integer indicating the octet position within string that is
the first occurrence. The return value is based on the octet position of the identified byte.
Behavior Type
Immutable
Syntax
INSTRB ( string , substring [, position [, occurrence ] ] )
Parameters
string
substring
position
Is a nonzero integer indicating the character of string where HP Vertica begins the
search. If position is negative, then HP Vertica counts backward from the end of
string and then searches backward from the resulting position. The first byte of
string occupies the default position 1, and position cannot be 0.
occurrence
Notes
Both position and occurrence must be of types that can resolve to an integer. The default values of
both parameters are 1, meaning HP Vertica begins searching at the first byte of string for the first
SQLReference Manual
SQL Functions
occurrence of substring. The return value is relative to the beginning of string, regardless of the
value of position, and is expressed in octets.
If the search is unsuccessful (that is, if substring does not appear occurrence times after the
position character of string, then the return value is 0.
Example
SELECT INSTRB('strae', '');
INSTRB
-------5
(1 row)
See Also
l
INSTR
ISUTF8
Tests whether a string is a valid UTF-8 string. Returns true if the string conforms to UTF-8
standards, and false otherwise. This function is useful to test strings for UTF-8 compliance before
passing them to one of the regular expression functions, such as REGEXP_LIKE, which expect
UTF-8 characters by default.
ISUTF8 checks for invalid UTF8 byte sequences, according to UTF-8 rules:
l
invalid bytes
an Overload Encoding
The presence of an invalid UTF8 byte sequence results in a return value of false.
Syntax
ISUTF8( string );
Parameters
string
SQLReference Manual
SQL Functions
Examples
=> SELECT ISUTF8(E'\xC2\xBF'); -- UTF-8 INVERTED QUESTION MARK ISUTF8
-------t
(1 row)
=> SELECT ISUTF8(E'\xC2\xC0'); -- UNDEFINED UTF-8 CHARACTER
ISUTF8
-------f
(1 row)
LEAST
Returns the smallest value in a list of expressions.
Behavior Type
Stable
Syntax
LEAST ( expression1, expression2, ... expression-n );
Parameters
expression1, expression2, and expression-n are the expressions to be evaluated.
Notes
l
Works for all data types, and implicitly casts similar types. See Examples below.
Examples
This example returns 5 as the least:
SELECT LEAST(7, 5, 9);
least
------5
(1 row)
Putting quotes around the integer expressions returns the same result as the first example:
SQLReference Manual
SQL Functions
In the above example, the values are being compared as strings, so '10' would be less than '2'.
The next example returns 1.5, as INTEGER 2 is implicitly cast to FLOAT:
SELECT LEAST(2, 1.5);
least
------1.5
(1 row)
See Also
l
GREATEST
LEASTB
Returns the function's least argument, using binary ordering, not UTF-8 character ordering.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
LEASTB ( expression1, expression2, ... expression-n );
Parameters
expression1, expression2, and expression-n are the expressions to be evaluated.
Notes
l
Works for all data types, and implicitly casts similar types. See Examples below.
Examples
The following command selects strasse as the least in the series of inputs:
SELECT LEASTB('strae', 'strasse');
LEASTB
--------strasse
(1 row)
Putting quotes around the integer expressions returns the same result as the first example:
SELECT LEASTB('7', '5', '9');
LEASTB
-------5
(1 row)
In the above example, the values are being compared as strings, so '10' would be less than '2'.
The next example returns 1.5, as INTEGER 2 is implicitly cast to FLOAT:
SQLReference Manual
SQL Functions
The following example returns 'analytic' as the least in the series of inputs:
SELECT LEASTB('vertica', 'analytic', 'database');
LEASTB
---------analytic
(1 row)
See Also
l
GREATESTB
LEFT
Returns the specified characters from the left side of a string.
Behavior Type
Immutable
Syntax
LEFT ( string , length )
Parameters
string
length
SQLReference Manual
SQL Functions
Examples
SELECT LEFT('vertica', 3);
left
-----ver
(1 row)
SELECT LEFT('strae', 5);
LEFT
------stra
(1 row)
See Also
l
SUBSTR
LENGTH
The LENGTH() function:
l
Returns the string length in UTF-8 characters for CHAR and VARCHAR columns
Returns the string length in bytes (octets) for BINARY and VARBINARY columns
Strips the padding from CHAR expressions but not from VARCHAR expressions
Behavior Type
Immutable
Syntax
LENGTH ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Examples
Expression
Result
SELECT LENGTH('1234
'::CHAR(10));
SELECT LENGTH('1234
'::VARCHAR(10));
SELECT LENGTH('1234
'::BINARY(10));
10
SELECT LENGTH('1234
'::VARBINARY(10));
See Also
l
BIT_LENGTH
LOWER
Starting in Release 5.1, this function treats the string argument as a UTF-8 encoded string, rather
than depending on the collation setting of the locale (for example, collation=binary) to identify the
encoding. Prior to Release 5.1, the behavior type of this function was stable.
Returns a VARCHAR value containing the argument converted to lowercase letters.
Behavior Type
Immutable
Syntax
LOWER ( expression )
Parameters
expression
Notes
LOWER is restricted to 32750 octet inputs, since it is possible for the UTF-8 representation of
result to double in size.
SQLReference Manual
SQL Functions
Examples
SELECT LOWER('AbCdEfG');
lower
---------abcdefg
(1 row)
SELECT LOWER('The Cat In The Hat');
lower
-------------------the cat in the hat
(1 row)
dbadmin=> SELECT LOWER('TUDIANT');
LOWER
---------tudiant
(1 row)
LOWERB
Returns a character string with each ASCII character converted to lowercase. Multibyte characters
are not converted and are skipped.
Behavior Type
Immutable
Syntax
LOWERB ( expression )
Parameters
expression
Examples
In the following example, the multibyte UTF-8 character is not converted to lowercase:
SELECT LOWERB('TUDIANT');
LOWERB
---------tudiant
(1 row)
SQLReference Manual
SQL Functions
SELECT LOWER('TUDIANT');
LOWER
---------tudiant
(1 row)
SELECT LOWERB('AbCdEfG'); LOWERB
--------abcdefg
(1 row)
SELECT LOWERB('The Vertica Database');
LOWERB
---------------------the vertica database
(1 row)
LPAD
Returns a VARCHAR value representing a string of a specific length filled on the left with specific
characters.
Behavior Type
Immutable
Syntax
LPAD ( expression , length [ , fill ] )
Parameters
expression
length
fill
Examples
SELECT LPAD('database', 15, 'xzy');
lpad
----------------xzyxzyxdatabase
(1 row)
If the string is already longer than the specified length it is truncated on the right:
SQLReference Manual
SQL Functions
LTRIM
Returns a VARCHAR value representing a string with leading blanks removed from the left side
(beginning).
Behavior Type
Immutable
Syntax
LTRIM ( expression [ , characters ] )
Parameters
expression
characters
(CHAR or VARCHAR) specifies the characters to remove from the left side of
expression. The default is the space character.
Examples
SELECT LTRIM('zzzyyyyyyxxxxxxxxtrim', 'xyz');
LTRIM
------trim
(1 row)
See Also
l
BTRIM
RTRIM
TRIM
SQLReference Manual
SQL Functions
MD5
Calculates the MD5 hash of string, returning the result as a VARCHAR string in hexadecimal.
Behavior Type
Immutable
Syntax
MD5 ( string )
Parameters
string
Examples
=> SELECT MD5('123');
md5
---------------------------------202cb962ac59075b964b07152d234b70
(1 row)
=> SELECT MD5('Vertica'::bytea);
md5
---------------------------------fc45b815747d8236f9f6fdb9c2c3f676
(1 row)
OCTET_LENGTH
Takes one argument as an input and returns the string length in octets for all string types.
Behavior Type
Immutable
Syntax
OCTET_LENGTH ( expression )
SQLReference Manual
SQL Functions
Parameters
expression
Notes
l
If the data type of expression is a CHAR, VARCHAR or VARBINARY, the result is the same as
the actual length of expression in octets. For CHAR, the length does not include any trailing
spaces.
If the data type of expression is BINARY, the result is the same as the fixed-length of
expression.
Examples
Expression
Result
');
1234');
');
1234');
SELECT OCTET_LENGTH('abc'::VARBINARY);
');
SELECT OCTET_LENGTH(''::BINARY);
SELECT OCTET_LENGTH(null::VARBINARY);
SELECT OCTET_LENGTH(null::BINARY);
SQLReference Manual
SQL Functions
See Also
l
BIT_LENGTH
CHARACTER_LENGTH
LENGTH
OVERLAY
Returns a VARCHAR value representing a string having had a substring replaced by another string.
Behavior Type
Immutable if using OCTETS, Stable otherwise
Syntax
OVERLAY ( expression1 PLACING expression2 FROM position
... [ FOR extent ]
... [ USING { CHARACTERS | OCTETS } ] )
Parameters
expression1
expression2
position
extent
Examples
SELECT OVERLAY('123456789' PLACING 'xxx' FROM 2);
OVERLAY
-----------
SQLReference Manual
SQL Functions
1xxx56789
(1 row)
SELECT OVERLAY('123456789' PLACING 'XXX' FROM 2 USING OCTETS);
OVERLAY
----------1XXX56789
(1 row)
SELECT OVERLAY('123456789' PLACING 'xxx' FROM 2 FOR 4);
OVERLAY
---------1xxx6789
(1 row)
SELECT OVERLAY('123456789' PLACING 'xxx' FROM 2 FOR 5);
OVERLAY
--------1xxx789
(1 row)
SELECT OVERLAY('123456789' PLACING 'xxx' FROM 2 FOR 6);
OVERLAY
--------1xxx89
(1 row)
OVERLAYB
Returns an octet value representing a string having had a substring replaced by another string.
Behavior Type
Immutable
Syntax
OVERLAYB ( expression1, expression2, position [ , extent ] )
Parameters
expression1
expression2
position
(INTEGER) is the octet position (counting from one) at which to begin the overlay
extent
SQLReference Manual
SQL Functions
Notes
The OVERLAYB function treats the multibyte character string as a string of octets (bytes) and use
octet numbers as incoming and outgoing position specifiers and lengths.The strings themselves
are type VARCHAR, but they treated as if each byte was a separate character.
Examples
SELECT OVERLAYB('123456789', '', 2);
OVERLAYB
---------189
(1 row)
SELECT OVERLAYB('123456789', '', 2);
OVERLAYB
---------189
(1 row)
SELECT OVERLAYB('123456789', 'xxx', 2);
OVERLAYB
----------1xxx56789
(1 row)
SELECT OVERLAYB('123456789', 'xxx', 2, 4);
OVERLAYB
---------1xxx6789
(1 row)
SELECT OVERLAYB('123456789', 'xxx', 2, 5);
OVERLAYB
--------1xxx789
(1 row)
SELECT OVERLAYB('123456789', 'xxx', 2, 6);
OVERLAYB
--------1xxx89
(1 row)
POSITION
Starting in Release 5.1, this function treats the string argument as a UTF-8 encoded string, rather
than depending on the collation setting of the locale (for example, collation=binary) to identify the
encoding. Prior to Release 5.1, the behavior type of this function was stable.
Returns an INTEGER value representing the character location of a specified substring with a
string (counting from one).
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax 1
POSITION ( substring IN string [ USING { CHARACTERS | OCTETS } ] )
Parameters
substring
string
Syntax 2
POSITION ( substring IN string )
Parameters
substring
string
Notes
l
When the string and substring are CHAR or VARCHAR, the return value is based on either the
character or octet position of the substring.
When the string and substring are VARBINARY, the return value is always based on the octet
position of the substring.
The string and substring must be consistent. Do not mix VARBINARY with CHAR or
VARCHAR.
SQLReference Manual
SQL Functions
Examples
SELECT POSITION('' IN 'tudiant' USING CHARACTERS);
position
---------1
(1 row)
SELECT POSITION('' IN 'strae' USING OCTETS);
position
---------5
(1 row)
SELECT POSITION('c' IN 'abcd' USING CHARACTERS);
position
---------3
(1 row)
SELECT POSITION(VARBINARY '456' IN VARBINARY '123456789');
position
---------4
(1 row)
SELECT POSITION('n' in 'Len') as 'default',
POSITIONB('Len', 'n') as 'POSITIONB',
POSITION('n' in 'Len' USING CHARACTERS) as 'pos_chars',
POSITION('n' in 'Len' USING OCTETS) as 'pos_oct',INSTR('Len','n'),
INSTRB('Len','n'),REGEXP_INSTR('Len','n');
-[ RECORD 1 ]+-default
| 4
POSITIONB
| 5
pos_chars
| 4
pos_oct
| 5
INSTR
| 4
INSTRB
| 5
REGEXP_INSTR | 4
POSITIONB
Returns an INTEGER value representing the octet location of a specified substring with a string
(counting from one).
Behavior Type
Immutable
Syntax
POSITIONB ( string, substring )
SQLReference Manual
SQL Functions
Parameters
string
substring
Examples
SELECT POSITIONB('strae', 'e');
POSITIONB
----------5
(1 row)
SELECT POSITIONB('tudiant', '');
position
---------1
(1 row)
QUOTE_IDENT
Returns the given string, suitably quoted, to be used as an identifier in a SQL statement string.
Quotes are added only if necessary; that is, if the string contains non-identifier characters, is a SQL
keyword, such as '1time', 'Next week' and 'Select'. Embedded double quotes are doubled.
Behavior Type
Immutable
Syntax
QUOTE_IDENT( string )
Parameters
string
Notes
l
SQL identifiers, such as table and column names, are stored as created, and references to them
are resolved using case-insensitive compares. Thus, you do not need to double-quote mixed-
SQLReference Manual
SQL Functions
case identifiers.
l
HP Vertica quotes all currently-reserved keywords, even those not currently being used.
Examples
Quoted identifiers are case-insensitive, and HP Vertica does not supply the quotes:
SELECT QUOTE_IDENT('VErtIcA');
QUOTE_IDENT
------------VErtIcA
(1 row)
SELECT QUOTE_IDENT('Vertica database');
QUOTE_IDENT
-------------------"Vertica database"
(1 row)
The following example uses the SQL keyword, SELECT; results are double quoted:
SELECT QUOTE_IDENT('select');
QUOTE_IDENT
------------"select"
(1 row)
QUOTE_LITERAL
Returns the given string, suitably quoted, to be used as a string literal in a SQL statement string.
Embedded single quotes and backslashes are doubled.
Behavior Type
Immutable
Syntax
QUOTE_LITERAL ( string )
SQLReference Manual
SQL Functions
Parameters
string
Notes
HP Vertica recognizes two consecutive single quotes within a string literal as one single quote
character. For example, 'You''re here!'. This is the SQL standard representation and is
preferred over the form, 'You\'re here!', as backslashes are not parsed as before.
Examples
SELECT QUOTE_LITERAL('You''re here!');
QUOTE_LITERAL
----------------'You''re here!'
(1 row)
SELECT QUOTE_LITERAL('You\'re here!');
WARNING: nonstandard use of \' in a string literal at character 22
HINT: Use '' to write quotes in strings, or use the escape string syntax (E'\'').
See Also
l
REPEAT
Returns a VARCHAR or VARBINARY value that repeats the given value COUNT times, given a
value and a count this function.
If the return value is truncated the given value might not be repeated count times, and the last
occurrence of the given value might be truncated.
Behavior Type
Immutable
Syntax
REPEAT ( string , repetitions )
SQLReference Manual
SQL Functions
Parameters
string
repetitions
Notes
If the repetitions field depends on the contents of a column (is not a constant), then the repeat
operator maximum length is 65000 bytes. You can add a cast of the repeat to cast the result down
to a size big enough for your purposes (reflects the actual maximum size) so you can do other
things with the result.
REPEAT () and || check for result strings longer than 65000. REPEAT () silently truncates to 65000
octets, and || reports an error (including the octet length).
Examples
The following example repeats vmart three times:
SELECT REPEAT ('vmart', 3);
repeat
----------------vmartvmartvmart
(1 row)
If you know that colx can never be greater than 3, the solution is to add a cast (::VARCHAR(3)):
SELECT '123456' || REPEAT('a', colx)::VARCHAR(3);
REPLACE
Replaces all occurrences of characters in a string with another set of characters.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
REPLACE ( string , target , replacement )
Parameters
string
target
replacement
Examples
SELECT REPLACE('Documentation%20Library', '%20', ' ');
replace
----------------------Documentation Library
(1 row)
SELECT REPLACE('This & That', '&', 'and');
replace
--------------This and That
(1 row)
SELECT REPLACE('strae', '', 'ss');
REPLACE
--------strasse
(1 row)
RIGHT
Returns the specified characters from the right side of a string.
Behavior Type
Immutable
Syntax
RIGHT ( string , length )
SQLReference Manual
SQL Functions
Parameters
string
length
Examples
The following command returns the last three characters of the string 'vertica':
SELECT RIGHT('vertica', 3);|
right
------ica
(1 row)
The following command returns the last two characters of the string 'strae':
SELECT RIGHT('strae', 2);
RIGHT
------e
(1 row)
See Also
l
SUBSTR
RPAD
Returns a VARCHAR value representing a string of a specific length filled on the right with specific
characters.
Behavior Type
Immutable
Syntax
RPAD ( expression , length [ , fill ] )
SQLReference Manual
SQL Functions
Parameters
expression
length
fill
Examples
SELECT RPAD('database', 15, 'xzy');
rpad
----------------databasexzyxzyx
(1 row)
If the string is already longer than the specified length it is truncated on the right:
SELECT RPAD('database', 6, 'xzy');
rpad
-------databa
(1 row)
RTRIM
Returns a VARCHAR value representing a string with trailing blanks removed from the right side
(end).
Behavior Type
Immutable
Syntax
RTRIM ( expression [ , characters ] )
Parameters
expression
SQLReference Manual
SQL Functions
characters
(CHAR or VARCHAR) specifies the characters to remove from the right side of
expression. The default is the space character.
Examples
SELECT RTRIM('trimzzzyyyyyyxxxxxxxx', 'xyz');
ltrim
------trim
(1 row)
See Also
l
BTRIM
LTRIM
TRIM
SPACE
Inserts blank spaces into a specified location within a character string.
Behavior Type
Immutable
Syntax
SELECT INSERT( 'string1', || SPACE (n) || 'string2');
Parameters
string1
string2
(VARCHAR) Is the remainder of the string that appears after the inserted spaces
Example
The following example inserts 10 spaces between the strings 'x' and 'y':
SQLReference Manual
SQL Functions
SPLIT_PART
Starting in Release 5.1, this function treats the string argument as a UTF-8 encoded string, rather
than depending on the collation setting of the locale (for example, collation=binary) to identify the
encoding. Prior to Release 5.1, the behavior type of this function was stable.
Splits string on the delimiter and returns the location of the beginning of the given field (counting
from one).
Behavior Type
Immutable
Syntax
SPLIT_PART ( string , delimiter , field )
Parameters
string
delimiter
field
Notes
Use this with the character form of the subfield.
Examples
The specified integer of 2 returns the second string, or def.
SELECT SPLIT_PART('abc~@~def~@~ghi', '~@~', 2);
SPLIT_PART
-----------def
SQLReference Manual
SQL Functions
(1 row)
In the next example, specify 3, which returns the third string, or 789.
SELECT SPLIT_PART('123~|~456~|~789', '~|~', 3);
SPLIT_PART
-----------789
(1 row)
The tildes are for readability only. Omitting them returns the same results:
SELECT SPLIT_PART('123|456|789', '|', 3);
SPLIT_PART
-----------789
(1 row)
See what happens if you specify an integer that exceeds the number of strings: No results.
SELECT SPLIT_PART('123|456|789', '|', 4);
SPLIT_PART
-----------(1 row)
SPLIT_PARTB
Splits string on the delimiter and returns the location of the beginning of the given field (counting
from one). The VARCHAR arguments are treated as octets rather than UTF-8 characters.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
SPLIT_PARTB ( string , delimiter , field )
Parameters
string
delimiter
field
Notes
Use this function with the character form of the subfield.
Examples
The specified integer of 3 returns the third string, or soupon.
SELECT SPLIT_PARTB('strae~@~caf~@~soupon', '~@~', 3);
SPLIT_PARTB
------------soupon
(1 row)
The tildes are for readability only. Omitting them returns the same results:
SELECT SPLIT_PARTB('strae @ caf @ soupon', '@', 3);
SPLIT_PARTB
------------soupon
(1 row)
See what happens if you specify an integer that exceeds the number of strings: No results.
SELECT SPLIT_PARTB('strae @ caf @ soupon', '@', 4);
SPLIT_PARTB
------------(1 row)
SQLReference Manual
SQL Functions
STRPOS
Starting in Release 5.1, this function treats the string argument as a UTF-8 encoded string, rather
than depending on the collation setting of the locale (for example, collation=binary) to identify the
encoding. Prior to Release 5.1, the behavior type of this function was stable.
Returns an INTEGER value representing the character location of a specified substring within a
string (counting from one).
Behavior Type
Immutable
Syntax
STRPOS ( string , substring )
Parameters
string
substring
Notes
STRPOS is similar to POSITION although POSITION allows finding by characters and by octet.
If the string is not found, the return value is zero.
Examples
SELECT STRPOS('abcd','c');
strpos
-------3
(1 row)
SQLReference Manual
SQL Functions
STRPOSB
Returns an INTEGER value representing the location of a specified substring within a string,
counting from one, where each octet in the string is counted (as opposed to characters).
Behavior Type
Immutable
Syntax
STRPOSB ( string , substring )
Parameters
string
substring
Notes
STRPOSB is identical to POSITIONB except for the order of the arguments.
Examples
=> SELECT STRPOSB('strae', 'e');
STRPOSB
--------7
(1 row)
=> SELECT STRPOSB('tudiant', 'tud');
STRPOSB
--------3
(1 row)
SUBSTR
Returns VARCHAR or VARBINARY value representing a substring of a specified string.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
SUBSTR ( string , position [ , extent ] )
Parameters
string
position
extent
Notes
SUBSTR truncates DOUBLE PRECISION input values.
Examples
=> SELECT SUBSTR('abc'::binary(3),1);
substr
-------abc
(1 row)
=> SELECT SUBSTR('123456789', 3, 2);
substr
-------34
(1 row)
=> SELECT SUBSTR('123456789', 3);
substr
--------3456789
(1 row)
=> SELECT SUBSTR(TO_BITSTRING(HEX_TO_BINARY('0x10')), 2, 2);
substr
-------00
(1 row)
=> SELECT SUBSTR(TO_HEX(10010), 2, 2);
substr
-------71
(1 row)
SQLReference Manual
SQL Functions
SUBSTRB
Returns an octet value representing the substring of a specified string.
Behavior Type
Immutable
Syntax
SUBSTRB ( string , position [ , extent ] )
Parameters
string
position
extent
Notes
l
This function treats the multibyte character string as a string of octets (bytes) and uses octet
numbers as incoming and outgoing position specifiers and lengths.The strings themselves are
type VARCHAR, but they treated as if each octet were a separate character.
Examples
=> SELECT SUBSTRB('soupon', 5);
SUBSTRB
--------on
(1 row)
=> SELECT SUBSTRB('soupon', 5, 2);
SUBSTRB
--------
(1 row)
SQLReference Manual
SQL Functions
=>SELECT SUBSTRB('abc'::binary(3),1);
ERROR: function substrb(binary, int) does not exist, or permission is denied for substrb
(binary, int)
HINT: No function matches the given name and argument types. You may need to add explicit
type casts.
SUBSTRING
Returns a value representing a substring of the specified string at the given position, given a value,
a position, and an optional length.
Behavior Type
Immutable if USING OCTETS, stable otherwise.
Syntax
SUBSTRING ( string , position [ , length ]
... [USING {CHARACTERS | OCTETS } ] )
SUBSTRING ( string FROM position [ FOR length ]
... [USING { CHARACTERS | OCTETS } ] )
Parameters
string
position
length
SQLReference Manual
SQL Functions
Notes
l
Neither length nor position can be negative, and the position cannot be zero because it is one
based. If these forms are violated, the system returns an error:
SELECT SUBSTRING('ab'::binary(2), -1, 2);
ERROR: negative or zero substring start position not allowed
Examples
=> SELECT SUBSTRING('abc'::binary(3),1);
SUBSTRING
----------abc
(1 row)
=> SELECT SUBSTRING('soupon', 5, 2 USING CHARACTERS);
SUBSTRING
----------o
(1 row)
=> SELECT SUBSTRING('soupon', 5, 2 USING OCTETS);
SUBSTRB
--------
(1 row)
TO_BITSTRING
Returns a VARCHAR that represents the given VARBINARY value in bitstring format.
Behavior Type
Immutable
Syntax
TO_BITSTRING ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
VARCHAR TO_BITSTRING(VARBINARY) converts data from binary type to character type
(where the character representation is the bitstring format). This function is the inverse of
BITSTRING_TO_BINARY:
TO_BITSTRING(BITSTRING_TO_BINARY(x)) = x)
BITSTRING_TO_BINARY(TO_BITSTRING(x)) = x)
Examples
SELECT TO_BITSTRING('ab'::BINARY(2));
to_bitstring
-----------------0110000101100010
(1 row)
SELECT TO_BITSTRING(HEX_TO_BINARY('0x10'));
to_bitstring
-------------00010000
(1 row)
SELECT TO_BITSTRING(HEX_TO_BINARY('0xF0'));
to_bitstring
-------------11110000
(1 row)
See Also
l
BITCOUNT
BITSTRING_TO_BINARY
TO_HEX
Returns a VARCHAR or VARBINARY representing the hexadecimal equivalent of a number.
Behavior Type
Immutable
Syntax
TO_HEX ( number )
SQLReference Manual
SQL Functions
Parameters
number
Notes
VARCHAR TO_HEX(INTEGER) and VARCHAR TO_HEX(VARBINARY) are similar. The
function converts data from binary type to character type (where the character representation is in
hexadecimal format). This function is the inverse of HEX_TO_BINARY.
TO_HEX(HEX_TO_BINARY(x)) = x);
HEX_TO_BINARY(TO_HEX(x)) = x);
Examples
SELECT TO_HEX(123456789);
TO_HEX
--------75bcd15
(1 row)
For VARBINARY inputs, the returned value is not preceded by "0x". For example:
SELECT TO_HEX('ab'::binary(2));
TO_HEX
-------6162
(1 row)
TRANSLATE
Replaces individual characters in string_to_replace with other characters.
Behavior Type
Immutable
Syntax
TRANSLATE ( string_to_replace , from_string , to_string );
SQLReference Manual
SQL Functions
Parameters
string_to_replace
String to be translated.
from_string
to_string
Example
SELECT TRANSLATE('strae', '', 'ss');
TRANSLATE
----------strase
(1 row)
TRIM
Combines the BTRIM, LTRIM, and RTRIM functions into a single function.
Behavior Type
Immutable
Syntax
TRIM ( [ [ LEADING | TRAILING | BOTH ] characters FROM ] expression )
Parameters
LEADING
Removes the specified characters from the left side of the string
TRAILING
Removes the specified characters from the right side of the string
BOTH
Removes the specified characters from both sides of the string (default)
characters
expression
SQLReference Manual
SQL Functions
Examples
SELECT '-' || TRIM(LEADING 'x' FROM 'xxdatabasexx') || '-';
?column?
--------------databasexx(1 row)
SELECT '-' || TRIM(TRAILING 'x' FROM 'xxdatabasexx') || '-';
?column?
--------------xxdatabase(1 row)
SELECT '-' || TRIM(BOTH 'x' FROM 'xxdatabasexx') || '-';
?column?
------------database(1 row)
SELECT '-' || TRIM('x' FROM 'xxdatabasexx') || '-';
?column?
------------database(1 row)
SELECT '-' || TRIM(LEADING FROM '
?column?
--------------database (1 row)
SELECT '-' || TRIM('
?column?
------------database(1 row)
database
database
') || '-';
') || '-';
See Also
l
BTRIM
LTRIM
RTRIM
UPPER
Starting in Release 5.1, this function treats the string argument as a UTF-8 encoded string, rather
than depending on the collation setting of the locale (for example, collation=binary) to identify the
encoding. Prior to Release 5.1, the behavior type of this function was stable.
Returns a VARCHAR value containing the argument converted to uppercase letters.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
UPPER ( expression )
Parameters
expression
Notes
UPPER is restricted to 32750 octet inputs, since it is possible for the UTF-8 representation of result
to double in size.
Examples
=> SELECT UPPER('AbCdEfG');
UPPER
---------ABCDEFG
(1 row)
=> SELECT UPPER('tudiant');
UPPER
---------TUDIANT
(1 row)
UPPERB
Returns a character string with each ASCII character converted to uppercase. Multibyte characters
are not converted and are skipped.
Behavior Type
Immutable
Syntax
UPPERB ( expression )
SQLReference Manual
SQL Functions
Parameters
expression
Examples
In the following example, the multibyte UTF-8 character is not converted to uppercase:
=> SELECT UPPERB('tudiant');
UPPERB
---------TUDIANT
(1 row)
=> SELECT UPPERB('AbCdEfG');
UPPERB
--------ABCDEFG
(1 row)
=> SELECT UPPERB('The Vertica Database');
UPPERB
---------------------THE VERTICA DATABASE
(1 row)
V6_ATON
Converts an IPv6 address represented as a character string to a binary string.
Behavior Type
Immutable
Syntax
V6_ATON ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
The following syntax converts an IPv6 address represented as the character string A to a binary
string B.
V6_ATON trims any spaces from the right of A and calls the Linux function inet_pton.
V6_ATON(VARCHAR A) -> VARBINARY(16) B
If A has no colons it is prepended with '::ffff:'. If A is NULL, too long, or if inet_pton returns an error,
the result is NULL.
Examples
SELECT V6_ATON('2001:DB8::8:800:200C:417A');
v6_aton
-----------------------------------------------------\001\015\270\000\000\000\000\000\010\010\000 \014Az
(1 row)
SELECT V6_ATON('1.2.3.4');
v6_aton
-----------------------------------------------------------------\000\000\000\000\000\000\000\000\000\000\377\377\001\002\003\004
(1 row)
SELECT TO_HEX(V6_ATON('2001:DB8::8:800:200C:417A'));
to_hex
---------------------------------20010db80000000000080800200c417a
(1 row)
SELECT V6_ATON('::1.2.3.4');
v6_aton
-----------------------------------------------------------------\000\000\000\000\000\000\000\000\000\000\000\000\001\002\003\004
(1 row)
See Also
l
V6_NTOA
V6_NTOA
Converts an IPv6 address represented as varbinary to a character string.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
V6_NTOA ( expression )
Parameters
expression
Notes
The following syntax converts an IPv6 address represented as VARBINARY B to a string A.
V6_NTOA right-pads B to 16 bytes with zeros, if necessary, and calls the Linux function inet_ntop.
V6_NTOA(VARBINARY B) -> VARCHAR A
Examples
> SELECT V6_NTOA(' \001\015\270\000\000\000\000\000\010\010\000 \014Az');
v6_ntoa
--------------------------2001:db8::8:800:200c:417a
(1 row)
> SELECT V6_NTOA(V6_ATON('1.2.3.4'));
v6_ntoa
--------1.2.3.4
(1 row)
> SELECT V6_NTOA(V6_ATON('::1.2.3.4'));
v6_ntoa
----------::1.2.3.4
(1 row)
See Also
l
V6_ATON
SQLReference Manual
SQL Functions
V6_SUBNETA
Calculates a subnet address in CIDR (Classless Inter-Domain Routing) format from a binary or
alphanumeric IPv6 address.
Behavior Type
Immutable
Syntax
V6_SUBNETA ( expression1, expression2 )
Parameters
expression1
expression2
Notes
The following syntax calculates a subnet address in CIDR format from a binary or varchar IPv6
address.
V6_SUBNETA masks a binary IPv6 address B so that the N leftmost bits form a subnet address,
while the remaining rightmost bits are cleared. It then converts to an alphanumeric IPv6 address,
appending a slash and N.
V6_SUBNETA(BINARY B, INT8 N) -> VARCHAR C
The following syntax calculates a subnet address in CIDR format from an alphanumeric IPv6
address.
V6_SUBNETA(VARCHAR A, INT8 N) -> V6_SUBNETA(V6_ATON(A), N) -> VARCHAR C
Examples
> SELECT V6_SUBNETA(V6_ATON('2001:db8::8:800:200c:417a'), 28);
v6_subneta
--------------2001:db0::/28
SQLReference Manual
SQL Functions
(1 row)
See Also
l
V6_SUBNETN
V6_SUBNETN
Calculates a subnet address in CIDR (Classless Inter-Domain Routing) format from a varbinary or
alphanumeric IPv6 address.
Behavior Type
Immutable
Syntax
V6_SUBNETN ( expression1, expression2 )
Parameters
expression1
expression2
Notes
The following syntax masks a BINARY IPv6 address B so that the N left-most bits of S form a
subnet address, while the remaining right-most bits are cleared.
V6_SUBNETN right-pads B to 16 bytes with zeros, if necessary and masks B, preserving its N-bit
subnet prefix.
SQLReference Manual
SQL Functions
If B is NULL or longer than 16 bytes, or if N is not between 0 and 128 inclusive, the result is NULL.
S = [B]/N in Classless Inter-Domain Routing notation (CIDR notation).
The following syntax masks an alphanumeric IPv6 address A so that the N leftmost bits form a
subnet address, while the remaining rightmost bits are cleared.
V6_SUBNETN(VARCHAR A, INT8 N) -> V6_SUBNETN(V6_ATON(A), N) -> VARBINARY(16) S
Example
This example returns VARBINARY, after using V6_ATON to convert the VARCHAR string to VARBINARY:
> SELECT V6_SUBNETN(V6_ATON('2001:db8::8:800:200c:417a'), 28);
v6_subnetn
--------------------------------------------------------------\001\015\260\000\000\000\000\000\000\000\000\000\000\000\000
See Also
l
V6_ATON
V6_SUBNETA
V6_TYPE
Characterizes a binary or alphanumeric IPv6 address B as an integer type.
Behavior Type
Immutable
Syntax
V6_TYPE ( expression )
Parameters
expression
SQLReference Manual
SQL Functions
Notes
V6_TYPE(VARBINARY B) returns INT8 T.
V6_TYPE(VARCHAR A) -> V6_TYPE(V6_ATON(A)) -> INT8 T
The IPv6 types are defined in the Network Working Group's IP Version 6 Addressing Architecture
memo.
GLOBAL = 0
LINKLOCAL = 1
LOOPBACK = 2
UNSPECIFIED = 3
MULTICAST = 4
IPv4-mapped and IPv4-compatible IPv6 addresses are also interpreted, as specified in IPv4 Global
Unicast Address Assignments.
l
Details
IPv4 (either kind):
0.0.0.0/8
127.0.0.0/8
169.254.0.0/16
172.16.0.0/12
192.168.0.0/16
224.0.0.0/4
others
UNSPECIFIED
LOOPBACK
LINKLOCAL
LINKLOCAL
LINKLOCAL
MULTICAST
GLOBAL
10.0.0.0/8
::0/128
fe80::/10
ff00::/8
others
UNSPECIFIED
LINKLOCAL
MULTICAST
GLOBAL
::1/128
LINKLOCAL
IPv6:
LOOPBACK
SQLReference Manual
SQL Functions
Examples
> SELECT V6_TYPE(V6_ATON('192.168.2.10'));
v6_type
--------1
(1 row)
> SELECT V6_TYPE(V6_ATON('2001:db8::8:800:200c:417a'));
v6_type
--------0
(1 row)
See Also
l
INET_ATON
SQLReference Manual
SQL Functions
CURRENT_DATABASE
Returns a VARCHAR value containing the name of the database to which you are connected.
Behavior Type
Immutable
Syntax
CURRENT_DATABASE()
Notes
l
Examples
SELECT CURRENT_DATABASE();
CURRENT_DATABASE
-----------------VMart
(1 row)
The following command returns the same results without the parentheses:
SELECT CURRENT_DATABASE;
CURRENT_DATABASE
-----------------VMart
(1 row)
CURRENT_SCHEMA
Returns the name of the current schema.
SQLReference Manual
SQL Functions
Behavior Type
Stable
Syntax
CURRENT_SCHEMA()
Privileges
None
Notes
The CURRENT_SCHEMA function does not require parentheses.
Examples
The following command returns the name of the current schema:
=> SELECT CURRENT_SCHEMA();
current_schema
---------------public
(1 row)
The following command returns the same results without the parentheses:
=> SELECT CURRENT_SCHEMA;
current_schema
---------------public
(1 row)
The following command shows the current schema, listed after the current user, in the search path:
=> SHOW SEARCH_PATH;
name
|
setting
-------------+--------------------------------------------------search_path | "$user", public, v_catalog, v_monitor, v_internal
(1 row)
See Also
l
SET SEARCH_PATH
SQLReference Manual
SQL Functions
CURRENT_USER
Returns a VARCHAR containing the name of the user who initiated the current database
connection.
Behavior Type
Stable
Syntax
CURRENT_USER()
Notes
l
Examples
SELECT CURRENT_USER();
CURRENT_USER
-------------dbadmin
(1 row)
The following command returns the same results without the parentheses:
SELECT CURRENT_USER;
CURRENT_USER
-------------dbadmin
(1 row)
DBNAME (function)
Returns a VARCHAR value containing the name of the database to which you are connected.
DBNAME is equivalent to CURRENT_DATABASE.
SQLReference Manual
SQL Functions
Behavior Type
Immutable
Syntax
DBNAME()
Examples
SELECT DBNAME();
dbname
-----------------VMart
(1 row)
HAS_TABLE_PRIVILEGE
Indicates whether a user can access a table in a particular way. The function returns a true (t) or
false (f) value.
A superuser can check all other user's table privileges.
Users without superuser privileges can use HAS_TABLE_PRIVILEGE to check:
l
Tables in a schema to which they have been granted USAGE privileges, and at least one other
table privilege, as described in GRANT (Table).
Behavior Type
Stable
Syntax
HAS_TABLE_PRIVILEGE ( [ user, ] [[db-name.]schema-name.]table , privilege )
Parameters
user
SQLReference Manual
SQL Functions
[[db-name.]schema.]
table
privilege
SELECT Allows the user to SELECT from any column of the specified
table.
INSERT Allows the user to INSERT records into the specified table and
to use the COPY command to load the table.
DELETE Allows the user to delete a row from the specified table.
Examples
SELECT HAS_TABLE_PRIVILEGE('store.store_dimension', 'SELECT');
HAS_TABLE_PRIVILEGE
--------------------t
(1 row)
SELECT HAS_TABLE_PRIVILEGE('release', 'store.store_dimension', 'INSERT');
HAS_TABLE_PRIVILEGE
--------------------t
(1 row)
SELECT HAS_TABLE_PRIVILEGE('store.store_dimension', 'UPDATE');
HAS_TABLE_PRIVILEGE
--------------------t
(1 row)
SQLReference Manual
SQL Functions
SESSION_USER
Returns a VARCHAR containing the name of the user who initiated the current database session.
Behavior Type
Stable
Syntax
SESSION_USER()
Notes
l
Examples
SELECT SESSION_USER();
session_user
-------------dbadmin
(1 row)
The following command returns the same results without the parentheses:
SELECT SESSION_USER;
session_user
-------------dbadmin
(1 row)
SQLReference Manual
SQL Functions
USER
Returns a VARCHAR containing the name of the user who initiated the current database
connection.
Behavior Type
Stable
Syntax
USER()
Notes
l
Examples
SELECT USER();
current_user
-------------dbadmin
(1 row)
The following command returns the same results without the parentheses:
SELECT USER;
current_user
-------------dbadmin
(1 row)
USERNAME
Returns a VARCHAR containing the name of the user who initiated the current database
connection.
Behavior Type
Stable
SQLReference Manual
SQL Functions
Syntax
USERNAME()
Notes
l
Examples
SELECT USERNAME();
username
-------------dbadmin
(1 row)
VERSION
Returns a VARCHAR containing an HP Vertica node's version information.
Behavior Type
Stable
Syntax
VERSION()
Examples
SELECT VERSION();
VERSION
-------------------------------------------------Vertica Analytic Database v4.0.12-20100513010203
(1 row)
The parentheses are required. If you omit them, the system returns an error:
SELECT VERSION;
ERROR: column "version" does not exist
SQLReference Manual
SQL Functions
Timeseries Functions
Timeseries aggregate functions evaluate the values of a given set of variables over time and group
those values into a window for analysis and aggregation.
One output row is produced per time sliceor per partition per time sliceif partition expressions
are present.
See Also
l
TIMESERIES Clause
CONDITIONAL_CHANGE_EVENT [Analytic]
CONDITIONAL_TRUE_EVENT [Analytic]
l
l
TS_FIRST_VALUE
Processes the data that belongs to each time slice. A time series aggregate (TSA) function, TS_
FIRST_VALUE returns the value at the start of the time slice, where an interpolation scheme is
applied if the timeslice is missing, in which case the value is determined by the values
corresponding to the previous (and next) timeslices based on the interpolation scheme of const
(linear). There is one value per time slice per partition.
Behavior Type
Immutable
Syntax
TS_FIRST_VALUE ( expression [ IGNORE NULLS ]
... [, { 'CONST' | 'LINEAR' }
] )
Parameters
expression
SQLReference Manual
SQL Functions
IGNORE NULLS
'CONST' | 'LINEAR'
Notes
The function returns one output row per time slice or one output row per partition per time slice if
gap-filling policy as defined by the TIMESERIES Clause; however, each time series aggregate
function can specify its own interpolation policy. For example:
SELECT slice_time, symbol,
TS_FIRST_VALUE(bid, 'const') fv_c,
TS_FIRST_VALUE(bid, 'linear') fv_l,
TS_LAST_VALUE(bid, 'const') lv_c
FROM TickStore
TIMESERIES slice_time AS '3 seconds'
OVER(PARTITION BY symbol ORDER BY ts);
Example
For detailed examples, see Gap Filling and Interpolation in the Analyzing Data Guide.
See Also
TIMESERIES Clause
TS_LAST_VALUE
l
l
SQLReference Manual
SQL Functions
TS_LAST_VALUE
Processes the data that belongs to each time slice. A time series aggregate (TSA) function, TS_
LAST_VALUE returns the value at the end of the time slice, where an interpolation scheme is
applied if the timeslice is missing, in which case the value is determined by the values
corresponding to the previous (and next) timeslices based on the interpolation scheme of const
(linear). There is one value per time slice per partition.
Behavior Type
Immutable
Syntax
TS_LAST_VALUE ( expression [ IGNORE NULLS ]
... [, { 'CONST' | 'LINEAR' }
] )
Parameters
expression
IGNORE NULLS
'CONST' | 'LINEAR'
Notes
l
The function returns one output row per time slice or one output row per partition per time slice if
partition expressions are specified.
Multiple time series aggregate functions can exists in the same query. They share the same
SQLReference Manual
SQL Functions
gap-filling policy as defined by the TIMESERIES Clause; however, each time series aggregate
function can specify its own interpolation policy. For example:
SELECT slice_time, symbol,
TS_FIRST_VALUE(bid, 'const') fv_c,
TS_FIRST_VALUE(bid, 'linear') fv_l,
TS_LAST_VALUE(bid, 'const') lv_c
FROM TickStore
TIMESERIES slice_time AS 3 seconds
OVER(PARTITION BY symbol ORDER BY ts);
Example
For detailed examples, see Gap Filling and Interpolation in the Analyzing Data Guide.
See Also
TIMESERIES Clause
TS_FIRST_VALUE
l
l
SQLReference Manual
SQL Functions
URI_PERCENT_DECODE
Decodes a percent-encoded Universal Resource Identifier (URI) according to the RFC 3986
standard.
Syntax
URI_PERCENT_DECODE (expression)
Behavior Type
Immutable
Parameters
expression
Examples
The following example invokes uri_percent_decode on the Websites column of the URI table and
returns a decoded URI:
=> SELECT URI_PERCENT_DECODE(Websites) from URI;
URI_PERCENT_DECODE
----------------------------------------------http://www.faqs.org/rfcs/rfc3986.html x xj%a%
(1 row)
The following example returns the original URI in the Websites column and its decoded version:
=> SELECT Websites, URI_PERCENT_DECODE (Websites) from URI;
Websites
|
URI_PERCENT_DECODE
---------------------------------------------------+-------------------------------------------http://www.faqs.org/rfcs/rfc3986.html+x%20x%6a%a% |
http://www.faqs.org/rfcs/rfc3986.html x xj%a%
(1 row)
SQLReference Manual
SQL Functions
URI_PERCENT_ENCODE
Encodes a Universal Resource Identifier (URI) according to the RFC 3986 standard for percent
encoding. In addition, for compatibility with older encoders this function converts '+' to space;
space is converted to %20 by uri_percent_encode.
Syntax
URI_PERCENT_ENCODE (expression)
Behavior Type
Immutable
Parameters
expression
Examples
The following example shows how the uri_percent_encode function is invoked on a the Websites
column of the URI table and returns an encoded URI:
=> SELECT URI_PERCENT_ENCODE(Websites) from URI;
URI_PERCENT_ENCODE
-----------------------------------------https%3A%2F%2F1.800.gay%3A443%2Fhttp%2Fexample.com%2F%3F%3D11%2F15
(1 row)
The following example returns the original URI in the Websites column and it's encoded form:
=> SELECT Websites, URI_PERCENT_ENCODE(Websites) from URI;
Websites
URI_PERCENT_ENCODE
----------------------------+-----------------------------------------http://example.com/?=11/15 | https%3A%2F%2F1.800.gay%3A443%2Fhttp%2Fexample.com%2F%3F%3D11%2F15
(1 row)
SQLReference Manual
SQL Functions
HP Vertica Meta-Functions
HP Vertica built-in (meta) functions access the internal state of HP Vertica and are used in
SELECT queries with the function name and an argument (where required). These functions are not
part of the SQL standard and take the following form:
SELECT <meta-function-name>(<args>);
Note: The query cannot contain other clauses, such as FROM or WHERE.
The behavior type of HP Vertica meta-functions is immutable.
SQLReference Manual
SQL Functions
ADD_LOCATION
Adds a storage location to the cluster. Use this function to add a new location, optionally with a
location label. You can also add a location specifically for user access, and then grant one or more
users access to the location.
Deprecated: ADD_LOCATIONhas been deprecated and will be removed in a future release.
Use the CREATE LOCATIONstatement instead.
Syntax
ADD_LOCATION ( 'path'
Parameters
path
node
[Optional] Indicates the cluster node on which a storage location resides. If you
omit this parameter, the function adds the location to only the initiator node.
Specifying the node parameter as an empty string ('') adds a storage location
to all cluster nodes in a single transaction.
Note: If you specify a node, you must also add a usage parameter.
SQLReference Manual
SQL Functions
usage
DATA: Stores only data files. Use this option for labeled storage locations.
USER: Allows non-dbadmin users access to the storage location for data
files (not temp files), once they are granted privileges. DO NOT create a
storage location for later use in a storage policy. Storage locations with
policies must be for DATA usage. Also, note that this keyword is orthogonal
to DATA and TEMP, and does not specify a particular usage, other than
being accessible to non-dbadmin users with assigned privileges. You cannot
alter a storage location to or from USER usage.
Note: You can use this parameter only in conjunction with the node option.
If you omit the usage parameter, the default is DATA,TEMP.
location_label
Privileges
Must be a superuser.
Example
This example adds a location that stores data and temporary files on the initiator node:
SQLReference Manual
SQL Functions
This example shows you how to add a new DATA storage location with a label, SSD. The label
identifies the location when you create storage policies. Specifying the ALLNODES keyword adds
the storage location to all nodes in a single transaction:
=> CREATE LOCATION '/home/dbadmin/SSD/schemas' ALL NODES USAGE 'DATA'
LABEL 'SSD';
See Also
l
ALTER_LOCATION_USE
DROP_LOCATION
RESTORE_LOCATION
RETIRE_LOCATION
ADVANCE_EPOCH
Manually closes the current epoch and begins a new epoch.
Syntax
ADVANCE_EPOCH ( [ integer ] )
Parameters
integer
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Notes
This function is primarily maintained for backward compatibility with earlier versions of HP Vertica.
Example
The following command increments the epoch number by 1:
=> SELECT ADVANCE_EPOCH(1);
See Also
l
ALTER_LOCATION_USE
Alters the type of files that can be stored at the specified storage location.
Syntax
ALTER_LOCATION_USE ( 'path' , 'node' , 'usage' )
Parameters
path
node
[Optional] The HP Vertica node with the storage location. Specifying the node parameter
as an empty string ('') alters the location across all cluster nodes in a single transaction.
SQLReference Manual
SQL Functions
usage
DATA: The storage location stores only data files. This is the supported use for both a
USER storage location, and a labeled storage location.
TEMP: The location stores only temporary files that are created during loads or
queries.
Privileges
Must be a superuser.
Example
The following example alters the storage location across all cluster nodes to store only data:
=> SELECT ALTER_LOCATION_USE ('/thirdVerticaStorageLocation/' , '' , 'DATA');
See Also
l
ADD_LOCATION
DROP_LOCATION
SQLReference Manual
SQL Functions
RESTORE_LOCATION
RETIRE_LOCATION
ALTER_LOCATION_LABEL
Alters the location label. Use this function to add, change, or remove a location label. You change a
location label only if it is not currently in use as part of a storage policy.
You can use this function to remove a location label. However, you cannot remove a location label if
the name being removed is used in a storage policy, and the location from which you are removing
the label is the last available storage for its associated objects.
Note: If you label an existing storage location that already contains data, and then include the
labeled location in one or more storage policies, existing data could be moved. If the ATM
determines data stored on a labeled location does not comply with a storage policy, the ATM
moves the data elsewhere.
Syntax
ALTER_LOCATION_LABEL ( 'path' , 'node' , 'location_label' )
Parameters
path
node
location_label
Specifies a storage label as a string, for instance SSD. You can change an
existing label assigned to a storage location, or add a new label. Specifying an
empty string ('') removes an existing label.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Example
The following example alters (or adds) the label SSD to the storage location at the given path on all
cluster nodes:
VMART=> select alter_location_label('/home/dbadmin/SSD/tables','', 'SSD');
alter_location_label
--------------------------------------/home/dbadmin/SSD/tables label changed.
(1 row)
See Also
l
CLEAR_OBJECT_STORAGE_POLICY
SET_OBJECT_STORAGE_POLICY
ANALYZE_CONSTRAINTS
Analyzes and reports on constraint violations within the current schema search path, or external to
that path if you specify a database name (noted in the syntax statement and parameter table).
You can check for constraint violations by passing arguments to the function as follows:
l
An empty argument (' '), which returns violations on all tables within the current schema
Syntax
ANALYZE_CONSTRAINTS [ ( '' )
... | ( '[[db-name.]schema.]table [.column_name]' )
... | ( '[[db-name.]schema.]table' , 'column' ) ]
Parameters
('')
Analyzes and reports on all tables within the current schema search path.
SQLReference Manual
SQL Functions
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
column
Analyzes and reports on all constraints referring to the specified table that
contains the column.
Privileges
l
Notes
ANALYZE_CONSTRAINTS() performs a lock in the same way that SELECT * FROM t1 holds a
lock on table t1. See LOCKS for additional information.
SELECT DISABLE_DUPLICATE_KEY_ERROR
SELECT REENABLE_DUPLICATE_KEY_ERROR
Return Values
ANALYZE_CONSTRAINTS returns results in a structured set (see table below) that lists the
schema name, table name, column name, constraint name, constraint type, and the column values
that caused the violation.
SQLReference Manual
SQL Functions
If the result set is empty, then no constraint violations exist; for example:
> SELECT ANALYZE_CONSTRAINTS ('public.product_dimension', 'product_key');
Schema Name | Table Name | Column Names | Constraint Name | Constraint Type | Column
Values
-------------+------------+--------------+-----------------+-----------------+-------------(0 rows)
The following result set shows a primary key violation, along with the value that caused the
violation ('10'):
=> SELECT ANALYZE_CONSTRAINTS ('');
Schema Name | Table Name | Column Names | Constraint Name | Constraint Type | Column
Values
-------------+------------+--------------+-----------------+-----------------+-------------store
t1
c1
pk_t1
PRIMARY
('10')
(1 row)
The result set columns are described in further detail in the following table:
Column Name Data Type
Description
Schema Name
VARCHAR
Table Name
VARCHAR
Column Names
VARCHAR
Constraint Name
VARCHAR
The given name of the primary key, foreign key, unique, or not
null constraint, if specified.
Constraint Type
VARCHAR
Column Values
VARCHAR
SQLReference Manual
SQL Functions
If you run the function on a table that has no constraints declared (even if duplicates are present),
the system returns an error message:
> SELECT ANALYZE_CONSTRAINTS('source');
ERROR 4072: No constraints defined
If you run the function with incorrect syntax, the system returns an error message with a hint; for
example, if you run one of the following:
l
If you run ANALYZE_CONSTRAINTS from a non-default locale, the function returns an error with a
hint:
> \locale LENINFO 2567: Canonical locale: 'en'
Standard collation: 'LEN'
English
> SELECT ANALYZE_CONSTRAINTS('t1');
ERROR: ANALYZE_CONSTRAINTS is currently not supported in
non-default locales
HINT: Set the locale in this session to
en_US@collation=binary using the command
"\locale en_US@collation=binary"
SQLReference Manual
SQL Functions
Examples
Given the following inputs, HP Vertica returns one row, indicating one violation, because the same
primary key value (10) was inserted into table t1 twice:
CREATE TABLE t1(c1 INT);
ALTER TABLE t1 ADD CONSTRAINT pk_t1 PRIMARY KEY (c1);
CREATE PROJECTION t1_p (c1) AS SELECT *
FROM t1 UNSEGMENTED ALL NODES;
INSERT INTO t1 values (10);
INSERT INTO t1 values (10); --Duplicate primary key value
\x
Expanded display is on.
SELECT ANALYZE_CONSTRAINTS('t1');
-[ RECORD 1 ]---+-------Schema Name
| public
Table Name
| t1
Column Names
| c1
Constraint Name | pk_t1
Constraint Type | PRIMARY
Column Values
| ('10')
If the second INSERT statement above had contained any different value, the result would have
been 0 rows (no violations).
In the following example, create a table that contains three integer columns, one a unique key and
one a primary key:
CREATE TABLE table_1(
a INTEGER,
b_UK INTEGER UNIQUE,
c_PK INTEGER PRIMARY KEY
);
Insert some values into table table_1 and commit the changes:
SQLReference Manual
SQL Functions
Insert duplicate unique and primary key values and run ANALYZE_CONSTRAINTS on table
table_1 again. The system shows two violations: one against the primary key and one against the
unique key:
INSERT INTO table_1 VALUES (1, 1, 1);
COMMIT;
SELECT ANALYZE_CONSTRAINTS('table_1');
The following command looks for constraint validations on only the unique key in the table table_1,
qualified with its schema name:
=> SELECT ANALYZE_CONSTRAINTS('public.table_1', 'b_UK');
-[ RECORD 1 ]---+--------Schema Name
| public
Table Name
| table_1
Column Names
| b_UK
Constraint Name | C_UNIQUE
Constraint Type | UNIQUE
Column Values
| ('1')
(1 row)
The following example shows that you can specify the same column more than once; ANALYZE_
CONSTRAINTS, however, returns the violation only once:
SQLReference Manual
SQL Functions
The following example creates a new table, table_2, and inserts a foreign key and different
(character) data types:
CREATE TABLE table_2 (
x VARCHAR(3),
y_PK VARCHAR(4),
z_FK INTEGER REFERENCES table_1(c_PK));
Alter the table to create a multicolumn unique key and multicolumn foreign key and create
superprojections:
ALTER TABLE table_2
ADD CONSTRAINT table_2_multiuk PRIMARY KEY (x, y_PK);
WARNING 2623: Column "x" definition changed to NOT NULL
WARNING 2623: Column "y_PK" definition changed to NOT NULL
The following command inserts a missing foreign key (0) into table dim_1 and commits the
changes:
INSERT INTO table_2 VALUES ('r1', 'Xpk1', 0);
COMMIT;
Checking for constraints on the table table_2 in the public schema detects a foreign key
violation:
=> SELECT ANALYZE_CONSTRAINTS('public.table_2');
-[ RECORD 1 ]---+---------Schema Name
| public
Table Name
| table_2
Column Names
| z_FK
Constraint Name | C_FOREIGN
Constraint Type | FOREIGN
Column Values
| ('0')
Now add a duplicate value into the unique key and commit the changes:
INSERT INTO table_2 VALUES ('r2', 'Xpk1', 1);
INSERT INTO table_2 VALUES ('r1', 'Xpk1', 1);
SQLReference Manual
SQL Functions
COMMIT;
Checking for constraint violations on table table_2 detects the duplicate unique key error:
SELECT ANALYZE_CONSTRAINTS('table_2');
-[ RECORD 1 ]---+---------------Schema Name
| public
Table Name
| table_2
Column Names
| z_FK
Constraint Name | C_FOREIGN
Constraint Type | FOREIGN
Column Values
| ('0')
-[ RECORD 2 ]---+---------------Schema Name
| public
Table Name
| table_2
Column Names
| x, y_PK
Constraint Name | table_2_multiuk
Constraint Type | PRIMARY
Column Values
| ('r1', 'Xpk1')
Create a table with multicolumn foreign key and create the superprojections:
CREATE TABLE table_3(
z_fk1 VARCHAR(3),
z_fk2 VARCHAR(4));
ALTER TABLE table_3
ADD CONSTRAINT table_3_multifk FOREIGN KEY (z_fk1, z_fk2)
REFERENCES table_2(x, y_PK);
Insert a foreign key that matches a foreign key in table table_2 and commit the changes:
INSERT INTO table_3 VALUES ('r1', 'Xpk1');
COMMIT;
Add a value that does not match and commit the change:
INSERT INTO table_3 VALUES ('r1', 'NONE');
COMMIT;
SQLReference Manual
SQL Functions
Schema Name
Table Name
Column Names
Constraint Name
Constraint Type
Column Values
|
|
|
|
|
|
public
table_3
z_fk1, z_fk2
table_3_multifk
FOREIGN
('r1', 'NONE')
SQLReference Manual
SQL Functions
Column Names
Constraint Name
Constraint Type
Column Values
(5 rows)
|
|
|
|
a
C_PRIMARY
PRIMARY
('1')
ANALYZE_CORRELATIONS
Analyzes the specified tables for pairs of columns that are strongly correlated. Stores only the 20
pairs with the strongest correlation. ANALYZE_CORRELATIONSalso analyzes statistics.
For example, state name and country name columns are strongly correlated because the city name
usually, but perhaps not always, identifies the state name. The city of Conshohoken is uniquely
associated with Pennsylvania, whereas the city of Boston exists in Georgia, Indiana, Kentucky,
New York, Virginia, and Massachusetts. In this case, city name is strongly correlated with state
name.
For Database Designer to take advantage of these correlations, run Database Designer
programmatically. Use DESIGNER_SET_ANALYZE_CORRELATIONS_MODE to specify that
Database Designer should consider existing column correlations. Make sure to specify that
Database Designer not analyze statistics so that Database Designer does not override the existing
statistics.
Behavior Type
Immutable
Syntax
ANALYZE_CORRELATIONS (
'[database_name.][schema_name.]table_name',
[recalculate] )
SQLReference Manual
SQL Functions
Parameters
database_name
schema_name
table_name
recalculate
Specifies to analyze the correlated columns, even if they have been analyzed
before, type BOOLEAN. Default: 'false'.
Permissions
l
Notes
l
Projections do not change based on the analysis results. To implement the results of
ANALYZE_CORRELATIONS, you must run Database Designer.
Example
In the following example, ANALYZE_CORRELATIONS analyzes column correlations for all tables
in the public schema,even if they currently exist. The correlations that ANALYZE_
CORRELATIONSfinds are saved so that Database Designer can use them the next time it runs on
the VMart database:
=> SELECT ANALYZE_CORRELATIONS (
'public.*',
'true');
ANALYZE_CORRELATIONS
---------------------0
(1 row)
See Also
l
DESIGNER_SET_ANALYZE_CORRELATIONS_MODE
SQLReference Manual
SQL Functions
ANALYZE_EXTERNAL_ROW_COUNT
ANALYZE_EXTERNAL_ROW_COUNTcalculates the exact number of rows in an external table.
ANALYZE_EXTERNAL_ROW_COUNTruns in the background. To cancel row count analysis,
press Ctrl+C in a vsql shell, or call the INTERRUPT_STATEMENT() function.
You cannot calculate the row count on external tables using DO_TM_TASK('ANALYZE_ROW_
COUNT').
Syntax
ANALYZE_STATISTICS [ ('') ... | ( '[ [ db-name.]schema.]table' ) ]
Parameters
''
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Specifies the name of the external table for which to calculate the exact
row count.
Privileges
Any INSERT/UPDATE/DELETE privilege on the external table
Examples
The following queries show how ANALYZE_EXTERNAL_ROW_COUNT calculates the exact row
count for all external tables.The function then calculates the exact row count for the loader_
rejects table:
=> SELECT ANALYZE_EXTERNAL_ROW_COUNT('');
=> SELECT ANALYZE_EXTERNAL_ROW_COUNT('loader_rejects');
SQLReference Manual
SQL Functions
See Also
l
ANALYZE_HISTOGRAM
ANALYZE_STATISTICS
ANALYZE_WORKLOAD
DROP_STATISTICS
DROP_EXTERNAL_ROW_COUNT
EXPORT_STATISTICS
IMPORT_STATISTICS
INTERRUPT_STATEMENT
VALIDATE_STATISTICS
ANALYZE_HISTOGRAM
Collects and aggregates data samples and storage information from all nodes that store projections
associated with the specified table or column.
If the function returns successfully, HP Vertica writes the statistics to the catalog. The query
optimizer uses this collected data to recommend the best possible plan to execute a query. Without
analyzing table statistics, the query optimizer assumes uniform distribution of data values and
equal storage usage for all projections.
ANALYZE_HISTOGRAM is a DDL operation that auto-commits the current transaction, if any. The
ANALYZE_HISTOGRAM function reads a variable amount of disk contents to aggregate sample
data for statistical analysis. Use the function's percent float parameter to specify the total disk
space from which HP Vertica collects sample data. The ANALYZE_STATISTICS function returns
similar data but uses a fixed disk space amount (10 percent). Analyzing more than 10 percent disk
space takes proportionally longer to process, but produces a higher level of sampling accuracy.
ANALYZE_HISTOGRAM is supported on local temporary tables, but not on global temporary
tables.
Syntax
ANALYZE_HISTOGRAM ('') ... | ( '[ [ db-name.]schema.]table [.column-name ]' [, percent ] )
SQLReference Manual
SQL Functions
Return Value
0Success. If an error occurs, refer to vertica.log for details.
Parameters
''
[[db-name.]schema.]
table
Specifies the name of the table and collects statistics for all projections of
that table. If you are using more than one schema, specify the schema that
contains the projection, as noted in the [[db-name.]schema.] entry.
[.column-name]
percent
[Optional] Specifies what percentage of data to read from disk (not the
amount of data to analyze). Specify a float from 1100, such as 33.3. By
default, the function reads 10% of the table data from disk.
For more information, see Collecting Statistics in the Administrator's
Guide.
SQLReference Manual
SQL Functions
Privileges
l
To obtain...
ANALYZE_
A fixed-size statistical data sampling (10 percent per disk). This function returns
STATISTICS
ANALYZE_
A specified percentage of disk data sampling (from 1100). If you analyze more
HISTOGRAM than 10 percent data per disk, this function is more accurate than ANALYZE_
STATISTICS, but requires proportionately longer to return statistics.
ANALYZE_
EXTERNAL_
ROW_
COUNT
Analyzing Results
To retrieve hints about underperforming queries and the associated root causes, use the
ANALYZE_WORKLOAD function. This function runs the Workload Analyzer and returns tuning
recommendations, such as "run analyze_statistics on schema.table.column". You or your
database administrator should act upon the tuning recommendations.
You can also find database tuning recommendations on the Management Console.
Canceling ANALYZE_HISTOGRAM
You can cancel this function during analysis by issuing CTRL-C in a vsql shell or by invoking the
INTERRUPT_STATEMENT() function.
SQLReference Manual
SQL Functions
Usage Considerations
By default, HP Vertica analyzes more than one column (subject to resource limits) in a single-query
execution plan to:
l
Help speed up analysis of relatively small tables that have a large number of columns
Examples
In this example, the ANALYZE_STATISTICS() function reads 10 percent of the disk data. This is
the static default value for this function. The function returns 0 for success:
=> SELECT ANALYZE_STATISTICS('shipping_dimension.shipping_key');
ANALYZE_STATISTICS
-------------------0
(1 row)
This example uses ANALYZE_HISTOGRAM () without specifying a percentage value. Since this
function has a default value of 10 percent, it returns the identical data as the ANALYZE_
STATISTICS() function, and returns 0 for success:
=> SELECT ANALYZE_HISTOGRAM('shipping_dimension.shipping_key');
ANALYZE_HISTOGRAM
------------------0
This example uses ANALYZE_HISTOGRAM (), specifying its percent parameter as 100, indicating
to read the entire disk to gather data. After the function performs a full column scan, it returns 0 for
success:
=> SELECT ANALYZE_HISTOGRAM('shipping_dimension.shipping_key', 100);
ANALYZE_HISTOGRAM
------------------0
SQLReference Manual
SQL Functions
------------------0
The following query calculates the exact number of rows in the external table loader_rejects:
=> SELECT ANALYZE_EXTERNAL_ROW_COUNT('loader_rejects');
ANALYZE_EXTERNAL_ROW_COUNT
---------------------------0
See Also
l
ANALYZE_STATISTICS
ANALYZE_WORKLOAD
DROP_STATISTICS
EXPORT_STATISTICS
IMPORT_STATISTICS
INTERRUPT_STATEMENT
ANALYZE_STATISTICS
Collects and aggregates data samples and storage information from all nodes that store projections
associated with the specified table or column.
If the function returns successfully, HP Vertica writes the statistics to the catalog. The query
optimizer uses this collected data to recommend the best possible plan to execute a query. Without
analyzing table statistics, the query optimizer assumes uniform distribution of data values and
equal storage usage for all projections.
ANALYZE_STATISTICS is a DDL operation that auto-commits the current transaction, if any. The
ANALYZE_STATISTICS function reads a fixed, 10 percent of disk contents to aggregate sample
data for statistical analysis. To obtain a larger (or smaller) data sampling, use the ANALYZE_
HISTOGRAM function, which lets you specify the percent of disk to read. Analyzing more that 10
percent disk space takes proportionally longer to process but results in a higher level of sampling
accuracy. ANALYZE_STATISTICSis supported on local temporary tables, but not on global
temporary tables.
SQLReference Manual
SQL Functions
Syntax
ANALYZE_STATISTICS [ ('') ... | ( '[ [ db-name.]schema.]table [.column-name ]' ) ]
Parameters
''
[[db-name.]schema.]
table
Specifies the name of the table and collects statistics for all projections of
that table.
If you are using more than one schema, specify the schema that contains
the projection, as notes in the [[db-name.]schema.] entry.
[.column-name]
Privileges
l
SQLReference Manual
SQL Functions
Use this
function...
To obtain...
ANALYZE_
A fixed-size statistical data sampling (10 percent per disk). This function returns
STATISTICS
ANALYZE_
A specified percentage of disk data sampling (from 1100). If you analyze more
HISTOGRAM than 10 percent data per disk, this function is more accurate than ANALYZE_
STATISTICS, but requires proportionately longer to return statistics.
ANALYZE_
EXTERNAL_
ROW_
COUNT
Analyzing Results
To retrieve hints about underperforming queries and the associated root causes, use the
ANALYZE_WORKLOAD function. This function runs the Workload Analyzer and returns tuning
recommendations, such as "run analyze_statistics on schema.table.column". You or your
database administrator should act upon the tuning recommendations.
You can also find database tuning recommendations on the Management Console.
Usage Considerations
l
You cannot run ANALYZE_STATISTICSon a anchor table for a live aggregate projection or
Top-K projection.
By default, HP Vertica analyzes more than one column (subject to resource limits) in a singlequery execution plan to:
SQLReference Manual
SQL Functions
Help speed up analysis of relatively small tables that have a large number of columns
Examples
The following examples show you how to compute statistics using the ANALYZE_STATISTICS
function.
Compute statistics on all projections in the VMart database:
=> SELECT ANALYZE_STATISTICS ('');
analyze_statistics
-------------------0
(1 row)
See Also
l
ANALYZE_HISTOGRAM
ANALYZE_WORKLOAD
SQLReference Manual
SQL Functions
ANALYZE_EXTERNAL_ROW_COUNT
DROP_STATISTICS
DROP_EXTERNAL_ROW_COUNT
EXPORT_STATISTICS
IMPORT_STATISTICS
INTERRUPT_STATEMENT
VALIDATE_STATISTICS
ANALYZE_WORKLOAD
Runs the Workload Analyzer (WLA), a utility that analyzes system information held in system
tables.
The Workload Analyzer intelligently monitors the performance of SQL queries and workload history,
resources, and configurations to identify the root causes for poor query performance. Calling the
ANALYZE_WORKLOAD function returns tuning recommendations for all events within the scope
and time that you specify.
Tuning recommendations are based on a combination of statistics, system and data collector
events, and database-table-projection design. WLA's recommendations let database
administrators quickly and easily tune query performance.
See Understanding WLA Triggering Conditions in the Administrator's Guide for the most common
triggering conditions and recommendations.
Syntax
ANALYZE_WORKLOAD ( 'scope' [, 'since_time' | , save_data ] );
Note: The since_time and save_data arguments are optional, but mutually exclusive. You
cannot specify both arguments.
SQLReference Manual
SQL Functions
Parameters
scope
since_time
[Optional] Limits the object analysis for scope to begin at a specific time, up to, and
including, the current system status. If you omit the since_time parameter,
ANALYZE_WORKLOAD returns recommendations on events since the last recorded
time that you last called this function.
Note: You must explicitly cast strings used for the since_time parameter to
TIMESTAMP or TIMESTAMPTZ. For example:
SELECT ANALYZE_WORKLOAD('T1', '2010-10-04 11:18:15'::TIMESTAMPTZ);
SELECT ANALYZE_WORKLOAD('T1', TIMESTAMPTZ '2010-10-04 11:18:15');
save_data
Return Values
Column
Data type
Description
observation_
count
INTEGER
Integer for the total number of events observed for this tuning
recommendation. For example, if you see a return value of 1,
WLA is making its first tuning recommendation for the event
in 'scope'.
SQLReference Manual
SQL Functions
Column
Data type
Description
first_
observation_time
TIMESTAM
PTZ
last_
observation_time
TIMESTAM
PTZ
tuning_parameter
VARCHAR
tuning_
description
VARCHAR
SQLReference Manual
SQL Functions
Column
Data type
Description
tuning_command
VARCHAR
VARCHAR
Privileges
Must be a superuser.
Examples
See Running ANALYZE_WORKLOAD() for Recommendations in the Administrator's Guide for
examples.
SQLReference Manual
SQL Functions
See Also
l
TUNING_RECOMMENDATIONS
Analyzing Workloads
AUDIT
Estimates the raw data size of a database, a schema, a projection, or a table as it is counted in an
audit of the database size.
The AUDIT function estimates the size using the same data sampling method as the audit that HP
Vertica performs to determine if a database is compliant with the database size allowances in its
license. The results of this function are not considered when HP Vertica determines whether the
size of the database complies with the HP Vertica license's data allowance. See How HP Vertica
Calculates Database Size in the Administrator's Guide for details.
Note: This function can only audit the size of tables, projections, schemas, and databases
which the user has permission to access. If a non-superuser attempts to audit the entire
database, the audit will only estimate the size of the data that the user is allowed to read.
Syntax
AUDIT([name] [, granularity] [, error_tolerance [, confidence_level]])
Parameters
name
SQLReference Manual
SQL Functions
granularity
Indicates the level at which the audit reports its results. The recognized levels
are:
l
'schema'
'table'
'projection'
By default, the granularity is the same level as name. For example, if name is a
schema, then the size of the entire schema is reported. If you instead specify
'table' as the granularity, AUDIT reports the size of each table in the
schema. The granularity must be finer than that of object: specifying
'schema' for an audit of a table has no effect.
The results of an audit with a granularity are reported in the V_
CATALOG.USER_AUDITS system table.
error_tolerance
Specifies the percentage margin of error allowed in the audit estimate. Enter
the tolerance value as a decimal number, between 0 and 100. The default
value is 5, for a 5% margin of error.
Note: The lower this value is, the more resources the audit uses since it will
perform more data sampling. Setting this value to 0 results in a full audit of the
database, which is very resource intensive, as all of the data in the database
is analyzed. Doing a full audit of the database significantly impacts
performance and is not recommended on a production database.
confidence_level
SQLReference Manual
SQL Functions
Permissions
l
Note: AUDIT() works only on the tables where the user calling the function has SELECT
permissions.
Notes
Due to the iterative sampling used in the auditing process, making the error tolerance a small
fraction of a percent (0.00001, for example) can cause the AUDIT function to run for a longer period
than a full database audit.
Examples
To audit the entire database:
=> SELECT AUDIT('');
AUDIT
---------76376696
(1 row)
To audit the database with a 25% level of tolerance and a 90% confidence level:
=> SELECT AUDIT('',25,90);
AUDIT
---------76402672
(1 row)
SQLReference Manual
SQL Functions
SQLReference Manual
SQL Functions
object_id
object_type
object_schema
object_name
audit_start_timestamp
audit_end_timestamp
confidence_level_percent
error_tolerance_percent
used_sampling
confidence_interval_lower_bound_bytes
confidence_interval_upper_bound_bytes
sample_count
cell_count
|
|
|
|
|
|
|
|
|
|
|
|
|
45035996273717644
TABLE
online_sales
online_sales_fact
2011-04-05 09:24:48.368575-04
2011-04-05 09:24:48.379307-04
99
5
t
34692956
36536644
10000
9000000
AUDIT_FLEX
Estimates the ROS size of one or more flexible tables contained in a database, schema, or
projection. Use this function for flex tables only. Invoking audit_flex() with a columnar table
results in an error.
The audit_flex() function measures encoded, compressed data stored in ROS containers for the
__raw__ column of one or more flexible tables. The function does not audit other flex table columns
that are created as, or promoted to, real columns. Temporary flex tables are not included in the
audit.
Each time a user calls audit_flex(), HP Vertica stores the results in the V_CATALOG.USER_
AUDITS system table.
Syntax
AUDIT_FLEX (name)
SQLReference Manual
SQL Functions
Parameters
name
Specifies what database entity to audit. Enter the entity name as a string in single quotes
(''), as follows:
l
Empty string ('') Return the size of the ROS containers for all flexible tables in the
database. You cannot enter the database name.
Schema name ('schema_name') Return the size of all __raw__ columns of flexible
tables in schema_name.
A projection name ('proj_name') Return the ROS size of a projection for a __raw__
column.
Permissions
l
Note: AUDIT_FLEX() works only on the flexible tables, projections, schemas, and databases
to which the user has permissions.
Examples
To audit the flex tables in the database:
dbs=> select audit_flex('');
audit_flex
-----------8567679
(1 row)
SQLReference Manual
SQL Functions
8567679
(1 row)
To report the results of all audits saved in the USER_AUDITS, the following shows part of an
extended display from the system table showing an audit run on a schema called test, and the
entire database, dbs:
dbs=> \x
Expanded display is on.
dbs=> select * from user_audits;
-[ RECORD 1 ]-------------------------+-----------------------------size_bytes
| 0
user_id
| 45035996273704962
user_name
| release
object_id
| 45035996273736664
object_type
| SCHEMA
object_schema
|
object_name
| test
audit_start_timestamp
| 2014-02-04 14:52:15.126592-05
audit_end_timestamp
| 2014-02-04 14:52:15.139475-05
confidence_level_percent
| 99
error_tolerance_percent
| 5
used_sampling
| f
confidence_interval_lower_bound_bytes | 0
confidence_interval_upper_bound_bytes | 0
sample_count
| 0
cell_count
| 0
-[ RECORD 2 ]-------------------------+-----------------------------size_bytes
| 38051
user_id
| 45035996273704962
user_name
| release
object_id
| 45035996273704974
object_type
| DATABASE
object_schema
|
object_name
| dbs
SQLReference Manual
SQL Functions
audit_start_timestamp
| 2014-02-05 13:44:41.11926-05
audit_end_timestamp
| 2014-02-05 13:44:41.227035-05
confidence_level_percent
| 99
error_tolerance_percent
| 5
used_sampling
| f
confidence_interval_lower_bound_bytes | 38051
confidence_interval_upper_bound_bytes | 38051
sample_count
| 0
cell_count
| 0
-[ RECORD 3 ]-------------------------+-----------------------------.
.
.
AUDIT_LICENSE_SIZE
Triggers an immediate audit of the database size to determine if it is in compliance with the raw data
storage allowance included in your HP Vertica license. The audit is performed in the background, so
this function call returns immediately. To see the results of the audit when it is done, use the GET_
COMPLIANCE_STATUS function.
Syntax
AUDIT_LICENSE_SIZE()
Privileges
Must be a superuser.
Example
=> SELECT audit_license_size();
audit_license_size
-------------------Service hurried
(1 row)
AUDIT_LICENSE_TERM
Triggers an immediate audit to determine if the HP Vertica license has expired. The audit happens
in the background, so this function returns immediately. To see the result of the audit, use the GET_
COMPLIANCE_STATUS function.
SQLReference Manual
SQL Functions
Syntax
AUDIT_LICENSE_TERM()
Privileges
Must be a superuser.
Example
=> SELECT AUDIT_LICENSE_TERM();
AUDIT_LICENSE_TERM
-------------------Service hurried
(1 row)
BUILD_FLEXTABLE_VIEW
Creates, or recreates, a view for a default or user-defined _keys table, ignoring any empty keys.
Syntax
build_flextable_view('flex_table' [ [,'view_name'] [,'user_keys_table'] ])
Arguments
flex_table
view_name
SQLReference Manual
SQL Functions
user_keys_
table
Examples
Following are examples of calling build_flextable_view with 1, 2, or 3 arguments.
SQLReference Manual
SQL Functions
1. Call the function with two arguments, a flex table, darkdata, and the name of the view to
create, dd_view, in this example:
=> select build_flextable_view('darkdata', 'dd_view');
build_flextable_view
----------------------------------------------The view public.dd_view is ready for querying
(1 row)
2. Alternatively, create a table based on the default keys table, but without content:
=> create table new_darkdata_keys as select * from darkdata_keys LIMIT 0;
CREATE TABLE
kdb=> select * from new_darkdata_keys;
key_name | frequency | data_type_guess
----------+-----------+-----------------
SQLReference Manual
SQL Functions
(0 rows)
3. Given an existing table (or creating one with no data), insert one or more keys:
=> create table dd_keys as select * from darkdata_keys limit 0;
CREATE TABLE
=> insert into dd_keys (key_name) values ('user.lang');
OUTPUT
-------1
(1 row)
=> insert into dd_keys (key_name) values ('user.name');
OUTPUT
-------1
(1 row)
=> select * from dd_keys;
key_name | frequency | data_type_guess
-----------+-----------+----------------user.lang |
|
user.name |
|
(2 rows)
See Also
l
COMPUTE_FLEXTABLE_KEYS
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
SQLReference Manual
SQL Functions
MATERIALIZE_FLEXTABLE_COLUMNS
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
CANCEL_REBALANCE_CLUSTER
Stops any rebalance task currently in progress.
Syntax
CANCEL_REBALANCE_CLUSTER()
Privileges
Must be a superuser.
Example
=> SELECT CANCEL_REBALANCE_CLUSTER();
CANCEL_REBALANCE_CLUSTER
-------------------------CANCELED
(1 row)
See Also
l
START_REBALANCE_CLUSTER
REBALANCE_CLUSTER
CANCEL_REFRESH
Cancels refresh-related internal operations initiated by START_REFRESH().
Syntax
CANCEL_REFRESH()
Privileges
None
SQLReference Manual
SQL Functions
Notes
l
Refresh tasks run in a background thread in an internal session, so you cannot use
INTERRUPT_STATEMENT to cancel those statements. Instead, use CANCEL_REFRESH to
cancel statements that are run by refresh-related internal sessions.
CANCEL_REFRESH() cancels the refresh operation running on a node, waits for the
cancelation to complete, and returns SUCCESS.
Example
Cancel a refresh operation executing in the background.
t=> SELECT START_REFRESH();
START_REFRESH
---------------------------------------Starting refresh background process.
(1 row)
=> SELECT CANCEL_REFRESH();
CANCEL_REFRESH
---------------------------------------Stopping background refresh process.
(1 row)
See Also
l
INTERRUPT_STATEMENT
SESSIONS
START_REFRESH
PROJECTION_REFRESHES
CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY
Changes the run-time priority of a query that is actively running.
SQLReference Manual
SQL Functions
Syntax
CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY(TRANSACTION_ID, 'value')
Parameters
TRANSACTION_ID
'value'
Privileges
No special privileges required. However, non-super users can change the run-time priority of their
own queries only. In addition, non-superusers can never raise the run-time priority of a query to a
level higher than that of the resource pool.
Example
=> SELECT CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY(45035996273705748, 'low');
CHANGE_RUNTIME_PRIORITY
Changes the run-time priority of a query that is actively running. Note that, while this function is still
valid, you should instead use CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY to change run-time
priority. CHANGE_RUNTIME_PRIORITY will be deprecated in a future release of Vertica.
Syntax
CHANGE_RUNTIME_PRIORITY(TRANSACTION_ID,STATEMENT_ID, 'value')
SQLReference Manual
SQL Functions
Parameters
TRANSACTION_ID
STATEMENT_ID
'value'
Privileges
No special privileges required. However, non-super users can change the run-time priority of their
own queries only. In addition, non-superusers can never raise the run-time priority of a query to a
level higher than that of the resource pool.
Example
=> SELECT CHANGE_RUNTIME_PRIORITY(45035996273705748, NULL, 'low');
CLEAR_CACHES
Clears the HP Vertica internal cache files.
Syntax
CLEAR_CACHES ( )
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
If you want to run benchmark tests for your queries, in addition to clearing the internal HP Vertica
cache files, clear the Linux file system cache. The kernel uses unallocated memory as a cache to
hold clean disk blocks. If you are running version 2.6.16 or later of Linux and you have root access,
you can clear the kernel filesystem cache as follows:
1. Make sure that all data is the cache is written to disk:
# sync
2. Writing to the drop_caches file causes the kernel to drop clean caches, dentries, and inodes
from memory, causing that memory to become free, as follows:
n
Example
The following example clears the HP Vertica internal cache files:
=> SELECT CLEAR_CACHES();
CLEAR_CACHES
-------------Cleared
(1 row)
CLEAR_DATA_COLLECTOR
Clears all memory and disk records on the Data Collector tables and functions and resets collection
statistics in the V_MONITOR.DATA_COLLECTOR system table. A superuser can clear Data
SQLReference Manual
SQL Functions
Syntax
CLEAR_DATA_COLLECTOR( [ 'component' ] )
Parameters
component
Clears memory and disk records for the specified component only. If you provide no
argument, the function clears all Data Collector memory and disk records for all
components.
For the current list of component names, query the V_MONITOR.DATA_
COLLECTOR system table.
Privileges
Must be a superuser.
Examples
The following command clears memory and disk records for the ResourceAcquisitions component:
=> SELECT clear_data_collector('ResourceAcquisitions');
clear_data_collector
---------------------CLEAR
(1 row)
The following command clears data collection for all components on all nodes:
=> SELECT clear_data_collector();
clear_data_collector
---------------------CLEAR
(1 row)
See Also
DATA_COLLECTOR
l
l
SQLReference Manual
SQL Functions
CLEAR_PROFILING
HP Vertica stores profiled data is in memory, so depending on how much data you collect, profiling
could be memory intensive. You can use this function to clear profiled data from memory.
Syntax
CLEAR_PROFILING( 'profiling-type' )
Parameters
profiling-type
The type of profiling data you want to clear. Can be one of:
l
sessionclears profiling for basic session parameters and lock time out
data
queryclears profiling for general information about queries that ran, such as
the query strings used and the duration of queries
eeclears profiling for information about the execution run of each query
Example
The following statement clears profiled data for queries:
=> SELECT CLEAR_PROFILING('query');
See Also
l
DISABLE_PROFILING
ENABLE_PROFILING
CLEAR_PROJECTION_REFRESHES
Triggers HP Vertica to clear information about refresh operations for projections immediately.
SQLReference Manual
SQL Functions
Syntax
CLEAR_PROJECTION_REFRESHES()
Notes
Information about a refresh operationwhether successful or unsuccessfulis maintained in the
PROJECTION_REFRESHES system table until either the CLEAR_PROJECTION_
REFRESHES() function is executed or the storage quota for the table is exceeded. The
PROJECTION_REFRESHES.IS_EXECUTING column returns a boolean value that indicates whether the
refresh is currently running (t) or occurred in the past (f).
Privileges
Must be a superuser.
Example
To immediately purge projection refresh history, use the CLEAR_PROJECTION_REFRESHES()
function:
=> SELECT CLEAR_PROJECTION_REFRESHES();
CLEAR_PROJECTION_REFRESHES
---------------------------CLEAR
(1 row)
Only the rows where the PROJECTION_REFRESHES.IS_EXECUTING column equals false are cleared.
See Also
l
PROJECTION_REFRESHES
REFRESH
START_REFRESH
l
l
SQLReference Manual
SQL Functions
CLEAR_RESOURCE_REJECTIONS
Clears the content of the RESOURCE_REJECTIONS and DISK_RESOURCE_REJECTIONS
system tables. Normally, these tables are only cleared during a node restart. This function lets you
clear the tables whenever you need. For example, you might want to clear the system tables after
you resolved a disk space issue that was causing disk resource rejections.
Syntax
CLEAR_RESOURCE_REJECTIONS();
Privileges
Must be a superuser.
Example
The following command clears the content of the RESOURCE_REJECTIONS and DISK_
RESOURCE_REJECTIONS system tables:
=> SELECT clear_resource_rejections();
clear_resource_rejections
--------------------------OK
(1 row)
See Also
l
DISK_RESOURCE_REJECTIONS
RESOURCE_REJECTIONS
CLEAR_OBJECT_STORAGE_POLICY
Removes an existing storage policy. The specified object will no longer use a default storage
location. Any existing data stored currently at the labeled location in the object's storage policy is
moved to default storage during the next TM moveout operation.
Syntax
CLEAR_OBJECT_STORAGE_POLICY ( 'object_name' [,'key_min', 'key_max'] [, 'enforce_storage_move'
] )
SQLReference Manual
SQL Functions
Parameters
object_name
key_min, key_max
Specifies the table partition key value ranges stored at the labeled
location. These parameters are applicable only when object_name is a
table.
enforce_storage_move
[Optional] If true, moves the storage containers that belong to this object
to a new location immediately. If false (the default), this move occurs
automatically sometime after the next moveout operation.
Privileges
Must be a superuser.
Examples
This example shows how to clear the storage policy for the object lineorder. Changes take effect
after the next moveout:
release=> select clear_object_storage_policy('lineorder');
clear_object_storage_policy
----------------------------------Default storage policy cleared.
(1 row)
See Also
l
ALTER_LOCATION_LABEL
SET_OBJECT_STORAGE_POLICY
CLOSE_SESSION
Interrupts the specified external session, rolls back the current transaction, if any, and closes the
socket.
SQLReference Manual
SQL Functions
Syntax
CLOSE_SESSION ( 'sessionid' )
Parameters
sessionid
A string that specifies the session to close. This identifier is unique within the cluster
at any point in time but can be reused when the session closes.
Privileges
None; however, a non-superuser can only close his or her own session.
Notes
l
Closing of the session is processed asynchronously. It could take some time for the session to
be closed. Check the SESSIONS table for the status.
Messages
The following are the messages you could encounter:
l
Examples
User session opened. RECORD 2 shows the user session running COPY DIRECT statement.
SQLReference Manual
SQL Functions
Query the sessions table again for current status, and you can see that the second session has
been closed:
=> SELECT * FROM SESSIONS;
-[ RECORD 1 ]--------------+--------------------------------------------
SQLReference Manual
SQL Functions
node_name
user_name
client_hostname
client_pid
login_timestamp
session_id
client_label
transaction_start
transaction_id
transaction_description
statement_start
statement_id
last_statement_duration_us
current_statement
ssl_state
authentication_method
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v_vmartdb_node0001
dbadmin
127.0.0.1:52110
4554
2011-01-03 14:05:40.252625-05
stress04-4325:0x14
2011-01-03 14:05:44.325781
45035996273728326
user dbadmin (select * from SESSIONS;)
2011-01-03 16:12:07.841298
20
2099
SELECT * FROM SESSIONS;
None
Trust
Controlling Sessions
The database administrator must be able to disallow new incoming connections in order to shut
down the database. On a busy system, database shutdown is prevented if new sessions connect
after the CLOSE_SESSION or CLOSE_ALL_SESSIONS() command is invokedand before the
database actually shuts down.
One option is for the administrator to issue the SHUTDOWN('true') command, which forces the
database to shut down and disallow new connections. See SHUTDOWN in the SQL Reference
Manual.
Another option is to modify the MaxClientSessions parameter from its original value to 0, in order
to prevent new non-dbadmin users from connecting to the database.
1. Determine the original value for the MaxClientSessions parameter by querying the V_
MONITOR.CONFIGURATIONS_PARAMETERS system table:
=> SELECT CURRENT_VALUE FROM CONFIGURATION_PARAMETERS WHERE parameter_
name='MaxClientSessions';
CURRENT_VALUE
--------------50
(1 row)
SQLReference Manual
SQL Functions
When the session no longer appears in the SESSIONS table, disconnect and run the Stop
Database command.
5. Restart the database.
6. Restore the MaxClientSessions parameter to its original value:
=> ALTER DATABASE mydb SET MaxClientSessions = 50;
See Also
l
CLOSE_ALL_SESSIONS
CONFIGURATION_PARAMETERS
SESSIONS
SHUTDOWN
l
l
CLOSE_ALL_SESSIONS
Closes all external sessions except the one issuing the CLOSE_ALL_SESSIONS functions.
Syntax
CLOSE_ALL_SESSIONS()
SQLReference Manual
SQL Functions
Privileges
None; however, a non-superuser can only close his or her own session.
Notes
Closing of the sessions is processed asynchronously. It might take some time for the session to be
closed. Check the SESSIONS table for the status.
Database shutdown is prevented if new sessions connect after the CLOSE_SESSION or CLOSE_
ALL_SESSIONS() command is invoked (and before the database is actually shut down). See
Controlling Sessions below.
Message
close_all_sessions | Close all sessions command sent. Check SESSIONS for progress.
Examples
Two user sessions opened, each on a different node:
vmartdb=> SELECT * FROM sessions;
-[ RECORD 1 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
transaction_description
| user dbadmin (select * from sessions;)
statement_start
| 2011-01-03 15:36:13.896288
statement_id
| 10
last_statement_duration_us | 14978
current_statement
| select * from sessions;
ssl_state
| None
authentication_method
| Trust
-[ RECORD 2 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0002
user_name
| dbadmin
client_hostname
| 127.0.0.1:57174
client_pid
| 30117
login_timestamp
| 2011-01-03 15:33:00.842021-05
session_id
| stress05-27944:0xc1a
client_label
|
transaction_start
| 2011-01-03 15:34:46.538102
SQLReference Manual
SQL Functions
transaction_id
transaction_description
| -1
| user dbadmin (COPY Mart_Fact FROM '/data/mart_Fact.tbl'
DELIMITER '|' NULL '\\n';)
statement_start
| 2011-01-03 15:34:46.538862
statement_id
|
last_statement_duration_us | 26250
current_statement
| COPY Mart_Fact FROM '/data/Mart_Fact.tbl' DELIMITER '|'
NULL '\\n';
ssl_state
| None
authentication_method
| Trust
-[ RECORD 3 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0003
user_name
| dbadmin
client_hostname
| 127.0.0.1:56367
client_pid
| 1191
login_timestamp
| 2011-01-03 15:31:44.939302-05
session_id
| stress06-25663:0xbec
client_label
|
transaction_start
| 2011-01-03 15:34:51.05939
transaction_id
| 54043195528458775
transaction_description
| user dbadmin (COPY Mart_Fact FROM '/data/Mart_Fact.tbl'
DELIMITER '|' NULL '\\n' DIRECT;)
statement_start
| 2011-01-03 15:35:46.436748
statement_id
|
last_statement_duration_us | 1591403
current_statement
| COPY Mart_Fact FROM '/data/Mart_Fact.tbl' DELIMITER '|'
NULL '\\n' DIRECT;
ssl_state
| None
authentication_method
| Trust
RECORD 1 ]--------------+----------------------------------v_vmartdb_node0001
dbadmin
127.0.0.1:52110
4554
2011-01-03 14:05:40.252625-05
stress04-4325:0x14
2011-01-03 14:05:44.325781
45035996273728326
user dbadmin (SELECT * FROM sessions;)
2011-01-03 16:19:56.720071
SQLReference Manual
SQL Functions
statement_id
last_statement_duration_us
current_statement
ssl_state
authentication_method
|
|
|
|
|
25
15605
SELECT * FROM SESSIONS;
None
Trust
Controlling Sessions
The database administrator must be able to disallow new incoming connections in order to shut
down the database. On a busy system, database shutdown is prevented if new sessions connect
after the CLOSE_SESSION or CLOSE_ALL_SESSIONS() command is invokedand before the
database actually shuts down.
One option is for the administrator to issue the SHUTDOWN('true') command, which forces the
database to shut down and disallow new connections. See SHUTDOWN in the SQL Reference
Manual.
Another option is to modify the MaxClientSessions parameter from its original value to 0, in order
to prevent new non-dbadmin users from connecting to the database.
1. Determine the original value for the MaxClientSessions parameter by querying the V_
MONITOR.CONFIGURATIONS_PARAMETERS system table:
=> SELECT CURRENT_VALUE FROM CONFIGURATION_PARAMETERS WHERE parameter_
name='MaxClientSessions';
CURRENT_VALUE
--------------50
(1 row)
SQLReference Manual
SQL Functions
When the session no longer appears in the SESSIONS table, disconnect and run the Stop
Database command.
5. Restart the database.
6. Restore the MaxClientSessions parameter to its original value:
=> ALTER DATABASE mydb SET MaxClientSessions = 50;
See Also
l
CLOSE_SESSION
CONFIGURATION_PARAMETERS
SHUTDOWN
SESSIONS
l
l
COMPUTE_FLEXTABLE_KEYS
Computes the virtual columns (keys and values) from the VMap data of a flex table and repopulates
the associated _keys table. The keys table has the following columns:
l
key_name
frequency
data_type_guess
SQLReference Manual
SQL Functions
Syntax
compute_flextable_keys('flex_table')
Arguments
flex_table The name of a flex table.
Examples
During execution, this function determines a data type for each virtual column, casting the values it
computes to VARCHAR, LONG VARCHAR, or LONG VARBINARY, depending on the length of the key, and
whether the key includes nested maps.
The following examples illustrate this function and the results of populating the _keys table, once
you've created a flex table (darkdata1) and loaded data:
=> create flex table darkdata1();
CREATE TABLE
=> copy darkdata1 from '/test/flextable/DATA/tweets_12.json' parser fjsonparser();
Rows Loaded
------------12
(1 row)
=> select compute_flextable_keys('darkdata1');
compute_flextable_keys
-------------------------------------------------Please see public.darkdata1_keys for updated keys
(1 row)
=> select * from darkdata1_keys;
key_name
| frequency |
data_type_guess
----------------------------------------------------------+-----------+--------------------contributors
|
8 | varchar(20)
coordinates
|
8 | varchar(20)
created_at
|
8 | varchar(60)
entities.hashtags
|
8 | long varbinary
(186)
entities.urls
|
8 | long varbinary
(32)
entities.user_mentions
|
8 | long varbinary
(674)
.
.
.
retweeted_status.user.time_zone
|
1 | varchar(20)
retweeted_status.user.url
|
1 | varchar(68)
retweeted_status.user.utc_offset
|
1 | varchar(20)
retweeted_status.user.verified
|
1 | varchar(20)
SQLReference Manual
SQL Functions
(125 rows)
Description
key_name
frequency The number of times the virtual column occurs in the map.
data_
type_
guess
The data type for each virtual column, cast to VARCHAR, LONG VARCHAR or LONG
VARBINARY, depending on the length of the key, and whether the key includes one or
more nested maps.
In the _keys table output, the data_type_guess column values are also followed by
a value in parentheses, such as varchar(20). The value indicates the padded
width of the key column, as calculated by the longest field, multiplied by the
FlexTableDataTypeGuessMultiplier configuration parameter value. For more
information, see Setting Flex Table Parameters.
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
MATERIALIZE_FLEXTABLE_COLUMNS
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
Combines the functionality of BUILD_FLEXTABLE_VIEW and COMPUTE_FLEXTABLE_KEYS
to compute virtual columns (keys) from the VMap data of a flex table, and construct a view.
Creating a view with this function ignores empty keys. If you don't need to perform both operations
together, use one of the single-operation functions.
Syntax
compute_flextable_keys_and_build_view('flex_table')
SQLReference Manual
SQL Functions
Arguments
flex_table The name of a flex table.
Examples
The following example calls the function for the darkdata flex table.
=> select compute_flextable_keys_and_build_view('darkdata');
compute_flextable_keys_and_build_view
----------------------------------------------------------------------Please see public.darkdata_keys for updated keys
The view public.darkdata_view is ready for querying
(1 row)
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS
MATERIALIZE_FLEXTABLE_COLUMNS
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
CURRENT_SCHEMA
Returns the name of the current schema.
Behavior Type
Stable
Syntax
CURRENT_SCHEMA()
Privileges
None
SQLReference Manual
SQL Functions
Notes
The CURRENT_SCHEMA function does not require parentheses.
Examples
The following command returns the name of the current schema:
=> SELECT CURRENT_SCHEMA();
current_schema
---------------public
(1 row)
The following command returns the same results without the parentheses:
=> SELECT CURRENT_SCHEMA;
current_schema
---------------public
(1 row)
The following command shows the current schema, listed after the current user, in the search path:
=> SHOW SEARCH_PATH;
name
|
setting
-------------+--------------------------------------------------search_path | "$user", public, v_catalog, v_monitor, v_internal
(1 row)
See Also
l
SET SEARCH_PATH
DATA_COLLECTOR_HELP
Returns online usage instructions about the Data Collector, the DATA_COLLECTOR system table, and
the Data Collector control functions.
Syntax
DATA_COLLECTOR_HELP()
SQLReference Manual
SQL Functions
Privileges
None
Returns
The DATA_COLLECTOR_HELP() function returns the following information:
=> SELECT DATA_COLLECTOR_HELP();
----------------------------------------------------------------------------Usage Data Collector
The data collector retains history of important system activities.
This data can be used as a reference of what actions have been taken
by users, but it can also be used to locate performance bottlenecks,
or identify potential improvements to the Vertica configuration.
This data is queryable via Vertica system tables.
Acccess a list of data collector components, and some statistics, by running:
SELECT * FROM v_monitor.data_collector;
The amount of data retained by size and time can be controlled with several
functions.
To just set the size amount:
set_data_collector_policy(<component>,
<memory retention (KB)>,
<disk retention (KB)>);
To set both the size and time amounts (the smaller one will dominate):
set_data_collector_policy(<component>,
<memory retention (KB)>,
<disk retention (KB)>,
<interval>);
To set just the time amount:
set_data_collector_time_policy(<component>,
<interval>);
To set the time amount for all tables:
set_data_collector_time_policy(<interval>);
The current retention policy for a component can be queried with:
get_data_collector_policy(<component>);
Data on disk is kept in the "DataCollector" directory under the Vertica
\catalog path. This directory also contains instructions on how to load
the monitoring data into another Vertica database.
To move the data collector logs and instructions to other storage locations,
create labeled storage locations using add_location and then use:
set_data_collector_storage_location(<storage_label>);
SQLReference Manual
SQL Functions
See Also
l
DATA_COLLECTOR
TUNING_RECOMMENDATIONS
Analyzing Workloads
DISABLE_DUPLICATE_KEY_ERROR
Disables error messaging when HP Vertica finds duplicate PRIMARY KEY/UNIQUE KEY values
at run time. Queries execute as though no constraints are defined on the schema. Effects are
session scoped.
Caution: When called, DISABLE_DUPLICATE_KEY_ERROR() suppresses data integrity
checking and can lead to incorrect query results. Use this function only after you insert
duplicate primary keys into a dimension table in the presence of a pre-join projection. Then
correct the violations and turn integrity checking back on with REENABLE_DUPLICATE_
KEY_ERROR().
Syntax
DISABLE_DUPLICATE_KEY_ERROR();
Privileges
Must be a superuser.
Examples
The following series of commands create a table named dim and the corresponding projection:
SQLReference Manual
SQL Functions
The next two statements create a table named fact and the pre-join projection that joins fact to
dim.
CREATE TABLE fact(fk INTEGER REFERENCES dim(pk));
CREATE PROJECTION prejoin_p (fk, pk, x) AS SELECT * FROM fact, dim WHERE pk=fk ORDER BY
x;
The following statements load values into table dim. The last statement inserts a duplicate primary
key value of 1:
INSERT INTO dim values (1,1);
INSERT INTO dim values (2,2);
INSERT INTO dim values (1,2); --Constraint violation
COMMIT;
Table dim now contains duplicate primary key values, but you cannot delete the violating row
because of the presence of the pre-join projection. Any attempt to delete the record results in the
following error message:
ROLLBACK: Duplicate primary key detected in FK-PK join Hash-Join (x dim_p), value 1
In order to remove the constraint violation (pk=1), use the following sequence of commands, which
puts the database back into the state just before the duplicate primary key was added.
To remove the violation:
1. Save the original dim rows that match the duplicated primary key:
CREATE TEMP TABLE dim_temp(pk integer, x integer);
INSERT INTO dim_temp SELECT * FROM dim WHERE pk=1 AND x=1; -- original dim row
SQLReference Manual
SQL Functions
The difference between this message and the rollback message in the previous example is that
a fact row contains a foreign key that matches the duplicated primary key, which has been
inserted. A row with values from the fact and dimension table is now in the pre-join projection.
In order for the DELETE statement (Step 3 in the following example) to complete successfully,
extra predicates are required to identify the original dimension table values (the values that are
in the pre-join).
This example is nearly identical to the previous example, except that an additional INSERT
statement joins the fact table to the dimension table by a primary key value of 1:
INSERT INTO
INSERT INTO
INSERT INTO
primary key
INSERT INTO
COMMIT;
dim values
dim values
fact values
value=1
dim values
(1,1);
(2,2);
(1);
SQLReference Manual
SQL Functions
1. Save the original dim and fact rows that match the duplicated primary key:
CREATE
CREATE
INSERT
INSERT
TEMP
TEMP
INTO
INTO
3. Remove the duplicate primary keys. These steps also implicitly remove all fact rows with the
matching foreign key.
4. Remove the original row that contains duplicate values:
DELETE FROM dim WHERE pk=1 AND x=1;
Note: The extra predicate (x=1) specifies removal of the original (1,1) row, rather than the
newly inserted (1,2) values that caused the violation.
7. Reinsert the original values back into the fact and dimension table:
INSERT INTO dim SELECT * from dim_temp;
INSERT INTO fact SELECT * from fact_temp;
COMMIT;
SQLReference Manual
SQL Functions
See Also
l
ANALYZE_CONSTRAINTS
REENABLE_DUPLICATE_KEY_ERROR
DISABLE_ELASTIC_CLUSTER
Disables elastic cluster scaling, which prevents HP Vertica from bundling data into chunks that are
easily transportable to other nodes when performing cluster resizing. The main reason to disable
elastic clustering is if you find that the slightly unequal data distribution in your cluster caused by
grouping data into discrete blocks results in performance issues.
Syntax
DISABLE_ELASTIC_CLUSTER()
Privileges
Must be a superuser.
Example
=> SELECT DISABLE_ELASTIC_CLUSTER();
DISABLE_ELASTIC_CLUSTER
------------------------DISABLED
(1 row)
See Also
l
ENABLE_ELASTIC_CLUSTER
DISABLE_LOCAL_SEGMENTS
Disable local data segmentation, which breaks projections segments on nodes into containers that
can be easily moved to other nodes. See Local Data Segmentation in the Administrator's Guide for
details.
SQLReference Manual
SQL Functions
Syntax
DISABLE_LOCAL_SEGMENTS()
Privileges
Must be a superuser.
Example
=> SELECT DISABLE_LOCAL_SEGMENTS();
DISABLE_LOCAL_SEGMENTS
-----------------------DISABLED
(1 row)
DISABLE_PROFILING
Disables profiling for the profiling type you specify.
Syntax
DISABLE_PROFILING( 'profiling-type' )
Parameters
profiling-type
The type of profiling data you want to disable. Can be one of:
l
sessiondisables profiling for basic session parameters and lock time out
data
querydisables profiling for general information about queries that ran, such
as the query strings used and the duration of queries
eedisables profiling for information about the execution run of each query
Example
The following statement disables profiling on query execution runs:
SQLReference Manual
SQL Functions
See Also
l
CLEAR_PROFILING
ENABLE_PROFILING
DISPLAY_LICENSE
Returns the terms of your HP Vertica license. The information this function displays is:
l
The start and end dates for which the license is valid (or "Perpetual" if the license has no
expiration).
The number of days you are allowed to use HP Vertica after your license term expires (the grace
period)
The amount of data your database can store, if your license includes a data allowance.
Syntax
DISPLAY_LICENSE()
Privileges
None
Examples
=> SELECT DISPLAY_LICENSE();
DISPLAY_LICENSE
---------------------------------------------------HP Vertica Systems, Inc.
1/1/2011
12/31/2011
30
SQLReference Manual
SQL Functions
50TB
(1 row)
DO_TM_TASK
Runs a Tuple Mover operation on one or more projections defined on the specified table.
Tip: You do not need to stop the Tuple Mover to run this function.
Syntax
DO_TM_TASK ( 'task' [ , '[[db-name.]schema.]table' |
'[[db-name.]schema.]projection' ] )
Parameters
task
Note: You cannot analyze the row count of external tables with
this option. You must use ANALYZE_EXTERNAL_ROW_
COUNT.
SQLReference Manual
SQL Functions
[[db-name.]schema.]
table
Runs a tuple mover operation for all projections within the specified table.
When using more than one schema, specify the schema that contains the
table with the projections you want to affect, as noted above.
projection
Privileges
l
Notes
DO_TM_TASK() is useful for moving out all projections from a table or database without having to
name each projection individually.
Examples
The following example performs a moveout of all projections for the t1 table:
=> SELECT DO_TM_TASK('moveout', 't1');
SQLReference Manual
SQL Functions
See Also
l
COLUMN_STORAGE
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
DROP_EXTERNAL_ROW_COUNT
Removes the exact row count statistic for the specified external table.
DROP_EXTERNAL_ROW_COUNTruns in the background. To cancel row count analysis, press
Ctrl+C in a vsql shell or call the INTERRUPT_STATEMENT() function.
It can be time consuming to regenerate statistics once they have been dropped.
Syntax
DROP_EXTERNAL_ROW_COUNT [ ('') | ('[[db-name.]schema-name.]table' ];
Parameters
''
Empty string. Specifies that HP Vertica drop the exact row count statistic
for all external tables.
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
SQLReference Manual
SQL Functions
table
Specifies the name of the external table for which to remove the exact row
count.
Privileges
l
Examples
This example shows how you use the command to drop base statistics for the external table in the
current schema, loader_rejects:
=> SELECT DROP_EXTERNAL_ROW_COUNT('loader_rejects');
See Also
l
ANALYZE_STATISTICS
ANALYZE_EXTERNAL_ROW_COUNT
DROP_STATISTICS
EXPORT_STATISTICS
IMPORT_STATISTICS
VALIDATE_STATISTICS
DROP_LICENSE
Drops a Flex Zone license key from the global catalog.
Syntax
DROP_LICENSE( 'license name' )
SQLReference Manual
SQL Functions
Parameters
license name
The name of the license to drop. The name can be found in the licenses table.
Privileges
Must be a superuser.
Notes
For more information about license keys, see Managing Licenses in the Administrator's Guide.
Examples
=> SELECT DROP_LICENSE('/tmp/vlicense.dat');
DROP_LOCATION
Removes the specified storage location.
Syntax
DROP_LOCATION ( 'path' , 'node' )
Parameters
path
node
The HP Vertica node where the location is available. A value of "" (an empty string) means
to perform this operation on all nodes.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Examples
The following example shows how to drop a storage location on node3, which was used to store
temp files:
=> SELECT DROP_LOCATION('/data' , 'node3');
SQLReference Manual
SQL Functions
See Also
l
ADD_LOCATION
ALTER_LOCATION_USE
RESTORE_LOCATION
RETIRE_LOCATION
DROP_PARTITION
Forces the partition of projections (if needed) and then drops the specified partition.
Syntax
DROP_PARTITION ( table_name , partition_value [ , ignore_moveout_errors, reorganize_data ])
Parameters
table-name
partition_value
SQLReference Manual
SQL Functions
ignore_moveout_errors
Note: If you set this parameter to true and the WOS includes data for
the partition in WOS, partition data in WOS is not dropped.
reorganize_data
Permissions
l
Table owner
SQLReference Manual
SQL Functions
One container holds the data that belongs to the partition that is to be dropped.
Examples
Using the example schema in Defining Partitions, the following command explicitly drops the 2009
partition key from table trade:
SELECT DROP_PARTITION('trade', 2009);
DROP_PARTITION
------------------Partition dropped
(1 row)
The following example creates a table called dates and partitions the table by year:
CREATE TABLE dates (year INTEGER NOT NULL,
month VARCHAR(8) NOT NULL)
PARTITION BY year * 12 + month;
The following statement drops the partition using a constant for Oct 2010 (2010*12 + 10 = 24130):
SQLReference Manual
SQL Functions
See Also
l
Dropping Partitions
ADVANCE_EPOCH
COLUMN_STORAGE
CREATE TABLE
DO_TM_TASK
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
PROJECTIONS
SQLReference Manual
SQL Functions
DROP_STATISTICS
Removes statistics for the specified table and lets you optionally specify the category of statistics
to drop.
Syntax
DROP_STATISTICS { ('') | ('[[db-name.]schema-name.]table' [, {'BASE' | 'HISTOGRAMS' | 'ALL'}
])};
Parameters
''
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Drops statistics for all projections within the specified table. When using
more than one schema, specify the schema that contains the table with
the projections you want to delete, as noted in the syntax.
CATEGORY
Privileges
l
Usage Considerations
Once dropped, statistics can be time consuming to regenerate.
SQLReference Manual
SQL Functions
If you want the query optimizer to use the default statistics instead of the statistics that ANALYZE_
STATISTICSgenerates, use DROP_STATISTICSto drop the generated statistics for one more
projections.
Examples
The following command analyzes all statistics on all tables in the database:
=> SELECT ANALYZE_STATISTICS('');
ANALYZE_STATISTICS
-------------------0
(1 row)
This command drops base statistics for the table store_sales_fact in the store schema:
=> SELECT DROP_STATISTICS('store.store_sales_fact', 'BASE');
DROP_STATISTICS
----------------0
(1 row)
See Also
l
ANALYZE_STATISTICS
ANALYZE_EXTERNAL_ROW_COUNT
SQLReference Manual
SQL Functions
DROP_EXTERNAL_ROW_COUNT
EXPORT_STATISTICS
IMPORT_STATISTICS
VALIDATE_STATISTICS
DUMP_CATALOG
Returns an internal representation of the HP Vertica catalog. This function is used for diagnostic
purposes.
Syntax
DUMP_CATALOG()
Privileges
None; however, function dumps only the objects visible to the user.
Notes
To obtain an internal representation of the HP Vertica catalog for diagnosis, run the query:
=> SELECT DUMP_CATALOG();
DUMP_LOCKTABLE
Returns information about deadlocked clients and the resources they are waiting for.
Syntax
DUMP_LOCKTABLE()
SQLReference Manual
SQL Functions
Privileges
None
Notes
Use DUMP_LOCKTABLE if HP Vertica becomes unresponsive:
1. Open an additional vsql connection.
2. Execute the query:
=> SELECT DUMP_LOCKTABLE();
You get the session_id value from the V_MONITOR.SESSIONS system table.
See Also
l
CLOSE_ALL_SESSIONS
CLOSE_SESSION
LOCKS
SESSIONS
SQLReference Manual
SQL Functions
DUMP_PARTITION_KEYS
Dumps the partition keys of all projections in the system.
Syntax
DUMP_PARTITION_KEYS( )
Note: The ROS objects of partitioned tables without partition keys are ignored by the tuple
mover and are not merged during automatic tuple mover operations.
Privileges
None; however function dumps only the tables for which user has SELECT privileges.
Example
=> SELECT DUMP_PARTITION_KEYS( );
Partition keys on node v_vmart_node0001
Projection 'states_b0'
Storage [ROS container]
No of partition keys: 1
Partition keys: NH
Storage [ROS container]
No of partition keys: 1
Partition keys: MA
Projection 'states_b1'
Storage [ROS container]
No of partition keys: 1
Partition keys: VT
Storage [ROS container]
No of partition keys: 1
Partition keys: ME
Storage [ROS container]
No of partition keys: 1
Partition keys: CT
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PROJECTION_PARTITION_KEYS
SQLReference Manual
SQL Functions
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
PARTITIONS
DUMP_PROJECTION_PARTITION_KEYS
Dumps the partition keys of the specified projection.
Syntax
DUMP_PROJECTION_PARTITION_KEYS(
'projection_name' )
Parameters
projection_name
Privileges
l
Example
The following example creates a simple table called states and partitions the data by state:
=> CREATE TABLE states (year INTEGER NOT NULL,
state VARCHAR NOT NULL)
PARTITION BY state;
=> CREATE PROJECTION states_p (state, year)
AS SELECT * FROM states
ORDER BY state, year UNSEGMENTED ALL NODES;
SQLReference Manual
SQL Functions
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
PROJECTIONS
DUMP_TABLE_PARTITION_KEYS
Dumps the partition keys of all projections anchored on the specified table.
Syntax
DUMP_TABLE_PARTITION_KEYS ( 'table_name' )
Parameters
table_name
Privilege
l
SQLReference Manual
SQL Functions
Examples
The following example creates a simple table called states and partitions the data by state:
=> CREATE TABLE states (year INTEGER NOT NULL,
state VARCHAR NOT NULL)
PARTITION BY state;
=> CREATE PROJECTION states_p (state, year) AS
SELECT * FROM states
ORDER BY state, year UNSEGMENTED ALL NODES;
Now dump the partition keys of all projections anchored on table states:
=> SELECT DUMP_TABLE_PARTITION_KEYS( 'states' );
Partition keys on helios_node0001
Projection 'states_p_node0004'
No of partition keys: 1
Projection 'states_p_node0003'
No of partition keys: 1
Projection 'states_p_node0002'
No of partition keys: 1
Projection 'states_p_node0001'
No of partition keys: 1
Partition keys on helios_node0002
...
(1 row)
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
EMPTYMAP
Constructs a new VMap with one row, but without keys or data. Use this transform function to
populate a map without using a flex parser, either from SQL queries, or from map data present
SQLReference Manual
SQL Functions
Syntax
emptymap()
Arguments
None
Examples
To create an empty map:
=> select emptymap();
emptymap
-----------------------------------------------------------------\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
(1 row)
If you create an empty map from an existing flex table, the new map will have the same number of
rows as the table from which it was created. For example, creating an empty map from the
darkdata table, which has 12 rows of JSON data has the following result:
=> select emptymap() from darkdata;
emptymap
-----------------------------------------------------------------\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
(12 rows)
See Also
l
MAPAGGREGATE
MAPCONTAINSKEY
SQLReference Manual
SQL Functions
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
ENABLE_ELASTIC_CLUSTER
Enables elastic cluster scaling, which makes enlarging or reducing the size of your database
cluster more efficient by segmenting a node's data into chunks that can be easily moved to other
hosts.
Note: Databases created using HP Vertica Version 5.0 and later have elastic cluster enabled
by default. You need to use this function on databases created before version 5.0 in order for
them to use the elastic clustering feature.
Syntax
ENABLE_ELASTIC_CLUSTER()
Privileges
Must be a superuser.
Example
=> SELECT ENABLE_ELASTIC_CLUSTER();
ENABLE_ELASTIC_CLUSTER
SQLReference Manual
SQL Functions
-----------------------ENABLED
(1 row)
See Also
l
DISABLE_ELASTIC_CLUSTER
ENABLE_LOCAL_SEGMENTS
Enables local storage segmentation, which breaks projections segments on nodes into containers
that can be easily moved to other nodes. See Local Data Segmentation in the Administrator's Guide
for more information.
Syntax
ENABLE_LOCAL_SEGMENTS()
Privileges
Must be a superuser.
Example
=> SELECT ENABLE_LOCAL_SEGMENTS();
ENABLE_LOCAL_SEGMENTS
----------------------ENABLED
(1 row)
ENABLE_PROFILING
Enables profiling for the profiling type you specify.
Note: HP Vertica stores profiled data is in memory, so depending on how much data you
collect, profiling could be memory intensive.
Syntax
ENABLE_PROFILING( 'profiling-type' )
SQLReference Manual
SQL Functions
Parameters
profiling-type
The type of profiling data you want to enable. Can be one of:
l
sessionenables profiling for basic session parameters and lock time out
data
queryenables profiling for general information about queries that ran, such
as the query strings used and the duration of queries
eeenables profiling for information about the execution run of each query
Example
The following statement enables profiling on query execution runs:
=> SELECT ENABLE_PROFILING('ee');
ENABLE_PROFILING
---------------------EE Profiling Enabled
(1 row)
See Also
l
CLEAR_PROFILING
DISABLE_PROFILING
ENFORCE_OBJECT_STORAGE_POLICY
Applies object storage policies immediately, instead of waiting for the Tuple Mover to perform the
next moveout. Calling this function is equivalent to setting the enforce_storage_move parameter
on related meta-functions. You typically use this function as the last step before dropping a storage
location.
This function invokes the Tuple Mover on a one-time basis.
Syntax
ENFORCE_OBJECT_STORAGE_POLICY ( 'object_name', [, 'key_min', 'key_max'] )
SQLReference Manual
SQL Functions
Parameters
object_name
Identifies the database object whose storage policies are to be applied. The
object_name parameter can resolve to a database, schema, or table.
key_min, key_max
Privileges
Must be the object owner to enforce the storage policy and have access to the storage location.
Examples
This example shows how to apply storage-policy updates to the test table:
=> select enforce_object_storage_policy("test");
See Also
l
CLEAR_OBJECT_STORAGE_POLICY
RETIRE_LOCATION
DROP_LOCATION
EVALUATE_DELETE_PERFORMANCE
Evaluates projections for potential DELETE performance issues. If there are issues found, a
warning message is displayed. For steps you can take to resolve delete and update performance
issues, see Optimizing Deletes and Updates for Performance in the Administrator's Guide. This
function uses data sampling to determine whether there are any issues with a projection. Therefore,
it does not generate false-positives warnings, but it can miss some cases where there are
performance issues.
Note: Optimizing for delete performance is the same as optimizing for update performance.
So, you can use this function to help optimize a projection for updates as well as deletes.
SQLReference Manual
SQL Functions
Syntax
EVALUATE_DELETE_PERFORMANCE ( 'target' )
Parameters
target
The name of a projection or table. If you supply the name of a projection, only that
projection is evaluated for DELETE performance issues. If you supply the name of a
table, then all of the projections anchored to the table will be evaluated for issues.
If you do not provide a projection or table name, EVALUATE_DELETE_
PERFORMANCE examines all of the projections that you can access for DELETE
performance issues. Depending on the size you your database, this may take a long
time.
Privileges
None
Notes
When evaluating multiple projections, EVALUATE_DELETE_PERFORMANCE reports up to ten
projections that have issues, and refers you to a table that contains the full list of issues it has
found.
Example
The following example demonstrates how you can use EVALUATE_DELETE_PERFORMANCE
to evaluate your projections for slow DELETE performance.
=> create table example (A int, B int,C int);
CREATE TABLE
=> create projection one_sort (A,B,C) as (select A,B,C from example) order by A;
CREATE PROJECTION
=> create projection two_sort (A,B,C) as (select A,B,C from example) order by A,B;
CREATE PROJECTION
=> select evaluate_delete_performance('one_sort');
evaluate_delete_performance
--------------------------------------------------No projection delete performance concerns found.
SQLReference Manual
SQL Functions
(1 row)
=> select evaluate_delete_performance('two_sort');
evaluate_delete_performance
--------------------------------------------------No projection delete performance concerns found.
(1 row)
The previous example showed that there was no structural issue with the projection that would
cause poor DELETE performance. However, the data contained within the projection can create
potential delete issues if the sorted columns do not uniquely identify a row or small number of rows.
In the following example, Perl is used to populate the table with data using a nested series of loops.
The inner loop populates column C, the middle loop populates column B, and the outer loop
populates column A. The result is column A contains only three distinct values (0, 1, and 2), while
column B slowly varies between 20 and 0 and column C changes in each row. EVALUATE_
DELETE_PERFORMANCE is run against the projections again to see if the data within the
projections causes any potential DELETE performance issues.
=> \! perl -e 'for ($i=0; $i<3; $i++) { for ($j=0; $j<21; $j++) { for ($k=0; $k<19; $k++)
{ printf "%d,%d,%d\n", $i,$j,$k;}}}' | /opt/vertica/bin/vsql -c "copy example from stdin
delimiter ',' direct;"
Password:
=> select * from example;
A | B | C
---+----+---0 | 20 | 18
0 | 20 | 17
0 | 20 | 16
0 | 20 | 15
0 | 20 | 14
0 | 20 | 13
0 | 20 | 12
0 | 20 | 11
0 | 20 | 10
0 | 20 | 9
0 | 20 | 8
0 | 20 | 7
0 | 20 | 6
0 | 20 | 5
0 | 20 | 4
0 | 20 | 3
0 | 20 | 2
0 | 20 | 1
0 | 20 | 0
0 | 19 | 18
1157 rows omitted
2 | 1 | 0
2 | 0 | 18
2 | 0 | 17
2 | 0 | 16
2 | 0 | 15
2 | 0 | 14
2 | 0 | 13
SQLReference Manual
SQL Functions
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
2 | 0 |
=> SELECT
COUNT
------1197
(1 row)
=> SELECT
COUNT
------3
(1 row)
=> select
12
11
10
9
8
7
6
5
4
3
2
1
0
COUNT (*) FROM example;
evaluate_delete_performance('one_sort');
evaluate_delete_performance
--------------------------------------------------Projection exhibits delete performance concerns.
(1 row)
release=> select evaluate_delete_performance('two_sort');
evaluate_delete_performance
--------------------------------------------------No projection delete performance concerns found.
(1 row)
The one_sort projection has potential delete issues since it only sorts on column A which has few
distinct values. This means that each value in the sort column corresponds to many rows in the
projection, which negatively impacts DELETE performance. Since the two_sort projection is sorted
on columns A and B, each combination of values in the two sort columns identifies just a few rows,
allowing deletes to be performed faster.
Not supplying a projection name results in all of the projections you can access being evaluated for
DELETE performance issues.
=> select evaluate_delete_performance();
evaluate_delete_performance
--------------------------------------------------------------------------The following projection exhibits delete performance concerns:
"public"."one_sort"
See v_catalog.projection_delete_concerns for more details.
(1 row)
SQLReference Manual
SQL Functions
EXPORT_CATALOG
Generates a SQL script that you can use to recreate a physical schema design in its current state
on a different cluster. This function always attempts to recreate projection statements with KSAFE
clauses, if they exist in the original definitions, or OFFSET clauses if they do not.
Syntax
EXPORT_CATALOG ( [ 'destination'
] , [ 'scope'
] )
Parameters
destination
Specifies the path and name of the SQL output file. An empty string (''), which is
the default, outputs the script to standard output. The function writes the script to
the catalog directory if no destination is specified.
If you specify a file that does not exist, the function creates one. If the file preexists, the function silently overwrites its contents.
scope
TABLESExports all tables and constraints for which the user has
permissions. See also EXPORT_TABLES.
Privileges
None. However:
l
Example
The following example exports the design to standard output:
SQLReference Manual
SQL Functions
See Also
l
EXPORT_OBJECTS
EXPORT_TABLES
EXPORT_OBJECTS
Generates a SQL script you can use to recreate catalog objects on a different cluster. The
generated script includes only the non-virtual objects to which the user has access. The function
exports catalog objects in order dependency for correct recreation. Running the generated SQL
script on another cluster then creates all referenced objects before their dependent objects.
The EXPORT_OBJECTS function always attempts to recreate projection statements with KSAFE
clauses, if they existed in the original definitions, or OFFSET clauses, if they did not.
None of the EXPORT_OBJECTS parameters accepts a NULL value as input. EXPORT_
OBJECTS returns an error if an explicitly-specified object does not exist, or the user does not have
access to the object.
Syntax
EXPORT_OBJECTS( [ 'destination' ] , [ 'scope' ] , [ 'ksafe' ] )
Parameters
destination
Specifies the path and name of the SQL output file. The default empty string ('')
outputs the script to standard output. The function writes the script to the catalog
directory if no destination is specified.
If you specify a file that does not exist, the function creates one. If the file preexists, the function silently overwrites its contents.
SQLReference Manual
SQL Functions
scope
An empty string (' ')exports all non-virtual objects to which the user has
access, including constraints. (Note that constraints are not objects that can be
passed as individual arguments.) An empty string is the default scope value if
you do not limit the export.
ksafe
Determines if the statistics are regenerated before loading them into the design
context
Specifies whether to incorporate a MARK_DESIGN_KSAFE statement with the
correct K-safe value for the database:
l
Privileges
None. However:
l
SQLReference Manual
SQL Functions
Example
The following example exports all the non-virtual objects to which the user has access to standard
output. The example uses false for the last parameter, indicating that the file will not include the
MARK_DESIGN_KSAFE statement at the end.
=> SELECT EXPORT_OBJECTS(' ',' ',false);
See Also
l
EXPORT_CATALOG
EXPORT_TABLES
Exporting Objects
EXPORT_STATISTICS
Generates an XML file that contains statistics for the database. You can optionally export statistics
on a single database object (table, projection, or table column).
Before you export statistics for the database, run ANALYZE_STATISTICS() to automatically
collect the most up to date statistics information.
Syntax
EXPORT_STATISTICS ( 'destination' [, '[[ db-name.]schema.]object [.column-name ]'])
Parameters
destination
Specifies the path and name of the XML output file. An empty string
returns the script to the screen.If you do not use an absolute path, the path
you give will be interpreted relative to the database's catalog directory.
(For example, if you just give a file name, the file will be written there.)
SQLReference Manual
SQL Functions
[[db-name.]schema.]
object
Specifies the name of the object (table or projection) to export and exports
statistics for that object. If the object is a table, this function exports
statistics for all projections of that table.
Note: If you are using more than one schema, specify the schema
that contains the table, as noted in the [[db-name.]schema.] entry.
[.column-name]
Privileges
Must be a superuser.
Examples
The following statement exports statistics on the VMart example database to a file:
vmart=> SELECT EXPORT_STATISTICS('/opt/vertica/examples/VMart_Schema/vmart_stats.xml');
EXPORT_STATISTICS
----------------------------------Statistics exported successfully
(1 row)
The next statement exports statistics on a single column (price) from a table called food:
=> SELECT EXPORT_STATISTICS('/opt/vertica/examples/VMart_Schema/price.xml',
'food.price');
SQLReference Manual
SQL Functions
----------------------------------EXPORT_STATISTICS
----------------------------------Statistics exported successfully
(1 row)
See Also
l
ANALYZE_STATISTICS
DROP_STATISTICS
IMPORT_STATISTICS
VALIDATE_STATISTICS
EXPORT_TABLES
Generates a SQL script that can be used to recreate a logical schema (schemas, tables,
constraints, and views) on a different cluster.
Syntax
EXPORT_TABLES ( [ 'destination' ] , [ 'scope' ] )
Parameters
destination
Specifies the path and name of the SQL output file. An empty string (''), which is
the default, outputs the script to standard output. The function writes the script to
the catalog directory if no destination is specified.
If you specify a file that does not exist, the function creates one. If the file preexists, the function silently overwrites its contents.
SQLReference Manual
SQL Functions
scope
An empty string (' ')exports all non-virtual table objects to which the user has
access, including table schemas, sequences, and constraints. Exporting all
non-virtual objects is the default scope, and what the function exports if you do
not specify a scope.
Privileges
None; however:
l
Example
The following example exports the store_orders_fact table of the store schema (in the current
database) to standard output:
=> SELECT EXPORT_TABLES(' ','store.store_orders_fact');
SQLReference Manual
SQL Functions
See Also
EXPORT_CATALOG
EXPORT_OBJECTS
l
l
FLUSH_DATA_COLLECTOR
Waits until memory logs are moved to disk and then flushes the Data Collector, synchronizing the
log with the disk storage. A superuser can flush Data Collector information for an individual
component or for all components.
Syntax
FLUSH_DATA_COLLECTOR( [ 'component' ] )
Parameters
component
Flushes the specified component. If you provide no argument, the function flushes
the Data Collector in full.
For the current list of component names, query the V_MONITOR.DATA_
COLLECTOR system table.
Privileges
Must be a superuser.
Examples
The following command flushes the Data Collector for the ResourceAcquisitions component:
=> SELECT flush_data_collector('ResourceAcquisitions');
flush_data_collector
---------------------FLUSH
(1 row)
SQLReference Manual
SQL Functions
See Also
DATA_COLLECTOR
l
l
GET_AHM_EPOCH
Returns the number of the epoch in which the Ancient History Mark is located. Data deleted up to
and including the AHM epoch can be purged from physical storage.
Syntax
GET_AHM_EPOCH()
Privileges
None
Examples
SELECT GET_AHM_EPOCH();
GET_AHM_EPOCH
---------------------Current AHM epoch: 0
(1 row)
GET_AHM_TIME
Returns a TIMESTAMP value representing the Ancient History Mark. Data deleted up to and
including the AHM epoch can be purged from physical storage.
SQLReference Manual
SQL Functions
Syntax
GET_AHM_TIME()
Privileges
None
Examples
SELECT GET_AHM_TIME();
GET_AHM_TIME
------------------------------------------------Current AHM Time: 2010-05-13 12:48:10.532332-04
(1 row)
See Also
l
SET DATESTYLE
TIMESTAMP
GET_AUDIT_TIME
Reports the time when the automatic audit of database size occurs. HP Vertica performs this audit
if your HP Vertica license includes a data size allowance. For details of this audit, see Managing
Your License Key in the Administrator's Guide. To change the time the audit runs, use the SET_
AUDIT_TIME function.
Syntax
GET_AUDIT_TIME()
Privileges
None
Example
=> SELECT get_audit_time();
SQLReference Manual
SQL Functions
get_audit_time
----------------------------------------------------The audit is scheduled to run at 11:59 PM each day.
(1 row)
GET_COMPLIANCE_STATUS
Displays whether your database is in compliance with your HP Vertica license agreement. This
information includes the results of HP Vertica's most recent audit of the database size (if your
license has a data allowance as part of its terms), and the license term (if your license has an end
date).
The information displayed by GET_COMPLIANCE_STATUS includes:
l
The estimated size of the database (see How HP Vertica Calculates Database Size in the
Administrator's Guide for an explanation of the size estimate).
Whether your database complies with the data allowance terms of your license agreement.
Note: If your license does not have a data allowance or end date, some of the values may not
appear in the output for GET_COMPLIANCE_STATUS.
If the audit shows your license is not in compliance with your data allowance, you should either
delete data to bring the size of the database under the licensed amount, or upgrade your license. If
your license term has expired, you should contact HP immediately to renew your license. See
Managing Your License Key in the Administrator's Guide for further details.
Syntax
GET_COMPLIANCE_STATUS()
SQLReference Manual
SQL Functions
Privileges
None
Example
GET_COMPLIANCE_STATUS
--------------------------------------------------------------------------------Raw Data Size: 2.00GB +/- 0.003GB
License Size : 4.000GB
Utilization : 50%
Audit Time
: 2011-03-09 09:54:09.538704+00
Compliance Status : The database is in compliance with respect to raw data size.
License End Date: 04/06/2011
Days Remaining: 28.59
(1 row)
GET_CURRENT_EPOCH
The epoch into which data (COPY, INSERT, UPDATE, and DELETE operations) is currently being
written.
Returns the number of the current epoch.
Syntax
GET_CURRENT_EPOCH()
Privileges
None
Examples
SELECT GET_CURRENT_EPOCH();
GET_CURRENT_EPOCH
------------------683
(1 row)
GET_DATA_COLLECTOR_POLICY
Retrieves a brief statement about the retention policy for the specified component.
SQLReference Manual
SQL Functions
Syntax
GET_DATA_COLLECTOR_POLICY( 'component' )
Parameters
component
Privileges
None
Example
The following query returns the history of all resource acquisitions by specifying the
ResourceAcquisitions component:
=> SELECT get_data_collector_policy('ResourceAcquisitions');
get_data_collector_policy
---------------------------------------------1000KB kept in memory, 10000KB kept on disk.
(1 row)
See Also
DATA_COLLECTOR
l
l
GET_LAST_GOOD_EPOCH
A term used in manual recovery, LGE (Last Good Epoch) refers to the most recent epoch that can
be recovered.
Returns the number of the last good epoch.
Syntax
GET_LAST_GOOD_EPOCH()
SQLReference Manual
SQL Functions
Privileges
None
Examples
SELECT GET_LAST_GOOD_EPOCH();
GET_LAST_GOOD_EPOCH
--------------------682
(1 row)
GET_NUM_ACCEPTED_ROWS
Returns the number of rows loaded into the database for the last completed load for the current
session. GET_NUM_ACCEPTED_ROWS is a meta-function. Do not use it as a value in an
INSERT query.
The number of accepted rows is not available for a load that is currently in process. Check the
LOAD_STREAMS system table for its status.
Also, this meta-function supports only loads from STDIN or a single file on the initiator. You cannot
use GET_NUM_ACCEPTED_ROWS for multi-node loads.
Syntax
GET_NUM_ACCEPTED_ROWS();
Privileges
None
Note: The data regarding accepted rows from the last load during the current session does not
persist, and is lost when you initiate a new load.
Examples
This examples shows the number of accepted rows from the vmart_load_data.sql meta-command.
=> \i vmart_load_data.sql;
SQLReference Manual
SQL Functions
See Also
l
GET_NUM_REJECTED_ROWS
GET_NUM_REJECTED_ROWS
Returns the number of rows that were rejected during the last completed load for the current
session. GET_NUM_REJECTED_ROWS is a meta-function. Do not use it as a value in an
INSERT query.
Rejected row information is unavailable for a load that is currently running. The number of rejected
rows is not available for a load that is currently in process. Check the LOAD_STREAMS system
table for its status.
Also, this meta-function supports only loads from STDIN or a single file on the initiator. You cannot
use GET_NUM_REJECTED_ROWS for multi-node loads.
Syntax
GET_NUM_REJECTED_ROWS();
Privileges
None
Note: The data regarding rejected rows from the last load during the current session does not
persist, and is dropped when you initiate a new load.
Examples
This example shows the number of rejected rows from the vmart_load_data.sql meta-command.
=>
\i vmart_load_data.sql
SQLReference Manual
SQL Functions
See Also
l
GET_NUM_ACCEPTED_ROWS
GET_PROJECTION_STATUS
Returns information relevant to the status of a projection.
Syntax
GET_PROJECTION_STATUS ( '[[db-name.]schema-name.]projection' );
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection
Is the name of the projection for which to display status. When using more
than one schema, specify the schema that contains the projection, as
noted above.
Privileges
None
Description
GET_PROJECTION_STATUS returns information relevant to the status of a projection:
l
SQLReference Manual
SQL Functions
Notes
l
To view a list of the nodes in a database, use the View Database Command in the
Administration Tools.
Examples
=> SELECT GET_PROJECTION_STATUS('public.customer_dimension_site01');
GET_PROJECTION_STATUS
---------------------------------------------------------------------------------------------Current system K is 1.
# of Nodes: 4.
public.customer_dimension_site01 [Segmented: No] [Seg Cols: ] [K: 3] [public.customer_
dimension_site04, public.customer_dimension_site03,
public.customer_dimension_site02]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
See Also
l
GET_PROJECTIONS, GET_TABLE_PROJECTIONS
GET_PROJECTIONS, GET_TABLE_PROJECTIONS
Note: This function was formerly named GET_TABLE_PROJECTIONS(). HP Vertica still
supports the former function name.
Returns information relevant to the status of a table:
SQLReference Manual
SQL Functions
The number of projections for which the specified table is the anchor table
Syntax
GET_PROJECTIONS ( '[[db-name.]schema-name.]table' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Is the name of the table for which to list projections. When using more than
one schema, specify the schema that contains the table.
Privileges
None
Notes
l
You can use GET_PROJECTIONS to monitor the progress of a projection data refresh. See
ALTER PROJECTION.
To view a list of the nodes in a database, use the View Database Command in the
Administration Tools.
SQLReference Manual
SQL Functions
Examples
The following example gets information about the store_dimension table in the VMart schema:
=> SELECT GET_PROJECTIONS('store.store_dimension');
-------------------------------------------------------------------------------------Current system K is 1.
# of Nodes: 4.
Table store.store_dimension has 4 projections.
Projection Name: [Segmented] [Seg Cols] [# of Buddies] [Buddy Projections] [Safe]
[UptoDate]
---------------------------------------------------------store.store_dimension_node0004 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0003, store.store_dimension_node0002, store.store_dimension_node0001]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
store.store_dimension_node0003 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0004, store.store_dimension_node0002, store.store_dimension_node0001]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
store.store_dimension_node0002 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0004, store.store_dimension_node0003, store.store_dimension_node0001]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
store.store_dimension_node0001 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0004, store.store_dimension_node0003, store.store_dimension_node0002]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
(1 row)
See Also
l
GET_PROJECTION_STATUS
HAS_ROLE
Indicates, with a Boolean value, whether a role has been assigned to a user. This function is useful
for letting you check your own role membership.
Behavior Type
Stable
Syntax 1
HAS_ROLE( [ 'user_name' ,] 'role_name' );
SQLReference Manual
SQL Functions
Syntax 2
HAS_ROLE( 'role_name' );
Parameters
user_name
[Optional] The name of a user to look up. Currently, only a superuser can supply the
user_name argument.
role_name
The name of the role you want to verify has been granted.
Privileges
Users can check their own role membership by calling HAS_ROLE('role_name'), but only a
superuser can look up other users' memberships using the optional user_name parameter.
Notes
You can query V_CATALOG system tables ROLES, GRANTS, and USERS to show any directlyassigned roles; however, these tables do not indicate whether a role is available to a user when
roles may be available through other roles (indirectly).
Examples
User Bob wants to see if he has been granted the commentor role:
=> SELECT HAS_ROLE('commentor');
Output t for true indicates that Bob has been assigned the commentor role:
HAS_ROLE
---------t
(1 row)
In the following function call, a superuser checks if the logadmin role has been granted to user Bob:
=> SELECT HAS_ROLE('Bob', 'logadmin');
HAS_ROLE
---------t
SQLReference Manual
SQL Functions
(1 row)
To view the names of all roles users can access, along with any roles that have been assigned to
those roles, query the V_CATALOG.ROLES system table. An asterisk in the output means role
granted WITH ADMIN OPTION.
=> SELECT * FROM roles;
role_id
|
name
| assigned_roles
-------------------+-----------------+---------------45035996273704964 | public
|
45035996273704966 | dbduser
|
45035996273704968 | dbadmin
| dbduser*
45035996273704972 | pseudosuperuser | dbadmin*
45035996273704974 | logreader
|
45035996273704976 | logwriter
|
45035996273704978 | logadmin
| logreader,
logwriter
(7 rows)
See Also
l
GRANTS
ROLES
USERS
IMPORT_STATISTICS
Imports statistics from the XML file generated by the EXPORT_STATISTICS command.
Syntax
IMPORT_STATISTICS ( 'XML_statistics_file' )
Parameters
XML_statistics_file
Specifies the path and name of the XML input file (which is the output of
EXPORT_STATISTICS function), type VARCHAR.
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Usage Considerations
l
Imported statistics override existing statistics for all projections on the table referenced in the
XMLfile.
IMPORT_STATISTICS imports only valid statistics. If the source file has invalid statistics for a
specific column, those statistics are not imported and a warning occurs. If the statistics file has
an invalid structure, the import operation fails. To check a statistics file for validity, run
VALIDATE_STATISTICS.
Example
Import the statistics for the VMart database that EXPORT_STATISTICSsaved.
=> SELECT IMPORT_STATISTICS('/opt/vertica/examples/VMart_Schema/vmart_stats.xml');
IMPORT_STATISTICS
---------------------------------------------------------------------------Importing statistics for projection date_dimension_super column date_key failure (stats
did not contain row counts)
Importing statistics for projection date_dimension_super column date failure (stats did
not contain row counts)
Importing statistics for projection date_dimension_super column full_date_description
failure (stats did not contain row counts)
...
(1 row)
See Also
l
ANALYZE_STATISTICS
DROP_STATISTICS
EXPORT_STATISTICS
SQLReference Manual
SQL Functions
INTERRUPT_STATEMENT
Interrupts the specified statement (within an external session), rolls back the current transaction,
and writes a success or failure message to the log file.
Syntax
INTERRUPT_STATEMENT( 'session_id ', statement_id )
Parameters
session_id
Specifies the session to interrupt. This identifier is unique within the cluster at
any point in time.
statement_id
Privileges
Must be a superuser.
Notes
l
If the statement_id is valid, the statement is interruptible. The command is successfully sent
and returns a success message. Otherwise the system returns an error.
Messages
The following list describes messages you might encounter:
Message
Meaning
This message
indicates
success.
SQLReference Manual
SQL Functions
Message
Meaning
The session ID
argument to the
interrupt
command does
not match a
running session.
The statement ID
does not match (or
no longer
matches) the ID of
a running
statement (if any).
The statement is
DDL or otherwise
non-interruptible.
The session is
internal, and only
statements run by
external sessions
can be interrupted.
Examples
Two user sessions are open. RECORD 1 shows user session running SELECT FROM SESSION, and
RECORD 2 shows user session running COPY DIRECT:
=> SELECT * FROM SESSIONS;
-[ RECORD 1 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
transaction_description
| user dbadmin (select * from sessions;)
statement_start
| 2011-01-03 15:36:13.896288
statement_id
| 10
SQLReference Manual
SQL Functions
last_statement_duration_us | 14978
current_statement
| select * from sessions;
ssl_state
| None
authentication_method
| Trust
-[ RECORD 2 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0003
user_name
| dbadmin
client_hostname
| 127.0.0.1:56367
client_pid
| 1191
login_timestamp
| 2011-01-03 15:31:44.939302-05
session_id
| stress06-25663:0xbec
client_label
|
transaction_start
| 2011-01-03 15:34:51.05939
transaction_id
| 54043195528458775
transaction_description
| user dbadmin (COPY Mart_Fact FROM '/data/Mart_Fact.tbl'
DELIMITER '|' NULL '\\n' DIRECT;)
statement_start
| 2011-01-03 15:35:46.436748
statement_id
| 5
last_statement_duration_us | 1591403
current_statement
| COPY Mart_Fact FROM '/data/Mart_Fact.tbl' DELIMITER '|'
NULL '\\n' DIRECT;
ssl_state
| None
authentication_method
| Trust
Verify that the interrupted statement is no longer active by looking at the current_statement column
in the SESSIONS system table. This column becomes blank when the statement has been
interrupted:
=> SELECT * FROM SESSIONS;
-[ RECORD 1 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
transaction_description
| user dbadmin (select * from sessions;)
statement_start
| 2011-01-03 15:36:13.896288
statement_id
| 10
last_statement_duration_us | 14978
current_statement
| select * from sessions;
SQLReference Manual
SQL Functions
ssl_state
| None
authentication_method
| Trust
-[ RECORD 2 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0003
user_name
| dbadmin
client_hostname
| 127.0.0.1:56367
client_pid
| 1191
login_timestamp
| 2011-01-03 15:31:44.939302-05
session_id
| stress06-25663:0xbec
client_label
|
transaction_start
| 2011-01-03 15:34:51.05939
transaction_id
| 54043195528458775
transaction_description
| user dbadmin (COPY Mart_Fact FROM '/data/Mart_Fact.tbl'
DELIMITER '|' NULL '\\n' DIRECT;)
statement_start
| 2011-01-03 15:35:46.436748
statement_id
| 5
last_statement_duration_us | 1591403
current_statement
|
ssl_state
| None
authentication_method
| Trust
See Also
l
SESSIONS
Managing Sessions
Configuration Parameters
INSTALL_LICENSE
Installs the license key in the global catalog.
Syntax
INSTALL_LICENSE( 'filename' )
Parameters
filename
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
For more information about license keys, see Managing Your License Key in the Administrator's
Guide.
Examples
=> SELECT INSTALL_LICENSE('/tmp/vlicense.dat');
LAST_INSERT_ID
Returns the last value of a column whose value is automatically incremented through the AUTO_
INCREMENT or IDENTITY Column-Constraint. If multiple sessions concurrently load the same
table, the returned value is the last value generated for an AUTO_INCREMENT column by an
insert in that session.
Behavior Type
Volatile
Syntax
LAST_INSERT_ID()
Privileges
l
Table owner
Notes
l
This function works only with AUTO_INCREMENT and IDENTITY columns. See columnconstraints for the CREATE TABLE statement.
LAST_INSERT_ID does not work with sequence generators created through the CREATE
SEQUENCE statement.
SQLReference Manual
SQL Functions
Examples
Create a sample table called customer4.
=> CREATE TABLE customer4(
ID IDENTITY(2,2),
lname VARCHAR(25),
fname VARCHAR(25),
membership_card INTEGER
);
=> INSERT INTO customer4(lname, fname, membership_card)
VALUES ('Gupta', 'Saleem', 475987);
Notice that the IDENTITY column has a seed of 2, which specifies the value for the first row loaded
into the table, and an increment of 2, which specifies the value that is added to the IDENTITY value
of the previous row.
Query the table you just created:
=> SELECT * FROM customer4;
ID | lname | fname | membership_card
----+-------+--------+----------------2 | Gupta | Saleem |
475987
(1 row)
SQLReference Manual
SQL Functions
| membership_card
See Also
l
ALTER SEQUENCE
CREATE SEQUENCE
DROP SEQUENCE
SEQUENCES
Sequence Privileges
MAKE_AHM_NOW
Sets the Ancient History Mark (AHM) to the greatest allowable value, and lets you drop any
projections that existed before the issue occurred.
Caution: This function is intended for use by Administrators only.
Syntax
MAKE_AHM_NOW ( [ true ] )
SQLReference Manual
SQL Functions
Parameters
true
[Optional] Allows AHM to advance when nodes are down. Note: If the AHM is advanced
after the last good epoch of the failed nodes, those nodes must recover all data from
scratch. Use with care.
Privileges
Must be a superuser.
Notes
l
Sets the AHM to LGE at least to the current epoch at the time MAKE_AHM_NOW() was
issued.
All history is lost and you cannot perform historical queries prior to the current epoch.
Example
=> SELECT MAKE_AHM_NOW();
MAKE_AHM_NOW
-----------------------------AHM set (New AHM Epoch: 683)
(1 row)
The following command allows the AHM to advance, even though node 2 is down:
=> SELECT
WARNING:
WARNING:
WARNING:
MAKE_AHM_NOW(true);
Received no response from v_vmartdb_node0002 in get cluster LGE
Received no response from v_vmartdb_node0002 in get cluster LGE
Received no response from v_vmartdb_node0002 in set AHM
MAKE_AHM_NOW
-----------------------------AHM set (New AHM Epoch: 684)
(1 row)
SQLReference Manual
SQL Functions
See Also
l
DROP PROJECTION
MARK_DESIGN_KSAFE
SET_AHM_EPOCH
SET_AHM_TIME
MAPAGGREGATE
Returns a LONG VARBINARY VMap with keys and value pairs supplied from two VARCHAR input
columns of an existing columnar table. Using this function requires specifying an over() clause for
the source table. The examples here use the over (PARTITION BEST) clause.
Syntax
mapaggregate(source_column1, source_column2)
Arguments
source_column1
Table column with values to use as the keys of the key/value pair of the
returned VMap data.
source_column2
Table column with values to use as the values in the key/value pair of the
returned VMap data.
Examples
This example creates a columnar table btest, with two VARCHAR columns, named keys and
values, and adds three sets of values:
=> create table btest(keys varchar(10), values varchar(10));
CREATE TABLE
=> copy btest from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> one|1
>> two|2
>> three|3
>> \.
SQLReference Manual
SQL Functions
After populating the btest table, calling mapaggregate() return the raw_map data:
=>
The next example illustrates using MAPTOSTRING() with the returned raw_map from
mapaggregate() to see the values:
=> select maptostring(raw_map) from (select mapaggregate(keys, values) over(PARTITION
BEST) from btest) bit;
maptostring
---------------------------------------------{
"one": "1",
"three":
"3",
"two": "2"
}
(1 row)
See Also
l
EMPTYMAP
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
SQLReference Manual
SQL Functions
MAPVALUES
MAPVERSION
MAPCONTAINSKEY
Determines whether a VMap contains a virtual column (key). This scalar function returns true (t) if
the virtual column exists, or false (f) if it does not. Determining that a key exists before calling
maplookup()lets you distinguish between NULL returns, which that function uses for both a nonexistent key, and an existing key with a NULL value.
Syntax
mapcontainskey(VMap_data, 'virtual_column_name')
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex
table, data returned from a map function such as maplookup(), or other
database content.
virtual_column_name
Examples
This example uses maplookup() and the mapcontainskey() functions. Displaying the results
returned from both functions differentiates whether the empty fields that maplookup() returns
indicate a NULL value for the row (t), or no value (f):
=> select maplookup(__raw__, 'user.location'), mapcontainskey(__raw__, 'user.location')
from darkdata order by 1;
maplookup | mapcontainskey
-----------+---------------| t
| t
| t
| t
Chile
| t
Narnia
| t
Uptown.. | t
chicago
| t
| f
| f
SQLReference Manual
SQL Functions
| f
| f
(12 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPCONTAINSVALUE
Determines whether a VMap contains a specific value. Use this scalar function to return true (t) if
the value exists, or false (f) if it does not.
Syntax
mapcontainsvalue(VMap_data, 'virtual_column_value')
SQLReference Manual
SQL Functions
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex
table, data returned from a map function such as maplookup(), or
other database content.
virtual_column_value
Examples
This example shows a flex table (ftest), populated with some virtual columns and values. Both
virtual columns are named one:
=> create flex table ftest();
CREATE TABLE
=> copy ftest from stdin parser fjsonparser();
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> {"one":1, "two":2}
>> {"one":"one","2":"2"}
>> \.
Calling mapcontainsvalue() on the ftest map data returns false (f) for the first virtual column,
and true (t) for the second , which contains the value one:
=> select mapcontainsvalue(__raw__, 'one') from ftest;
mapcontainsvalue
-----------------f
t
(2 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPITEMS
MAPKEYS
SQLReference Manual
SQL Functions
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPITEMS
Returns information about items in a VMap. Use this transform function with one or more optional
arguments to access polystructured values within the VMap data. This function requires an over()
clause. The examples here use over(PARTITION BEST).
Syntax
mapItems(VMap_data [, passthrough_arg [,...] ])
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table,
data returned from a map function such as maplookup(), or other database
content.
passthrough_ [Optional] One or more arguments indicating keys within the map data in VMap_
arg
data.
Examples
This example uses a flex table darkmountain, populated with JSON data. This query uses the
count() function to return the number of virtual columns found in the map data:
=> select count(keys) from (select mapitems(darkmountain.__raw__) over(PARTITION BEST)
from darkmountain) as a;
count
------19
(1 row)
SQLReference Manual
SQL Functions
This example shows a snippet of the return data querying a flex table of all items in the map data:
=> select * from (select mapitems(darkmountain.__raw__) over(PARTITION BEST) from
darkmountain) as a;
keys
|
values
-------------+--------------hike_safety | 50.6
name
| Mt Washington
type
| mountain
height
| 17000
hike_safety | 12.2
name
| Denali
type
| mountain
height
| 29029
hike_safety | 34.1
name
| Everest
type
| mountain
height
| 14000
hike_safety | 22.8
name
| Kilimanjaro
type
| mountain
height
| 29029
hike_safety | 15.4
name
| Mt St Helens
type
| volcano
(19 rows)
SQLReference Manual
SQL Functions
3. Call mapkeys on the flex table's __raw__ column to see the flex table's keys, but not their
submaps. The return values indicate three_Array as one of the virtual columns:
=> select mapkeys(__raw__) over() from mapper;
keys
------------five_Map
four
one
six
three_Array
two
(6 rows)
4. Call mapitems on flex table mapper with three_Array as a pass-through argument to the
function to return the array values:
=> select __identity__, mapitems(three_Array) OVER(PARTITION BY __identity__) from
mapper;
__identity__ | keys |
values
--------------+------+-----------1 | 0
| three_One
1 | 1
| three_Two
1 | 2
| 3
1 | 3
| three_Four
(4 rows)
SQLReference Manual
SQL Functions
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPKEYS
Returns the virtual columns (and values) present in any VMap data. This transform function
requires an over(PARTITION BEST) clause, as shown in the example.
Syntax
mapkeys(VMap_data)
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table, data
returned from a map function such as maplookup(), or other database content.
SQLReference Manual
SQL Functions
Examples
This example uses a flex table darkdata, populated with JSON tweet data. This query returns the
number of virtual columns found in the map data:
=> select count(keys) from (SELECT mapkeys(darkdata.__raw__) over(PARTITION BEST) from
darkdata) as a;
count
------550
(1 row)
This example shows a snippet of the return data querying an ordered list of all virtual columns in the
map data:
=> select * from (SELECT mapkeys(darkdata.__raw__) over(PARTITION BEST) from darkdata) as
a;
keys
------------------------------------contributors
coordinates
created_ at
delete.status.id
delete.status.id_str
delete.status.user_id
delete.status.user_id_str
entities.hashtags
entities.media
entities.urls
entities.user_mentions
favorited
geo
id
.
.
.
user.statuses_count
user.time_zone
user.url
user.utc_offset
user.verified
(125 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
SQLReference Manual
SQL Functions
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPKEYSINFO
Returns virtual column information from a given map. This transform function requires an over
(PARTITION BEST)clause, as shown in the example.
Syntax
mapkeysinfo(VMap_data)
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table, data
returned from a map function such as maplookup(), or other database content.
Returns
This function is a superset of the MAPKEYS() function. It returns the following information about
each virtual column:
Column
Description
keys
length
The data length of the key name, which can differ from the actual string length.
SQLReference Manual
SQL Functions
Column
Description
type_oid
The OID type into which the value should be converted. Currently, the type is always
116 for a LONG VARCHAR, or 199 for a nested map, stored as a LONG VARBINARY.
row_num
field_num
Examples
This example shows a snippet of the return data querying an ordered list of all virtual columns in the
map data:
=> select * from (SELECT mapkeysinfo(darkdata.__raw__) over(PARTITION BEST) from
darkdata) as a;
keys
| length | type_oid | row_num |
field_num
----------------------------------------------------------+--------+----------+--------+----------contributors
|
0 |
116 |
1 |
0
coordinates
|
0 |
116 |
1 |
1
created_at
|
30 |
116 |
1 |
2
entities.hashtags
|
93 |
199 |
1 |
3
entities.media
|
772 |
199 |
1 |
4
entities.urls
|
16 |
199 |
1 |
5
entities.user_mentions
|
16 |
199 |
1 |
6
favorited
|
1 |
116 |
1 |
7
geo
|
0 |
116 |
1 |
8
id
|
18 |
116 |
1 |
9
id_str
|
18 |
116 |
1 |
10
.
.
.
delete.status.id
|
18 |
116 |
11 |
0
delete.status.id_str
|
18 |
116 |
11 |
1
delete.status.user_id
|
9 |
116 |
11 |
2
delete.status.user_id_str
|
9 |
116 |
11 |
3
SQLReference Manual
SQL Functions
delete.status.id
0
delete.status.id_str
1
delete.status.user_id
2
delete.status.user_id_str
3
(550 rows)
18 |
116 |
12 |
18 |
116 |
12 |
9 |
116 |
12 |
9 |
116 |
12 |
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPLOOKUP
Returns values associated with a single key. This scalar function returns a LONG VARCHAR with
virtual column values, or NULL if the virtual column does not exist. Column names are case
insensitive.
Before using maplookup, you can use these two functions to find out about your VMap data:
l
SQLReference Manual
SQL Functions
You can control the behavior for non-scalar values when loading data with the fjsonparser parser
and its flatten-arrays argument. See Loading JSONData and the FJSONPARSER reference.
Syntax
maplookup (VMap_data, 'virtual_column_name' [USING PARAMETERS [case_sensitive=
{false | true}] [, buffer_size=n] ] )
Any VMap data. The VMap can exist as the __raw__ column of
a flex table, data returned from a map function such as
maplookup(), or other database content.
virtual_column_name
buffer_size
case_sensitive
Examples
This example shows how to return the row values of one virtual column, user.location:
=> select maplookup(__raw__, 'user.location') from darkdata order by 1;
maplookup
----------Chile
Narnia
Uptown
.
SQLReference Manual
SQL Functions
.
chicago
(12 rows)
SQLReference Manual
SQL Functions
4. Use maplookup with buffer_size=0 for the logs table name key. All of the values are
returned:
=> SELECT MapLookup(__raw__, 'name' USING PARAMETERS buffer_size=0) FROM logs;
MapLookup
----------sierra
ben
janis
jen
(4 rows)
5. The example continues with buffer_size 3, 5, and 6. Now, maplookup() returns only values
with a byte length less than, or equal to (<=), the specified buffer_size:
=> SELECT MapLookup(__raw__, 'name' USING PARAMETERS buffer_size=3) FROM logs;
MapLookup
----------ben
jen
(4 rows)
=> SELECT MapLookup(__raw__, 'name' USING PARAMETERS buffer_size=5) FROM logs;
MapLookup
----------janis
jen
ben
(4 rows)
=> SELECT MapLookup(__raw__, 'name' USING PARAMETERS buffer_size=6) FROM logs;
MapLookup
----------sierra
janis
jen
ben
(4 rows)
SQLReference Manual
SQL Functions
For example, if you use maplookup without first checking the existence of a key, the following
output (12 empty rows) is ambiguous. Does a location key exist, exist with a NULL value in a row,
or exist without a value?
=> select maplookup(__raw__, 'user.location') from darkdata;
maplookup
-----------
(12 rows)
To disambiguate empty rows, use the mapcontainskey() function in conjunction with maplookup
(). When maplookup returns an empty field, the corresponding value from mapcontainskey
indicates t for a NULL value, or ffor no value.
The following vsql example output from both functions annotates rows without values in purple. The
example also shows location Narnia as a value in the user.location virtual column:
=> select maplookup(__raw__, 'user.location'), mapcontainskey(__raw__, 'user.location')
from darkdata order by 1;
maplookup | mapcontainskey
-----------+---------------| t
| t
| t
| t
Chile
| t
Narnia
| t
Uptown.. | t
SQLReference Manual
SQL Functions
chicago
|
|
|
|
|
t
f
f
f
f
>>>>>>>>>>No
>>>>>>>>>>No
>>>>>>>>>>No
>>>>>>>>>>No
value
value
value
value
(12 rows)
SQLReference Manual
SQL Functions
The next examples illustrate using several invocations of maplookup() to return values from the
map __raw__ column (after creating the table and loading data). Compare the returned results to the
maptostring() output in the previous example.
=> create flex table bake();
CREATE TABLE
kdb=> copy bake from '/vertica/test/flextable/DATA/bake.json' parser fjsonparser(flatten_
arrays=1,flatten_maps=0);
Rows Loaded
------------1
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.0'),'type') from bake;
maplookup
----------Regular
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.1'),'type') from bake;
maplookup
----------Chocolate
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.2'),'type') from bake;
maplookup
----------Blueberry
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.3'),'type') from bake;
maplookup
-------------Devil's Food
(1 row)
SQLReference Manual
SQL Functions
{
"TEST": "upper1"
}
{
"TEst": "half1"
}
{
"test": "lower2",
"TEst": "half2"
}
{
"TEST": "upper2",
"TEst": "half3"
}
{
"test": "lower3",
"TEST": "upper3"
}
{
"TEst": "half4",
"test": "lower4",
"TEST": "upper4"
}
{
"TesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTestt
estTesttestTesttestTesttestTesttestTesttest":"1",
"TesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTestt
estTesttestTesttestTesttestTesttestTest12345":"2"
}
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
SQLReference Manual
SQL Functions
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPSIZE
Returns the number of virtual columns present in any VMap data. Use this scalar function to
determine the size of keys.
Syntax
mapsize(VMap_data)
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table, data
returned from a map function such as maplookup(), or other database content.
Examples
This example shows the returned sizes from the number of keys in the flex table darkmountain:
=> select mapsize(__raw__) from darkmountain;
mapsize
--------3
4
4
4
4
(5 rows)
SQLReference Manual
SQL Functions
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPTOSTRING
Recursively builds a string representation VMap data, including nested JSONmaps. Use this
transform function to display the VMap contents in a readable format. The function returns a LONG
VARCHAR. Use maptostring to see how map data is nested before querying virtual columns with
mapvalues().
Syntax
maptostring(VMap_data [using parameters canonical_json={true | false}])
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table,
data returned from a map function such as maplookup(), or other database
content.
SQLReference Manual
SQL Functions
Parameters
canonical_json
=bool
[Optional parameter] Default canonical-json=true
Produces canonical JSON output by default, using the first instance of any
duplicate keys in the map data.
Use this parameter as other UDFparameters, preceded by using
parameters, as shown in the examples. Setting this argument to false
maintains the previous behavior of maptostring(), and returns same-name
keys and their values.
Examples
The following example creates a sample flex table, darkdata. After loading sample JSON data
from STDIN, the example continues by calling maptostring() twice with both values for the
canonical_json parameter, illustrating the different results on the flex table __raw__column data.
1. Create sample table:
=> create flex table darkdata();
CREATE TABLE
3. Call maptostring() with its default behavior using canonical JSONoutput. Notice the flex
table contents. The function returns the first duplicate key and its value ("aaa": "1"), and
omits remaining duplicate keys ("aaa": "2"):
=> select maptostring (__raw__) from darkdata;
maptostring
-----------------------------------------------------------{
"AAA" : "3",
SQLReference Manual
SQL Functions
"aaa" : "1",
"bbb" : "aaa\"bbb"
}
(1 row)
"1",
"2",
"3",
"aaa"bbb"
}
(1 row)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPVALUES
MAPVERSION
SQLReference Manual
SQL Functions
MAPVALUES
Returns a string representation of the top-level values from a VMap. This transform function
requires an over() clause. The examples uses an over(PARTITION BEST) clause.
Syntax
mapvalues(VMap_data)
Arguments
VMap_data
The VMap from which values should be returned. The VMap can exist as the __raw_
_ column of a flex table, data returned from a map function such as maplookup(), or
other database content.
Examples
The following example uses mapvalues() with a darkmountain flex table, returning the values.
=> select * from (select mapvalues(darkmountain.__raw__) over(PARTITION BEST) from
darkmountain) as a;
values
--------------29029
34.1
Everest
mountain
29029
15.4
Mt St Helens
volcano
17000
12.2
Denali
mountain
14000
22.8
Kilimanjaro
mountain
50.6
Mt Washington
mountain
(19 rows)
SQLReference Manual
SQL Functions
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVERSION
MAPVERSION
Returns the version or invalidity of any map data. This scalar function returns the map version (such
as 1), or -1 if the map data is invalid.
Syntax
mapversion(VMap_data)
Arguments
VMap_data
The VMap data either from a __raw__ column in a flex table, or from the data returned
from a map function such as maplookup().
Examples
The following example uses mapversion() with the darkmountainflex table, returning mapversion
1 for the flex table map data:
SQLReference Manual
SQL Functions
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MARK_DESIGN_KSAFE
Enables or disables high availability in your environment, in case of a failure. Before enabling
recovery, MARK_DESIGN_KSAFE queries the catalog to determine whether a cluster's physical
schema design meets the following requirements:
l
Large table superprojections are segmented with each segment on a different node.
Each large table projection has at least one buddy projection for K-safety=1 (or two buddy
SQLReference Manual
SQL Functions
Note: Projections are considered to be buddies if they contain the same columns and have
the same segmentation. They can have different sort orders.
Syntax
MARK_DESIGN_KSAFE ( k )
Parameters
k
2 enables high availability if the schema design meets requirements for K-safety=2
1 enables high availability if the schema design meets requirements for K-safety=1
0 disables high availability
If you specify a k value of one (1) or two (2), HP Vertica returns one of the following messages.
Success:
Marked design n-safe
Failure:
The schema does not meet requirements for K=n.
Fact table projection projection-name
has insufficient "buddy" projections.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
l
The database's internal recovery state persists across database restarts but it is not checked at
startup time.
If a database has automatic recovery enabled, you must temporarily disable automatic recovery
before creating a new table.
When one node fails on a system marked K-safe=1, the remaining nodes are available for DML
operations.
Examples
=> SELECT MARK_DESIGN_KSAFE(1);
mark_design_ksafe
---------------------Marked design 1-safe
(1 row)
If the physical schema design is not K-Safe, messages indicate which projections do not have a
buddy:
=> SELECT MARK_DESIGN_KSAFE(1);
The given K value is not correct;
the schema is 0-safe
Projection pp1 has 0 buddies,
which is smaller that the given K of 1
Projection pp2 has 0 buddies,
which is smaller that the given K of 1
.
.
.
(1 row)
See Also
l
SYSTEM
SQLReference Manual
SQL Functions
Failure Recovery
MATERIALIZE_FLEXTABLE_COLUMNS
Materializes virtual columns listed as key_names in the flextable_keys table. You can optionally
indicate the number of columns to materialize, and use a keys table other than the default. If you do
not specify the number of columns, the function materializes up to 50 virtual column key names.
Calling this function requires that you first compute flex table keys using either COMPUTE_
FLEXTABLE_KEYS or COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
Note: Materializing any virtual column into a real column with this function affects data storage
limits. Each materialized column counts against the data storage limit of your HPVertica
Enterprise Edition (EE) license. This increase is reflected when HP Vertica next performs a
license compliance audit. To manually check your EElicense compliance, call the audit()
function, described in the SQL Reference Manual.
Syntax
materialize_flextable_columns('flex_table' [, n-columns [, keys_table_name] ])
Arguments
flex_table
The name of the flex table with columns to materialize. Specifying only
the flex table name attempts to materialize up to 50 columns of key
names in the default flex_table_keys table, skipping any columns
already materialized, and ignoring any empty keys. To materialize a
specific number of columns, use the optional parameter n_columns,
described next.
n-columns
SQLReference Manual
SQL Functions
keys_table_name
Examples
The following example loads a sample file of tweets (tweets_10000.json) into the flex table
twitter_r.
After loading data and computing keys for the sample flex table, the example calls materialize_
flextable_columns to materialize the first four columns:
=> copy twitter_r from '/home/release/KData/tweets_10000.json' parser fjsonparser();
Rows Loaded
------------10000
(1 row)
=> select compute_flextable_keys ('twitter_r');
compute_flextable_keys
--------------------------------------------------Please see public.twitter_r_keys for updated keys
(1 row)
=> select materialize_flextable_columns('twitter_r', 4);
materialize_flextable_columns
------------------------------------------------------------------------------The following columns were added to the table public.twitter_r:
contributors
entities.hashtags
entities.urls
For more details, run the following query:
SELECT * FROM v_catalog.materialize_flextable_columns_results WHERE table_schema =
'public' and table_name = 'twitter_r';
(1 row)
SQLReference Manual
SQL Functions
-------------------+--------------+------------+------------------------------+-------------------+--------+-------------------------------------------------------45035996273733172 | public
| twitter_r | 2013-11-20 17:00:27.945484-05
| contributors
| ADDED | Added successfully
45035996273733172 | public
| twitter_r | 2013-11-20 17:00:27.94551-05
| entities.hashtags | ADDED | Added successfully
45035996273733172 | public
| entities.urls
| ADDED
45035996273733172 | public
| twitter_r | 2013-11-20 17:00:27.945532-05
| created_at
| EXISTS | Column of same name already exists in table definition
(4 rows)
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
MEASURE_LOCATION_PERFORMANCE
Measures disk performance for the location specified.
Syntax
MEASURE_LOCATION_PERFORMANCE ( 'path' , 'node' )
Parameters
path
node
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
l
To get a list of all node names on your cluster, query the V_MONITOR.DISK_STORAGE
system table:
=> SELECT node_name from DISK_STORAGE;
node_name
------------------v_vmartdb_node0004
v_vmartdb_node0004
v_vmartdb_node0005
v_vmartdb_node0005
v_vmartdb_node0006
v_vmartdb_node0006
(6 rows)
If you intend to create a tiered disk architecture in which projections, columns, and partitions are
stored on different disks based on predicted or measured access patterns, you need to measure
storage location performance for each location in which data is stored. You do not need to
measure storage location performance for temp data storage locations because temporary files
are stored based on available space.
The method of measuring storage location performance applies only to configured clusters. If
you want to measure a disk before configuring a cluster see Measuring Storage Performance.
Storage location performance equates to the amount of time it takes to read and write 1MB of
data from the disk. This time equates to:
IO time = Time to read/write 1MB + Time to seek = 1/Throughput + 1/Latency
Throughput is the average throughput of sequential reads/writes (units in MB per second)
Latency is for random reads only in seeks (units in seeks per second)
Note: The IO time of a faster storage location is less than a slower storage location.
Example
The following example measures the performance of a storage location on v_vmartdb_node0004:
=> SELECT MEASURE_LOCATION_PERFORMANCE('/secondVerticaStorageLocation/' , 'v_vmartdb_
node0004');
SQLReference Manual
SQL Functions
WARNING:
progress
measure_location_performance
-------------------------------------------------Throughput : 122 MB/sec. Latency : 140 seeks/sec
See Also
l
CREATE LOCATION
ALTER_LOCATION_USE
RESTORE_LOCATION
RETIRE_LOCATION
MERGE_PARTITIONS
Merges ROS containers that have data belonging to partitions in a specified partition key range:
partitionKeyFromto partitionKeyTo.
Note: This function is deprecated in HP Vertica 7.0.
Syntax
MERGE_PARTITIONS ( table_name , partition_key_from , partition_key_to )
Parameters
table_name
partition_key_from
partition_key_to
SQLReference Manual
SQL Functions
Privileges
l
Table owner
Notes
l
You cannot run MERGE_PARTITIONS() on a table with data that is not reorganized. You must
reorganize the data first using ALTER_TABLE table REORGANIZE, or PARTITION_TABLE(table).
The edge values are included in the range, and partition_key_from must be less than or equal
to partition_key_to.
Inclusion of partitions in the range is based on the application of less than (<)/greater than (>)
operators of the corresponding data type.
Examples
=>
=>
=>
=>
=>
=>
=>
=>
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
MERGE_PARTITIONS('T1',
MERGE_PARTITIONS('T1',
MERGE_PARTITIONS('T1',
MERGE_PARTITIONS('T1',
MERGE_PARTITIONS('T1',
MERGE_PARTITIONS('T1',
MERGE_PARTITIONS('T1',
MERGE_PARTITIONS('T1',
'200', '400');
'800', '800');
'CA', 'MA');
'false', 'true');
'06/06/2008', '06/07/2008');
'02:01:10', '04:20:40');
'06/06/2008 02:01:10', '06/07/2008 02:01:10');
'8 hours', '1 day 4 hours 20 seconds');
MOVE_PARTITIONS_TO_TABLE
Moves partitions from a source table to a target table.
MOVE_PARTITIONS_TO_TABLEworks even if a node is recovering from being down.
SQLReference Manual
SQL Functions
Syntax
MOVE_PARTITIONS_TO_TABLE (
'[[db-name.]schema.]source_table',
'min_range_value',
'max_range_value',
[[db-name.]schema.]target_table'
)
Parameters
[db-name.]schema
Specifies a schema and, optionally, a database that you are connected to.
Include the schema name if multiple schemas are defined in the database. A
fully qualified name specifies its database and schemafor example:
mydb.myschema.thisDbObject
source_table
min_range_value
The minimum value of the partition to be moved. To move one partition, the
minimum and maximum values should be the same.
max_range_value
The maximum value of the partition to be moved. To move one partition, the
minimum and maximum values should be the same.
target_table
Privileges
l
If the target table exists, you must own, or have USAGEprivileges, on the source.
If target table is created as part of moving partitions, you must have CREATE privileges.
Examples
If you call MOVE_PARTITIONS_TO_TABLE and the target table does not exist, the function
creates the table automatically. In the following example, the target table partn_backup.tradfes_
200801 does not exist. MOVE_PARTITIONS_TO_TABLEcreates the table and moves the
partition. In addition, HP Vertica copies all the constraints associated with the source table except
any foreign key constraints.
SQLReference Manual
SQL Functions
See Also
l
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
SWAP_PARTITIONS_BETWEEN_TABLES
Moving Partitions
MOVE_RETIRED_LOCATION_DATA
Moves all data from either a single retired storage location or all retired storage locations in the
database. This function migrates the data to non-retired storage locations based on the storage
policies of the objects whose data is stored in the location.
Syntax
MOVE_RETIRED_LOCATION_DATA(['location_path'] ['node'])
SQLReference Manual
SQL Functions
Arguments
['location_path']
['node']
Privileges
The user must be a superuser .
Usage Considerations
This function forces the Tuple Mover to move data out of the retired location or locations.
Normally, the Tuple Mover only migrates data out of retired storage locations as it consolidates data
into larger ROS containers. This function does not return until all of the data has moved off of the
retired storage location or locations.
Examples
The following example:
1. Queries the STORAGE_LOCATIONS system table to show which storage locations are
retired.
2. Queries the STORAGE_CONTAINERS system table to show the current location of the
messages table, which is currently stored in the retired storage location named ssd.
3. Calls MOVE_RETIRED_LOCATION_DATA to move the data off of the ssd storage location.
4. Repeats the previous query to show the storage location of the messages table.
SQLReference Manual
SQL Functions
See Also
l
RETIRE_LOCATION
RESTORE_LOCATION
PARTITION_PROJECTION
Forces the split of ROS containers for a specified projection.
SQLReference Manual
SQL Functions
Syntax
PARTITION_PROJECTION ( '[[db-name.]schema.]projection_name' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection_name
Privileges
l
Table owner
Usage Considerations
l
Partitioning expressions take immutable functions only, so that the same information be
available across all nodes.
Examples
In this example, the SELECT PARTITION_PROJECTION command forces a split of ROS
containers on the states_p_node01 projection:
=> SELECT PARTITION_PROJECTION ('states_p_node01');
PARTITION_PROJECTION
-----------------------Projection partitioned
(1 row)
SQLReference Manual
SQL Functions
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_TABLE
PARTITION_TABLE
Forces the database to split ROS containers in the specified table that contain multiple distinct
values of the partitioning expression. Only ROS containers with more than one distinct value can be
split.
Syntax
PARTITION_TABLE ( '[[db-name.]schema.]table_name' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table_name
Privileges
l
Table owner
SQLReference Manual
SQL Functions
Usage Considerations
l
You cannot run PARTITION_TABLEon a table that is an anchor table for a live aggregate
projection or a Top-K projection.
If you use a function when partitioning a table, that function must be immutable.
Examples
The following example creates a simple table called states and partitions the data by state.
=> CREATE TABLE states (year INTEGER NOT NULL,
state VARCHAR NOT NULL)
PARTITION BY state;
=> CREATE PROJECTION states_p (state, year) AS
SELECT * FROM states
ORDER BY state, year UNSEGMENTED ALL NODES;
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
SQLReference Manual
SQL Functions
PURGE
Permanently removes deleted data from physical storage so that the disk space can be reused.
You can purge historical data up to and including the epoch in which the Ancient History Mark is
contained.
Purges all projections in the physical schema. PURGEdoes not delete temporary tables.
Syntax
PURGE()
Privileges
l
Table owner
Notes
l
Caution: PURGE could temporarily take up significant disk space while the data is being
purged.
See Also
l
PARTITION_TABLE
PURGE_PROJECTION
PURGE_TABLE
STORAGE_CONTAINERS
SQLReference Manual
SQL Functions
PURGE_PARTITION
Purges a table partition of deleted rows. Similar to PURGE() and PURGE_PROJECTION(), this function
removes deleted data from physical storage so you can reuse the disk space. PURGE_PARTITION()
removes data from the AHM epoch and earlier only.
Syntax
PURGE_PARTITION ( '[[db_name.]schema_name.]table_name', partition_key )
Parameters
[[db_name.]schema_name.]
table_name
partition_key
Privileges
l
Table owner
Example
The following example lists the count of deleted rows for each partition in a table, then calls PURGE_
PARTITION() to purge the deleted rows from the data.
=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
AS deleted_row_count FROM partitions
GROUP BY partition_key,table_schema,projection_name
ORDER BY partition_key;
partition_key | table_schema | projection_name | deleted_row_count
---------------+--------------+-----------------+------------------0
| public
| t_super
|
2
1
| public
| t_super
|
2
2
| public
| t_super
|
2
3
| public
| t_super
|
2
SQLReference Manual
SQL Functions
4
| public
| t_super
|
2
5
| public
| t_super
|
2
6
| public
| t_super
|
2
7
| public
| t_super
|
2
8
| public
| t_super
|
2
9
| public
| t_super
|
1
(10 rows)
=> SELECT PURGE_PARTITION('t',5); -- Purge partition with key 5.
purge_partition
-----------------------------------------------------------------------Task: merge partitions
(Table: public.t) (Projection: public.t_super)
(1 row)
=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
AS deleted_row_count FROM partitions
GROUP BY partition_key,table_schema,projection_name
ORDER BY partition_key;
See Also
l
PURGE
PURGE_PROJECTION
PURGE_TABLE
STORAGE_CONTAINERS
PURGE_PROJECTION
Permanently removes deleted data from physical storage so that the disk space can be reused.
You can purge historical data up to and including the epoch in which the Ancient History Mark is
contained.
Purges the specified projection.
SQLReference Manual
SQL Functions
Syntax
PURGE_PROJECTION ( '[[db-name.]schema.]projection_name' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection_name
Identifies the projection name. When using more than one schema,
specify the schema that contains the projection, as noted above.
Privileges
l
Table owner
Notes
See PURGE for notes about the outcome of purge operations.
Examples
This example shows how to purge a projection.
=> CREATE TABLE tbl (x INT , y INT);
CREATE TABLE
=> CREATE PROJECTION tbl_p AS SELECT x FROM tbl;
CREATE PROJECTION
=> SELECT PURGE_PROJECTION ('tbl_p');
purge_projection
------------------Projection purged
(1 row)
SQLReference Manual
SQL Functions
See Also
l
PURGE_TABLE
STORAGE_CONTAINERS
PURGE_TABLE
Note: This function was formerly named PURGE_TABLE_PROJECTIONS(). HP Vertica still
supports the former function name.
Permanently removes deleted data from physical storage so that the disk space can be reused.
You can purge historical data up to and including the epoch in which the Ancient History Mark is
contained.
Purges all projections of the specified table. You cannot use this function to purge temporary tables.
Syntax
PURGE_TABLE ( '[[db-name.]schema.]table_name' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table_name
Privileges
l
Table owner
Caution: PURGE_TABLE could temporarily take up significant disk space while the data is
being purged.
SQLReference Manual
SQL Functions
Example
The following example purges all projections for the store sales fact table located in the Vmart
schema:
=> SELECT PURGE_TABLE('store.store_sales_fact');
See Also
l
PURGE
PURGE_TABLE
STORAGE_CONTAINERS
REALIGN_CONTROL_NODES
Chooses control nodes (spread hosts)from all cluster nodes and assigns the rest of the nodes in
the cluster to a control node. Calling this function respects existing fault groups, which you can
view by querying the V_CATALOG.CLUSTER_LAYOUT system table. This view also lets you see the
proposed new layout for nodes in the cluster.
Note: You use this function with other cluster management functions. For details, see Defining
and Realigning Control Nodes on an Existing Cluster in the Administrator's Guide.
Syntax
REALIGN_CONTROL_NODES()
Privileges
Must be a superuser.
Example
The following command chooses control nodes from all cluster nodes and assigns the rest of the
nodes in the cluster to a control node:
SQLReference Manual
SQL Functions
See Also
l
V_CATALOG.CLUSTER_LAYOUT
REBALANCE_CLUSTER
Call this function to begin rebalancing data in the cluster synchronously.
A rebalance operation performs the following tasks:
l
Refreshes projections
When to Rebalance
Rebalancing is useful (or necessary) after you:
l
Mark one or more nodes as ephemeral in preparation of removing them from the cluster
Add one or more nodes to the cluster so that HP Vertica can populate the empty nodes with data
Remove one or more nodes from the cluster so that HP Vertica can redistribute the data among
the remaining nodes
Change the scaling factor of an elastic cluster, which determines the number of storage
SQLReference Manual
SQL Functions
Set the control node size or realign control nodes on a large cluster layout
Specify more than 120 nodes in your initial HP Vertica cluster configuration
Because this function runs the rebalance task synchronously, it does not return until the data has
been rebalanced. Closing or dropping the session cancels the rebalance task.
Important: On large cluster arrangements, you typically use this function in a flow, described
Defining and Realigning Control Nodes in the Administrator's Guide. After you change the
number and distribution of control nodes (spread hosts), you must run REBALANCE_CLUSTER()
for fault tolerance to be realized.
Syntax
REBALANCE_CLUSTER()
Privileges
Must be a superuser.
Example
The following command rebalances data across the cluster.
=> SELECT REBALANCE_CLUSTER();
REBALANCE_CLUSTER
------------------REBALANCED
(1 row)
See Also
l
START_REBALANCE_CLUSTER
CANCEL_REBALANCE_CLUSTER
SQLReference Manual
SQL Functions
NODES
REBALANCE_TABLE
Synchronously rebalances data in the specified table.
A rebalance operation performs the following tasks:
l
When to Rebalance
Rebalancing is useful (or necessary) after you:
l
Mark one or more nodes as ephemeral in preparation of removing them from the cluster
Add one or more nodes to the cluster so that HP Vertica can populate the empty nodes with data
Change the scaling factor of an elastic cluster, which determines the number of storage
containers used to store a projection across the database
Set the control node size or realign control nodes on a large cluster layout
Syntax
REBALANCE_TABLE('schema.table_name')
SQLReference Manual
SQL Functions
Parameters
[schema]
[Optional] Specifies the name of the schema that contains the table that you want to
rebalance. If you do not specify a schema-name, the statement checks for matching
tables in the first schema listed in the current search_path.
table_name
Privileges
Must be a superuser.
Example
The following command shows how to rebalance data on the specified table.
=> SELECT REBALANCE_TABLE('online_sales.online_sales_fact');
REBALANCE_TABLE
------------------REBALANCED
(1 row)
See Also
REBALANCE_CLUSTER
Rebalancing Data Across Nodes in the Administrator's Guide
NODES
REENABLE_DUPLICATE_KEY_ERROR
Restores the default behavior of error reporting by reversing the effects of DISABLE_DUPLICATE_
KEY_ERROR. Effects are session scoped.
Syntax
REENABLE_DUPLICATE_KEY_ERROR();
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Examples
For examples and usage, see DISABLE_DUPLICATE_KEY_ERROR.
See Also
l
ANALYZE_CONSTRAINTS
REFRESH
Performs a synchronous, optionally-targeted refresh of a specified table's projections.
Information about a refresh operationwhether successful or unsuccessfulis maintained in the
PROJECTION_REFRESHES system table until either the CLEAR_PROJECTION_
REFRESHES() function is executed or the storage quota for the table is exceeded. The
PROJECTION_REFRESHES.IS_EXECUTING column returns a boolean value that indicates whether the
refresh is currently running (t) or occurred in the past (f).
Syntax
REFRESH ( '[[db-name.]schema.]table_name [ , ... ]' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table_name
Returns
Column Name Description
SQLReference Manual
SQL Functions
Projection Name
Anchor Table
Status
Refresh Method
Error Count
Duration (sec)
Privileges
REFRESH() works only if invoked on tables owned by the calling user.
Notes
l
Unlike START_REFRESH(), which runs in the background, REFRESH() runs in the foreground
of the caller's session.
The REFRESH() function refreshes only the projections in the specified table.
SQLReference Manual
SQL Functions
If you run REFRESH() without arguments, it refreshes all non up-to-date projections. If the
function returns a header string with no results, then no projections needed refreshing.
Examples
The following example refreshes the projections in tables t1 and t2:
=> SELECT REFRESH('t1, t2');
REFRESH
---------------------------------------------------------------------------------------Refresh completed with the following outcomes:
Projection Name: [Anchor Table] [Status] [Refresh Method] [Error Count] [Duration (sec)]
---------------------------------------------------------------------------------------"public"."t1_p": [t1] [refreshed] [scratch] [0] [0]"public"."t2_p": [t2] [refreshed]
[scratch] [0] [0]
This next example shows that only the projection on table t was refreshed:
=> SELECT REFRESH('allow, public.deny, t');
REFRESH
---------------------------------------------------------------------------------------Refresh completed with the following outcomes:
Projection Name: [Anchor Table] [Status] [Refresh Method] [Error Count] [Duration (sec)]
---------------------------------------------------------------------------------------"n/a"."n/a": [n/a] [failed: insufficient permissions on table "allow"] [] [1] [0]
"n/a"."n/a": [n/a] [failed: insufficient permissions on table "public.deny"] [] [1] [0]
"public"."t_p1": [t] [refreshed] [scratch] [0] [0]
See Also
l
CLEAR_PROJECTION_REFRESHES
PROJECTION_REFRESHES
START_REFRESH
RELEASE_ALL_JVM_MEMORY
Forces all sessions to release the memory consumed by their Java Virtual Machines (JVM).
SQLReference Manual
SQL Functions
Syntax
RELEASE_ALL_JVM_MEMORY();
Permissions
Must be a superuser.
Example
The following example demonstrates viewing the JVMmemory use in all open sessions, then
calling RELEASE_ALL_JVM_MEMORY()to release the memory:
=> select user_name,jvm_memory_kb FROM V_MONITOR.SESSIONS;
user_name | jvm_memory_kb
-----------+--------------dbadmin
|
79705
(1 row)
=> SELECT RELEASE_ALL_JVM_MEMORY();
RELEASE_ALL_JVM_MEMORY
----------------------------------------------------------------------------Close all JVM sessions command sent. Check v_monitor.sessions for progress.
(1 row)
=> SELECT user_name,jvm_memory_kb FROM V_MONITOR.SESSIONS;
user_name | jvm_memory_kb
-----------+--------------dbadmin
|
0
(1 row)
See Also
l
RELEASE_JVM_MEMORY
RELEASE_JVM_MEMORY
Terminates a Java Virtual Machine (JVM), making available the memory the JVM was using.
Syntax
RELEASE_JVM_MEMORY();
SQLReference Manual
SQL Functions
Privileges
None.
Examples
User session opened. RECORD 2 shows the user session running COPY DIRECT statement.
=> SELECT RELEASE_JVM_MEMORY();
release_jvm_memory
----------------------------------------Java process killed and memory released
(1 row)
See Also
l
RELEASE_ALL_JVM_MEMORY
RELOAD_SPREAD
Calling this function with the required true argument updates cluster changes (such as new or realigned control nodes spread hosts or fault groups or new/dropped cluster nodes), to the catalog's
spread configuration file.
Important: This function is often used in a multi-step process for large and elastic cluster
arrangements. Calling RELOAD_SPREAD(true) might require that you restart the database,
which you do using the Administration Tools. You must then rebalance the cluster for fault
tolerance to be realized. See Defining and Realigning Control Nodes in the Administrator's
Guide for more information.
Syntax
RELOAD_SPREAD(true)
Parameters
true
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Example
The following command updates the cluster with changes to control messaging:
=> SELECT reload_spread(true);
reload_spread
--------------reloaded
(1 row)
See Also
l
REBALANCE_CLUSTER
V_CATALOG.CLUSTER_LAYOUT
RESET_LOAD_BALANCE_POLICY
Resets the counter each host in the cluster maintains to track which host it will refer a client to
when the native connection load balancing scheme is set to ROUNDROBIN. To reset the counter,
you must run this function on all nodes in your cluster.
Syntax
RESET_LOAD_BALANCE_POLICY()
Notes
This function only has an effect if the current native connection load balancing scheme is
ROUNDROBIN.
SQLReference Manual
SQL Functions
Permissions
This function can be called only by a superuser .
Example
The following example demonstrates calling RESET_LOAD_BALANCE_POLICY:
=> SELECT RESET_LOAD_BALANCE_POLICY();
RESET_LOAD_BALANCE_POLICY
------------------------------------------------------------------------Successfully reset stateful client load balance policies: "roundrobin".
(1 row)
RESTORE_LOCATION
Restores a storage location that was previously retired with RETIRE_LOCATION.
Syntax
RESTORE_LOCATION ( 'path', 'node' )
Parameters
path
node
The HP Vertica node where the retired location is available. A value of "" (an empty string)
means to perform this operation on all nodes. The operation fails if you have dropped any
locations.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Examples
The following example shows how to restore the retired storage location on node3:
=> SELECT RESTORE_LOCATION ('/thirdHP VerticaStorageLocation/' , 'v_vmartdb_node0004');
See Also
l
CREATE LOCATION
ALTER_LOCATION_USE
DROP_LOCATION
RETIRE_LOCATION
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_
VIEW
Restores the _keys table and the _view, linking them with their associated flex table if either is
dropped. This function notes whether it restores one or both.
Syntax
restore_flextable_default_keys_table_and_view('flex_table')
Arguments
flex_table The name of a flex table .
SQLReference Manual
SQL Functions
Examples
This example invokes the function with an existing flex table, restoring both the _keys table and _
view:
=> select restore_flextable_default_keys_table_and_view('darkdata');
restore_flextable_default_keys_table_and_view
---------------------------------------------------------------------------------The keys table public.darkdata_keys was restored successfully.
The view public.darkdata_view was restored successfully.
(1 row)
This example shows the function restoring darkdata_view, but noting that darkdata_keys does
not need restoring:
=> select restore_flextable_default_keys_table_and_view('darkdata');
restore_flextable_default_keys_table_and_view
-----------------------------------------------------------------------------------------------The keys table public.darkdata_keys already exists and is linked to darkdata.
The view public.darkdata_view was restored successfully.
(1 row)
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
MATERIALIZE_FLEXTABLE_COLUMNS
RETIRE_LOCATION
Makes the specified storage location inactive.
SQLReference Manual
SQL Functions
Syntax
RETIRE_LOCATION ( 'path', 'node' [, 'enforce_storage_move' ] )
Parameters
path
node
enforce_storage_move
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
No new data is stored at the retired location, unless you first restore it with the RESTORE_
LOCATION() function.
By default, if the storage location being retired contains stored data, the data is not moved.
Thus, you cannot drop the storage location. Instead, HP Vertica removes the stored data
through one or more mergeouts. If you want to drop the location immediately after retiring it, add
the enforce_storage_move parameter, using a value of true.
If the storage location being retired is used only for temp files or you use enforce_storage_move,
you can drop the location. See Dropping Storage Locations in the Administrators Guide and the
DROP_LOCATION() function.
Examples
The following examples show two approaches to retiring a storage location.
You can specify that a storage location be dropped automatically at a future time:
=> SELECT RETIRE_LOCATION ('/data' , 'v_vmartdb_node0004');
See Also
l
CREATE LOCATION
ALTER_LOCATION_USE
DROP_LOCATION
RESTORE_LOCATION
SQLReference Manual
SQL Functions
SET_AHM_EPOCH
Sets the Ancient History Mark (AHM) to the specified epoch. This function allows deleted data up
to and including the AHM epoch to be purged from physical storage.
SET_AHM_EPOCH is normally used for testing purposes. Consider SET_AHM_TIME instead,
which is easier to use.
Syntax
SET_AHM_EPOCH ( epoch, [ true ] )
Parameters
epoch
true
Privileges
Must be a superuser.
Notes
If you use SET_AHM_EPOCH , the number of the specified epoch must be:
l
SQLReference Manual
SQL Functions
Less than or equal to the cluster last good epoch (the minimum of the last good epochs of the
individual nodes in the cluster)
Less than or equal to the cluster refresh epoch (the minimum of the refresh epochs of the
individual nodes in the cluster)
Use the SYSTEM table to see current values of various epochs related to the AHM; for example:
=> SELECT * from SYSTEM;
-[ RECORD 1 ]------------+--------------------------current_timestamp
| 2009-08-11 17:09:54.651413
current_epoch
| 1512
ahm_epoch
| 961
last_good_epoch
| 1510
refresh_epoch
| -1
designed_fault_tolerance | 1
node_count
| 4
node_down_count
| 0
current_fault_tolerance | 1
catalog_revision_number | 1590
wos_used_bytes
| 0
wos_row_count
| 0
ros_used_bytes
| 41490783
ros_row_count
| 1298104
total_used_bytes
| 41490783
total_row_count
| 1298104
All nodes must be up. You cannot use SET_AHM_EPOCH when any node in the cluster is down,
except by using the optional true parameter.
When a node is down and you issue SELECT MAKE_AHM_NOW(), the following error is printed to the
vertica.log:
Some nodes were excluded from setAHM. If their LGE is before the AHM they will perform
full recovery.
Examples
The following command sets the AHM to a specified epoch of 12:
=> SELECT SET_AHM_EPOCH(12);
The following command sets the AHM to a specified epoch of 2 and allows the AHM to advance
despite a failed node:
=> SELECT SET_AHM_EPOCH(2, true);
SQLReference Manual
SQL Functions
See Also
l
MAKE_AHM_NOW
SET_AHM_TIME
SYSTEM
SET_AHM_TIME
Sets the Ancient History Mark (AHM) to the epoch corresponding to the specified time on the
initiator node. This function allows historical data up to and including the AHM epoch to be purged
from physical storage.
Syntax
SET_AHM_TIME ( time , [ true ] )
Parameters
time
true
Privileges
Must be a superuser.
Notes
l
SET_AHM_TIME returns a TIMESTAMP WITH TIME ZONE value representing the end point of
the AHM epoch.
You cannot change the AHM when any node in the cluster is down, except by using the optional
true parameter.
When a node is down and you issue SELECT MAKE_AHM_NOW(), the following error is printed to
the vertica.log:
SQLReference Manual
SQL Functions
Some nodes were excluded from setAHM. If their LGE is before the AHM they will perform
full recovery.
Examples
Epochs depend on a configured epoch advancement interval. If an epoch includes a three-minute
range of time, the purge operation is accurate only to within minus three minutes of the specified
timestamp:
=> SELECT SET_AHM_TIME('2008-02-27 18:13');
set_ahm_time
-----------------------------------AHM set to '2008-02-27 18:11:50-05'
(1 row)
Note: The 05 part of the output string is a time zone value, an offset in hours from UTC
(Universal Coordinated Time, traditionally known as Greenwich Mean Time, or GMT).
In the previous example, the actual AHM epoch ends at 18:11:50, roughly one minute before the
specified timestamp. This is because SET_AHM_TIME selects the epoch that ends at or before
the specified timestamp. It does not select the epoch that ends after the specified timestamp
because that would purge data deleted as much as three minutes after the AHM.
For example, using only hours and minutes, suppose that epoch 9000 runs from 08:50 to 11:50 and
epoch 9001 runs from 11:50 to 15:50. SET_AHM_TIME('11:51') chooses epoch 9000 because it
ends roughly one minute before the specified timestamp.
In the next example, if given an environment variable set as date =`date`; the following
command fails if a node is down:
=> SELECT SET_AHM_TIME('$date');
In order to force the AHM to advance, issue the following command instead:
=> SELECT SET_AHM_TIME('$date', true);
See Also
l
MAKE_AHM_NOW
SET_AHM_EPOCH
SQLReference Manual
SQL Functions
SET DATESTYLE
TIMESTAMP
SET_AUDIT_TIME
Sets the time that HP Vertica performs automatic database size audit to determine if the size of the
database is compliant with the raw data allowance in your HP Vertica license. Use this function if
the audits are currently scheduled to occur during your database's peak activity time. This is
normally not a concern, since the automatic audit has little impact on database performance.
Audits are scheduled by the preceding audit, so changing the audit time does not affect the next
scheduled audit. For example, if your next audit is scheduled to take place at 11:59PM and you use
SET_AUDIT_TIME to change the audit schedule 3AM, the previously scheduled 11:59PM audit
still runs. As that audit finishes, it schedules the next audit to occur at 3AM.
If you want to prevent the next scheduled audit from running at its scheduled time, you can change
the scheduled time using SET_AUDIT_TIME then manually trigger an audit to run immediately
using AUDIT_LICENSE_SIZE. As the manually-triggered audit finishes, it schedules the next audit
to occur at the time you set using SET_AUDIT_TIME (effectively overriding the previously
scheduled audit).
Syntax
SET_AUDIT_TIME(time)
time
A string containing the time in 'HH:MM AM/PM' format (for example, '1:00 AM') when the
audit should run daily.
Privileges
Must be a superuser.
Example
=> SELECT SET_AUDIT_TIME('3:00 AM');
SET_AUDIT_TIME
----------------------------------------------------------------------The scheduled audit time will be set to 3:00 AM after the next audit.
(1 row)
SQLReference Manual
SQL Functions
SET_CONTROL_SET_SIZE
For existing database clusters, use this function to specify the number of cluster nodes on which
you want to deploy control messaging (spread). The SET_CONTROL_SET_SIZE() function works the
same as the install_vertica --large cluster <integer>option.
You can run SET_CONTROL_SET_SIZE()after the database cluster is already defined, but before you
call this function, the database must be up.
Note: You use this function with other cluster management functions. For details, see Defining
and Realigning Control Nodes on an Existing Cluster in the Administrator's Guide.
Syntax
SET_CONTROL_SET_SIZE(integer)
Parameters
integer
Privileges
Must be a superuser.
Note
To see if the current spread hosts and the control designations in the Catalog match, query the V_
CATALOG.LARGE_CLUSTER_CONFIGURATION_STATUS system table.
Example
The following command tells HP Vertica that you want to run spread on two cluster nodes:
=> SELECT set_control_set_size(2);
SET_CONTROL_SET_SIZE
---------------------Control size set
(1 row)
SQLReference Manual
SQL Functions
See Also
l
V_CATALOG.CLUSTER_LAYOUT
SET_DATA_COLLECTOR_POLICY
Sets a size restraint (memory and disk space in kilobytes) for the specified Data Collector table on
all nodes. If nodes are down, the failed nodes receive the setting when they rejoin the cluster.
You can use this function to set a size restraint only, or you can include the optional interval
argument to set disk capacity for both size and time in a single command.
If you specify interval, HP Vertica enforces the setting that is exceeded first (size or time).
Before you include a time restraint, verify that the disk size capacity is sufficiently large.
If you want to specify just a time restraint, or you want to turn off a time restraint you set using this
function, see SET_DATA_COLLECTOR_TIME_POLICY().
Syntax
SET_DATA_COLLECTOR_POLICY('component', 'memoryKB', 'diskKB' [,'interval']
Parameters
component
memoryKB
diskKB
interval
[Default off] Takes an optional interval argument to specify how long to retain the
specified component on disk. To disable a time restraint, set interval to -1.
Note: Any negative input will turn off the time restraint
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
l
Before you change a retention policy, view its current setting by calling the GET_DATA_
COLLECTOR_POLICY() function.
If you don't know the name of a component, query the V_MONITOR.DATA_COLLECTOR system
table for a list; for example:
=> SELECT DISTINCT component, description FROM data_collector
ORDER BY 1 ASC;
Examples
The following command returns the retention policy for the ResourceAcquisitions component:
=> SELECT get_data_collector_policy('ResourceAcquisitions');
get_data_collector_policy
---------------------------------------------1000KB kept in memory, 10000KB kept on disk.
(1 row)
This command changes the memory and disk setting for ResourceAcquisitions from its current
setting of 1,000 KB memory and 10,000 KB disk space to 1500 KB and 25000 KB, respectively:
=> SELECT set_data_collector_policy('ResourceAcquisitions', '1500', '25000');
set_data_collector_policy
--------------------------SET
(1 row)
This command sets the RequestsIssued component to 1500 KB memory and 11000 KBon disk,
and includes a 3-minute time restraint:
=> SELECT set_data_collector_policy('RequestsIssued', '1500', '11000', '3
minutes'::interval);
set_data_collector_policy
--------------------------SET
(1 row)
The following command disables the 3-minute retention policy for the RequestsIssued component:
=> SELECT set_data_collector_policy('RequestsIssued', '-1');
set_data_collector_policy
SQLReference Manual
SQL Functions
--------------------------SET
(1 row)
See Also
l
GET_DATA_COLLECTOR_POLICY
SET_DATA_COLLECTOR_TIME_POLICY()
DATA_COLLECTOR
SET_DATA_COLLECTOR_TIME_POLICY
Sets a time capacity for individual Data Collector tables on all nodes. If nodes are down, the failed
nodes receive the setting when they rejoin the cluster.
If you specify interval, HP Vertica enforces the setting that is exceeded first (size or time).
Before you include a time restraint, verify that the disk size capacity is sufficiently large.
If you want to configure both time and size restraints at the same time, see SET_DATA_COLLECTOR_
POLICY.
Syntax
SET_DATA_COLLECTOR_TIME_POLICY( ['component',] 'interval' )
Parameters
component
[Optional] Configures the time retention policy for the specified component. If you
omit the component argument, HP Vertica sets the specified time capacity for all
Data Collector tables.
interval
Specifies the time restraint on disk using an INTERVAL type. To disable a time
restraint, set interval to -1.
Note: Any negative input turns off the time restraint
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Usage Considerations
l
Before you change a retention policy, view its current setting by calling the GET_DATA_
COLLECTOR_POLICY function.
To illustrate, the following command in the left column is equivalent to running the series of
commands on the right:
Run one command
SELECT set_data_collector_time_policy
('v_monitor.query_requests',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('RequestsIssued',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('RequestsCompleted',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('Errors',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('ResourceAcquisitions',
'3 minutes'::interval);
SQLReference Manual
SQL Functions
The SET_DATA_COLLECTOR_TIME_POLICY function updates the time capacity for all Data
Collector tables in the V_MONITOR.QUERY_REQUESTS view. The new setting overrides any
previous settings for every Data Collector table in that view.
Examples
The following command configures the Backups component to be retained on disk for 1 day:
=> SELECT set_data_collector_time_policy('Backups', '1 day'::interval);
set_data_collector_time_policy
-------------------------------SET
(1 row)
This command disables the 1-day restraint for the Backups component:
=> SELECT set_data_collector_time_policy('Backups', '-1');
set_data_collector_time_policy
-------------------------------SET
(1 row)
This command sets a 30-minute time capacity for all Data Collector tables in a single command:
=> SELECT set_data_collector_time_policy('30 minutes'::interval);
set_data_collector_time_policy
-------------------------------SET
(1 row)
To view current retention policy settings for each Data Collector table, call the GET_DATA_
COLLECTION_POLICY() function. In the next example, the time restraint is included.
=> SELECT get_data_collector_policy('RequestsIssued');
get_data_collector_policy
----------------------------------------------------------------------------2000KB kept in memory, 50000KB kept on disk. 2 years 3 days 15:08 hours kept
on disk.
(1 row)
If the time policy setting is disabled, the output of GET_DATA_COLLECTION_POLICY() returns "Time
based retention disabled."
2000KB kept in memory, 50000KB kept on disk. Time based retention disabled.
SQLReference Manual
SQL Functions
See Also
l
GET_DATA_COLLECTOR_POLICY
SET_DATA_COLLECTOR_POLICY
DATA_COLLECTOR
SET_LOAD_BALANCE_POLICY
Sets how native connection load balancing chooses a host to handle a client connection. See About
Native Connection Load Balancing in the Administrator's Guide for more information.
Syntax
SET_LOAD_BALANCE_POLICY('policy')
Parameters
policy
The name of the load balancing policy to use. Can be one of the following:
l
NONE: Disables native connection load balancing. This is the default setting.
Notes
Even if the load balancing policy is set to something other than NONE on the server, clients must
indicate they want their connections to be load balanced by setting a connection property.
Permissions
Can only be used by a superuser .
SQLReference Manual
SQL Functions
Example
The following example demonstrates enabling native connection load balancing on the server by
setting the load balancing scheme to ROUNDROBIN:
=> SELECT SET_LOAD_BALANCE_POLICY('ROUNDROBIN');
SET_LOAD_BALANCE_POLICY
-------------------------------------------------------------------------------Successfully changed the client initiator load balancing policy to: roundrobin
(1 row)
SET_LOCATION_PERFORMANCE
Sets disk performance for the location specified.
Syntax
SET_LOCATION_PERFORMANCE ( 'path' , 'node' , 'throughput' , 'average_latency' )
Parameters
path
node
throughput
average_latency
Specifies the average latency for the location. The average_latency must be 1
or more.
Privileges
Must be a superuser.
Notes
To obtain the throughput and average latency for the location, run the MEASURE_LOCATION_
PERFORMANCE() function before you attempt to set the location's performance.
SQLReference Manual
SQL Functions
Example
The following example sets the performance of a storage location on node2 to a throughput of 122
megabytes per second and a latency of 140 seeks per second.
=> SELECT SET_LOCATION_PERFORMANCE('/secondVerticaStorageLocation/','node2','122','140');
See Also
l
CREATE LOCATION
MEASURE_LOCATION_PERFORMANCE
SET_SCALING_FACTOR
Sets the scaling factor that determines the size of the storage containers used when rebalancing
the database and when using local data segmentation is enabled. See Cluster Scaling for details.
Syntax
SET_SCALING_FACTOR(factor)
Parameters
factor
An integer value between 1 and 32. HP Vertica uses this value to calculate the number
of storage containers each projection is broken into when rebalancing or when local data
segmentation is enabled.
Note: Setting the scaling factor value too high can cause nodes to create too many small
container files, greatly reducing efficiency and potentially causing a "Too many
ROScontainers" error (also known as "ROS pushback"). The scaling factor should be set high
enough so that rebalance can transfer local segments to satisfy the skew threshold, but small
enough that the number of storage containers does not exceed ROS pushback. The number of
storage containers should be greater than or equal to the number of partitions multiplied by the
number of local segments (# storage containers >= # partitions * # local segments).
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Example
=> SELECT SET_SCALING_FACTOR(12);
SET_SCALING_FACTOR
-------------------SET
(1 row)
SET_OBJECT_STORAGE_POLICY
Creates or changes an object storage policy by associating a database object with a labeled
storage location.
Note: You cannot create a storage policy on a USER type storage location.
Syntax
SET_OBJECT_STORAGE_POLICY ( 'object_name', 'location_label' [, 'key_min', 'key_max'] [,
enforce_storage_move] )
Parameters
object_name
location_label
key_min, key_max
enforce_storage_move
[Optional] Applicable only when setting a storage policy for an object that
has data stored at another labeled location. Specify this parameter as
true to move all existing storage data to the target location within this
function's transaction. This function does not return until the operation is
complete.
SQLReference Manual
SQL Functions
Privileges
Must be the object owner to set the storage policy and have access to the storage location.
Examples
This example shows how to set a storage policy for the table states to use the storage labeled SSD
as its default location:
VMART=> select set_object_storage_policy ('states', 'SSD');
set_object_storage_policy
----------------------------------Default storage policy set.
(1 row)
SQLReference Manual
SQL Functions
See Also
l
ALTER_LOCATION_LABEL
CLEAR_OBJECT_STORAGE_POLICY
SHUTDOWN
Forces a database to shut down, even if there are users connected.
Syntax
SHUTDOWN ( [ 'false' | 'true' ] )
Parameters
false
[Default] Returns a message if users are connected. Has the same effect as supplying
no parameters.
true
Performs a moveout operation and forces the database to shut down, disallowing further
connections.
Privileges
Must be a superuser.
Notes
l
Issuing the shutdown command without arguments or with the default (false) argument returns a
message if users are connected, and the shutdown fails. If no users are connected, the
database performs a moveout operation and shuts down.
Issuing the SHUTDOWN('true') command forces the database to shut down whether users are
connected or not.
SQLReference Manual
SQL Functions
You can check the status of the shutdown operation in the vertica.log file:
2010-03-09 16:51:52.625 unknown:0x7fc6d6d2e700
[Init] <INFO> Shutdown complete. Exiting.
Examples
The following command attempts to shut down the database. Because users are connected, the
command fails:
=> SELECT SHUTDOWN('false');
NOTICE: Cannot shut down while users are connected
SHUTDOWN
----------------------------Shutdown: aborting shutdown
(1 row)
Using the 'true' parameter forces the database to shut down, even though clients might be
connected:
=> SELECT SHUTDOWN('true');
SHUTDOWN
---------------------------Shutdown: moveout complete
(1 row)
See Also
l
SESSIONS
SQLReference Manual
SQL Functions
SLEEP
Waits a specified number of seconds before executing another statement or command.
Syntax
SLEEP( seconds )
Parameters
seconds
The wait time, specified in one or more seconds (0 or higher) expressed as a positive
integer. Single quotes are optional; for example, SLEEP(3) is the same as SLEEP
('3').
Notes
l
This function returns value 0 when successful; otherwise it returns an error message due to
syntax errors.
Example
The following command suspends execution for 100 seconds:
=> SELECT SLEEP(100);
sleep
------0
(1 row)
START_REBALANCE_CLUSTER
A rebalance operation performs the following tasks:
SQLReference Manual
SQL Functions
Refreshes projections
When to Rebalance
Rebalancing is useful (or necessary) after you:
l
Mark one or more nodes as ephemeral in preparation of removing them from the cluster
Add one or more nodes to the cluster so that HP Vertica can populate the empty nodes with data
Remove one or more nodes from the cluster so that HP Vertica can redistribute the data among
the remaining nodes
Change the scaling factor of an elastic cluster, which determines the number of storage
containers used to store a projection across the database
Set the control node size or realign control nodes on a large cluster layout
Specify more than 120 nodes in your initial HP Vertica cluster configuration
Asynchronously starts a data rebalance task. Since this function starts the rebalance task in the
background, it returns immediately after the task has started. Since it is a background task,
rebalancing will continue even if the session that started it is closed. It even continues after a
cluster recovery if the database shuts down while it is in progress. The only way to stop the task is
by the CANCEL_REBALANCE_CLUSTER function.
Syntax
START_REBALANCE_CLUSTER()
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Example
=> SELECT START_REBALANCE_CLUSTER();
START_REBALANCE_CLUSTER
------------------------REBALANCING
(1 row)
See Also
l
CANCEL_REBALANCE_CLUSTER
REBALANCE_CLUSTER
START_REFRESH
Transfers data to projections that are not able to participate in query execution due to missing or
out-of-date data.
Syntax
START_REFRESH()
Notes
l
When a design is deployed through the Database Designer, it is automatically refreshed. See
Deploying a Design in the Administrator's Guide.
SQLReference Manual
SQL Functions
If a projection is updated from scratch, the data stored in the projection represents the table
columns as of the epoch in which the refresh commits. As a result, the query optimizer might not
choose the new projection for AT EPOCH queries that request historical data at epochs older
than the refresh epoch of the projection. Projections refreshed from buddies retain history and
can be used to answer historical queries.
Privileges
None
Example
The following command starts the refresh operation:
=> SELECT START_REFRESH();
start_refresh
---------------------------------------Starting refresh background process.
See Also
l
CLEAR_PROJECTION_REFRESHES
MARK_DESIGN_KSAFE
PROJECTION_REFRESHES
PROJECTIONS
SWAP_PARTITIONS_BETWEEN_TABLES
Swaps partitions between a staging table and a target table. The two tables must have the same:
l
Column definitions
Segmentation
SQLReference Manual
SQL Functions
Partitioning expression
Number of projections
Syntax
SWAP_PARTITIONS_BETWEEN_TABLES (
'[[db-name.]schema.]staging_table',
'min_range_value',
'max_range_value',
'[[db-name.]schema.]target_table'
)
Parameters
[db-name.]schema
Specifies a schema and, optionally, a database that you are connected to.
Include the schema name if multiple schemas are defined in the database. A
fully qualified name specifies its database and schemafor example:
mydb.myschema.thisDbObject
staging_table
min_range_value
max_range_value
target_table
Privileges
To swap partitions, you must be a DBADMINuser or the owner of both the staging table and the
target table.
SQLReference Manual
SQL Functions
Notes
l
You cannot swap partitions with a table that has pre-join projections.
If the partitions of both tables are empty, you see a warning, but the swap still occurs. Because
the partitions are empty, there is no change to the partitions.
If the partitions are not in the same storage tier, you see a warning but the swap still occurs. The
partitions remain in their existing storage tier.
Examples
The following example shows how to use SWAP_PARTITIONS_BETWEEN_TWO_TABLES to
swap the partitions between two tables. In this statement, you swap the 2008 and 2009 partitions.
=> SELECT SWAP_PARTITIONS_BETWEEN_TABLES ( 'customer_info', 2008, 2009, 'member_info');
See Also
l
DROP_PARTITION
MOVE_PARTITIONS_TO_TABLE
Swapping Partitions
Moving Partitions
SYNCH_WITH_HCATALOG_SCHEMA
Copies the structure of a Hive database schema available through the HCatalog Connector to an
Vertica Analytic Database schema.
Syntax
SYNC_WITH_HCATALOG_SCHEMA( local_schema, hcatalog_schema, [drop_tables] )
SQLReference Manual
SQL Functions
Parameters
local_schema The existing Vertica Analytic Database schema to store the copied HCatalog
schema's metadata
hcatalog_
schema
[drop_
tables]
Notes
You should always create an empty schema for the local_schema parameter. Tables in the
hcatalog_schema overwrite any identically named table in local_schema, which can lead to data
loss.
Permissions
The user must have CREATE privileges on local_schema and USAGE permissions on hcatalog_
schema.
Example
The following example shows using SYNCH_WITH_HCATALOG_SCHEMAto copy the metadata
from an HCatalog schema named hcat to an Vertica Analytic Database schema named hcat_local:
=> CREATE SCHEMA hcat_local;
CREATE SCHEMA
=> SELECT sync_with_hcatalog_schema('hcat_local', 'hcat');
sync_with_hcatalog_schema
---------------------------------------Schema hcat_local synchronized with hcat
tables in hcat = 56
tables altered in hcat_local = 0
tables created in hcat_local = 56
stale tables in hcat_local = 0
table changes erred in hcat_local = 0
(1 row)
=> -- Use vsql's \d command to describe a table in the synced schema
=> \d hcat_local.messages
List of Fields by Tables
Schema
|
Table | Column
Type
| Size
SQLReference Manual
SQL Functions
VALIDATE_STATISTICS
Validates statistics in the XML file generated by the EXPORT_STATISTICS command.
Syntax
VALIDATE_STATISTICS ( 'XML_statistics_file' )
Parameters
XML_statistics_file
Specifies the path and name of the XML file that contains the statistics
you want to validate, type VARCHAR.
Privileges
Must be a superuser.
Usage Considerations
l
IMPORT_STATISTICS imports only valid statistics. If the source file has invalid statistics for a
specific column, those statistics are not imported and a warning occurs. To identify the invalid
statistics, run VALIDATE_STATISTICS.
Example:Valid Statistics
The following example shows the results when the statistics are valid:
=> SELECT EXPORT_STATISTICS('cust_dim_stats.xml','customer_dimension');
SQLReference Manual
SQL Functions
EXPORT_STATISTICS
----------------------------------Statistics exported successfully
(1 row)
=> SELECT VALIDATE_STATISTICS('cust_dim_stats.xml');
VALIDATE_STATISTICS
--------------------(1 row)
---------------------
(1 row)
SQLReference Manual
SQL Functions
See Also
l
ANALYZE_STATISTICS
DROP_STATISTICS
EXPORT_STATISTICS
IMPORT_STATISTICS
SQLReference Manual
SQL Functions
DROP_LICENSE
Drops a Flex Zone license key from the global catalog.
Syntax
DROP_LICENSE( 'license name' )
Parameters
license name
The name of the license to drop. The name can be found in the licenses table.
Privileges
Must be a superuser.
Notes
For more information about license keys, see Managing Licenses in the Administrator's Guide.
Examples
=> SELECT DROP_LICENSE('/tmp/vlicense.dat');
DUMP_CATALOG
Returns an internal representation of the HP Vertica catalog. This function is used for diagnostic
purposes.
Syntax
DUMP_CATALOG()
SQLReference Manual
SQL Functions
Privileges
None; however, function dumps only the objects visible to the user.
Notes
To obtain an internal representation of the HP Vertica catalog for diagnosis, run the query:
=> SELECT DUMP_CATALOG();
EXPORT_CATALOG
Generates a SQL script that you can use to recreate a physical schema design in its current state
on a different cluster. This function always attempts to recreate projection statements with KSAFE
clauses, if they exist in the original definitions, or OFFSET clauses if they do not.
Syntax
EXPORT_CATALOG ( [ 'destination'
] , [ 'scope'
] )
Parameters
destination
Specifies the path and name of the SQL output file. An empty string (''), which is
the default, outputs the script to standard output. The function writes the script to
the catalog directory if no destination is specified.
If you specify a file that does not exist, the function creates one. If the file preexists, the function silently overwrites its contents.
SQLReference Manual
SQL Functions
scope
TABLESExports all tables and constraints for which the user has
permissions. See also EXPORT_TABLES.
Privileges
None. However:
l
Example
The following example exports the design to standard output:
=> SELECT EXPORT_CATALOG('','DESIGN');
See Also
l
EXPORT_OBJECTS
EXPORT_TABLES
EXPORT_OBJECTS
Generates a SQL script you can use to recreate catalog objects on a different cluster. The
generated script includes only the non-virtual objects to which the user has access. The function
exports catalog objects in order dependency for correct recreation. Running the generated SQL
script on another cluster then creates all referenced objects before their dependent objects.
SQLReference Manual
SQL Functions
The EXPORT_OBJECTS function always attempts to recreate projection statements with KSAFE
clauses, if they existed in the original definitions, or OFFSET clauses, if they did not.
None of the EXPORT_OBJECTS parameters accepts a NULL value as input. EXPORT_
OBJECTS returns an error if an explicitly-specified object does not exist, or the user does not have
access to the object.
Syntax
EXPORT_OBJECTS( [ 'destination'
] , [ 'scope'
] , [
'ksafe' ] )
Parameters
destination
Specifies the path and name of the SQL output file. The default empty string ('')
outputs the script to standard output. The function writes the script to the catalog
directory if no destination is specified.
If you specify a file that does not exist, the function creates one. If the file preexists, the function silently overwrites its contents.
scope
An empty string (' ')exports all non-virtual objects to which the user has
access, including constraints. (Note that constraints are not objects that can be
passed as individual arguments.) An empty string is the default scope value if
you do not limit the export.
SQLReference Manual
SQL Functions
ksafe
Determines if the statistics are regenerated before loading them into the design
context
Specifies whether to incorporate a MARK_DESIGN_KSAFE statement with the
correct K-safe value for the database:
l
Privileges
None. However:
l
Example
The following example exports all the non-virtual objects to which the user has access to standard
output. The example uses false for the last parameter, indicating that the file will not include the
MARK_DESIGN_KSAFE statement at the end.
=> SELECT EXPORT_OBJECTS(' ',' ',false);
See Also
l
EXPORT_CATALOG
EXPORT_TABLES
Exporting Objects
INSTALL_LICENSE
Installs the license key in the global catalog.
Syntax
INSTALL_LICENSE( 'filename' )
SQLReference Manual
SQL Functions
Parameters
filename
Privileges
Must be a superuser.
Notes
For more information about license keys, see Managing Your License Key in the Administrator's
Guide.
Examples
=> SELECT INSTALL_LICENSE('/tmp/vlicense.dat');
MARK_DESIGN_KSAFE
Enables or disables high availability in your environment, in case of a failure. Before enabling
recovery, MARK_DESIGN_KSAFE queries the catalog to determine whether a cluster's physical
schema design meets the following requirements:
l
Large table superprojections are segmented with each segment on a different node.
Each large table projection has at least one buddy projection for K-safety=1 (or two buddy
projections for K-safety=2).
Buddy projections are also segmented across database nodes, but the distribution is modified
so that segments that contain the same data are distributed to different nodes. See High
Availability Through Projections in the Concepts Guide.
Note: Projections are considered to be buddies if they contain the same columns and have
the same segmentation. They can have different sort orders.
SQLReference Manual
SQL Functions
Syntax
MARK_DESIGN_KSAFE ( k )
Parameters
k
2 enables high availability if the schema design meets requirements for K-safety=2
1 enables high availability if the schema design meets requirements for K-safety=1
0 disables high availability
If you specify a k value of one (1) or two (2), HP Vertica returns one of the following messages.
Success:
Marked design n-safe
Failure:
The schema does not meet requirements for K=n.
Fact table projection projection-name
has insufficient "buddy" projections.
Privileges
Must be a superuser.
Notes
l
The database's internal recovery state persists across database restarts but it is not checked at
startup time.
If a database has automatic recovery enabled, you must temporarily disable automatic recovery
before creating a new table.
When one node fails on a system marked K-safe=1, the remaining nodes are available for DML
operations.
SQLReference Manual
SQL Functions
Examples
=> SELECT MARK_DESIGN_KSAFE(1);
mark_design_ksafe
---------------------Marked design 1-safe
(1 row)
If the physical schema design is not K-Safe, messages indicate which projections do not have a
buddy:
=> SELECT MARK_DESIGN_KSAFE(1);
The given K value is not correct;
the schema is 0-safe
Projection pp1 has 0 buddies,
which is smaller that the given K of 1
Projection pp2 has 0 buddies,
which is smaller that the given K of 1
.
.
.
(1 row)
See Also
l
SYSTEM
Failure Recovery
SYNCH_WITH_HCATALOG_SCHEMA
Copies the structure of a Hive database schema available through the HCatalog Connector to an
Vertica Analytic Database schema.
Syntax
SYNC_WITH_HCATALOG_SCHEMA( local_schema, hcatalog_schema, [drop_tables] )
SQLReference Manual
SQL Functions
Parameters
local_schema The existing Vertica Analytic Database schema to store the copied HCatalog
schema's metadata
hcatalog_
schema
[drop_
tables]
Notes
You should always create an empty schema for the local_schema parameter. Tables in the
hcatalog_schema overwrite any identically named table in local_schema, which can lead to data
loss.
Permissions
The user must have CREATE privileges on local_schema and USAGE permissions on hcatalog_
schema.
Example
The following example shows using SYNCH_WITH_HCATALOG_SCHEMAto copy the metadata
from an HCatalog schema named hcat to an Vertica Analytic Database schema named hcat_local:
=> CREATE SCHEMA hcat_local;
CREATE SCHEMA
=> SELECT sync_with_hcatalog_schema('hcat_local', 'hcat');
sync_with_hcatalog_schema
---------------------------------------Schema hcat_local synchronized with hcat
tables in hcat = 56
tables altered in hcat_local = 0
tables created in hcat_local = 56
stale tables in hcat_local = 0
table changes erred in hcat_local = 0
(1 row)
=> -- Use vsql's \d command to describe a table in the synced schema
=> \d hcat_local.messages
List of Fields by Tables
Schema
|
Table | Column
Type
| Size
SQLReference Manual
SQL Functions
SET_LOAD_BALANCE_POLICY
Sets how native connection load balancing chooses a host to handle a client connection. See About
Native Connection Load Balancing in the Administrator's Guide for more information.
Syntax
SET_LOAD_BALANCE_POLICY('policy')
Parameters
policy
The name of the load balancing policy to use. Can be one of the following:
l
NONE: Disables native connection load balancing. This is the default setting.
SQLReference Manual
SQL Functions
Notes
Even if the load balancing policy is set to something other than NONE on the server, clients must
indicate they want their connections to be load balanced by setting a connection property.
Permissions
Can only be used by a superuser .
Example
The following example demonstrates enabling native connection load balancing on the server by
setting the load balancing scheme to ROUNDROBIN:
=> SELECT SET_LOAD_BALANCE_POLICY('ROUNDROBIN');
SET_LOAD_BALANCE_POLICY
-------------------------------------------------------------------------------Successfully changed the client initiator load balancing policy to: roundrobin
(1 row)
RESET_LOAD_BALANCE_POLICY
Resets the counter each host in the cluster maintains to track which host it will refer a client to
when the native connection load balancing scheme is set to ROUNDROBIN. To reset the counter,
you must run this function on all nodes in your cluster.
Syntax
RESET_LOAD_BALANCE_POLICY()
Notes
This function only has an effect if the current native connection load balancing scheme is
ROUNDROBIN.
Permissions
This function can be called only by a superuser .
SQLReference Manual
SQL Functions
Example
The following example demonstrates calling RESET_LOAD_BALANCE_POLICY:
=> SELECT RESET_LOAD_BALANCE_POLICY();
RESET_LOAD_BALANCE_POLICY
------------------------------------------------------------------------Successfully reset stateful client load balance policies: "roundrobin".
(1 row)
SET_CONTROL_SET_SIZE
For existing database clusters, use this function to specify the number of cluster nodes on which
you want to deploy control messaging (spread). The SET_CONTROL_SET_SIZE() function works the
same as the install_vertica --large cluster <integer>option.
You can run SET_CONTROL_SET_SIZE()after the database cluster is already defined, but before you
call this function, the database must be up.
Note: You use this function with other cluster management functions. For details, see Defining
and Realigning Control Nodes on an Existing Cluster in the Administrator's Guide.
Syntax
SET_CONTROL_SET_SIZE(integer)
Parameters
integer
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Note
To see if the current spread hosts and the control designations in the Catalog match, query the V_
CATALOG.LARGE_CLUSTER_CONFIGURATION_STATUS system table.
Example
The following command tells HP Vertica that you want to run spread on two cluster nodes:
=> SELECT set_control_set_size(2);
SET_CONTROL_SET_SIZE
---------------------Control size set
(1 row)
See Also
l
V_CATALOG.CLUSTER_LAYOUT
REALIGN_CONTROL_NODES
Chooses control nodes (spread hosts)from all cluster nodes and assigns the rest of the nodes in
the cluster to a control node. Calling this function respects existing fault groups, which you can
view by querying the V_CATALOG.CLUSTER_LAYOUT system table. This view also lets you see the
proposed new layout for nodes in the cluster.
Note: You use this function with other cluster management functions. For details, see Defining
and Realigning Control Nodes on an Existing Cluster in the Administrator's Guide.
Syntax
REALIGN_CONTROL_NODES()
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Example
The following command chooses control nodes from all cluster nodes and assigns the rest of the
nodes in the cluster to a control node:
=> SELECT realign_control_nodes();
See Also
l
V_CATALOG.CLUSTER_LAYOUT
RELOAD_SPREAD
Calling this function with the required true argument updates cluster changes (such as new or realigned control nodes spread hosts or fault groups or new/dropped cluster nodes), to the catalog's
spread configuration file.
Important: This function is often used in a multi-step process for large and elastic cluster
arrangements. Calling RELOAD_SPREAD(true) might require that you restart the database,
which you do using the Administration Tools. You must then rebalance the cluster for fault
tolerance to be realized. See Defining and Realigning Control Nodes in the Administrator's
Guide for more information.
Syntax
RELOAD_SPREAD(true)
Parameters
true
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Example
The following command updates the cluster with changes to control messaging:
=> SELECT reload_spread(true);
reload_spread
--------------reloaded
(1 row)
See Also
l
REBALANCE_CLUSTER
V_CATALOG.CLUSTER_LAYOUT
REBALANCE_CLUSTER
Call this function to begin rebalancing data in the cluster synchronously.
A rebalance operation performs the following tasks:
l
Refreshes projections
SQLReference Manual
SQL Functions
When to Rebalance
Rebalancing is useful (or necessary) after you:
l
Mark one or more nodes as ephemeral in preparation of removing them from the cluster
Add one or more nodes to the cluster so that HP Vertica can populate the empty nodes with data
Remove one or more nodes from the cluster so that HP Vertica can redistribute the data among
the remaining nodes
Change the scaling factor of an elastic cluster, which determines the number of storage
containers used to store a projection across the database
Set the control node size or realign control nodes on a large cluster layout
Specify more than 120 nodes in your initial HP Vertica cluster configuration
Because this function runs the rebalance task synchronously, it does not return until the data has
been rebalanced. Closing or dropping the session cancels the rebalance task.
Important: On large cluster arrangements, you typically use this function in a flow, described
Defining and Realigning Control Nodes in the Administrator's Guide. After you change the
number and distribution of control nodes (spread hosts), you must run REBALANCE_CLUSTER()
for fault tolerance to be realized.
Syntax
REBALANCE_CLUSTER()
Privileges
Must be a superuser.
Example
The following command rebalances data across the cluster.
=> SELECT REBALANCE_CLUSTER();
SQLReference Manual
SQL Functions
REBALANCE_CLUSTER
------------------REBALANCED
(1 row)
See Also
l
START_REBALANCE_CLUSTER
CANCEL_REBALANCE_CLUSTER
NODES
SQLReference Manual
SQL Functions
CANCEL_REBALANCE_CLUSTER
Stops any rebalance task currently in progress.
Syntax
CANCEL_REBALANCE_CLUSTER()
Privileges
Must be a superuser.
Example
=> SELECT CANCEL_REBALANCE_CLUSTER();
CANCEL_REBALANCE_CLUSTER
-------------------------CANCELED
(1 row)
See Also
l
START_REBALANCE_CLUSTER
REBALANCE_CLUSTER
DISABLE_ELASTIC_CLUSTER
Disables elastic cluster scaling, which prevents HP Vertica from bundling data into chunks that are
easily transportable to other nodes when performing cluster resizing. The main reason to disable
elastic clustering is if you find that the slightly unequal data distribution in your cluster caused by
grouping data into discrete blocks results in performance issues.
Syntax
DISABLE_ELASTIC_CLUSTER()
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Example
=> SELECT DISABLE_ELASTIC_CLUSTER();
DISABLE_ELASTIC_CLUSTER
------------------------DISABLED
(1 row)
See Also
l
ENABLE_ELASTIC_CLUSTER
DISABLE_LOCAL_SEGMENTS
Disable local data segmentation, which breaks projections segments on nodes into containers that
can be easily moved to other nodes. See Local Data Segmentation in the Administrator's Guide for
details.
Syntax
DISABLE_LOCAL_SEGMENTS()
Privileges
Must be a superuser.
Example
=> SELECT DISABLE_LOCAL_SEGMENTS();
DISABLE_LOCAL_SEGMENTS
-----------------------DISABLED
(1 row)
SQLReference Manual
SQL Functions
ENABLE_ELASTIC_CLUSTER
Enables elastic cluster scaling, which makes enlarging or reducing the size of your database
cluster more efficient by segmenting a node's data into chunks that can be easily moved to other
hosts.
Note: Databases created using HP Vertica Version 5.0 and later have elastic cluster enabled
by default. You need to use this function on databases created before version 5.0 in order for
them to use the elastic clustering feature.
Syntax
ENABLE_ELASTIC_CLUSTER()
Privileges
Must be a superuser.
Example
=> SELECT ENABLE_ELASTIC_CLUSTER();
ENABLE_ELASTIC_CLUSTER
-----------------------ENABLED
(1 row)
See Also
l
DISABLE_ELASTIC_CLUSTER
ENABLE_LOCAL_SEGMENTS
Enables local storage segmentation, which breaks projections segments on nodes into containers
that can be easily moved to other nodes. See Local Data Segmentation in the Administrator's Guide
for more information.
Syntax
ENABLE_LOCAL_SEGMENTS()
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Example
=> SELECT ENABLE_LOCAL_SEGMENTS();
ENABLE_LOCAL_SEGMENTS
----------------------ENABLED
(1 row)
REBALANCE_CLUSTER
Call this function to begin rebalancing data in the cluster synchronously.
A rebalance operation performs the following tasks:
l
Refreshes projections
When to Rebalance
Rebalancing is useful (or necessary) after you:
l
Mark one or more nodes as ephemeral in preparation of removing them from the cluster
Add one or more nodes to the cluster so that HP Vertica can populate the empty nodes with data
Remove one or more nodes from the cluster so that HP Vertica can redistribute the data among
the remaining nodes
SQLReference Manual
SQL Functions
Change the scaling factor of an elastic cluster, which determines the number of storage
containers used to store a projection across the database
Set the control node size or realign control nodes on a large cluster layout
Specify more than 120 nodes in your initial HP Vertica cluster configuration
Because this function runs the rebalance task synchronously, it does not return until the data has
been rebalanced. Closing or dropping the session cancels the rebalance task.
Important: On large cluster arrangements, you typically use this function in a flow, described
Defining and Realigning Control Nodes in the Administrator's Guide. After you change the
number and distribution of control nodes (spread hosts), you must run REBALANCE_CLUSTER()
for fault tolerance to be realized.
Syntax
REBALANCE_CLUSTER()
Privileges
Must be a superuser.
Example
The following command rebalances data across the cluster.
=> SELECT REBALANCE_CLUSTER();
REBALANCE_CLUSTER
------------------REBALANCED
(1 row)
See Also
l
START_REBALANCE_CLUSTER
CANCEL_REBALANCE_CLUSTER
SQLReference Manual
SQL Functions
NODES
SET_SCALING_FACTOR
Sets the scaling factor that determines the size of the storage containers used when rebalancing
the database and when using local data segmentation is enabled. See Cluster Scaling for details.
Syntax
SET_SCALING_FACTOR(factor)
Parameters
factor
An integer value between 1 and 32. HP Vertica uses this value to calculate the number
of storage containers each projection is broken into when rebalancing or when local data
segmentation is enabled.
Note: Setting the scaling factor value too high can cause nodes to create too many small
container files, greatly reducing efficiency and potentially causing a "Too many
ROScontainers" error (also known as "ROS pushback"). The scaling factor should be set high
enough so that rebalance can transfer local segments to satisfy the skew threshold, but small
enough that the number of storage containers does not exceed ROS pushback. The number of
storage containers should be greater than or equal to the number of partitions multiplied by the
number of local segments (# storage containers >= # partitions * # local segments).
Privileges
Must be a superuser.
Example
=> SELECT SET_SCALING_FACTOR(12);
SET_SCALING_FACTOR
-------------------SET
(1 row)
SQLReference Manual
SQL Functions
START_REBALANCE_CLUSTER
A rebalance operation performs the following tasks:
l
Refreshes projections
When to Rebalance
Rebalancing is useful (or necessary) after you:
l
Mark one or more nodes as ephemeral in preparation of removing them from the cluster
Add one or more nodes to the cluster so that HP Vertica can populate the empty nodes with data
Remove one or more nodes from the cluster so that HP Vertica can redistribute the data among
the remaining nodes
Change the scaling factor of an elastic cluster, which determines the number of storage
containers used to store a projection across the database
Set the control node size or realign control nodes on a large cluster layout
Specify more than 120 nodes in your initial HP Vertica cluster configuration
Asynchronously starts a data rebalance task. Since this function starts the rebalance task in the
background, it returns immediately after the task has started. Since it is a background task,
rebalancing will continue even if the session that started it is closed. It even continues after a
cluster recovery if the database shuts down while it is in progress. The only way to stop the task is
by the CANCEL_REBALANCE_CLUSTER function.
SQLReference Manual
SQL Functions
Syntax
START_REBALANCE_CLUSTER()
Privileges
Must be a superuser.
Example
=> SELECT START_REBALANCE_CLUSTER();
START_REBALANCE_CLUSTER
------------------------REBALANCING
(1 row)
See Also
l
CANCEL_REBALANCE_CLUSTER
REBALANCE_CLUSTER
SQLReference Manual
SQL Functions
ANALYZE_CONSTRAINTS
Analyzes and reports on constraint violations within the current schema search path, or external to
that path if you specify a database name (noted in the syntax statement and parameter table).
You can check for constraint violations by passing arguments to the function as follows:
l
An empty argument (' '), which returns violations on all tables within the current schema
Syntax
ANALYZE_CONSTRAINTS [ ( '' )
... | ( '[[db-name.]schema.]table [.column_name]' )
... | ( '[[db-name.]schema.]table' , 'column' ) ]
Parameters
('')
Analyzes and reports on all tables within the current schema search path.
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
column
Analyzes and reports on all constraints referring to the specified table that
contains the column.
Privileges
l
SQLReference Manual
SQL Functions
Notes
ANALYZE_CONSTRAINTS() performs a lock in the same way that SELECT * FROM t1 holds a
lock on table t1. See LOCKS for additional information.
SELECT DISABLE_DUPLICATE_KEY_ERROR
SELECT REENABLE_DUPLICATE_KEY_ERROR
Return Values
ANALYZE_CONSTRAINTS returns results in a structured set (see table below) that lists the
schema name, table name, column name, constraint name, constraint type, and the column values
that caused the violation.
If the result set is empty, then no constraint violations exist; for example:
> SELECT ANALYZE_CONSTRAINTS ('public.product_dimension', 'product_key');
Schema Name | Table Name | Column Names | Constraint Name | Constraint Type | Column
Values
-------------+------------+--------------+-----------------+-----------------+-------------(0 rows)
The following result set shows a primary key violation, along with the value that caused the
violation ('10'):
=> SELECT ANALYZE_CONSTRAINTS ('');
Schema Name | Table Name | Column Names | Constraint Name | Constraint Type | Column
Values
-------------+------------+--------------+-----------------+-----------------+-----------
SQLReference Manual
SQL Functions
---store
(1 row)
t1
c1
pk_t1
PRIMARY
('10')
The result set columns are described in further detail in the following table:
Column Name Data Type
Description
Schema Name
VARCHAR
Table Name
VARCHAR
Column Names
VARCHAR
Constraint Name
VARCHAR
The given name of the primary key, foreign key, unique, or not
null constraint, if specified.
Constraint Type
VARCHAR
Column Values
VARCHAR
If you run the function on a table that has no constraints declared (even if duplicates are present),
the system returns an error message:
SQLReference Manual
SQL Functions
If you run the function with incorrect syntax, the system returns an error message with a hint; for
example, if you run one of the following:
l
If you run ANALYZE_CONSTRAINTS from a non-default locale, the function returns an error with a
hint:
> \locale LENINFO 2567: Canonical locale: 'en'
Standard collation: 'LEN'
English
> SELECT ANALYZE_CONSTRAINTS('t1');
ERROR: ANALYZE_CONSTRAINTS is currently not supported in
non-default locales
HINT: Set the locale in this session to
en_US@collation=binary using the command
"\locale en_US@collation=binary"
Examples
Given the following inputs, HP Vertica returns one row, indicating one violation, because the same
primary key value (10) was inserted into table t1 twice:
CREATE TABLE t1(c1 INT);
ALTER TABLE t1 ADD CONSTRAINT pk_t1 PRIMARY KEY (c1);
CREATE PROJECTION t1_p (c1) AS SELECT *
FROM t1 UNSEGMENTED ALL NODES;
INSERT INTO t1 values (10);
INSERT INTO t1 values (10); --Duplicate primary key value
\x
Expanded display is on.
SELECT ANALYZE_CONSTRAINTS('t1');
-[ RECORD 1 ]---+-------Schema Name
| public
Table Name
| t1
SQLReference Manual
SQL Functions
Column Names
Constraint Name
Constraint Type
Column Values
|
|
|
|
c1
pk_t1
PRIMARY
('10')
If the second INSERT statement above had contained any different value, the result would have
been 0 rows (no violations).
In the following example, create a table that contains three integer columns, one a unique key and
one a primary key:
CREATE TABLE table_1(
a INTEGER,
b_UK INTEGER UNIQUE,
c_PK INTEGER PRIMARY KEY
);
Insert some values into table table_1 and commit the changes:
INSERT INTO table_1 values (1, 1, 1);
COMMIT;
Insert duplicate unique and primary key values and run ANALYZE_CONSTRAINTS on table
table_1 again. The system shows two violations: one against the primary key and one against the
unique key:
INSERT INTO table_1 VALUES (1, 1, 1);
COMMIT;
SELECT ANALYZE_CONSTRAINTS('table_1');
SQLReference Manual
SQL Functions
The following command looks for constraint validations on only the unique key in the table table_1,
qualified with its schema name:
=> SELECT ANALYZE_CONSTRAINTS('public.table_1', 'b_UK');
-[ RECORD 1 ]---+--------Schema Name
| public
Table Name
| table_1
Column Names
| b_UK
Constraint Name | C_UNIQUE
Constraint Type | UNIQUE
Column Values
| ('1')
(1 row)
The following example shows that you can specify the same column more than once; ANALYZE_
CONSTRAINTS, however, returns the violation only once:
SELECT ANALYZE_CONSTRAINTS('table_1', 'c_PK, C_PK');
-[ RECORD 1 ]---+---------Schema Name
| public
Table Name
| table_1
Column Names
| c_PK
Constraint Name | C_PRIMARY
Constraint Type | PRIMARY
Column Values
| ('1')
The following example creates a new table, table_2, and inserts a foreign key and different
(character) data types:
CREATE TABLE table_2 (
x VARCHAR(3),
y_PK VARCHAR(4),
z_FK INTEGER REFERENCES table_1(c_PK));
SQLReference Manual
SQL Functions
Alter the table to create a multicolumn unique key and multicolumn foreign key and create
superprojections:
ALTER TABLE table_2
ADD CONSTRAINT table_2_multiuk PRIMARY KEY (x, y_PK);
WARNING 2623: Column "x" definition changed to NOT NULL
WARNING 2623: Column "y_PK" definition changed to NOT NULL
The following command inserts a missing foreign key (0) into table dim_1 and commits the
changes:
INSERT INTO table_2 VALUES ('r1', 'Xpk1', 0);
COMMIT;
Checking for constraints on the table table_2 in the public schema detects a foreign key
violation:
=> SELECT ANALYZE_CONSTRAINTS('public.table_2');
-[ RECORD 1 ]---+---------Schema Name
| public
Table Name
| table_2
Column Names
| z_FK
Constraint Name | C_FOREIGN
Constraint Type | FOREIGN
Column Values
| ('0')
Now add a duplicate value into the unique key and commit the changes:
INSERT INTO table_2 VALUES ('r2', 'Xpk1', 1);
INSERT INTO table_2 VALUES ('r1', 'Xpk1', 1);
COMMIT;
Checking for constraint violations on table table_2 detects the duplicate unique key error:
SELECT ANALYZE_CONSTRAINTS('table_2');
-[ RECORD 1 ]---+---------------Schema Name
| public
Table Name
| table_2
Column Names
| z_FK
Constraint Name | C_FOREIGN
Constraint Type | FOREIGN
Column Values
| ('0')
-[ RECORD 2 ]---+---------------Schema Name
| public
Table Name
| table_2
Column Names
| x, y_PK
Constraint Name | table_2_multiuk
Constraint Type | PRIMARY
Column Values
| ('r1', 'Xpk1')
SQLReference Manual
SQL Functions
Create a table with multicolumn foreign key and create the superprojections:
CREATE TABLE table_3(
z_fk1 VARCHAR(3),
z_fk2 VARCHAR(4));
ALTER TABLE table_3
ADD CONSTRAINT table_3_multifk FOREIGN KEY (z_fk1, z_fk2)
REFERENCES table_2(x, y_PK);
Insert a foreign key that matches a foreign key in table table_2 and commit the changes:
INSERT INTO table_3 VALUES ('r1', 'Xpk1');
COMMIT;
Add a value that does not match and commit the change:
INSERT INTO table_3 VALUES ('r1', 'NONE');
COMMIT;
SQLReference Manual
SQL Functions
ANALYZE_CORRELATIONS
Analyzes the specified tables for pairs of columns that are strongly correlated. Stores only the 20
pairs with the strongest correlation. ANALYZE_CORRELATIONSalso analyzes statistics.
SQLReference Manual
SQL Functions
For example, state name and country name columns are strongly correlated because the city name
usually, but perhaps not always, identifies the state name. The city of Conshohoken is uniquely
associated with Pennsylvania, whereas the city of Boston exists in Georgia, Indiana, Kentucky,
New York, Virginia, and Massachusetts. In this case, city name is strongly correlated with state
name.
For Database Designer to take advantage of these correlations, run Database Designer
programmatically. Use DESIGNER_SET_ANALYZE_CORRELATIONS_MODE to specify that
Database Designer should consider existing column correlations. Make sure to specify that
Database Designer not analyze statistics so that Database Designer does not override the existing
statistics.
Behavior Type
Immutable
Syntax
ANALYZE_CORRELATIONS (
'[database_name.][schema_name.]table_name',
[recalculate] )
Parameters
database_name
schema_name
table_name
recalculate
Specifies to analyze the correlated columns, even if they have been analyzed
before, type BOOLEAN. Default: 'false'.
Permissions
l
SQLReference Manual
SQL Functions
Notes
l
Projections do not change based on the analysis results. To implement the results of
ANALYZE_CORRELATIONS, you must run Database Designer.
Example
In the following example, ANALYZE_CORRELATIONS analyzes column correlations for all tables
in the public schema,even if they currently exist. The correlations that ANALYZE_
CORRELATIONSfinds are saved so that Database Designer can use them the next time it runs on
the VMart database:
=> SELECT ANALYZE_CORRELATIONS (
'public.*',
'true');
ANALYZE_CORRELATIONS
---------------------0
(1 row)
See Also
l
DESIGNER_SET_ANALYZE_CORRELATIONS_MODE
DISABLE_DUPLICATE_KEY_ERROR
Disables error messaging when HP Vertica finds duplicate PRIMARY KEY/UNIQUE KEY values
at run time. Queries execute as though no constraints are defined on the schema. Effects are
session scoped.
Caution: When called, DISABLE_DUPLICATE_KEY_ERROR() suppresses data integrity
checking and can lead to incorrect query results. Use this function only after you insert
duplicate primary keys into a dimension table in the presence of a pre-join projection. Then
correct the violations and turn integrity checking back on with REENABLE_DUPLICATE_
KEY_ERROR().
SQLReference Manual
SQL Functions
Syntax
DISABLE_DUPLICATE_KEY_ERROR();
Privileges
Must be a superuser.
Examples
The following series of commands create a table named dim and the corresponding projection:
CREATE TABLE dim (pk INTEGER PRIMARY KEY, x INTEGER);
CREATE PROJECTION dim_p (pk, x) AS SELECT * FROM dim ORDER BY x UNSEGMENTED ALL NODES;
The next two statements create a table named fact and the pre-join projection that joins fact to
dim.
CREATE TABLE fact(fk INTEGER REFERENCES dim(pk));
CREATE PROJECTION prejoin_p (fk, pk, x) AS SELECT * FROM fact, dim WHERE pk=fk ORDER BY
x;
The following statements load values into table dim. The last statement inserts a duplicate primary
key value of 1:
INSERT INTO dim values (1,1);
INSERT INTO dim values (2,2);
INSERT INTO dim values (1,2); --Constraint violation
COMMIT;
Table dim now contains duplicate primary key values, but you cannot delete the violating row
because of the presence of the pre-join projection. Any attempt to delete the record results in the
following error message:
ROLLBACK: Duplicate primary key detected in FK-PK join Hash-Join (x dim_p), value 1
In order to remove the constraint violation (pk=1), use the following sequence of commands, which
puts the database back into the state just before the duplicate primary key was added.
To remove the violation:
SQLReference Manual
SQL Functions
1. Save the original dim rows that match the duplicated primary key:
CREATE TEMP TABLE dim_temp(pk integer, x integer);
INSERT INTO dim_temp SELECT * FROM dim WHERE pk=1 AND x=1; -- original dim row
The difference between this message and the rollback message in the previous example is that
a fact row contains a foreign key that matches the duplicated primary key, which has been
inserted. A row with values from the fact and dimension table is now in the pre-join projection.
In order for the DELETE statement (Step 3 in the following example) to complete successfully,
SQLReference Manual
SQL Functions
extra predicates are required to identify the original dimension table values (the values that are
in the pre-join).
This example is nearly identical to the previous example, except that an additional INSERT
statement joins the fact table to the dimension table by a primary key value of 1:
INSERT INTO
INSERT INTO
INSERT INTO
primary key
INSERT INTO
COMMIT;
dim values
dim values
fact values
value=1
dim values
(1,1);
(2,2);
(1);
TEMP
TEMP
INTO
INTO
3. Remove the duplicate primary keys. These steps also implicitly remove all fact rows with the
matching foreign key.
4. Remove the original row that contains duplicate values:
DELETE FROM dim WHERE pk=1 AND x=1;
Note: The extra predicate (x=1) specifies removal of the original (1,1) row, rather than the
newly inserted (1,2) values that caused the violation.
SQLReference Manual
SQL Functions
7. Reinsert the original values back into the fact and dimension table:
INSERT INTO dim SELECT * from dim_temp;
INSERT INTO fact SELECT * from fact_temp;
COMMIT;
See Also
l
ANALYZE_CONSTRAINTS
REENABLE_DUPLICATE_KEY_ERROR
LAST_INSERT_ID
Returns the last value of a column whose value is automatically incremented through the AUTO_
INCREMENT or IDENTITY Column-Constraint. If multiple sessions concurrently load the same
table, the returned value is the last value generated for an AUTO_INCREMENT column by an
insert in that session.
Behavior Type
Volatile
Syntax
LAST_INSERT_ID()
Privileges
l
Table owner
SQLReference Manual
SQL Functions
Notes
l
This function works only with AUTO_INCREMENT and IDENTITY columns. See columnconstraints for the CREATE TABLE statement.
LAST_INSERT_ID does not work with sequence generators created through the CREATE
SEQUENCE statement.
Examples
Create a sample table called customer4.
=> CREATE TABLE customer4(
ID IDENTITY(2,2),
lname VARCHAR(25),
fname VARCHAR(25),
membership_card INTEGER
);
=> INSERT INTO customer4(lname, fname, membership_card)
VALUES ('Gupta', 'Saleem', 475987);
Notice that the IDENTITY column has a seed of 2, which specifies the value for the first row loaded
into the table, and an increment of 2, which specifies the value that is added to the IDENTITY value
of the previous row.
Query the table you just created:
=> SELECT * FROM customer4;
ID | lname | fname | membership_card
----+-------+--------+----------------2 | Gupta | Saleem |
475987
(1 row)
SQLReference Manual
SQL Functions
| membership_card
See Also
l
ALTER SEQUENCE
CREATE SEQUENCE
DROP SEQUENCE
SEQUENCES
Sequence Privileges
SQLReference Manual
SQL Functions
REENABLE_DUPLICATE_KEY_ERROR
Restores the default behavior of error reporting by reversing the effects of DISABLE_DUPLICATE_
KEY_ERROR. Effects are session scoped.
Syntax
REENABLE_DUPLICATE_KEY_ERROR();
Privileges
Must be a superuser.
Examples
For examples and usage, see DISABLE_DUPLICATE_KEY_ERROR.
See Also
l
ANALYZE_CONSTRAINTS
SQLReference Manual
SQL Functions
Data Collector works in conjunction with an advisor tool called Workload Analyzer, which
intelligently monitors the performance of SQL queries and workloads and recommends tuning
actions based on observations of the actual workload history.
By default, Data Collector is on and retains information for all sessions. If performance issues
arise, a superuser can disable DC. See Data Collector Parameters and Enabling and Disabling
Data Collector in the Administrator's Guide.
This section describes the Data Collection control functions.
Related Topics
V_MONITOR.DATA_COLLECTOR
Retaining monitoring information and Analyzing Workloads in the Administrator's Guide
CLEAR_DATA_COLLECTOR
Clears all memory and disk records on the Data Collector tables and functions and resets collection
statistics in the V_MONITOR.DATA_COLLECTOR system table. A superuser can clear Data
Collector data for all components or specify an individual component
After you clear the Data Collector log, the information is no longer available for querying.
Syntax
CLEAR_DATA_COLLECTOR( [ 'component' ] )
SQLReference Manual
SQL Functions
Parameters
component
Clears memory and disk records for the specified component only. If you provide no
argument, the function clears all Data Collector memory and disk records for all
components.
For the current list of component names, query the V_MONITOR.DATA_
COLLECTOR system table.
Privileges
Must be a superuser.
Examples
The following command clears memory and disk records for the ResourceAcquisitions component:
=> SELECT clear_data_collector('ResourceAcquisitions');
clear_data_collector
---------------------CLEAR
(1 row)
The following command clears data collection for all components on all nodes:
=> SELECT clear_data_collector();
clear_data_collector
---------------------CLEAR
(1 row)
See Also
DATA_COLLECTOR
l
l
DATA_COLLECTOR_HELP
Returns online usage instructions about the Data Collector, the DATA_COLLECTOR system table, and
the Data Collector control functions.
SQLReference Manual
SQL Functions
Syntax
DATA_COLLECTOR_HELP()
Privileges
None
Returns
The DATA_COLLECTOR_HELP() function returns the following information:
=> SELECT DATA_COLLECTOR_HELP();
----------------------------------------------------------------------------Usage Data Collector
The data collector retains history of important system activities.
This data can be used as a reference of what actions have been taken
by users, but it can also be used to locate performance bottlenecks,
or identify potential improvements to the Vertica configuration.
This data is queryable via Vertica system tables.
Acccess a list of data collector components, and some statistics, by running:
SELECT * FROM v_monitor.data_collector;
The amount of data retained by size and time can be controlled with several
functions.
To just set the size amount:
set_data_collector_policy(<component>,
<memory retention (KB)>,
<disk retention (KB)>);
To set both the size and time amounts (the smaller one will dominate):
set_data_collector_policy(<component>,
<memory retention (KB)>,
<disk retention (KB)>,
<interval>);
To set just the time amount:
set_data_collector_time_policy(<component>,
<interval>);
To set the time amount for all tables:
set_data_collector_time_policy(<interval>);
The current retention policy for a component can be queried with:
get_data_collector_policy(<component>);
Data on disk is kept in the "DataCollector" directory under the Vertica
\catalog path. This directory also contains instructions on how to load
the monitoring data into another Vertica database.
SQLReference Manual
SQL Functions
To move the data collector logs and instructions to other storage locations,
create labeled storage locations using add_location and then use:
set_data_collector_storage_location(<storage_label>);
Additional commands can be used to configure the data collection logs.
The log can be cleared with:
clear_data_collector([<optional component>]);
The log can be synchronized with the disk storage using:
flush_data_collector([<optional component>]);
See Also
l
DATA_COLLECTOR
TUNING_RECOMMENDATIONS
Analyzing Workloads
FLUSH_DATA_COLLECTOR
Waits until memory logs are moved to disk and then flushes the Data Collector, synchronizing the
log with the disk storage. A superuser can flush Data Collector information for an individual
component or for all components.
Syntax
FLUSH_DATA_COLLECTOR( [ 'component' ] )
Parameters
component
Flushes the specified component. If you provide no argument, the function flushes
the Data Collector in full.
For the current list of component names, query the V_MONITOR.DATA_
COLLECTOR system table.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Examples
The following command flushes the Data Collector for the ResourceAcquisitions component:
=> SELECT flush_data_collector('ResourceAcquisitions');
flush_data_collector
---------------------FLUSH
(1 row)
See Also
DATA_COLLECTOR
l
l
GET_DATA_COLLECTOR_POLICY
Retrieves a brief statement about the retention policy for the specified component.
Syntax
GET_DATA_COLLECTOR_POLICY( 'component' )
Parameters
component
Privileges
None
SQLReference Manual
SQL Functions
Example
The following query returns the history of all resource acquisitions by specifying the
ResourceAcquisitions component:
=> SELECT get_data_collector_policy('ResourceAcquisitions');
get_data_collector_policy
---------------------------------------------1000KB kept in memory, 10000KB kept on disk.
(1 row)
See Also
DATA_COLLECTOR
l
l
SET_DATA_COLLECTOR_POLICY
Sets a size restraint (memory and disk space in kilobytes) for the specified Data Collector table on
all nodes. If nodes are down, the failed nodes receive the setting when they rejoin the cluster.
You can use this function to set a size restraint only, or you can include the optional interval
argument to set disk capacity for both size and time in a single command.
If you specify interval, HP Vertica enforces the setting that is exceeded first (size or time).
Before you include a time restraint, verify that the disk size capacity is sufficiently large.
If you want to specify just a time restraint, or you want to turn off a time restraint you set using this
function, see SET_DATA_COLLECTOR_TIME_POLICY().
Syntax
SET_DATA_COLLECTOR_POLICY('component', 'memoryKB', 'diskKB' [,'interval']
Parameters
component
memoryKB
diskKB
SQLReference Manual
SQL Functions
interval
[Default off] Takes an optional interval argument to specify how long to retain the
specified component on disk. To disable a time restraint, set interval to -1.
Note: Any negative input will turn off the time restraint
Privileges
Must be a superuser.
Notes
l
Before you change a retention policy, view its current setting by calling the GET_DATA_
COLLECTOR_POLICY() function.
If you don't know the name of a component, query the V_MONITOR.DATA_COLLECTOR system
table for a list; for example:
=> SELECT DISTINCT component, description FROM data_collector
ORDER BY 1 ASC;
Examples
The following command returns the retention policy for the ResourceAcquisitions component:
=> SELECT get_data_collector_policy('ResourceAcquisitions');
get_data_collector_policy
---------------------------------------------1000KB kept in memory, 10000KB kept on disk.
(1 row)
This command changes the memory and disk setting for ResourceAcquisitions from its current
setting of 1,000 KB memory and 10,000 KB disk space to 1500 KB and 25000 KB, respectively:
=> SELECT set_data_collector_policy('ResourceAcquisitions', '1500', '25000');
set_data_collector_policy
--------------------------SET
(1 row)
This command sets the RequestsIssued component to 1500 KB memory and 11000 KBon disk,
and includes a 3-minute time restraint:
SQLReference Manual
SQL Functions
The following command disables the 3-minute retention policy for the RequestsIssued component:
=> SELECT set_data_collector_policy('RequestsIssued', '-1');
set_data_collector_policy
--------------------------SET
(1 row)
See Also
l
GET_DATA_COLLECTOR_POLICY
SET_DATA_COLLECTOR_TIME_POLICY()
DATA_COLLECTOR
SET_DATA_COLLECTOR_TIME_POLICY
Sets a time capacity for individual Data Collector tables on all nodes. If nodes are down, the failed
nodes receive the setting when they rejoin the cluster.
If you specify interval, HP Vertica enforces the setting that is exceeded first (size or time).
Before you include a time restraint, verify that the disk size capacity is sufficiently large.
If you want to configure both time and size restraints at the same time, see SET_DATA_COLLECTOR_
POLICY.
Syntax
SET_DATA_COLLECTOR_TIME_POLICY( ['component',] 'interval' )
SQLReference Manual
SQL Functions
Parameters
component
[Optional] Configures the time retention policy for the specified component. If you
omit the component argument, HP Vertica sets the specified time capacity for all
Data Collector tables.
interval
Specifies the time restraint on disk using an INTERVAL type. To disable a time
restraint, set interval to -1.
Note: Any negative input turns off the time restraint
Privileges
Must be a superuser.
Usage Considerations
l
Before you change a retention policy, view its current setting by calling the GET_DATA_
COLLECTOR_POLICY function.
To illustrate, the following command in the left column is equivalent to running the series of
commands on the right:
SQLReference Manual
SQL Functions
SELECT set_data_collector_time_policy
('v_monitor.query_requests',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('RequestsIssued',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('RequestsCompleted',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('Errors',
'3 minutes'::interval);
SELECT set_data_collector_time_policy
('ResourceAcquisitions',
'3 minutes'::interval);
The SET_DATA_COLLECTOR_TIME_POLICY function updates the time capacity for all Data
Collector tables in the V_MONITOR.QUERY_REQUESTS view. The new setting overrides any
previous settings for every Data Collector table in that view.
Examples
The following command configures the Backups component to be retained on disk for 1 day:
=> SELECT set_data_collector_time_policy('Backups', '1 day'::interval);
set_data_collector_time_policy
-------------------------------SET
(1 row)
This command disables the 1-day restraint for the Backups component:
=> SELECT set_data_collector_time_policy('Backups', '-1');
set_data_collector_time_policy
-------------------------------SET
(1 row)
This command sets a 30-minute time capacity for all Data Collector tables in a single command:
=> SELECT set_data_collector_time_policy('30 minutes'::interval);
set_data_collector_time_policy
-------------------------------SET
(1 row)
To view current retention policy settings for each Data Collector table, call the GET_DATA_
COLLECTION_POLICY() function. In the next example, the time restraint is included.
SQLReference Manual
SQL Functions
If the time policy setting is disabled, the output of GET_DATA_COLLECTION_POLICY() returns "Time
based retention disabled."
2000KB kept in memory, 50000KB kept on disk. Time based retention disabled.
See Also
l
GET_DATA_COLLECTOR_POLICY
SET_DATA_COLLECTOR_POLICY
DATA_COLLECTOR
SQLReference Manual
SQL Functions
Permissions
To run the Database Designer functions, you must be one of the following:
l
Superuser
Have been granted the DBDUSER role and executed the SET ROLE DBDUSER command.
Once you have been granted the DBDUSER role, the role is in effect until it is revoked.
Important: When you grant the DBDUSER role, make sure to associate a resource pool
with that user to manage resources during Database Designer runs. Multiple users can run
Database Designer concurrently without interfering with each other or using up all the
cluster resources. When a user runs Database Designer, either using the Administration
Tools or programmatically, its execution is mostly contained by the user's resource pool,
but may spill over into some system resource pools for less-intensive tasks.
You can run Database Designer functions in vsql:
Setup Functions
This function directs Database Designer to create a new design:
l
DESIGNER_CREATE_DESIGN
Configuration Functions
The following functions allow you to specify properties of a particular design:
l
DESIGNER_DESIGN_PROJECTION_ENCODINGS
DESIGNER_SET_DESIGN_KSAFETY
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
DESIGNER_SET_DESIGN_TYPE
SQLReference Manual
SQL Functions
DESIGNER_SET_PROPOSED_UNSEGMENTED_PROJECTIONS
DESIGNER_SET_ANALYZE_CORRELATIONS_MODE
Input Functions
The following functions allow you to add tables and queries to your Database Designer design:
l
DESIGNER_ADD_DESIGN_QUERIES
DESIGNER_ADD_DESIGN_QUERIES_FROM RESULTS
DESIGNER_ADD_DESIGN_QUERY
DESIGNER_ADD_DESIGN_TABLES
Invocation Functions
These functions populate the Database Designer workspace and create design and deployment
scripts. You can also analyze statistics, deploy the design automatically, and drop the workspace
after the deployment:
l
DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY
DESIGNER_WAIT_FOR_DESIGN
Output Functions
The following functions display information about projections and scripts that the Database
Designer created:
l
DESIGNER_OUTPUT_ALL_DESIGN_PROJECTIONS
DESIGNER_OUTPUT_DEPLOYMENT_SCRIPT
Cleanup Functions
The following functions cancel any running Database Designer operation or drop a Database
Designer design and all its contents:
l
DESIGNER_CANCEL_POPULATE_DESIGN
DESIGNER_DROP_DESIGN
SQLReference Manual
SQL Functions
DESIGNER_DROP_ALL_DESIGNS
DESIGNER_ADD_DESIGN_QUERIES
Reads and parses all queries in the specified file. Adds accepted queries to the design and sets the
weight of each accepted query to 1.
Behavior Type
Immutable
Syntax
DESIGNER_ADD_DESIGN_QUERIES (
'design_name',
'file_name',
'informative_output' )
Parameters
design_name
file_name
informative_output
SQLReference Manual
SQL Functions
Permissions
l
You must have READ privilege on the storage location of the queries file.
You must have sufficient privileges to execute all queries in the queries file.
Notes
l
SQLReference Manual
SQL Functions
DESIGNER_ADD_DESIGN_QUERIES:
n
Examples
The following example adds the queries file vmart_queries.sql to the VMART_DESIGN design.
This file contains nine queries. Since the third parameter is 'true', DESIGNER_ADD_DESIGN_
QUERIES returns the results of adding the queries:
=> SELECT DESIGNER_ADD_DESIGN_QUERIES (
'VMART_DESIGN',
'/tmp/examples/vmart_queries.sql',
'true'
);
...
DESIGNER_ADD_DESIGN_QUERIES
---------------------------------------------------Number of accepted queries
=9
Number of queries referencing non-design tables =0
Number of unsupported queries
=0
Number of illegal queries
=0
(1 row)
See Also
l
DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS
DESIGNER_ADD_DESIGN_QUERY
DESIGNER_ADD_DESIGN_TABLES
DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS
Parses and executes a user query and retrieves only queries that contain the following columns:
SQLReference Manual
SQL Functions
QUERY_WEIGHT: Corresponding query weight values for the queries in QUERY_TEXT, a value
greater than 0 but no greater than 1. If empty, Database Designer sets the weight of that query to
1.
Behavior Type
Immutable
Syntax
DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS ( 'design_name', 'user_query' )
Parameters
design_name
user_query
A valid SQL query whose results contain columns named QUERY_TEXT and QUERY_
WEIGHT, type VARCHAR.
Permissions
l
You must have sufficient privileges to execute user_query and to execute each design query
retrieved from the results of user_query.
Notes
l
SQLReference Manual
SQL Functions
Example
The following example retrieves the query_text field from the 10 most recent queries in the
QUERY_REQUESTS system table QUERY_REQUESTS and adds the accepted queries to the
VMART_DESIGN design. QUERY_REQUESTS does not contains any weight value for those
queries:
=> SELECT DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS (
'VMART_DESIGN',
'SELECT request AS query_text FROM query_requests
ORDER BY start_timestamp DESC LIMIT 10;');
);
See Also
l
DESIGNER_ADD_DESIGN_QUERIES
DESIGNER_ADD_DESIGN_TABLES
DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS
DESIGNER_ADD_DESIGN_QUERY
Reads and parses the specified query, and if accepted, adds it to the design.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
DESIGNER_ADD_DESIGN_QUERY (
'design_name',
'design_query',
query_weight )
Parameters
design_name
Name of the Database Designer design to which you want to add the query, type
VARCHAR.
design_query
query_weight
Weight of query, any positive real number greater than 0 and no greater than 1.
Default: 1 You cannot add a weight of 0.
The weight of a query indicates its relative importance so that Database Designer
can prioritize the query when creating the design.
Permissions
l
Notes
l
SQLReference Manual
SQL Functions
Examples
The following example adds the specified query to the VMART_DESIGN design and assigns that
query a weight of 0.5:
=> SELECT DESIGNER_ADD_DESIGN_QUERY (
'VMART_DESIGN',
'SELECT customer_name, customer_type FROM vmart_design
ORDER BY customer_name ASC;',
0.5
);
See Also
l
DESIGNER_ADD_DESIGN_QUERIES
DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS
DESIGNER_ADD_DESIGN_TABLES
DESIGNER_ADD_DESIGN_TABLES
Adds the specified tables to a design.
Behavior Type
Immutable
Syntax
DESIGNER_ADD_DESIGN_TABLES (
'design_name',
'table_pattern',
[ 'analyze_statistics']
)
SQLReference Manual
SQL Functions
Parameters
design_name
table_pattern
analyze_statistics
Permissions
To run DESIGNER_ADD_DESIGN_TABLES and add tables to your design, you must be a
superuser or a user granted the DBDUSER role who:
l
Notes
You must run DESIGNER_ADD_DESIGN_TABLES before you add design queries to the design.
If no tables have been added to the design, HP Vertica does not accept the design queries.
SQLReference Manual
SQL Functions
Examples
The following example adds all the VMart tables to the VMART_DESIGN design, and analyzes
statistics for those tables:
=> SELECT DESIGNER_ADD_DESIGN_TABLES(
'VMART_DESIGN',
'online_sales.*',
'true'
);
DESIGNER_ADD_DESIGN_TABLES
---------------------------9
(1 row)
=> SELECT DESIGNER_ADD_DESIGN_TABLES(
'VMART_DESIGN',
'public.*',
'true'
);
DESIGNER_ADD_DESIGN_TABLES
---------------------------9
(1 row)
=> SELECT DESIGNER_ADD_DESIGN_TABLES(
'VMART_DESIGN',
'store.*',
'true'
);
DESIGNER_ADD_DESIGN_TABLES
---------------------------3
(1 row)
See Also
l
DESIGNER_ADD_DESIGN_QUERIES
DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS
DESIGNER_ADD_DESIGN_QUERY
DESIGNER_CANCEL_POPULATE_DESIGN
Cancels the population or deployment operation for the specified design if it is currently running.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
DESIGNER_CANCEL_POPULATE_DESIGN ( 'design_name' )
Parameters
design_name
Name of a currently running design that you want to cancel, type VARCHAR.
Permissions
To run DESIGNER_CANCEL_POPULATE_DESIGN on a design, you must be a superuser, or a
user granted the DBDUSER role who created the design.
Notes
l
When you cancel a deployment, the Database Designer cancels the projection refresh
operation. It does not roll back any projections that it has already deployed and refreshed.
Examples
The following example cancels a currently running design for VMART_DESIGN and then drops the
design:
=> SELECT DESIGNER_CANCEL_POPULATE_DESIGN ('VMART_DESIGN');=> SELECT DESIGNER_DROP_DESIGN
('VMART_DESIGN');
See Also
l
DESIGNER_DROP_ALL_DESIGNS
DESIGNER_DROP_DESIGN
DESIGNER_CREATE_DESIGN
Creates a design with the specified name.
Note: Be sure to back up the existing design using the EXPORT_CATALOG function before
SQLReference Manual
SQL Functions
running the Database Designer functions on an existing schema. You must explicitly back up
the existing design when using Database Designer programmatically.
Behavior Type
Immutable
Syntax
DESIGNER_CREATE_DESIGN ( 'design_name' )
Parameters
design_name
Name of the design you want to create, type VARCHAR. A Database Designer
design name can only contain alphanumeric characters and underscore (_)
characters.
Permissions
To run DESIGNER_CREATE_DESIGN, you must be a superuser, or a user granted the
DBDUSER role.
Notes
l
Two users may not have designs with the same name at the same time.
DESIGNS
DESIGN_TABLES
DEPLOYMENT_PROJECTIONS
DEPLOYMENT_PROJECTION_STATEMENTS
DESIGN_QUERIES
SQLReference Manual
SQL Functions
OUTPUT_DEPLOYMENT_STATUS
OUTPUT_EVENT_HISTORY
Examples
The following example creates a design named VMART_DESIGN:
=> SELECT DESIGNER_CREATE_DESIGN('VMART_DESIGN');
DESIGNER_CREATE_DESIGN
-----------------------0
(1 row)
See Also
l
DESIGNER_DROP_DESIGN
DESIGNER_DROP_ALL_DESIGNS
DESIGNER_DESIGN_PROJECTION_ENCODINGS
Analyze encoding in the specified projections, create a script to implement encoding
recommendations, and deploy the recommendations.
Behavior Type
Immutable
Syntax
DESIGNER_DESIGN_PROJECTION_ENCODINGS (
'projection_list',
'projection_ddl_script_file,
'deploy'
)
SQLReference Manual
SQL Functions
Parameters
projection_list
projection_ddl_script_file
deploy
Privileges
l
Be the OWNER of the projections for which you want to perform encoding analysis.
Have USAGE privilege on the schema that corresponds to all the specified projections.
Examples
The following example requests that Database Designer analyze the encoding of the projections of
the online_sales schema in the VMart example database, save the SQL statements in the script file
encodings.sql, but do not deploy the changes:
=> SELECT DESIGNER_DESIGN_PROJECTION_ENCODINGS (
'online_sales.*',
SQLReference Manual
SQL Functions
'encodings.sql',
'false'
);
DESIGNER_DESIGN_PROJECTION_ENCODINGS
-------------------------------------(1 row)
DESIGNER_DROP_ALL_DESIGNS
Removes all Database Designer-related schemas associated with the current user.
Use DESIGNER_DROP_ALL_DESIGNS to remove database objects after one or more Database
Designer session completes.
Behavior Type
Immutable
Syntax
DESIGNER_DROP_ALL_DESIGNS()
Parameters
None.
Privileges
If the superuser runs DESIGNER_DROP_ALL_DESIGNS, all designs are dropped.
If the DBDUSERruns DESIGNER_DROP_ALL_DESIGNS, the function only drops the designs
that the DBDUSERcreated.
Example
The following example removes all schema and their contents associated with the current user.
DESIGNER_DROP_ALL_DESIGNS returns the number of designs dropped:
=> SELECT DESIGNER_DROP_ALL_DESIGNS();
DESIGNER_DROP_ALL_DESIGNS
--------------------------2
SQLReference Manual
SQL Functions
(1 row)
See Also
l
DESIGNER_CANCEL_POPULATE_DESIGN
DESIGNER_DROP_DESIGN
DESIGNER_DROP_DESIGN
Removes the schema associated with the specified design and all its contents. Use DESIGNER_
DROP_DESIGN after a Database Designer design or deployment completes successfully or
terminates unexpectedly.
Behavior Type
Immutable
Syntax
DESIGNER_DROP_DESIGN ( 'design_name' )
Parameters
design_name
Name of the design you want to drop, type VARCHAR. To drop all designs you
have created, use DESIGNER_DROP_ALL_DESIGNS.
Permissions
You must be a superuser or a user granted the DBDUSER role who created the design, to run
DESIGNER_DROP_DESIGN.
Notes
If a Database Designer session terminates unexpectedly, you cannot recreate that design with the
same name unless you run DESIGNER_DROP_DESIGN to clean up any leftover files.
SQLReference Manual
SQL Functions
Example
The following example deletes the Database Designer design VMART_DESIGN, and all its
contents:
=> SELECT DESIGNER_DROP_DESIGN ('VMART_DESIGN');
See Also
l
DESIGNER_CANCEL_POPULATE_DESIGN
DESIGNER_DROP_ALL_DESIGNS
DESIGNER_OUTPUT_ALL_DESIGN_PROJECTIONS
Displays the DDL statements that define the design projections to STDOUT.
Behavior Type
Immutable
Syntax
DESIGNER_OUTPUT_ALL_DESIGN_PROJECTIONS ( 'design_name' )
Parameters
design_name
Name of the design for which to display the DDL statements that create the design
projections, type VARCHAR.
Permissions
You must be a superuser, or a user assigned the DBDUSER role, to run DESIGNER_OUTPUT_
ALL_DESIGN_PROJECTIONS.
Examples
The following example returns the design projection DDL statements for vmart_design:
SQLReference Manual
SQL Functions
SQLReference Manual
SQL Functions
See Also
l
DESIGNER_OUTPUT_DEPLOYMENT_SCRIPT
DESIGNER_OUTPUT_DEPLOYMENT_SCRIPT
Displays the deployment script for the specified design to STDOUT.
The deployment script includes the CREATE PROJECTION commands that are also in the design
script that you can display using DESIGNER_OUTPUT_ALL_DESIGN_PROJECTIONS.
If you have already deployed the design, this function does not return the script.
Behavior Type
Immutable
Syntax
DESIGNER_OUTPUT_DEPLOYMENT_SCRIPT ( 'design_name' )
Parameters
design_name
Name of the design for which you want to display the deployment script, type
VARCHAR.
Permissions
To run DESIGNER_OUTPUT_DEPLOYMENT_SCRIPT, you must be a superuser or a user
granted the DBDUSER role who created the design.
Examples
The following example displays the deployment script for VMART_DESIGN at STDOUT:
=> SELECT DESIGNER_OUTPUT_DEPLOYMENT_SCRIPT('VMART_DESIGN');
CREATE PROJECTION customer_dimension_DBD_1_rep_VMART_DESIGN /*createtype(D)*/
...
CREATE PROJECTION product_dimension_DBD_2_rep_VMART_DESIGN /*+createtype(D)*/
...
select refresh('public.customer_dimension,
SQLReference Manual
SQL Functions
public.product_dimension,
public.promotion.dimension,
public.date_dimension');
select make_ahm_now();
DROP PROJECTION public.customer_dimension_super CASCADE;
DROP PROJECTION public.product_dimension_super CASCADE;
...
See Also
l
DESIGNER_OUTPUT_ALL_DESIGN_PROJECTIONS
DESIGNER_RESET_DESIGN
Clears the specified design but preserves the design's configuration such as parameters, tables,
and queries. Running this function allows you to make additional changes to the design with or
without deployment.
DESIGNER_RESET_DESIGNdiscards all the run-specific information of the previous Database
Designer build or deployment of the specified design but keeps its configuration. You can make
changes to the design as needed, for example, by changing parameters or adding additional tables
and/or queries, before rerunning the design.
Behavior Type
Immutable
Syntax
DESIGNER_RESET_DESIGN ( 'design_name' )
Parameters
design_name
Permissions
You must be a superuser or a user granted the DBDUSER role who created the design, to run
DESIGNER_RESET_DESIGN.
SQLReference Manual
SQL Functions
Example
The following example resets the Database Designer design VMART_DESIGN:
=> SELECT DESIGNER_RESET_DESIGN ('VMART_DESIGN');
DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY
Populates the design and creates the design and deployment scripts. If specified, DESIGNER_
RUN_POPULATE_DESIGN_AND_DEPLOY also analyzes statistics, deploys the design, and
drops the workspace after the deployment.
Note: Make sure to back up the existing design using the EXPORT_CATALOG function
before running the Database Designer functions on an existing schema. You must explicitly
back up the existing design when using Database Designer programmatically.
Behavior Type
Immutable
Syntax
DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY (
'design_name',
'output_design_file',
'output_deployment_file',
[ 'analyze_statistics', ]
[ 'deploy', ]
[ 'drop_design_workspace', ]
[ 'continue_after_error', ]
)
Parameters
design_name
Name of the design that you want to populate and deploy, type
VARCHAR.
output_design_file
Absolute path for saving the file that contains the DDL statements that
create the design projections, type VARCHAR.
SQLReference Manual
SQL Functions
output_deployment_file
Absolute path for saving the file that contains the deployment script,
type VARCHAR.
analyze_statistics
deploy
drop_design_workspace
continue_after_error
Permissions
To run DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY, you must
l
Be a superuser, or a user granted the DBDUSER role who created the design.
Have WRITE privilege on the storage locations of the design and deployment scripts. If you do
not have permission, DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY creates and
deploys the design (if the deploy parameter is 'true'), but it cannot save the design and
deployment scripts.
Notes
l
SQLReference Manual
SQL Functions
Examples
The following example creates projections for and deploys the VMART_DESIGN design, and
analyzes statistics about the design tables. If an error occurs during execution, DESIGNER_RUN_
POPULATE_DESIGN_AND_DEPLOY terminates.
=> SELECT DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY (
'VMART_DESIGN',
'/tmp/examples/vmart_design_files/vmart_design_DDL',
'/tmp/examples/vmart_design_files/vmart_design_deployment_scripts',
'true',
'false',
'false',
'false'
);
DESIGNER_SET_ANALYZE_CORRELATIONS_MODE
Specifies how Database Designer should handle column correlations in a design. Depending on
what mode you set, Database Designer analyzes or reanalyzes existing column correlations and
considers them when creating a database design.
Behavior Type
Immutable
Syntax
DESIGNER_SET_ANALYZE_CORRELATIONS_MODE (
'design_name',
analyze_correlations_mode )
SQLReference Manual
SQL Functions
Parameters
design_name
analyze_correlations_mode
Permissions
l
SQLReference Manual
SQL Functions
Notes
l
HP Vertica recommends that you analyze correlations when the row count is at least
DBDCorrelationSampleRowCount, which defaults to 4000.
Setting the correlation analysis mode does not have any affect on whether or not Database
Designer analyzes statistics when creating a design.
Example
The following example specifies that Database Designer analyze all correlated columns and
consider them when creating a design:
=> SELECT DESIGNER_SET_ANALYZE_CORRELATIONS_MODE (
'VMART_DESIGN',
'3);
DESIGNER_SET_ANALYZE_CORRELATIONS_MODE
---------------------------------------3
(1 row)
See Also
l
ANALYZE_CORRELATIONS
DESIGNER_SET_DESIGN_KSAFETY
Sets the K-safety value for a comprehensive design and stores the K-safety value in the DESIGNS
table.
Behavior Type
Immutable
SQLReference Manual
SQL Functions
Syntax
DESIGNER_SET_DESIGN_KSAFETY (
'design_name'
[, ksafety_level ]
)
Parameters
design_name
Name of the design for which you want to set the K-safety value, type
VARCHAR.
ksafety_level
Value of K-safety that you want for the specified design, type INTEGER. The
value must be a valid K-safety value for your cluster. For example, if you have a
three- or four-node cluster, you cannot set the K-safety to 2.
If you do not set the design K-safety using this function, the defaults are:
l
If you are a DBDUSER, the system K-safety value is unchanged after creating
your design.
If you are a DBADMINuser and you set the design K-safety to a value:
l
Lower than the system K-safety, the system K-safety changes to the lower
value after Database Designer deploys the design.
Higher than the system K-safety, Database Designer creates the correct
number of buddy projections for the specified value. If you create the design
on all tables in the database, or all the tables in your database have the right
number of buddy projections, Database Designer changes the system Ksafety to that value if its valid on your cluster.
If you are not creating a design on all tables in the database and some of the
tables do not have enough buddy projections, Database Designer gives a
warning that the system K-safety cannot change and recommends which
tables need buddy projections in order to raise the K -safety value.
SQLReference Manual
SQL Functions
Permissions
To run DESIGNER_SET_DESIGN_KSAFETY, you must be a superuser, or a user granted the
DBDUSER role who created the design.
Notes
l
You cannot change the K-safety value of an incremental design. Incremental designs assume
the K-safety value of the database.
Examples
The following examples set the K-safety level for the VMART_DESIGN design:
=> SELECT DESIGNER_SET_DESIGN_KSAFETY('VMART_DESIGN', 1);
=> SELECT DESIGNER_SET_DESIGN_KSAFETY('VMART_DESIGN', 2);
See Also
l
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
DESIGNER_SET_DESIGN_TYPE
DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS
DESIGNER_SET_DESIGN_TYPE
Specifies whether Database Designer should create an initial or replacement design (the
COMPREHENSIVE option) or make incremental changes to the existing design using the design
queries you loaded into the design (the INCREMENTAL option). DESIGNER_SET_DESIGN_TYPE
stores the design mode in the DESIGNS table.
If you do not specify a design mode, Database Designer creates a comprehensive design.
Behavior Type
Immutable
Syntax
DESIGNER_SET_DESIGN_TYPE ( 'design_name', 'mode_name' )
SQLReference Manual
SQL Functions
Parameters
design_name
Name of the design for which you want to specify the design mode, type
VARCHAR.
mode_name
Name of the mode that Database Designer should use when designing the
database, type VARCHAR. Valid values are:
l
'COMPREHENSIVE'
'INCREMENTAL'
Permissions
You must be a superuser, or a user assigned the DBDUSER role, to run DESIGNER_SET_
DESIGN_TYPE.
Notes
Incremental designs always inherit the K-safety value of the database.
Examples
The following examples show the two design mode options for the VMART_DESIGN design:
=> SELECT DESIGNER_SET_DESIGN_TYPE(
'VMART_DESIGN',
'COMPREHENSIVE');
DESIGNER_SET_DESIGN_TYPE
-------------------------0
(1 row)
=> SELECT DESIGNER_SET_DESIGN_TYPE(
'VMART_DESIGN',
'INCREMENTAL');
DESIGNER_SET_DESIGN_TYPE
-------------------------0
(1 row)
SQLReference Manual
SQL Functions
See Also
l
DESIGNER_SET_DESIGN_KSAFETY
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
Designates what optimization objective Database Designer should use when optimizing your
database design:
l
QUERYOptimize for query performance, so that the queries run faster. This can result in a larger
database storage footprint because additional projections might be created.
LOADOptimize for load performance, so that the size of the database is minimized. This can
result in slower query performance.
Behavior Type
Immutable
Syntax
DESIGNER_SET_OPTIMIZATION_OBJECTIVE ( 'design_name', 'policy_name' )
Parameters
design_name
Name of the design for which you want to specify the optimization policy, type
VARCHAR.
SQLReference Manual
SQL Functions
policy_name
Name of the optimization policy for Database Designer to use when designing the
database, type VARCHAR. Valid values are:
l
'QUERY'
'LOAD'
'BALANCED'
Permissions
To run DESIGNER_SET_OPTIMIZATION_OBJECTIVE, you must be a superuser, or a user
granted the DBDUSER role who created the design.
Notes
The optimization only applies to a comprehensive design; Database Designer ignores this value for
incremental designs.
Examples
The following examples show the three optimization objective options for the VMART_DESIGN
design:
=> SELECT DESIGNER_SET_OPTIMIZATION_OBJECTIVE(
'VMART_DESIGN', 'LOAD');
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
----------------------------------0
(1 row)
=> SELECT DESIGNER_SET_OPTIMIZATION_OBJECTIVE(
'VMART_DESIGN', 'QUERY');
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
-----------------------------------0
(1 row)
=> SELECT DESIGNER_SET_OPTIMIZATION_OBJECTIVE(
'VMART_DESIGN', 'BALANCED');
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
-----------------------------------0
(1 row)
SQLReference Manual
SQL Functions
See Also
l
DESIGNER_SET_DESIGN_KSAFETY
DESIGNER_SET_DESIGN_TYPE
DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS
DESIGNER_SET_PROPOSE_UNSEGMENTED_
PROJECTIONS
Specifies that Database Designer can propose unsegmented projections for all design tables and
stores the setting in the DESIGNS table.
Segmentation splits individual projections into chunks of data of similar size, called segments. One
segment is created for and stored on each node. Projection segmentation provides high availability
and recovery, and optimizes query execution. For more information about segmentation, see
Projection Segmentation.
Behavior Type
Immutable
Syntax
DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS ( 'design_name', unsegmented )
Parameters
design_name
Name of the design for which you want segmented projections, type VARCHAR.
unsegmented
Permissions
To run DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS, you must be a superuser, or a user
granted the DBDUSER role who created the design.
SQLReference Manual
SQL Functions
Notes
DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS has no affect on one-node clusters; all
projections will be unsegmented.
Example
The following example specifies that Database Designer propose a database design where all
projections are segmented:
=> SELECT DESIGNER_SET_PROPOSE_UNSEGMENTED_PROJECTIONS(
'VMART_DESIGN', 'false');
See Also
l
DESIGNER_SET_DESIGN_KSAFETY
DESIGNER_SET_DESIGN_TYPE
DESIGNER_SET_OPTIMIZATION_OBJECTIVE
DESIGNER_WAIT_FOR_DESIGN
Waits for a currently running design to complete. DESIGNER_WAIT_FOR_DESIGN waits for
operations that are populating and deploying the design.
Behavior Type
Immutable
Syntax
DESIGNER_WAIT_FOR_DESIGN ( 'design_name' )
Parameters
design_name
Name of the currently running design that you want to complete, type VARCHAR.
SQLReference Manual
SQL Functions
Permissions
To run DESIGNER_WAIT_FOR_DESIGN on a currently running design, you must be a superuser,
or a user granted the DBDUSER role with USAGE privilege on the design schema.
Notes
If DESIGNER_WAIT_FOR_DESIGN is running in the foreground and still waiting, you can enter
Ctrl+C to stop DESIGNER_WAIT_FOR_DESIGN and return control to the user.
Examples
The following example requests to wait for the currently running design of VMART_DESIGN to
complete:
=> SELECT DESIGNER_WAIT_FOR_DESIGN ('VMART_DESIGN');
See Also
l
DESIGNER_CANCEL_POPULATE_DESIGN
DESIGNER_DROP_ALL_DESIGNS
DESIGNER_DROP_DESIGN
SQLReference Manual
SQL Functions
CLEAR_RESOURCE_REJECTIONS
Clears the content of the RESOURCE_REJECTIONS and DISK_RESOURCE_REJECTIONS
system tables. Normally, these tables are only cleared during a node restart. This function lets you
clear the tables whenever you need. For example, you might want to clear the system tables after
you resolved a disk space issue that was causing disk resource rejections.
Syntax
CLEAR_RESOURCE_REJECTIONS();
Privileges
Must be a superuser.
Example
The following command clears the content of the RESOURCE_REJECTIONS and DISK_
RESOURCE_REJECTIONS system tables:
=> SELECT clear_resource_rejections();
clear_resource_rejections
--------------------------OK
(1 row)
See Also
l
DISK_RESOURCE_REJECTIONS
RESOURCE_REJECTIONS
DUMP_LOCKTABLE
Returns information about deadlocked clients and the resources they are waiting for.
SQLReference Manual
SQL Functions
Syntax
DUMP_LOCKTABLE()
Privileges
None
Notes
Use DUMP_LOCKTABLE if HP Vertica becomes unresponsive:
1. Open an additional vsql connection.
2. Execute the query:
=> SELECT DUMP_LOCKTABLE();
You get the session_id value from the V_MONITOR.SESSIONS system table.
See Also
l
CLOSE_ALL_SESSIONS
CLOSE_SESSION
SQLReference Manual
SQL Functions
LOCKS
SESSIONS
DUMP_PARTITION_KEYS
Dumps the partition keys of all projections in the system.
Syntax
DUMP_PARTITION_KEYS( )
Note: The ROS objects of partitioned tables without partition keys are ignored by the tuple
mover and are not merged during automatic tuple mover operations.
Privileges
None; however function dumps only the tables for which user has SELECT privileges.
Example
=> SELECT DUMP_PARTITION_KEYS( );
Partition keys on node v_vmart_node0001
Projection 'states_b0'
Storage [ROS container]
No of partition keys: 1
Partition keys: NH
Storage [ROS container]
No of partition keys: 1
Partition keys: MA
Projection 'states_b1'
Storage [ROS container]
No of partition keys: 1
Partition keys: VT
Storage [ROS container]
No of partition keys: 1
Partition keys: ME
Storage [ROS container]
No of partition keys: 1
Partition keys: CT
SQLReference Manual
SQL Functions
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
PARTITIONS
EXPORT_TABLES
Generates a SQL script that can be used to recreate a logical schema (schemas, tables,
constraints, and views) on a different cluster.
Syntax
EXPORT_TABLES ( [ 'destination' ] , [ 'scope' ] )
Parameters
destination
Specifies the path and name of the SQL output file. An empty string (''), which is
the default, outputs the script to standard output. The function writes the script to
the catalog directory if no destination is specified.
If you specify a file that does not exist, the function creates one. If the file preexists, the function silently overwrites its contents.
SQLReference Manual
SQL Functions
scope
An empty string (' ')exports all non-virtual table objects to which the user has
access, including table schemas, sequences, and constraints. Exporting all
non-virtual objects is the default scope, and what the function exports if you do
not specify a scope.
Privileges
None; however:
l
Example
The following example exports the store_orders_fact table of the store schema (in the current
database) to standard output:
=> SELECT EXPORT_TABLES(' ','store.store_orders_fact');
SQLReference Manual
SQL Functions
See Also
EXPORT_CATALOG
EXPORT_OBJECTS
l
l
HAS_ROLE
Indicates, with a Boolean value, whether a role has been assigned to a user. This function is useful
for letting you check your own role membership.
Behavior Type
Stable
Syntax 1
HAS_ROLE( [ 'user_name' ,] 'role_name' );
Syntax 2
HAS_ROLE( 'role_name' );
Parameters
user_name
[Optional] The name of a user to look up. Currently, only a superuser can supply the
user_name argument.
role_name
The name of the role you want to verify has been granted.
Privileges
Users can check their own role membership by calling HAS_ROLE('role_name'), but only a
superuser can look up other users' memberships using the optional user_name parameter.
SQLReference Manual
SQL Functions
Notes
You can query V_CATALOG system tables ROLES, GRANTS, and USERS to show any directlyassigned roles; however, these tables do not indicate whether a role is available to a user when
roles may be available through other roles (indirectly).
Examples
User Bob wants to see if he has been granted the commentor role:
=> SELECT HAS_ROLE('commentor');
Output t for true indicates that Bob has been assigned the commentor role:
HAS_ROLE
---------t
(1 row)
In the following function call, a superuser checks if the logadmin role has been granted to user Bob:
=> SELECT HAS_ROLE('Bob', 'logadmin');
HAS_ROLE
---------t
(1 row)
To view the names of all roles users can access, along with any roles that have been assigned to
those roles, query the V_CATALOG.ROLES system table. An asterisk in the output means role
granted WITH ADMIN OPTION.
=> SELECT * FROM roles;
role_id
|
name
| assigned_roles
-------------------+-----------------+---------------45035996273704964 | public
|
45035996273704966 | dbduser
|
45035996273704968 | dbadmin
| dbduser*
45035996273704972 | pseudosuperuser | dbadmin*
45035996273704974 | logreader
|
45035996273704976 | logwriter
|
45035996273704978 | logadmin
| logreader,
logwriter
(7 rows)
SQLReference Manual
SQL Functions
See Also
l
GRANTS
ROLES
USERS
SET_CONFIG_PARAMETER
Important: Hewlett-Packard now encourages the use of the SET and CLEAR parameters in
the ALTER NODE, ALTER DATABASE, and ALTERSESSION statements to set and clear
configuration parameters. See Setting and Clearing Configuration Parameters for more
information.
Use SET_CONFIG_PARAMETER to specify the value of a configuration parameter. Because HP
Vertica is designed to operate with minimal configuration changes, use this capability sparingly.
Carefully follow any documented guidelines for the parameter you want to configure. If using 7.1, do
not manually edit any vertica.conf files. Additionally, do not use any workarounds to sync
vertica.conf files.
Syntax
SET_CONFIG_PARAMETER( 'parameter', value, ['node_name'])
Parameters
parameter
Specifies the name of the parameter value to set. See Configuration Parameters in
the Administrator's Guide for a list of supported parameters, their purposes, and
usage examples.
value
Specifies the value of the supplied parameter argument. Syntax for this argument
varies depending upon the parameter and its expected data type. For strings, enclose
the argument in single quotes; integer arguments can be unquoted.
If value is specified as NULL, the parameter is cleared at that level.
SQLReference Manual
SQL Functions
node_name
[Optional] Specifies the name of the node whose parameter value you want to set.
If no node is provided, or the node name is specified as NULL, the value is set at the
database level. Nodes that already have a value set for that particular parameter
retain their set value.
Note: Some parameters require restart for the value to take effect.
Examples
The following examples show how to use SET_CONFIG_PARAMETER in various situations.
Set a Configuration Parameter at Database Level
Set the AnalyzeRowCountInterval parameter to 3600 at the database level:
=> SELECT SET_CONFIG_PARAMETER ('AnalyzeRowCountInterval',3600);
See Also
Setting and Clearing Configuration Parameters
CONFIGURATION_PARAMETERS
SHUTDOWN
Forces a database to shut down, even if there are users connected.
Syntax
SHUTDOWN ( [ 'false' | 'true' ] )
SQLReference Manual
SQL Functions
Parameters
false
[Default] Returns a message if users are connected. Has the same effect as supplying
no parameters.
true
Performs a moveout operation and forces the database to shut down, disallowing further
connections.
Privileges
Must be a superuser.
Notes
l
Issuing the shutdown command without arguments or with the default (false) argument returns a
message if users are connected, and the shutdown fails. If no users are connected, the
database performs a moveout operation and shuts down.
Issuing the SHUTDOWN('true') command forces the database to shut down whether users are
connected or not.
You can check the status of the shutdown operation in the vertica.log file:
2010-03-09 16:51:52.625 unknown:0x7fc6d6d2e700
[Init] <INFO> Shutdown complete. Exiting.
Examples
The following command attempts to shut down the database. Because users are connected, the
command fails:
=> SELECT SHUTDOWN('false');
NOTICE: Cannot shut down while users are connected
SHUTDOWN
SQLReference Manual
SQL Functions
Using the 'true' parameter forces the database to shut down, even though clients might be
connected:
=> SELECT SHUTDOWN('true');
SHUTDOWN
---------------------------Shutdown: moveout complete
(1 row)
See Also
l
SESSIONS
SQLReference Manual
SQL Functions
ADVANCE_EPOCH
Manually closes the current epoch and begins a new epoch.
Syntax
ADVANCE_EPOCH ( [ integer ] )
Parameters
integer
Privileges
Must be a superuser.
Notes
This function is primarily maintained for backward compatibility with earlier versions of HP Vertica.
Example
The following command increments the epoch number by 1:
=> SELECT ADVANCE_EPOCH(1);
See Also
l
GET_AHM_EPOCH
Returns the number of the epoch in which the Ancient History Mark is located. Data deleted up to
and including the AHM epoch can be purged from physical storage.
SQLReference Manual
SQL Functions
Syntax
GET_AHM_EPOCH()
Privileges
None
Examples
SELECT GET_AHM_EPOCH();
GET_AHM_EPOCH
---------------------Current AHM epoch: 0
(1 row)
GET_AHM_TIME
Returns a TIMESTAMP value representing the Ancient History Mark. Data deleted up to and
including the AHM epoch can be purged from physical storage.
Syntax
GET_AHM_TIME()
Privileges
None
Examples
SELECT GET_AHM_TIME();
GET_AHM_TIME
------------------------------------------------Current AHM Time: 2010-05-13 12:48:10.532332-04
(1 row)
SQLReference Manual
SQL Functions
See Also
l
SET DATESTYLE
TIMESTAMP
GET_CURRENT_EPOCH
The epoch into which data (COPY, INSERT, UPDATE, and DELETE operations) is currently being
written.
Returns the number of the current epoch.
Syntax
GET_CURRENT_EPOCH()
Privileges
None
Examples
SELECT GET_CURRENT_EPOCH();
GET_CURRENT_EPOCH
------------------683
(1 row)
GET_LAST_GOOD_EPOCH
A term used in manual recovery, LGE (Last Good Epoch) refers to the most recent epoch that can
be recovered.
Returns the number of the last good epoch.
Syntax
GET_LAST_GOOD_EPOCH()
SQLReference Manual
SQL Functions
Privileges
None
Examples
SELECT GET_LAST_GOOD_EPOCH();
GET_LAST_GOOD_EPOCH
--------------------682
(1 row)
MAKE_AHM_NOW
Sets the Ancient History Mark (AHM) to the greatest allowable value, and lets you drop any
projections that existed before the issue occurred.
Caution: This function is intended for use by Administrators only.
Syntax
MAKE_AHM_NOW ( [ true ] )
Parameters
true
[Optional] Allows AHM to advance when nodes are down. Note: If the AHM is advanced
after the last good epoch of the failed nodes, those nodes must recover all data from
scratch. Use with care.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
l
Sets the AHM to LGE at least to the current epoch at the time MAKE_AHM_NOW() was
issued.
All history is lost and you cannot perform historical queries prior to the current epoch.
Example
=> SELECT MAKE_AHM_NOW();
MAKE_AHM_NOW
-----------------------------AHM set (New AHM Epoch: 683)
(1 row)
The following command allows the AHM to advance, even though node 2 is down:
=> SELECT
WARNING:
WARNING:
WARNING:
MAKE_AHM_NOW(true);
Received no response from v_vmartdb_node0002 in get cluster LGE
Received no response from v_vmartdb_node0002 in get cluster LGE
Received no response from v_vmartdb_node0002 in set AHM
MAKE_AHM_NOW
-----------------------------AHM set (New AHM Epoch: 684)
(1 row)
See Also
l
DROP PROJECTION
MARK_DESIGN_KSAFE
SET_AHM_EPOCH
SET_AHM_TIME
SQLReference Manual
SQL Functions
SET_AHM_EPOCH
Sets the Ancient History Mark (AHM) to the specified epoch. This function allows deleted data up
to and including the AHM epoch to be purged from physical storage.
SET_AHM_EPOCH is normally used for testing purposes. Consider SET_AHM_TIME instead,
which is easier to use.
Syntax
SET_AHM_EPOCH ( epoch, [ true ] )
Parameters
epoch
true
Privileges
Must be a superuser.
Notes
If you use SET_AHM_EPOCH , the number of the specified epoch must be:
l
Less than or equal to the cluster last good epoch (the minimum of the last good epochs of the
individual nodes in the cluster)
SQLReference Manual
SQL Functions
Less than or equal to the cluster refresh epoch (the minimum of the refresh epochs of the
individual nodes in the cluster)
Use the SYSTEM table to see current values of various epochs related to the AHM; for example:
=> SELECT * from SYSTEM;
-[ RECORD 1 ]------------+--------------------------current_timestamp
| 2009-08-11 17:09:54.651413
current_epoch
| 1512
ahm_epoch
| 961
last_good_epoch
| 1510
refresh_epoch
| -1
designed_fault_tolerance | 1
node_count
| 4
node_down_count
| 0
current_fault_tolerance | 1
catalog_revision_number | 1590
wos_used_bytes
| 0
wos_row_count
| 0
ros_used_bytes
| 41490783
ros_row_count
| 1298104
total_used_bytes
| 41490783
total_row_count
| 1298104
All nodes must be up. You cannot use SET_AHM_EPOCH when any node in the cluster is down,
except by using the optional true parameter.
When a node is down and you issue SELECT MAKE_AHM_NOW(), the following error is printed to the
vertica.log:
Some nodes were excluded from setAHM. If their LGE is before the AHM they will perform
full recovery.
Examples
The following command sets the AHM to a specified epoch of 12:
=> SELECT SET_AHM_EPOCH(12);
The following command sets the AHM to a specified epoch of 2 and allows the AHM to advance
despite a failed node:
=> SELECT SET_AHM_EPOCH(2, true);
SQLReference Manual
SQL Functions
See Also
l
MAKE_AHM_NOW
SET_AHM_TIME
SYSTEM
SET_AHM_TIME
Sets the Ancient History Mark (AHM) to the epoch corresponding to the specified time on the
initiator node. This function allows historical data up to and including the AHM epoch to be purged
from physical storage.
Syntax
SET_AHM_TIME ( time , [ true ] )
Parameters
time
true
Privileges
Must be a superuser.
Notes
l
SET_AHM_TIME returns a TIMESTAMP WITH TIME ZONE value representing the end point of
the AHM epoch.
You cannot change the AHM when any node in the cluster is down, except by using the optional
true parameter.
When a node is down and you issue SELECT MAKE_AHM_NOW(), the following error is printed to
the vertica.log:
SQLReference Manual
SQL Functions
Some nodes were excluded from setAHM. If their LGE is before the AHM they will perform
full recovery.
Examples
Epochs depend on a configured epoch advancement interval. If an epoch includes a three-minute
range of time, the purge operation is accurate only to within minus three minutes of the specified
timestamp:
=> SELECT SET_AHM_TIME('2008-02-27 18:13');
set_ahm_time
-----------------------------------AHM set to '2008-02-27 18:11:50-05'
(1 row)
Note: The 05 part of the output string is a time zone value, an offset in hours from UTC
(Universal Coordinated Time, traditionally known as Greenwich Mean Time, or GMT).
In the previous example, the actual AHM epoch ends at 18:11:50, roughly one minute before the
specified timestamp. This is because SET_AHM_TIME selects the epoch that ends at or before
the specified timestamp. It does not select the epoch that ends after the specified timestamp
because that would purge data deleted as much as three minutes after the AHM.
For example, using only hours and minutes, suppose that epoch 9000 runs from 08:50 to 11:50 and
epoch 9001 runs from 11:50 to 15:50. SET_AHM_TIME('11:51') chooses epoch 9000 because it
ends roughly one minute before the specified timestamp.
In the next example, if given an environment variable set as date =`date`; the following
command fails if a node is down:
=> SELECT SET_AHM_TIME('$date');
In order to force the AHM to advance, issue the following command instead:
=> SELECT SET_AHM_TIME('$date', true);
See Also
l
MAKE_AHM_NOW
SET_AHM_EPOCH
SQLReference Manual
SQL Functions
SET DATESTYLE
TIMESTAMP
BUILD_FLEXTABLE_VIEW
Creates, or recreates, a view for a default or user-defined _keys table, ignoring any empty keys.
Syntax
build_flextable_view('flex_table' [ [,'view_name'] [,'user_keys_table'] ])
Arguments
flex_table
view_name
user_keys_
table
SQLReference Manual
SQL Functions
Examples
Following are examples of calling build_flextable_view with 1, 2, or 3 arguments.
SQLReference Manual
SQL Functions
2. Alternatively, create a table based on the default keys table, but without content:
=> create table new_darkdata_keys as select * from darkdata_keys LIMIT 0;
CREATE TABLE
kdb=> select * from new_darkdata_keys;
key_name | frequency | data_type_guess
----------+-----------+----------------(0 rows)
3. Given an existing table (or creating one with no data), insert one or more keys:
=> create table dd_keys as select * from darkdata_keys limit 0;
CREATE TABLE
SQLReference Manual
SQL Functions
See Also
l
COMPUTE_FLEXTABLE_KEYS
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
MATERIALIZE_FLEXTABLE_COLUMNS
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
SQLReference Manual
SQL Functions
COMPUTE_FLEXTABLE_KEYS
Computes the virtual columns (keys and values) from the VMap data of a flex table and repopulates
the associated _keys table. The keys table has the following columns:
l
key_name
frequency
data_type_guess
Syntax
compute_flextable_keys('flex_table')
Arguments
flex_table The name of a flex table.
Examples
During execution, this function determines a data type for each virtual column, casting the values it
computes to VARCHAR, LONG VARCHAR, or LONG VARBINARY, depending on the length of the key, and
whether the key includes nested maps.
The following examples illustrate this function and the results of populating the _keys table, once
you've created a flex table (darkdata1) and loaded data:
=> create flex table darkdata1();
CREATE TABLE
=> copy darkdata1 from '/test/flextable/DATA/tweets_12.json' parser fjsonparser();
Rows Loaded
------------12
(1 row)
=> select compute_flextable_keys('darkdata1');
compute_flextable_keys
-------------------------------------------------Please see public.darkdata1_keys for updated keys
SQLReference Manual
SQL Functions
(1 row)
=> select * from darkdata1_keys;
key_name
| frequency |
data_type_guess
----------------------------------------------------------+-----------+--------------------contributors
|
8 | varchar(20)
coordinates
|
8 | varchar(20)
created_at
|
8 | varchar(60)
entities.hashtags
|
8 | long varbinary
(186)
entities.urls
|
8 | long varbinary
(32)
entities.user_mentions
|
8 | long varbinary
(674)
.
.
.
retweeted_status.user.time_zone
|
1 | varchar(20)
retweeted_status.user.url
|
1 | varchar(68)
retweeted_status.user.utc_offset
|
1 | varchar(20)
retweeted_status.user.verified
|
1 | varchar(20)
(125 rows)
Description
key_name
frequency The number of times the virtual column occurs in the map.
data_
type_
guess
The data type for each virtual column, cast to VARCHAR, LONG VARCHAR or LONG
VARBINARY, depending on the length of the key, and whether the key includes one or
more nested maps.
In the _keys table output, the data_type_guess column values are also followed by
a value in parentheses, such as varchar(20). The value indicates the padded
width of the key column, as calculated by the longest field, multiplied by the
FlexTableDataTypeGuessMultiplier configuration parameter value. For more
information, see Setting Flex Table Parameters.
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
SQLReference Manual
SQL Functions
MATERIALIZE_FLEXTABLE_COLUMNS
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
Combines the functionality of BUILD_FLEXTABLE_VIEW and COMPUTE_FLEXTABLE_KEYS
to compute virtual columns (keys) from the VMap data of a flex table, and construct a view.
Creating a view with this function ignores empty keys. If you don't need to perform both operations
together, use one of the single-operation functions.
Syntax
compute_flextable_keys_and_build_view('flex_table')
Arguments
flex_table The name of a flex table.
Examples
The following example calls the function for the darkdata flex table.
=> select compute_flextable_keys_and_build_view('darkdata');
compute_flextable_keys_and_build_view
----------------------------------------------------------------------Please see public.darkdata_keys for updated keys
The view public.darkdata_view is ready for querying
(1 row)
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS
MATERIALIZE_FLEXTABLE_COLUMNS
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
SQLReference Manual
SQL Functions
EMPTYMAP
Constructs a new VMap with one row, but without keys or data. Use this transform function to
populate a map without using a flex parser, either from SQL queries, or from map data present
elsewhere in the database.
Syntax
emptymap()
Arguments
None
Examples
To create an empty map:
=> select emptymap();
emptymap
-----------------------------------------------------------------\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
(1 row)
If you create an empty map from an existing flex table, the new map will have the same number of
rows as the table from which it was created. For example, creating an empty map from the
darkdata table, which has 12 rows of JSON data has the following result:
=> select emptymap() from darkdata;
emptymap
-----------------------------------------------------------------\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
\001\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000
(12 rows)
SQLReference Manual
SQL Functions
See Also
l
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPAGGREGATE
Returns a LONG VARBINARY VMap with keys and value pairs supplied from two VARCHAR input
columns of an existing columnar table. Using this function requires specifying an over() clause for
the source table. The examples here use the over (PARTITION BEST) clause.
Syntax
mapaggregate(source_column1, source_column2)
Arguments
source_column1
Table column with values to use as the keys of the key/value pair of the
returned VMap data.
source_column2
Table column with values to use as the values in the key/value pair of the
returned VMap data.
SQLReference Manual
SQL Functions
Examples
This example creates a columnar table btest, with two VARCHAR columns, named keys and
values, and adds three sets of values:
=> create table btest(keys varchar(10), values varchar(10));
CREATE TABLE
=> copy btest from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> one|1
>> two|2
>> three|3
>> \.
After populating the btest table, calling mapaggregate() return the raw_map data:
=>
The next example illustrates using MAPTOSTRING() with the returned raw_map from
mapaggregate() to see the values:
=> select maptostring(raw_map) from (select mapaggregate(keys, values) over(PARTITION
BEST) from btest) bit;
maptostring
---------------------------------------------{
"one": "1",
"three":
"3",
"two": "2"
}
(1 row)
See Also
l
EMPTYMAP
MAPCONTAINSKEY
SQLReference Manual
SQL Functions
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPCONTAINSKEY
Determines whether a VMap contains a virtual column (key). This scalar function returns true (t) if
the virtual column exists, or false (f) if it does not. Determining that a key exists before calling
maplookup()lets you distinguish between NULL returns, which that function uses for both a nonexistent key, and an existing key with a NULL value.
Syntax
mapcontainskey(VMap_data, 'virtual_column_name')
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex
table, data returned from a map function such as maplookup(), or other
database content.
virtual_column_name
SQLReference Manual
SQL Functions
Examples
This example uses maplookup() and the mapcontainskey() functions. Displaying the results
returned from both functions differentiates whether the empty fields that maplookup() returns
indicate a NULL value for the row (t), or no value (f):
=> select maplookup(__raw__, 'user.location'), mapcontainskey(__raw__, 'user.location')
from darkdata order by 1;
maplookup | mapcontainskey
-----------+---------------| t
| t
| t
| t
Chile
| t
Narnia
| t
Uptown.. | t
chicago
| t
| f
| f
| f
| f
(12 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
SQLReference Manual
SQL Functions
MAPVALUES
MAPVERSION
MAPCONTAINSVALUE
Determines whether a VMap contains a specific value. Use this scalar function to return true (t) if
the value exists, or false (f) if it does not.
Syntax
mapcontainsvalue(VMap_data, 'virtual_column_value')
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex
table, data returned from a map function such as maplookup(), or
other database content.
virtual_column_value
Examples
This example shows a flex table (ftest), populated with some virtual columns and values. Both
virtual columns are named one:
=> create flex table ftest();
CREATE TABLE
=> copy ftest from stdin parser fjsonparser();
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> {"one":1, "two":2}
>> {"one":"one","2":"2"}
>> \.
Calling mapcontainsvalue() on the ftest map data returns false (f) for the first virtual column,
and true (t) for the second , which contains the value one:
=> select mapcontainsvalue(__raw__, 'one') from ftest;
mapcontainsvalue
-----------------f
t
SQLReference Manual
SQL Functions
(2 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPDELIMITEDEXTRACTOR
Extracts data with a delimiter character, and other optional arguments, returning a single VMap
value. The USING PARAMETERS phrase specifies optional parameters for the function.
Parameters
delimiter
VARCHAR
header
VARCHAR
SQLReference Manual
SQL Functions
trim
BOOLEAN
treat_empty_
val_as_null
BOOLEAN
Examples
For this set of examples, we are using a short set of delimited data to load into a table with
mapdelimitedextractor:
Name|CITY|New city|State|zip
Tom|BOSTON|boston|MA|01
Eric|Burlington|BURLINGTON|MA|02
Jamie|cambridge|CAMBRIDGE|MA|08
2. Use COPY to load the delim.dat file. Use the flex tables fdelimitedparser with the
header='false' option:
=> copy dflex from '/home/release/kmm/flextables/delim.dat' parser fdelimitedparser
(header='false');
Rows Loaded
------------4
(1 row)
3. Create a columnar table, dtab, with an identity id column, a delim column, and a column to
hold a VMap, called vmap:
=> create table dtab (id IDENTITY(1,1), delim varchar(128), vmap long varbinary(512));
CREATE TABLE
SQLReference Manual
SQL Functions
4. Use COPY to load the delim.dat file into the dtab table, using the mapdelimitedextractor
function, specifying delimiter '!' in this example:
=> copy dtab(delim, vmap as mapdelimitedextractor(delim)) from
'/home/release/kmm/flextables/delim.dat'
delimiter '!';
Rows Loaded
------------4
(1 row)
5. Use the maptostring function for the flex table dflex to view the __raw__ column contents as
strings:
=> select maptostring(__raw__) from dflex limit 10;
maptostring
------------------------------------------------------------------------------------{
"ucol0" : "Jamie",
"ucol1" : "cambridge",
"ucol2" : "CAMBRIDGE",
"ucol3" : "MA",
"ucol4" : "08"
}
{
"ucol0"
"ucol1"
"ucol2"
"ucol3"
"ucol4"
:
:
:
:
:
"Name",
"CITY",
"New city",
"State",
"zip"
"ucol0"
"ucol1"
"ucol2"
"ucol3"
"ucol4"
:
:
:
:
:
"Tom",
"BOSTON",
"boston",
"MA",
"01"
"ucol0"
"ucol1"
"ucol2"
"ucol3"
"ucol4"
:
:
:
:
:
"Eric",
"Burlington",
"BURLINGTON",
"MA",
"02"
}
{
}
{
}
(4 rows)
SQLReference Manual
SQL Functions
6. Use the maptostring function again, this time with the dtab table's vmap column. Compare
the results of this output, and that from the flex table:
=> select maptostring(vmap) from dtab limit 10;
maptostring
----------------------------------------------------------------------------------{
"ucol0" : "Tom",
"ucol1" : "BOSTON",
"ucol2" : "boston",
"ucol3" : "MA",
"ucol4" : "01"
}
{
"ucol0"
"ucol1"
"ucol2"
"ucol3"
"ucol4"
:
:
:
:
:
"Name",
"CITY",
"New city",
"State",
"zip"
"ucol0"
"ucol1"
"ucol2"
"ucol3"
"ucol4"
:
:
:
:
:
"Eric",
"Burlington",
"BURLINGTON",
"MA",
"02"
"ucol0"
"ucol1"
"ucol2"
"ucol3"
"ucol4"
:
:
:
:
:
"Jamie",
"cambridge",
"CAMBRIDGE",
"MA",
"08"
}
{
}
{
}
(4 rows)
See Also
l
MAPJSONEXTRACTOR
MAPREGEXEXTRACTOR
MAPITEMS
Returns information about items in a VMap. Use this transform function with one or more optional
arguments to access polystructured values within the VMap data. This function requires an over()
clause. The examples here use over(PARTITION BEST).
SQLReference Manual
SQL Functions
Syntax
mapItems(VMap_data [, passthrough_arg [,...] ])
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table,
data returned from a map function such as maplookup(), or other database
content.
passthrough_ [Optional] One or more arguments indicating keys within the map data in VMap_
arg
data.
Examples
This example uses a flex table darkmountain, populated with JSON data. This query uses the
count() function to return the number of virtual columns found in the map data:
=> select count(keys) from (select mapitems(darkmountain.__raw__) over(PARTITION BEST)
from darkmountain) as a;
count
------19
(1 row)
This example shows a snippet of the return data querying a flex table of all items in the map data:
=> select * from (select mapitems(darkmountain.__raw__) over(PARTITION BEST) from
darkmountain) as a;
keys
|
values
-------------+--------------hike_safety | 50.6
name
| Mt Washington
type
| mountain
height
| 17000
hike_safety | 12.2
name
| Denali
type
| mountain
height
| 29029
hike_safety | 34.1
name
| Everest
type
| mountain
height
| 14000
hike_safety | 22.8
name
| Kilimanjaro
type
| mountain
height
| 29029
SQLReference Manual
SQL Functions
hike_safety | 15.4
name
| Mt St Helens
type
| volcano
(19 rows)
SQLReference Manual
SQL Functions
3. Call mapkeys on the flex table's __raw__ column to see the flex table's keys, but not their
submaps. The return values indicate three_Array as one of the virtual columns:
=> select mapkeys(__raw__) over() from mapper;
keys
------------five_Map
four
one
six
three_Array
two
(6 rows)
4. Call mapitems on flex table mapper with three_Array as a pass-through argument to the
function to return the array values:
=> select __identity__, mapitems(three_Array) OVER(PARTITION BY __identity__) from
mapper;
__identity__ | keys |
values
--------------+------+-----------1 | 0
| three_One
1 | 1
| three_Two
1 | 2
| 3
1 | 3
| three_Four
(4 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
SQLReference Manual
SQL Functions
MAPVALUES
MAPVERSION
MAPJSONEXTRACTOR
Extracts content of repeated JSON data objects, including nested maps, or data with an outer list of
JSON elements. The USING PARAMETERS phrase specifies optional parameters for the function.
Empty input does not generate a Warning or Error.
Note: The maximum size of each JSONkey within a __raw__ column is 255 bytes. Loading
JSONdata with keys longer than 255 bytes is unsupported.
Parameters
flatten_maps
BOOLEAN
flatten_
arrays
BOOLEAN
reject_on_
duplicate
BOOLEAN
reject_on_
empty_key
BOOLEAN
omit_empty_
keys
BOOLEAN
[Optional] Omits any key from the load data that does not
have a value (omit_empty_keys=true).
Default value: false
SQLReference Manual
SQL Functions
start_point
CHAR
Examples
These examples use the following sample JSONdata:
{
{
{
{
{
"id":
"id":
"id":
"id":
"id":
"5001",
"5002",
"5005",
"5007",
"5004",
"type":
"type":
"type":
"type":
"type":
"None" }
"Glazed" }
"Sugar" }
"Powdered Sugar" }
"Maple" }
2. Use COPY to load the bake_single.json file with the flex tables fjsonparser parser:
=> copy flexjson from '/home/dbadmin/data/bake_single.json' parser fjsonparser();
Rows Loaded
------------5
(1 row)
3. Create a columnar table, coljson, with an identity id column, a json column, and a column to
hold a VMap, called vmap:
=> create table coljson(id IDENTITY(1,1), json varchar(128), vmap long varbinary
(10000));
CREATE TABLE
4. Use COPY to load the bake_single.json file into the coljson table, using the
mapjsonextractor function:
SQLReference Manual
SQL Functions
5. Use the maptostring function for the flex table flexjson to output the __raw__ column
contents as strings:
=> select maptostring(__raw__) from flexjson limit 5;
maptostring
----------------------------------------------------{
"id" : "5001",
"type" : "None"
}
{
"id" : "5002",
"type" : "Glazed"
}
{
"id" : "5005",
"type" : "Sugar"
}
{
"id" : "5007",
"type" : "Powdered Sugar"
}
{
"id" : "5004",
"type" : "Maple"
}
(5 rows)
6. Use the maptostring function again, this time with the coljson table's vmap column and
compare the results. The element order differs:
=> select maptostring(vmap) from coljson limit 5;
maptostring
----------------------------------------------------{
"id" : "5001",
"type" : "None"
}
{
SQLReference Manual
SQL Functions
"id" : "5002",
"type" : "Glazed"
}
{
"id" : "5004",
"type" : "Maple"
}
{
"id" : "5005",
"type" : "Sugar"
}
{
"id" : "5007",
"type" : "Powdered Sugar"
}
(5 rows)
See Also
l
MAPDELIMITEDEXTRACTOR
MAPREGEXEXTRACTOR
MAPKEYS
Returns the virtual columns (and values) present in any VMap data. This transform function
requires an over(PARTITION BEST) clause, as shown in the example.
Syntax
mapkeys(VMap_data)
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table, data
returned from a map function such as maplookup(), or other database content.
Examples
This example uses a flex table darkdata, populated with JSON tweet data. This query returns the
number of virtual columns found in the map data:
SQLReference Manual
SQL Functions
This example shows a snippet of the return data querying an ordered list of all virtual columns in the
map data:
=> select * from (SELECT mapkeys(darkdata.__raw__) over(PARTITION BEST) from darkdata) as
a;
keys
------------------------------------contributors
coordinates
created_ at
delete.status.id
delete.status.id_str
delete.status.user_id
delete.status.user_id_str
entities.hashtags
entities.media
entities.urls
entities.user_mentions
favorited
geo
id
.
.
.
user.statuses_count
user.time_zone
user.url
user.utc_offset
user.verified
(125 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
SQLReference Manual
SQL Functions
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPKEYSINFO
Returns virtual column information from a given map. This transform function requires an over
(PARTITION BEST)clause, as shown in the example.
Syntax
mapkeysinfo(VMap_data)
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table, data
returned from a map function such as maplookup(), or other database content.
Returns
This function is a superset of the MAPKEYS() function. It returns the following information about
each virtual column:
Column
Description
keys
length
The data length of the key name, which can differ from the actual string length.
type_oid
The OID type into which the value should be converted. Currently, the type is always
116 for a LONG VARCHAR, or 199 for a nested map, stored as a LONG VARBINARY.
row_num
field_num
SQLReference Manual
SQL Functions
Examples
This example shows a snippet of the return data querying an ordered list of all virtual columns in the
map data:
=> select * from (SELECT mapkeysinfo(darkdata.__raw__) over(PARTITION BEST) from
darkdata) as a;
keys
| length | type_oid | row_num |
field_num
----------------------------------------------------------+--------+----------+--------+----------contributors
|
0 |
116 |
1 |
0
coordinates
|
0 |
116 |
1 |
1
created_at
|
30 |
116 |
1 |
2
entities.hashtags
|
93 |
199 |
1 |
3
entities.media
|
772 |
199 |
1 |
4
entities.urls
|
16 |
199 |
1 |
5
entities.user_mentions
|
16 |
199 |
1 |
6
favorited
|
1 |
116 |
1 |
7
geo
|
0 |
116 |
1 |
8
id
|
18 |
116 |
1 |
9
id_str
|
18 |
116 |
1 |
10
.
.
.
delete.status.id
|
18 |
116 |
11 |
0
delete.status.id_str
|
18 |
116 |
11 |
1
delete.status.user_id
|
9 |
116 |
11 |
2
delete.status.user_id_str
|
9 |
116 |
11 |
3
delete.status.id
|
18 |
116 |
12 |
0
delete.status.id_str
|
18 |
116 |
12 |
1
delete.status.user_id
|
9 |
116 |
12 |
2
delete.status.user_id_str
|
9 |
116 |
12 |
3
(550 rows)
SQLReference Manual
SQL Functions
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPLOOKUP
Returns values associated with a single key. This scalar function returns a LONG VARCHAR with
virtual column values, or NULL if the virtual column does not exist. Column names are case
insensitive.
Before using maplookup, you can use these two functions to find out about your VMap data:
l
You can control the behavior for non-scalar values when loading data with the fjsonparser parser
and its flatten-arrays argument. See Loading JSONData and the FJSONPARSER reference.
Syntax
maplookup (VMap_data, 'virtual_column_name' [USING PARAMETERS [case_sensitive=
{false | true}] [, buffer_size=n] ] )
SQLReference Manual
SQL Functions
Any VMap data. The VMap can exist as the __raw__ column of
a flex table, data returned from a map function such as
maplookup(), or other database content.
virtual_column_name
buffer_size
case_sensitive
Examples
This example shows how to return the row values of one virtual column, user.location:
=> select maplookup(__raw__, 'user.location') from darkdata order by 1;
maplookup
----------Chile
Narnia
Uptown
.
.
chicago
(12 rows)
SQLReference Manual
SQL Functions
returned values for a key can be greater than n bytes, and you allocate n bytes as the buffer_size.
Consider this simple JSONdata, which for this example is saved into a file, simple_name.json:
{
"name": "sierra",
"age": "63",
"eyes": "brown",
"weapon": "doggie"
}
{
"name": "janis",
"age": "10",
"eyes": "blue",
"weapon": "humor"
}
{
"name": "ben",
"age": "43",
"eyes": "blue",
"weapon": "sword"
}
{
"name": "jen",
"age": "38",
"eyes": "green",
"weapon": "shopping"
}
4. Use maplookup with buffer_size=0 for the logs table name key. All of the values are
returned:
SQLReference Manual
SQL Functions
5. The example continues with buffer_size 3, 5, and 6. Now, maplookup() returns only values
with a byte length less than, or equal to (<=), the specified buffer_size:
=> SELECT MapLookup(__raw__, 'name' USING PARAMETERS buffer_size=3) FROM logs;
MapLookup
----------ben
jen
(4 rows)
=> SELECT MapLookup(__raw__, 'name' USING PARAMETERS buffer_size=5) FROM logs;
MapLookup
----------janis
jen
ben
(4 rows)
=> SELECT MapLookup(__raw__, 'name' USING PARAMETERS buffer_size=6) FROM logs;
MapLookup
----------sierra
janis
jen
ben
(4 rows)
SQLReference Manual
SQL Functions
For example, if you use maplookup without first checking the existence of a key, the following
output (12 empty rows) is ambiguous. Does a location key exist, exist with a NULL value in a row,
or exist without a value?
=> select maplookup(__raw__, 'user.location') from darkdata;
maplookup
-----------
(12 rows)
To disambiguate empty rows, use the mapcontainskey() function in conjunction with maplookup
(). When maplookup returns an empty field, the corresponding value from mapcontainskey
indicates t for a NULL value, or ffor no value.
The following vsql example output from both functions annotates rows without values in purple. The
example also shows location Narnia as a value in the user.location virtual column:
=> select maplookup(__raw__, 'user.location'), mapcontainskey(__raw__, 'user.location')
from darkdata order by 1;
maplookup | mapcontainskey
-----------+---------------| t
| t
| t
| t
Chile
| t
Narnia
| t
Uptown.. | t
chicago
| t
| f >>>>>>>>>>No value
| f >>>>>>>>>>No value
| f >>>>>>>>>>No value
| f >>>>>>>>>>No value
(12 rows)
SQLReference Manual
SQL Functions
The next example first uses maptostring() to return the map contents of the table bake, so you
can see the contents of the map data in the examples that follow:
=> select maptostring(__raw__) from bake;
maptostring
--------------------------------------------------------------------------------items.item :
0.batters.batter :
0.id : 2001
0.type : Regular
1.id : 2002
1.type : Chocolate
2.id : 2003
2.type : Blueberry
3.id : 2004
3.type : Devil's Food
0.id : 0002
0.name :
CupCake
0.ppu : 0.55
0.topping :
0.id : 6001
0.type : None
1.id : 6002
1.type : Glazed
2.id : 6005
2.type : Sugar
3.id : 6007
3.type : Powdered Sugar
4.id : 6006
4.type : Chocolate with Sprinkles
5.id : 6003
5.type : Chocolate
6.id : 6004
6.type : Maple
0.type :
Muffin
(1 row)
The next examples illustrate using several invocations of maplookup() to return values from the
map __raw__ column (after creating the table and loading data). Compare the returned results to the
maptostring() output in the previous example.
=> create flex table bake();
CREATE TABLE
kdb=> copy bake from '/vertica/test/flextable/DATA/bake.json' parser fjsonparser(flatten_
arrays=1,flatten_maps=0);
Rows Loaded
------------1
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.0'),'type') from bake;
maplookup
-----------
SQLReference Manual
SQL Functions
Regular
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.1'),'type') from bake;
maplookup
----------Chocolate
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.2'),'type') from bake;
maplookup
----------Blueberry
(1 row)
=> select maplookup(maplookup(maplookup(maplookup(maplookup(__raw_
_,'items'),'item.0'),'batters'),'batter.3'),'type') from bake;
maplookup
-------------Devil's Food
(1 row)
SQLReference Manual
SQL Functions
}
{
"TEst": "half4",
"test": "lower4",
"TEST": "upper4"
}
{
"TesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTestt
estTesttestTesttestTesttestTesttestTesttest":"1",
"TesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTesttestTestt
estTesttestTesttestTesttestTesttestTest12345":"2"
}
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPSIZE
MAPTOSTRING
SQLReference Manual
SQL Functions
MAPVALUES
MAPVERSION
MAPREGEXEXTRACTOR
Extracts data results from a regular expression and returns the resulting VMap. Use the USING
PARAMETERS phrase to specify the regular expression.
Parameters
pattern=
VARCHAR
use_jit
BOOLEAN
record_terminator
VARCHAR
logline_column
VARCHAR
Examples
These examples use the following regular expression to search an HP Vertica log file for
information that includes the timestamp, date, thread_name, and thread_id.Note that this
regular expression has embedded newlines for illustrative and display purposes. To use this
expression, first remove the newline characters.
^(?<time>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d+)(?<thread_name>[A-Za-z ]+):
(?<thread_id>0x[0-9a-f]+)-?(?<transaction_id>[0-9a-f]+)?(?:\[(?<component>\w+)\]
<(?<level>\w+)> )?(?<(?<elevel>\w+)> @\[?(?<enode>\w+)\]?: )?(?<text>.*)
SQLReference Manual
SQL Functions
2. Use COPY to load a sample log file, using the flex tables fregexparser with the
header='false' option. This example has embedded newline characters for display
purposes:
=> copy flogs from '/home/dbadmin/data/vertica.log' PARSER fregexparser(pattern=
'^(?<time>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d+) (?<thread_name>[A-Za-z ]+):
(?<thread_id>0x[0-9a-f]+)-?(?<transaction_id>[0-9a-f]+)?
(?:\[(?<component>\w+)\] <(?<level>\w+)> )?(?:<(?<elevel>\w+)>
@\[?(?<enode>\w+)\]?: )?(?<text>.*)');
Rows Loaded
------------8434
(1 row)
3. Select some of the elements from the regular expression that returned data in the flogs flex
table:
4. Create a columnar table
=> SELECT component, level, elevel, enode, text FROM flogs order by 1 limit 10;
component | level | elevel | enode |
text
-----------+-------+--------+-------+-------------------------------------------Catalog
| INFO |
|
| Checking for missed restore table events
Catalog
| INFO |
|
| Found no missed restore table events
Catalog
| INFO |
|
| Checking for missed alter partition events
Catalog
| INFO |
|
| Checking for missed replace node events
Catalog
| INFO |
|
| Checking for missed replace node events
Catalog
| INFO |
|
| Checking for missed replace node events
Catalog
| INFO |
|
| Checking for missed alter partition events
Catalog
| INFO |
|
| Checking for missed restore table events
Catalog
| INFO |
|
| Found no missed alter partition events
Catalog
| INFO |
|
| Found no missed replace node events
(10 rows)
See Also
l
MAPDELIMITEDEXTRACTOR
MAPJSONEXTRACTOR
SQLReference Manual
SQL Functions
MAPSIZE
Returns the number of virtual columns present in any VMap data. Use this scalar function to
determine the size of keys.
Syntax
mapsize(VMap_data)
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table, data
returned from a map function such as maplookup(), or other database content.
Examples
This example shows the returned sizes from the number of keys in the flex table darkmountain:
=> select mapsize(__raw__) from darkmountain;
mapsize
--------3
4
4
4
4
(5 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
SQLReference Manual
SQL Functions
MAPKEYSINFO
MAPLOOKUP
MAPTOSTRING
MAPVALUES
MAPVERSION
MAPTOSTRING
Recursively builds a string representation VMap data, including nested JSONmaps. Use this
transform function to display the VMap contents in a readable format. The function returns a LONG
VARCHAR. Use maptostring to see how map data is nested before querying virtual columns with
mapvalues().
Syntax
maptostring(VMap_data [using parameters canonical_json={true | false}])
Arguments
VMap_data
Any VMap data. The VMap can exist as the __raw__ column of a flex table,
data returned from a map function such as maplookup(), or other database
content.
Parameters
canonical_json
=bool
[Optional parameter] Default canonical-json=true
Produces canonical JSON output by default, using the first instance of any
duplicate keys in the map data.
Use this parameter as other UDFparameters, preceded by using
parameters, as shown in the examples. Setting this argument to false
maintains the previous behavior of maptostring(), and returns same-name
keys and their values.
SQLReference Manual
SQL Functions
Examples
The following example creates a sample flex table, darkdata. After loading sample JSON data
from STDIN, the example continues by calling maptostring() twice with both values for the
canonical_json parameter, illustrating the different results on the flex table __raw__column data.
1. Create sample table:
=> create flex table darkdata();
CREATE TABLE
3. Call maptostring() with its default behavior using canonical JSONoutput. Notice the flex
table contents. The function returns the first duplicate key and its value ("aaa": "1"), and
omits remaining duplicate keys ("aaa": "2"):
=> select maptostring (__raw__) from darkdata;
maptostring
-----------------------------------------------------------{
"AAA" : "3",
"aaa" : "1",
"bbb" : "aaa\"bbb"
}
(1 row)
"1",
"2",
"3",
"aaa"bbb"
SQLReference Manual
SQL Functions
}
(1 row)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPVALUES
MAPVERSION
MAPVALUES
Returns a string representation of the top-level values from a VMap. This transform function
requires an over() clause. The examples uses an over(PARTITION BEST) clause.
Syntax
mapvalues(VMap_data)
Arguments
VMap_data
The VMap from which values should be returned. The VMap can exist as the __raw_
_ column of a flex table, data returned from a map function such as maplookup(), or
other database content.
SQLReference Manual
SQL Functions
Examples
The following example uses mapvalues() with a darkmountain flex table, returning the values.
=> select * from (select mapvalues(darkmountain.__raw__) over(PARTITION BEST) from
darkmountain) as a;
values
--------------29029
34.1
Everest
mountain
29029
15.4
Mt St Helens
volcano
17000
12.2
Denali
mountain
14000
22.8
Kilimanjaro
mountain
50.6
Mt Washington
mountain
(19 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
SQLReference Manual
SQL Functions
MAPTOSTRING
MAPVERSION
MAPVERSION
Returns the version or invalidity of any map data. This scalar function returns the map version (such
as 1), or -1 if the map data is invalid.
Syntax
mapversion(VMap_data)
Arguments
VMap_data
The VMap data either from a __raw__ column in a flex table, or from the data returned
from a map function such as maplookup().
Examples
The following example uses mapversion() with the darkmountainflex table, returning mapversion
1 for the flex table map data:
=> select mapversion(__raw__) from darkmountain;
mapversion
-----------1
1
1
1
1
(5 rows)
See Also
l
EMPTYMAP
MAPAGGREGATE
MAPCONTAINSKEY
MAPCONTAINSVALUE
SQLReference Manual
SQL Functions
MAPITEMS
MAPKEYS
MAPKEYSINFO
MAPLOOKUP
MAPSIZE
MAPTOSTRING
MAPVALUES
MATERIALIZE_FLEXTABLE_COLUMNS
Materializes virtual columns listed as key_names in the flextable_keys table. You can optionally
indicate the number of columns to materialize, and use a keys table other than the default. If you do
not specify the number of columns, the function materializes up to 50 virtual column key names.
Calling this function requires that you first compute flex table keys using either COMPUTE_
FLEXTABLE_KEYS or COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
Note: Materializing any virtual column into a real column with this function affects data storage
limits. Each materialized column counts against the data storage limit of your HPVertica
Enterprise Edition (EE) license. This increase is reflected when HP Vertica next performs a
license compliance audit. To manually check your EElicense compliance, call the audit()
function, described in the SQL Reference Manual.
Syntax
materialize_flextable_columns('flex_table' [, n-columns [, keys_table_name] ])
Arguments
flex_table
The name of the flex table with columns to materialize. Specifying only
the flex table name attempts to materialize up to 50 columns of key
names in the default flex_table_keys table, skipping any columns
already materialized, and ignoring any empty keys. To materialize a
specific number of columns, use the optional parameter n_columns,
described next.
SQLReference Manual
SQL Functions
n-columns
keys_table_name
Examples
The following example loads a sample file of tweets (tweets_10000.json) into the flex table
twitter_r.
After loading data and computing keys for the sample flex table, the example calls materialize_
flextable_columns to materialize the first four columns:
=> copy twitter_r from '/home/release/KData/tweets_10000.json' parser fjsonparser();
Rows Loaded
------------10000
(1 row)
=> select compute_flextable_keys ('twitter_r');
compute_flextable_keys
--------------------------------------------------Please see public.twitter_r_keys for updated keys
(1 row)
=> select materialize_flextable_columns('twitter_r', 4);
materialize_flextable_columns
------------------------------------------------------------------------------The following columns were added to the table public.twitter_r:
contributors
entities.hashtags
entities.urls
For more details, run the following query:
SELECT * FROM v_catalog.materialize_flextable_columns_results WHERE table_schema =
'public' and table_name = 'twitter_r';
(1 row)
SQLReference Manual
SQL Functions
45035996273733172 | public
| twitter_r | 2013-11-20 17:00:27.945532-05
| created_at
| EXISTS | Column of same name already exists in table definition
(4 rows)
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW
RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_
VIEW
Restores the _keys table and the _view, linking them with their associated flex table if either is
dropped. This function notes whether it restores one or both.
Syntax
restore_flextable_default_keys_table_and_view('flex_table')
SQLReference Manual
SQL Functions
Arguments
flex_table The name of a flex table .
Examples
This example invokes the function with an existing flex table, restoring both the _keys table and _
view:
=> select restore_flextable_default_keys_table_and_view('darkdata');
restore_flextable_default_keys_table_and_view
---------------------------------------------------------------------------------The keys table public.darkdata_keys was restored successfully.
The view public.darkdata_view was restored successfully.
(1 row)
This example shows the function restoring darkdata_view, but noting that darkdata_keys does
not need restoring:
=> select restore_flextable_default_keys_table_and_view('darkdata');
restore_flextable_default_keys_table_and_view
-----------------------------------------------------------------------------------------------The keys table public.darkdata_keys already exists and is linked to darkdata.
The view public.darkdata_view was restored successfully.
(1 row)
See Also
l
BUILD_FLEXTABLE_VIEW
COMPUTE_FLEXTABLE_KEYS
SQLReference Manual
SQL Functions
COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
MATERIALIZE_FLEXTABLE_COLUMNS
SQLReference Manual
SQL Functions
AUDIT
Estimates the raw data size of a database, a schema, a projection, or a table as it is counted in an
audit of the database size.
The AUDIT function estimates the size using the same data sampling method as the audit that HP
Vertica performs to determine if a database is compliant with the database size allowances in its
license. The results of this function are not considered when HP Vertica determines whether the
size of the database complies with the HP Vertica license's data allowance. See How HP Vertica
Calculates Database Size in the Administrator's Guide for details.
Note: This function can only audit the size of tables, projections, schemas, and databases
which the user has permission to access. If a non-superuser attempts to audit the entire
database, the audit will only estimate the size of the data that the user is allowed to read.
Syntax
AUDIT([name] [, granularity] [, error_tolerance [, confidence_level]])
Parameters
name
SQLReference Manual
SQL Functions
granularity
Indicates the level at which the audit reports its results. The recognized levels
are:
l
'schema'
'table'
'projection'
By default, the granularity is the same level as name. For example, if name is a
schema, then the size of the entire schema is reported. If you instead specify
'table' as the granularity, AUDIT reports the size of each table in the
schema. The granularity must be finer than that of object: specifying
'schema' for an audit of a table has no effect.
The results of an audit with a granularity are reported in the V_
CATALOG.USER_AUDITS system table.
error_tolerance
Specifies the percentage margin of error allowed in the audit estimate. Enter
the tolerance value as a decimal number, between 0 and 100. The default
value is 5, for a 5% margin of error.
Note: The lower this value is, the more resources the audit uses since it will
perform more data sampling. Setting this value to 0 results in a full audit of the
database, which is very resource intensive, as all of the data in the database
is analyzed. Doing a full audit of the database significantly impacts
performance and is not recommended on a production database.
confidence_level
SQLReference Manual
SQL Functions
Permissions
l
Note: AUDIT() works only on the tables where the user calling the function has SELECT
permissions.
Notes
Due to the iterative sampling used in the auditing process, making the error tolerance a small
fraction of a percent (0.00001, for example) can cause the AUDIT function to run for a longer period
than a full database audit.
Examples
To audit the entire database:
=> SELECT AUDIT('');
AUDIT
---------76376696
(1 row)
To audit the database with a 25% level of tolerance and a 90% confidence level:
=> SELECT AUDIT('',25,90);
AUDIT
---------76402672
(1 row)
SQLReference Manual
SQL Functions
SQLReference Manual
SQL Functions
object_id
object_type
object_schema
object_name
audit_start_timestamp
audit_end_timestamp
confidence_level_percent
error_tolerance_percent
used_sampling
confidence_interval_lower_bound_bytes
confidence_interval_upper_bound_bytes
sample_count
cell_count
|
|
|
|
|
|
|
|
|
|
|
|
|
45035996273717644
TABLE
online_sales
online_sales_fact
2011-04-05 09:24:48.368575-04
2011-04-05 09:24:48.379307-04
99
5
t
34692956
36536644
10000
9000000
AUDIT_FLEX
Estimates the ROS size of one or more flexible tables contained in a database, schema, or
projection. Use this function for flex tables only. Invoking audit_flex() with a columnar table
results in an error.
The audit_flex() function measures encoded, compressed data stored in ROS containers for the
__raw__ column of one or more flexible tables. The function does not audit other flex table columns
that are created as, or promoted to, real columns. Temporary flex tables are not included in the
audit.
Each time a user calls audit_flex(), HP Vertica stores the results in the V_CATALOG.USER_
AUDITS system table.
Syntax
AUDIT_FLEX (name)
SQLReference Manual
SQL Functions
Parameters
name
Specifies what database entity to audit. Enter the entity name as a string in single quotes
(''), as follows:
l
Empty string ('') Return the size of the ROS containers for all flexible tables in the
database. You cannot enter the database name.
Schema name ('schema_name') Return the size of all __raw__ columns of flexible
tables in schema_name.
A projection name ('proj_name') Return the ROS size of a projection for a __raw__
column.
Permissions
l
Note: AUDIT_FLEX() works only on the flexible tables, projections, schemas, and databases
to which the user has permissions.
Examples
To audit the flex tables in the database:
dbs=> select audit_flex('');
audit_flex
-----------8567679
(1 row)
SQLReference Manual
SQL Functions
8567679
(1 row)
To report the results of all audits saved in the USER_AUDITS, the following shows part of an
extended display from the system table showing an audit run on a schema called test, and the
entire database, dbs:
dbs=> \x
Expanded display is on.
dbs=> select * from user_audits;
-[ RECORD 1 ]-------------------------+-----------------------------size_bytes
| 0
user_id
| 45035996273704962
user_name
| release
object_id
| 45035996273736664
object_type
| SCHEMA
object_schema
|
object_name
| test
audit_start_timestamp
| 2014-02-04 14:52:15.126592-05
audit_end_timestamp
| 2014-02-04 14:52:15.139475-05
confidence_level_percent
| 99
error_tolerance_percent
| 5
used_sampling
| f
confidence_interval_lower_bound_bytes | 0
confidence_interval_upper_bound_bytes | 0
sample_count
| 0
cell_count
| 0
-[ RECORD 2 ]-------------------------+-----------------------------size_bytes
| 38051
user_id
| 45035996273704962
user_name
| release
object_id
| 45035996273704974
object_type
| DATABASE
object_schema
|
object_name
| dbs
SQLReference Manual
SQL Functions
audit_start_timestamp
| 2014-02-05 13:44:41.11926-05
audit_end_timestamp
| 2014-02-05 13:44:41.227035-05
confidence_level_percent
| 99
error_tolerance_percent
| 5
used_sampling
| f
confidence_interval_lower_bound_bytes | 38051
confidence_interval_upper_bound_bytes | 38051
sample_count
| 0
cell_count
| 0
-[ RECORD 3 ]-------------------------+-----------------------------.
.
.
AUDIT_LICENSE_SIZE
Triggers an immediate audit of the database size to determine if it is in compliance with the raw data
storage allowance included in your HP Vertica license. The audit is performed in the background, so
this function call returns immediately. To see the results of the audit when it is done, use the GET_
COMPLIANCE_STATUS function.
Syntax
AUDIT_LICENSE_SIZE()
Privileges
Must be a superuser.
Example
=> SELECT audit_license_size();
audit_license_size
-------------------Service hurried
(1 row)
AUDIT_LICENSE_TERM
Triggers an immediate audit to determine if the HP Vertica license has expired. The audit happens
in the background, so this function returns immediately. To see the result of the audit, use the GET_
COMPLIANCE_STATUS function.
SQLReference Manual
SQL Functions
Syntax
AUDIT_LICENSE_TERM()
Privileges
Must be a superuser.
Example
=> SELECT AUDIT_LICENSE_TERM();
AUDIT_LICENSE_TERM
-------------------Service hurried
(1 row)
GET_AUDIT_TIME
Reports the time when the automatic audit of database size occurs. HP Vertica performs this audit
if your HP Vertica license includes a data size allowance. For details of this audit, see Managing
Your License Key in the Administrator's Guide. To change the time the audit runs, use the SET_
AUDIT_TIME function.
Syntax
GET_AUDIT_TIME()
Privileges
None
Example
=> SELECT get_audit_time();
get_audit_time
----------------------------------------------------The audit is scheduled to run at 11:59 PM each day.
(1 row)
SQLReference Manual
SQL Functions
GET_COMPLIANCE_STATUS
Displays whether your database is in compliance with your HP Vertica license agreement. This
information includes the results of HP Vertica's most recent audit of the database size (if your
license has a data allowance as part of its terms), and the license term (if your license has an end
date).
The information displayed by GET_COMPLIANCE_STATUS includes:
l
The estimated size of the database (see How HP Vertica Calculates Database Size in the
Administrator's Guide for an explanation of the size estimate).
Whether your database complies with the data allowance terms of your license agreement.
Note: If your license does not have a data allowance or end date, some of the values may not
appear in the output for GET_COMPLIANCE_STATUS.
If the audit shows your license is not in compliance with your data allowance, you should either
delete data to bring the size of the database under the licensed amount, or upgrade your license. If
your license term has expired, you should contact HP immediately to renew your license. See
Managing Your License Key in the Administrator's Guide for further details.
Syntax
GET_COMPLIANCE_STATUS()
Privileges
None
SQLReference Manual
SQL Functions
Example
GET_COMPLIANCE_STATUS
--------------------------------------------------------------------------------Raw Data Size: 2.00GB +/- 0.003GB
License Size : 4.000GB
Utilization : 50%
Audit Time
: 2011-03-09 09:54:09.538704+00
Compliance Status : The database is in compliance with respect to raw data size.
License End Date: 04/06/2011
Days Remaining: 28.59
(1 row)
DISPLAY_LICENSE
Returns the terms of your HP Vertica license. The information this function displays is:
l
The start and end dates for which the license is valid (or "Perpetual" if the license has no
expiration).
The number of days you are allowed to use HP Vertica after your license term expires (the grace
period)
The amount of data your database can store, if your license includes a data allowance.
Syntax
DISPLAY_LICENSE()
Privileges
None
Examples
=> SELECT DISPLAY_LICENSE();
DISPLAY_LICENSE
---------------------------------------------------HP Vertica Systems, Inc.
1/1/2011
12/31/2011
30
50TB
SQLReference Manual
SQL Functions
(1 row)
SET_AUDIT_TIME
Sets the time that HP Vertica performs automatic database size audit to determine if the size of the
database is compliant with the raw data allowance in your HP Vertica license. Use this function if
the audits are currently scheduled to occur during your database's peak activity time. This is
normally not a concern, since the automatic audit has little impact on database performance.
Audits are scheduled by the preceding audit, so changing the audit time does not affect the next
scheduled audit. For example, if your next audit is scheduled to take place at 11:59PM and you use
SET_AUDIT_TIME to change the audit schedule 3AM, the previously scheduled 11:59PM audit
still runs. As that audit finishes, it schedules the next audit to occur at 3AM.
If you want to prevent the next scheduled audit from running at its scheduled time, you can change
the scheduled time using SET_AUDIT_TIME then manually trigger an audit to run immediately
using AUDIT_LICENSE_SIZE. As the manually-triggered audit finishes, it schedules the next audit
to occur at the time you set using SET_AUDIT_TIME (effectively overriding the previously
scheduled audit).
Syntax
SET_AUDIT_TIME(time)
time
A string containing the time in 'HH:MM AM/PM' format (for example, '1:00 AM') when the
audit should run daily.
Privileges
Must be a superuser.
Example
=> SELECT SET_AUDIT_TIME('3:00 AM');
SET_AUDIT_TIME
----------------------------------------------------------------------The scheduled audit time will be set to 3:00 AM after the next audit.
(1 row)
SQLReference Manual
SQL Functions
DROP_PARTITION
Forces the partition of projections (if needed) and then drops the specified partition.
Syntax
DROP_PARTITION ( table_name , partition_value [ , ignore_moveout_errors, reorganize_data ])
Parameters
table-name
partition_value
ignore_moveout_errors
Note: If you set this parameter to true and the WOS includes data for
the partition in WOS, partition data in WOS is not dropped.
SQLReference Manual
SQL Functions
reorganize_data
Permissions
l
Table owner
One container holds the data that belongs to the partition that is to be dropped.
SQLReference Manual
SQL Functions
You cannot perform a DROP_PARTITION operation on tables with projections that are not up to
date (have not been refreshed).
DROP_PARTITION fails if you do not set the optional third parameter to true and the function
encounters ROS's that do not have partition keys.
Examples
Using the example schema in Defining Partitions, the following command explicitly drops the 2009
partition key from table trade:
SELECT DROP_PARTITION('trade', 2009);
DROP_PARTITION
------------------Partition dropped
(1 row)
The following example creates a table called dates and partitions the table by year:
CREATE TABLE dates (year INTEGER NOT NULL,
month VARCHAR(8) NOT NULL)
PARTITION BY year * 12 + month;
The following statement drops the partition using a constant for Oct 2010 (2010*12 + 10 = 24130):
SELECT DROP_PARTITION('dates', '24130');
DROP_PARTITION
------------------Partition dropped
(1 row)
SQLReference Manual
SQL Functions
------------------Partition dropped
(1 row)
See Also
l
Dropping Partitions
ADVANCE_EPOCH
COLUMN_STORAGE
CREATE TABLE
DO_TM_TASK
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
PROJECTIONS
DUMP_PROJECTION_PARTITION_KEYS
Dumps the partition keys of the specified projection.
Syntax
DUMP_PROJECTION_PARTITION_KEYS(
'projection_name' )
Parameters
projection_name
SQLReference Manual
SQL Functions
Privileges
l
Example
The following example creates a simple table called states and partitions the data by state:
=> CREATE TABLE states (year INTEGER NOT NULL,
state VARCHAR NOT NULL)
PARTITION BY state;
=> CREATE PROJECTION states_p (state, year)
AS SELECT * FROM states
ORDER BY state, year UNSEGMENTED ALL NODES;
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
PROJECTIONS
SQLReference Manual
SQL Functions
DUMP_TABLE_PARTITION_KEYS
Dumps the partition keys of all projections anchored on the specified table.
Syntax
DUMP_TABLE_PARTITION_KEYS ( 'table_name' )
Parameters
table_name
Privilege
l
Examples
The following example creates a simple table called states and partitions the data by state:
=> CREATE TABLE states (year INTEGER NOT NULL,
state VARCHAR NOT NULL)
PARTITION BY state;
=> CREATE PROJECTION states_p (state, year) AS
SELECT * FROM states
ORDER BY state, year UNSEGMENTED ALL NODES;
Now dump the partition keys of all projections anchored on table states:
=> SELECT DUMP_TABLE_PARTITION_KEYS( 'states' );
Partition keys on helios_node0001
Projection 'states_p_node0004'
No of partition keys: 1
Projection 'states_p_node0003'
No of partition keys: 1
Projection 'states_p_node0002'
No of partition keys: 1
Projection 'states_p_node0001'
No of partition keys: 1
Partition keys on helios_node0002
...
(1 row)
SQLReference Manual
SQL Functions
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
MOVE_PARTITIONS_TO_TABLE
Moves partitions from a source table to a target table.
MOVE_PARTITIONS_TO_TABLEworks even if a node is recovering from being down.
Syntax
MOVE_PARTITIONS_TO_TABLE (
'[[db-name.]schema.]source_table',
'min_range_value',
'max_range_value',
[[db-name.]schema.]target_table'
)
Parameters
[db-name.]schema
Specifies a schema and, optionally, a database that you are connected to.
Include the schema name if multiple schemas are defined in the database. A
fully qualified name specifies its database and schemafor example:
mydb.myschema.thisDbObject
source_table
SQLReference Manual
SQL Functions
min_range_value
The minimum value of the partition to be moved. To move one partition, the
minimum and maximum values should be the same.
max_range_value
The maximum value of the partition to be moved. To move one partition, the
minimum and maximum values should be the same.
target_table
Privileges
l
If the target table exists, you must own, or have USAGEprivileges, on the source.
If target table is created as part of moving partitions, you must have CREATE privileges.
Examples
If you call MOVE_PARTITIONS_TO_TABLE and the target table does not exist, the function
creates the table automatically. In the following example, the target table partn_backup.tradfes_
200801 does not exist. MOVE_PARTITIONS_TO_TABLEcreates the table and moves the
partition. In addition, HP Vertica copies all the constraints associated with the source table except
any foreign key constraints.
=> SELECT MOVE_PARTITIONS_TO_TABLE (
'prod_trades',
'200801',
'200801',
'partn_backup.trades_200801');
MOVE_PARTITIONS_TO_TABLE
------------------------------------------------1 distinct partition values moved at epoch 15.
(1 row)
See Also
l
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
SQLReference Manual
SQL Functions
PARTITION_PROJECTION
SWAP_PARTITIONS_BETWEEN_TABLES
Moving Partitions
PARTITION_PROJECTION
Forces the split of ROS containers for a specified projection.
Syntax
PARTITION_PROJECTION ( '[[db-name.]schema.]projection_name' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection_name
Privileges
l
Table owner
Usage Considerations
l
Partitioning expressions take immutable functions only, so that the same information be
available across all nodes.
SQLReference Manual
SQL Functions
Examples
In this example, the SELECT PARTITION_PROJECTION command forces a split of ROS
containers on the states_p_node01 projection:
=> SELECT PARTITION_PROJECTION ('states_p_node01');
PARTITION_PROJECTION
-----------------------Projection partitioned
(1 row)
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_TABLE
PARTITION_TABLE
Forces the database to split ROS containers in the specified table that contain multiple distinct
values of the partitioning expression. Only ROS containers with more than one distinct value can be
split.
Syntax
PARTITION_TABLE ( '[[db-name.]schema.]table_name' )
SQLReference Manual
SQL Functions
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table_name
Privileges
l
Table owner
Usage Considerations
l
You cannot run PARTITION_TABLEon a table that is an anchor table for a live aggregate
projection or a Top-K projection.
If you use a function when partitioning a table, that function must be immutable.
Examples
The following example creates a simple table called states and partitions the data by state.
=> CREATE TABLE states (year INTEGER NOT NULL,
state VARCHAR NOT NULL)
PARTITION BY state;
=> CREATE PROJECTION states_p (state, year) AS
SELECT * FROM states
ORDER BY state, year UNSEGMENTED ALL NODES;
SQLReference Manual
SQL Functions
See Also
l
DO_TM_TASK
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PURGE_PARTITION
Purges a table partition of deleted rows. Similar to PURGE() and PURGE_PROJECTION(), this function
removes deleted data from physical storage so you can reuse the disk space. PURGE_PARTITION()
removes data from the AHM epoch and earlier only.
Syntax
PURGE_PARTITION ( '[[db_name.]schema_name.]table_name', partition_key )
Parameters
[[db_name.]schema_name.]
table_name
partition_key
SQLReference Manual
SQL Functions
Privileges
l
Table owner
Example
The following example lists the count of deleted rows for each partition in a table, then calls PURGE_
PARTITION() to purge the deleted rows from the data.
=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
AS deleted_row_count FROM partitions
GROUP BY partition_key,table_schema,projection_name
ORDER BY partition_key;
partition_key | table_schema | projection_name | deleted_row_count
---------------+--------------+-----------------+------------------0
| public
| t_super
|
2
1
| public
| t_super
|
2
2
| public
| t_super
|
2
3
| public
| t_super
|
2
4
| public
| t_super
|
2
5
| public
| t_super
|
2
6
| public
| t_super
|
2
7
| public
| t_super
|
2
8
| public
| t_super
|
2
9
| public
| t_super
|
1
(10 rows)
=> SELECT PURGE_PARTITION('t',5); -- Purge partition with key 5.
purge_partition
-----------------------------------------------------------------------Task: merge partitions
(Table: public.t) (Projection: public.t_super)
(1 row)
=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
AS deleted_row_count FROM partitions
GROUP BY partition_key,table_schema,projection_name
ORDER BY partition_key;
SQLReference Manual
SQL Functions
8
9
(10 rows)
| public
| public
| t_super
| t_super
|
|
2
1
See Also
l
PURGE
PURGE_PROJECTION
PURGE_TABLE
STORAGE_CONTAINERS
SWAP_PARTITIONS_BETWEEN_TABLES
Swaps partitions between a staging table and a target table. The two tables must have the same:
l
Column definitions
Segmentation
Partitioning expression
Number of projections
Syntax
SWAP_PARTITIONS_BETWEEN_TABLES (
'[[db-name.]schema.]staging_table',
'min_range_value',
'max_range_value',
'[[db-name.]schema.]target_table'
)
SQLReference Manual
SQL Functions
Parameters
[db-name.]schema
Specifies a schema and, optionally, a database that you are connected to.
Include the schema name if multiple schemas are defined in the database. A
fully qualified name specifies its database and schemafor example:
mydb.myschema.thisDbObject
staging_table
min_range_value
max_range_value
target_table
Privileges
To swap partitions, you must be a DBADMINuser or the owner of both the staging table and the
target table.
Notes
l
You cannot swap partitions with a table that has pre-join projections.
If the partitions of both tables are empty, you see a warning, but the swap still occurs. Because
the partitions are empty, there is no change to the partitions.
If the partitions are not in the same storage tier, you see a warning but the swap still occurs. The
partitions remain in their existing storage tier.
Examples
The following example shows how to use SWAP_PARTITIONS_BETWEEN_TWO_TABLES to
swap the partitions between two tables. In this statement, you swap the 2008 and 2009 partitions.
=> SELECT SWAP_PARTITIONS_BETWEEN_TABLES ( 'customer_info', 2008, 2009, 'member_info');
SQLReference Manual
SQL Functions
See Also
l
DROP_PARTITION
MOVE_PARTITIONS_TO_TABLE
Swapping Partitions
Moving Partitions
SQLReference Manual
SQL Functions
Profiling Functions
This section contains profiling functions specific to HP Vertica.
CLEAR_PROFILING
HP Vertica stores profiled data is in memory, so depending on how much data you collect, profiling
could be memory intensive. You can use this function to clear profiled data from memory.
Syntax
CLEAR_PROFILING( 'profiling-type' )
Parameters
profiling-type
The type of profiling data you want to clear. Can be one of:
l
sessionclears profiling for basic session parameters and lock time out
data
queryclears profiling for general information about queries that ran, such as
the query strings used and the duration of queries
eeclears profiling for information about the execution run of each query
Example
The following statement clears profiled data for queries:
=> SELECT CLEAR_PROFILING('query');
See Also
l
DISABLE_PROFILING
ENABLE_PROFILING
SQLReference Manual
SQL Functions
DISABLE_PROFILING
Disables profiling for the profiling type you specify.
Syntax
DISABLE_PROFILING( 'profiling-type' )
Parameters
profiling-type
The type of profiling data you want to disable. Can be one of:
l
sessiondisables profiling for basic session parameters and lock time out
data
querydisables profiling for general information about queries that ran, such
as the query strings used and the duration of queries
eedisables profiling for information about the execution run of each query
Example
The following statement disables profiling on query execution runs:
=> SELECT DISABLE_PROFILING('ee');
DISABLE_PROFILING
----------------------EE Profiling Disabled
(1 row)
See Also
l
CLEAR_PROFILING
ENABLE_PROFILING
ENABLE_PROFILING
Enables profiling for the profiling type you specify.
SQLReference Manual
SQL Functions
Note: HP Vertica stores profiled data is in memory, so depending on how much data you
collect, profiling could be memory intensive.
Syntax
ENABLE_PROFILING( 'profiling-type' )
Parameters
profiling-type
The type of profiling data you want to enable. Can be one of:
l
sessionenables profiling for basic session parameters and lock time out
data
queryenables profiling for general information about queries that ran, such
as the query strings used and the duration of queries
eeenables profiling for information about the execution run of each query
Example
The following statement enables profiling on query execution runs:
=> SELECT ENABLE_PROFILING('ee');
ENABLE_PROFILING
---------------------EE Profiling Enabled
(1 row)
See Also
l
CLEAR_PROFILING
DISABLE_PROFILING
SQLReference Manual
SQL Functions
See Also
l
V_CATALOG.PROJECTIONS
V_CATALOG.PROJECTION_COLUMNS
V_MONITOR.PROJECTION_REFRESHES
V_MONITOR.PROJECTION_STORAGE
EVALUATE_DELETE_PERFORMANCE
Evaluates projections for potential DELETE performance issues. If there are issues found, a
warning message is displayed. For steps you can take to resolve delete and update performance
issues, see Optimizing Deletes and Updates for Performance in the Administrator's Guide. This
function uses data sampling to determine whether there are any issues with a projection. Therefore,
it does not generate false-positives warnings, but it can miss some cases where there are
performance issues.
Note: Optimizing for delete performance is the same as optimizing for update performance.
So, you can use this function to help optimize a projection for updates as well as deletes.
Syntax
EVALUATE_DELETE_PERFORMANCE ( 'target' )
Parameters
target
The name of a projection or table. If you supply the name of a projection, only that
projection is evaluated for DELETE performance issues. If you supply the name of a
table, then all of the projections anchored to the table will be evaluated for issues.
If you do not provide a projection or table name, EVALUATE_DELETE_
PERFORMANCE examines all of the projections that you can access for DELETE
performance issues. Depending on the size you your database, this may take a long
time.
SQLReference Manual
SQL Functions
Privileges
None
Notes
When evaluating multiple projections, EVALUATE_DELETE_PERFORMANCE reports up to ten
projections that have issues, and refers you to a table that contains the full list of issues it has
found.
Example
The following example demonstrates how you can use EVALUATE_DELETE_PERFORMANCE
to evaluate your projections for slow DELETE performance.
=> create table example (A int, B int,C int);
CREATE TABLE
=> create projection one_sort (A,B,C) as (select A,B,C from example) order by A;
CREATE PROJECTION
=> create projection two_sort (A,B,C) as (select A,B,C from example) order by A,B;
CREATE PROJECTION
=> select evaluate_delete_performance('one_sort');
evaluate_delete_performance
--------------------------------------------------No projection delete performance concerns found.
(1 row)
=> select evaluate_delete_performance('two_sort');
evaluate_delete_performance
--------------------------------------------------No projection delete performance concerns found.
(1 row)
The previous example showed that there was no structural issue with the projection that would
cause poor DELETE performance. However, the data contained within the projection can create
potential delete issues if the sorted columns do not uniquely identify a row or small number of rows.
In the following example, Perl is used to populate the table with data using a nested series of loops.
The inner loop populates column C, the middle loop populates column B, and the outer loop
populates column A. The result is column A contains only three distinct values (0, 1, and 2), while
column B slowly varies between 20 and 0 and column C changes in each row. EVALUATE_
DELETE_PERFORMANCE is run against the projections again to see if the data within the
projections causes any potential DELETE performance issues.
SQLReference Manual
SQL Functions
=> \! perl -e 'for ($i=0; $i<3; $i++) { for ($j=0; $j<21; $j++) { for ($k=0; $k<19; $k++)
{ printf "%d,%d,%d\n", $i,$j,$k;}}}' | /opt/vertica/bin/vsql -c "copy example from stdin
delimiter ',' direct;"
Password:
=> select * from example;
A | B | C
---+----+---0 | 20 | 18
0 | 20 | 17
0 | 20 | 16
0 | 20 | 15
0 | 20 | 14
0 | 20 | 13
0 | 20 | 12
0 | 20 | 11
0 | 20 | 10
0 | 20 | 9
0 | 20 | 8
0 | 20 | 7
0 | 20 | 6
0 | 20 | 5
0 | 20 | 4
0 | 20 | 3
0 | 20 | 2
0 | 20 | 1
0 | 20 | 0
0 | 19 | 18
1157 rows omitted
2 | 1 | 0
2 | 0 | 18
2 | 0 | 17
2 | 0 | 16
2 | 0 | 15
2 | 0 | 14
2 | 0 | 13
2 | 0 | 12
2 | 0 | 11
2 | 0 | 10
2 | 0 | 9
2 | 0 | 8
2 | 0 | 7
2 | 0 | 6
2 | 0 | 5
2 | 0 | 4
2 | 0 | 3
2 | 0 | 2
2 | 0 | 1
2 | 0 | 0
=> SELECT COUNT (*) FROM example;
COUNT
------1197
(1 row)
=> SELECT COUNT (DISTINCT A) FROM example;
COUNT
------3
(1 row)
SQLReference Manual
SQL Functions
The one_sort projection has potential delete issues since it only sorts on column A which has few
distinct values. This means that each value in the sort column corresponds to many rows in the
projection, which negatively impacts DELETE performance. Since the two_sort projection is sorted
on columns A and B, each combination of values in the two sort columns identifies just a few rows,
allowing deletes to be performed faster.
Not supplying a projection name results in all of the projections you can access being evaluated for
DELETE performance issues.
=> select evaluate_delete_performance();
evaluate_delete_performance
--------------------------------------------------------------------------The following projection exhibits delete performance concerns:
"public"."one_sort"
See v_catalog.projection_delete_concerns for more details.
(1 row)
GET_PROJECTION_STATUS
Returns information relevant to the status of a projection.
Syntax
GET_PROJECTION_STATUS ( '[[db-name.]schema-name.]projection' );
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection
Is the name of the projection for which to display status. When using more
than one schema, specify the schema that contains the projection, as
noted above.
SQLReference Manual
SQL Functions
Privileges
None
Description
GET_PROJECTION_STATUS returns information relevant to the status of a projection:
l
Notes
l
To view a list of the nodes in a database, use the View Database Command in the
Administration Tools.
Examples
=> SELECT GET_PROJECTION_STATUS('public.customer_dimension_site01');
GET_PROJECTION_STATUS
---------------------------------------------------------------------------------------------Current system K is 1.
# of Nodes: 4.
public.customer_dimension_site01 [Segmented: No] [Seg Cols: ] [K: 3] [public.customer_
dimension_site04, public.customer_dimension_site03,
public.customer_dimension_site02]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
SQLReference Manual
SQL Functions
See Also
l
GET_PROJECTIONS, GET_TABLE_PROJECTIONS
GET_PROJECTIONS, GET_TABLE_PROJECTIONS
Note: This function was formerly named GET_TABLE_PROJECTIONS(). HP Vertica still
supports the former function name.
Returns information relevant to the status of a table:
l
The number of projections for which the specified table is the anchor table
Syntax
GET_PROJECTIONS ( '[[db-name.]schema-name.]table' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Is the name of the table for which to list projections. When using more than
one schema, specify the schema that contains the table.
SQLReference Manual
SQL Functions
Privileges
None
Notes
l
You can use GET_PROJECTIONS to monitor the progress of a projection data refresh. See
ALTER PROJECTION.
To view a list of the nodes in a database, use the View Database Command in the
Administration Tools.
Examples
The following example gets information about the store_dimension table in the VMart schema:
=> SELECT GET_PROJECTIONS('store.store_dimension');
-------------------------------------------------------------------------------------Current system K is 1.
# of Nodes: 4.
Table store.store_dimension has 4 projections.
Projection Name: [Segmented] [Seg Cols] [# of Buddies] [Buddy Projections] [Safe]
[UptoDate]
---------------------------------------------------------store.store_dimension_node0004 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0003, store.store_dimension_node0002, store.store_dimension_node0001]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
store.store_dimension_node0003 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0004, store.store_dimension_node0002, store.store_dimension_node0001]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
store.store_dimension_node0002 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0004, store.store_dimension_node0003, store.store_dimension_node0001]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
store.store_dimension_node0001 [Segmented: No] [Seg Cols: ] [K: 3] [store.store_
dimension_node0004, store.store_dimension_node0003, store.store_dimension_node0002]
[Safe: Yes] [UptoDate: Yes][Stats: Yes]
(1 row)
See Also
l
GET_PROJECTION_STATUS
REFRESH
Performs a synchronous, optionally-targeted refresh of a specified table's projections.
SQLReference Manual
SQL Functions
Syntax
REFRESH ( '[[db-name.]schema.]table_name [ , ... ]' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table_name
Returns
Column Name Description
Projection Name
Anchor Table
SQLReference Manual
SQL Functions
Status
Refresh Method
Error Count
Duration (sec)
Privileges
REFRESH() works only if invoked on tables owned by the calling user.
Notes
l
Unlike START_REFRESH(), which runs in the background, REFRESH() runs in the foreground
of the caller's session.
The REFRESH() function refreshes only the projections in the specified table.
If you run REFRESH() without arguments, it refreshes all non up-to-date projections. If the
function returns a header string with no results, then no projections needed refreshing.
SQLReference Manual
SQL Functions
Examples
The following example refreshes the projections in tables t1 and t2:
=> SELECT REFRESH('t1, t2');
REFRESH
---------------------------------------------------------------------------------------Refresh completed with the following outcomes:
Projection Name: [Anchor Table] [Status] [Refresh Method] [Error Count] [Duration (sec)]
---------------------------------------------------------------------------------------"public"."t1_p": [t1] [refreshed] [scratch] [0] [0]"public"."t2_p": [t2] [refreshed]
[scratch] [0] [0]
This next example shows that only the projection on table t was refreshed:
=> SELECT REFRESH('allow, public.deny, t');
REFRESH
---------------------------------------------------------------------------------------Refresh completed with the following outcomes:
Projection Name: [Anchor Table] [Status] [Refresh Method] [Error Count] [Duration (sec)]
---------------------------------------------------------------------------------------"n/a"."n/a": [n/a] [failed: insufficient permissions on table "allow"] [] [1] [0]
"n/a"."n/a": [n/a] [failed: insufficient permissions on table "public.deny"] [] [1] [0]
"public"."t_p1": [t] [refreshed] [scratch] [0] [0]
See Also
l
CLEAR_PROJECTION_REFRESHES
PROJECTION_REFRESHES
START_REFRESH
START_REFRESH
Transfers data to projections that are not able to participate in query execution due to missing or
out-of-date data.
Syntax
START_REFRESH()
SQLReference Manual
SQL Functions
Notes
l
When a design is deployed through the Database Designer, it is automatically refreshed. See
Deploying a Design in the Administrator's Guide.
If a projection is updated from scratch, the data stored in the projection represents the table
columns as of the epoch in which the refresh commits. As a result, the query optimizer might not
choose the new projection for AT EPOCH queries that request historical data at epochs older
than the refresh epoch of the projection. Projections refreshed from buddies retain history and
can be used to answer historical queries.
Privileges
None
Example
The following command starts the refresh operation:
=> SELECT START_REFRESH();
start_refresh
---------------------------------------Starting refresh background process.
See Also
l
CLEAR_PROJECTION_REFRESHES
MARK_DESIGN_KSAFE
SQLReference Manual
SQL Functions
PROJECTION_REFRESHES
PROJECTIONS
SQLReference Manual
SQL Functions
Purge Functions
This section contains purge functions specific to HP Vertica.
PURGE
Permanently removes deleted data from physical storage so that the disk space can be reused.
You can purge historical data up to and including the epoch in which the Ancient History Mark is
contained.
Purges all projections in the physical schema. PURGEdoes not delete temporary tables.
Syntax
PURGE()
Privileges
l
Table owner
Notes
l
Caution: PURGE could temporarily take up significant disk space while the data is being
purged.
See Also
l
PARTITION_TABLE
PURGE_PROJECTION
PURGE_TABLE
SQLReference Manual
SQL Functions
STORAGE_CONTAINERS
PURGE_PARTITION
Purges a table partition of deleted rows. Similar to PURGE() and PURGE_PROJECTION(), this function
removes deleted data from physical storage so you can reuse the disk space. PURGE_PARTITION()
removes data from the AHM epoch and earlier only.
Syntax
PURGE_PARTITION ( '[[db_name.]schema_name.]table_name', partition_key )
Parameters
[[db_name.]schema_name.]
table_name
partition_key
Privileges
l
Table owner
Example
The following example lists the count of deleted rows for each partition in a table, then calls PURGE_
PARTITION() to purge the deleted rows from the data.
=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
AS deleted_row_count FROM partitions
GROUP BY partition_key,table_schema,projection_name
ORDER BY partition_key;
partition_key | table_schema | projection_name | deleted_row_count
SQLReference Manual
SQL Functions
---------------+--------------+-----------------+------------------0
| public
| t_super
|
2
1
| public
| t_super
|
2
2
| public
| t_super
|
2
3
| public
| t_super
|
2
4
| public
| t_super
|
2
5
| public
| t_super
|
2
6
| public
| t_super
|
2
7
| public
| t_super
|
2
8
| public
| t_super
|
2
9
| public
| t_super
|
1
(10 rows)
=> SELECT PURGE_PARTITION('t',5); -- Purge partition with key 5.
purge_partition
-----------------------------------------------------------------------Task: merge partitions
(Table: public.t) (Projection: public.t_super)
(1 row)
=> SELECT partition_key,table_schema,projection_name,sum(deleted_row_count)
AS deleted_row_count FROM partitions
GROUP BY partition_key,table_schema,projection_name
ORDER BY partition_key;
See Also
l
PURGE
PURGE_PROJECTION
PURGE_TABLE
STORAGE_CONTAINERS
SQLReference Manual
SQL Functions
PURGE_PROJECTION
Permanently removes deleted data from physical storage so that the disk space can be reused.
You can purge historical data up to and including the epoch in which the Ancient History Mark is
contained.
Purges the specified projection.
Caution: PURGE_PROJECTION could temporarily take up significant disk space while
purging the data.
Syntax
PURGE_PROJECTION ( '[[db-name.]schema.]projection_name' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection_name
Identifies the projection name. When using more than one schema,
specify the schema that contains the projection, as noted above.
Privileges
l
Table owner
Notes
See PURGE for notes about the outcome of purge operations.
Examples
This example shows how to purge a projection.
=> CREATE TABLE tbl (x INT , y INT);
SQLReference Manual
SQL Functions
CREATE TABLE
=> CREATE PROJECTION tbl_p AS SELECT x FROM tbl;
CREATE PROJECTION
=> SELECT PURGE_PROJECTION ('tbl_p');
purge_projection
------------------Projection purged
(1 row)
See Also
l
PURGE_TABLE
STORAGE_CONTAINERS
PURGE_TABLE
Note: This function was formerly named PURGE_TABLE_PROJECTIONS(). HP Vertica still
supports the former function name.
Permanently removes deleted data from physical storage so that the disk space can be reused.
You can purge historical data up to and including the epoch in which the Ancient History Mark is
contained.
Purges all projections of the specified table. You cannot use this function to purge temporary tables.
Syntax
PURGE_TABLE ( '[[db-name.]schema.]table_name' )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table_name
SQLReference Manual
SQL Functions
Privileges
l
Table owner
Caution: PURGE_TABLE could temporarily take up significant disk space while the data is
being purged.
Example
The following example purges all projections for the store sales fact table located in the Vmart
schema:
=> SELECT PURGE_TABLE('store.store_sales_fact');
See Also
l
PURGE
PURGE_TABLE
STORAGE_CONTAINERS
SQLReference Manual
SQL Functions
CANCEL_REFRESH
Cancels refresh-related internal operations initiated by START_REFRESH().
Syntax
CANCEL_REFRESH()
Privileges
None
Notes
l
Refresh tasks run in a background thread in an internal session, so you cannot use
INTERRUPT_STATEMENT to cancel those statements. Instead, use CANCEL_REFRESH to
cancel statements that are run by refresh-related internal sessions.
CANCEL_REFRESH() cancels the refresh operation running on a node, waits for the
cancelation to complete, and returns SUCCESS.
Example
Cancel a refresh operation executing in the background.
t=> SELECT START_REFRESH();
START_REFRESH
---------------------------------------Starting refresh background process.
(1 row)
SQLReference Manual
SQL Functions
See Also
l
INTERRUPT_STATEMENT
SESSIONS
START_REFRESH
PROJECTION_REFRESHES
CLOSE_ALL_SESSIONS
Closes all external sessions except the one issuing the CLOSE_ALL_SESSIONS functions.
Syntax
CLOSE_ALL_SESSIONS()
Privileges
None; however, a non-superuser can only close his or her own session.
Notes
Closing of the sessions is processed asynchronously. It might take some time for the session to be
closed. Check the SESSIONS table for the status.
Database shutdown is prevented if new sessions connect after the CLOSE_SESSION or CLOSE_
ALL_SESSIONS() command is invoked (and before the database is actually shut down). See
Controlling Sessions below.
Message
close_all_sessions | Close all sessions command sent. Check SESSIONS for progress.
SQLReference Manual
SQL Functions
Examples
Two user sessions opened, each on a different node:
vmartdb=> SELECT * FROM sessions;
-[ RECORD 1 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
transaction_description
| user dbadmin (select * from sessions;)
statement_start
| 2011-01-03 15:36:13.896288
statement_id
| 10
last_statement_duration_us | 14978
current_statement
| select * from sessions;
ssl_state
| None
authentication_method
| Trust
-[ RECORD 2 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0002
user_name
| dbadmin
client_hostname
| 127.0.0.1:57174
client_pid
| 30117
login_timestamp
| 2011-01-03 15:33:00.842021-05
session_id
| stress05-27944:0xc1a
client_label
|
transaction_start
| 2011-01-03 15:34:46.538102
transaction_id
| -1
transaction_description
| user dbadmin (COPY Mart_Fact FROM '/data/mart_Fact.tbl'
DELIMITER '|' NULL '\\n';)
statement_start
| 2011-01-03 15:34:46.538862
statement_id
|
last_statement_duration_us | 26250
current_statement
| COPY Mart_Fact FROM '/data/Mart_Fact.tbl' DELIMITER '|'
NULL '\\n';
ssl_state
| None
authentication_method
| Trust
-[ RECORD 3 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0003
user_name
| dbadmin
client_hostname
| 127.0.0.1:56367
client_pid
| 1191
login_timestamp
| 2011-01-03 15:31:44.939302-05
session_id
| stress06-25663:0xbec
client_label
|
transaction_start
| 2011-01-03 15:34:51.05939
transaction_id
| 54043195528458775
transaction_description
| user dbadmin (COPY Mart_Fact FROM '/data/Mart_Fact.tbl'
DELIMITER '|' NULL '\\n' DIRECT;)
statement_start
| 2011-01-03 15:35:46.436748
statement_id
|
SQLReference Manual
SQL Functions
last_statement_duration_us | 1591403
current_statement
| COPY Mart_Fact FROM '/data/Mart_Fact.tbl' DELIMITER '|'
NULL '\\n' DIRECT;
ssl_state
| None
authentication_method
| Trust
RECORD 1 ]--------------+----------------------------------v_vmartdb_node0001
dbadmin
127.0.0.1:52110
4554
2011-01-03 14:05:40.252625-05
stress04-4325:0x14
2011-01-03 14:05:44.325781
45035996273728326
user dbadmin (SELECT * FROM sessions;)
2011-01-03 16:19:56.720071
25
15605
SELECT * FROM SESSIONS;
None
Trust
Controlling Sessions
The database administrator must be able to disallow new incoming connections in order to shut
down the database. On a busy system, database shutdown is prevented if new sessions connect
after the CLOSE_SESSION or CLOSE_ALL_SESSIONS() command is invokedand before the
database actually shuts down.
One option is for the administrator to issue the SHUTDOWN('true') command, which forces the
database to shut down and disallow new connections. See SHUTDOWN in the SQL Reference
Manual.
Another option is to modify the MaxClientSessions parameter from its original value to 0, in order
to prevent new non-dbadmin users from connecting to the database.
SQLReference Manual
SQL Functions
1. Determine the original value for the MaxClientSessions parameter by querying the V_
MONITOR.CONFIGURATIONS_PARAMETERS system table:
=> SELECT CURRENT_VALUE FROM CONFIGURATION_PARAMETERS WHERE parameter_
name='MaxClientSessions';
CURRENT_VALUE
--------------50
(1 row)
When the session no longer appears in the SESSIONS table, disconnect and run the Stop
Database command.
5. Restart the database.
6. Restore the MaxClientSessions parameter to its original value:
=> ALTER DATABASE mydb SET MaxClientSessions = 50;
See Also
l
CLOSE_SESSION
CONFIGURATION_PARAMETERS
SQLReference Manual
SQL Functions
SHUTDOWN
SESSIONS
l
l
CLOSE_SESSION
Interrupts the specified external session, rolls back the current transaction, if any, and closes the
socket.
Syntax
CLOSE_SESSION ( 'sessionid' )
Parameters
sessionid
A string that specifies the session to close. This identifier is unique within the cluster
at any point in time but can be reused when the session closes.
Privileges
None; however, a non-superuser can only close his or her own session.
Notes
l
Closing of the session is processed asynchronously. It could take some time for the session to
be closed. Check the SESSIONS table for the status.
Messages
The following are the messages you could encounter:
SQLReference Manual
SQL Functions
Examples
User session opened. RECORD 2 shows the user session running COPY DIRECT statement.
=> SELECT * FROM sessions;
-[ RECORD 1 ]--------------+----------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
transaction_description
| user dbadmin (SELECT * FROM sessions;)
statement_start
| 2011-01-03 15:36:13.896288
statement_id
| 10
last_statement_duration_us | 14978
current_statement
| select * from sessions;
ssl_state
| None
authentication_method
| Trust
-[ RECORD 2 ]--------------+----------------------------------------------node_name
| v_vmartdb_node0002
user_name
| dbadmin
client_hostname
| 127.0.0.1:57174
client_pid
| 30117
login_timestamp
| 2011-01-03 15:33:00.842021-05
session_id
| stress05-27944:0xc1a
client_label
|
transaction_start
| 2011-01-03 15:34:46.538102
transaction_id
| -1
transaction_description
| user dbadmin (COPY ClickStream_Fact FROM
'/data/clickstream/1g/ClickStream_Fact.tbl'
DELIMITER '|' NULL '\\n' DIRECT;)
statement_start
| 2011-01-03 15:34:46.538862
statement_id
|
last_statement_duration_us | 26250
current_statement
| COPY ClickStream_Fact FROM '/data/clickstream
/1g/ClickStream_Fact.tbl' DELIMITER '|' NULL
'\\n' DIRECT;
ssl_state
| None
SQLReference Manual
SQL Functions
authentication_method
| Trust
Query the sessions table again for current status, and you can see that the second session has
been closed:
=> SELECT * FROM SESSIONS;
-[ RECORD 1 ]--------------+-------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
transaction_description
| user dbadmin (select * from SESSIONS;)
statement_start
| 2011-01-03 16:12:07.841298
statement_id
| 20
last_statement_duration_us | 2099
current_statement
| SELECT * FROM SESSIONS;
ssl_state
| None
authentication_method
| Trust
Controlling Sessions
The database administrator must be able to disallow new incoming connections in order to shut
down the database. On a busy system, database shutdown is prevented if new sessions connect
after the CLOSE_SESSION or CLOSE_ALL_SESSIONS() command is invokedand before the
database actually shuts down.
One option is for the administrator to issue the SHUTDOWN('true') command, which forces the
database to shut down and disallow new connections. See SHUTDOWN in the SQL Reference
Manual.
Another option is to modify the MaxClientSessions parameter from its original value to 0, in order
to prevent new non-dbadmin users from connecting to the database.
SQLReference Manual
SQL Functions
1. Determine the original value for the MaxClientSessions parameter by querying the V_
MONITOR.CONFIGURATIONS_PARAMETERS system table:
=> SELECT CURRENT_VALUE FROM CONFIGURATION_PARAMETERS WHERE parameter_
name='MaxClientSessions';
CURRENT_VALUE
--------------50
(1 row)
When the session no longer appears in the SESSIONS table, disconnect and run the Stop
Database command.
5. Restart the database.
6. Restore the MaxClientSessions parameter to its original value:
=> ALTER DATABASE mydb SET MaxClientSessions = 50;
See Also
l
CLOSE_ALL_SESSIONS
CONFIGURATION_PARAMETERS
SQLReference Manual
SQL Functions
SESSIONS
SHUTDOWN
l
l
GET_NUM_ACCEPTED_ROWS
Returns the number of rows loaded into the database for the last completed load for the current
session. GET_NUM_ACCEPTED_ROWS is a meta-function. Do not use it as a value in an
INSERT query.
The number of accepted rows is not available for a load that is currently in process. Check the
LOAD_STREAMS system table for its status.
Also, this meta-function supports only loads from STDIN or a single file on the initiator. You cannot
use GET_NUM_ACCEPTED_ROWS for multi-node loads.
Syntax
GET_NUM_ACCEPTED_ROWS();
Privileges
None
Note: The data regarding accepted rows from the last load during the current session does not
persist, and is lost when you initiate a new load.
Examples
This examples shows the number of accepted rows from the vmart_load_data.sql meta-command.
=> \i vmart_load_data.sql;
=> SELECT GET_NUM_ACCEPTED_ROWS ();
GET_NUM_ACCEPTED_ROWS
----------------------300000
(1 row)
SQLReference Manual
SQL Functions
See Also
l
GET_NUM_REJECTED_ROWS
GET_NUM_REJECTED_ROWS
Returns the number of rows that were rejected during the last completed load for the current
session. GET_NUM_REJECTED_ROWS is a meta-function. Do not use it as a value in an
INSERT query.
Rejected row information is unavailable for a load that is currently running. The number of rejected
rows is not available for a load that is currently in process. Check the LOAD_STREAMS system
table for its status.
Also, this meta-function supports only loads from STDIN or a single file on the initiator. You cannot
use GET_NUM_REJECTED_ROWS for multi-node loads.
Syntax
GET_NUM_REJECTED_ROWS();
Privileges
None
Note: The data regarding rejected rows from the last load during the current session does not
persist, and is dropped when you initiate a new load.
Examples
This example shows the number of rejected rows from the vmart_load_data.sql meta-command.
=>
\i vmart_load_data.sql
SQLReference Manual
SQL Functions
See Also
l
GET_NUM_ACCEPTED_ROWS
INTERRUPT_STATEMENT
Interrupts the specified statement (within an external session), rolls back the current transaction,
and writes a success or failure message to the log file.
Syntax
INTERRUPT_STATEMENT( 'session_id ', statement_id )
Parameters
session_id
Specifies the session to interrupt. This identifier is unique within the cluster at
any point in time.
statement_id
Privileges
Must be a superuser.
Notes
l
If the statement_id is valid, the statement is interruptible. The command is successfully sent
and returns a success message. Otherwise the system returns an error.
Messages
The following list describes messages you might encounter:
SQLReference Manual
SQL Functions
Message
Meaning
This message
indicates
success.
The session ID
argument to the
interrupt
command does
not match a
running session.
The statement ID
does not match (or
no longer
matches) the ID of
a running
statement (if any).
The statement is
DDL or otherwise
non-interruptible.
The session is
internal, and only
statements run by
external sessions
can be interrupted.
Examples
Two user sessions are open. RECORD 1 shows user session running SELECT FROM SESSION, and
RECORD 2 shows user session running COPY DIRECT:
=> SELECT * FROM SESSIONS;
-[ RECORD 1 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
SQLReference Manual
SQL Functions
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
transaction_description
| user dbadmin (select * from sessions;)
statement_start
| 2011-01-03 15:36:13.896288
statement_id
| 10
last_statement_duration_us | 14978
current_statement
| select * from sessions;
ssl_state
| None
authentication_method
| Trust
-[ RECORD 2 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0003
user_name
| dbadmin
client_hostname
| 127.0.0.1:56367
client_pid
| 1191
login_timestamp
| 2011-01-03 15:31:44.939302-05
session_id
| stress06-25663:0xbec
client_label
|
transaction_start
| 2011-01-03 15:34:51.05939
transaction_id
| 54043195528458775
transaction_description
| user dbadmin (COPY Mart_Fact FROM '/data/Mart_Fact.tbl'
DELIMITER '|' NULL '\\n' DIRECT;)
statement_start
| 2011-01-03 15:35:46.436748
statement_id
| 5
last_statement_duration_us | 1591403
current_statement
| COPY Mart_Fact FROM '/data/Mart_Fact.tbl' DELIMITER '|'
NULL '\\n' DIRECT;
ssl_state
| None
authentication_method
| Trust
Verify that the interrupted statement is no longer active by looking at the current_statement column
in the SESSIONS system table. This column becomes blank when the statement has been
interrupted:
=> SELECT * FROM SESSIONS;
-[ RECORD 1 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0001
user_name
| dbadmin
client_hostname
| 127.0.0.1:52110
client_pid
| 4554
login_timestamp
| 2011-01-03 14:05:40.252625-05
session_id
| stress04-4325:0x14
client_label
|
transaction_start
| 2011-01-03 14:05:44.325781
transaction_id
| 45035996273728326
SQLReference Manual
SQL Functions
transaction_description
| user dbadmin (select * from sessions;)
statement_start
| 2011-01-03 15:36:13.896288
statement_id
| 10
last_statement_duration_us | 14978
current_statement
| select * from sessions;
ssl_state
| None
authentication_method
| Trust
-[ RECORD 2 ]--------------+---------------------------------------------------node_name
| v_vmartdb_node0003
user_name
| dbadmin
client_hostname
| 127.0.0.1:56367
client_pid
| 1191
login_timestamp
| 2011-01-03 15:31:44.939302-05
session_id
| stress06-25663:0xbec
client_label
|
transaction_start
| 2011-01-03 15:34:51.05939
transaction_id
| 54043195528458775
transaction_description
| user dbadmin (COPY Mart_Fact FROM '/data/Mart_Fact.tbl'
DELIMITER '|' NULL '\\n' DIRECT;)
statement_start
| 2011-01-03 15:35:46.436748
statement_id
| 5
last_statement_duration_us | 1591403
current_statement
|
ssl_state
| None
authentication_method
| Trust
See Also
l
SESSIONS
Managing Sessions
Configuration Parameters
RELEASE_ALL_JVM_MEMORY
Forces all sessions to release the memory consumed by their Java Virtual Machines (JVM).
Syntax
RELEASE_ALL_JVM_MEMORY();
Permissions
Must be a superuser.
SQLReference Manual
SQL Functions
Example
The following example demonstrates viewing the JVMmemory use in all open sessions, then
calling RELEASE_ALL_JVM_MEMORY()to release the memory:
=> select user_name,jvm_memory_kb FROM V_MONITOR.SESSIONS;
user_name | jvm_memory_kb
-----------+--------------dbadmin
|
79705
(1 row)
=> SELECT RELEASE_ALL_JVM_MEMORY();
RELEASE_ALL_JVM_MEMORY
----------------------------------------------------------------------------Close all JVM sessions command sent. Check v_monitor.sessions for progress.
(1 row)
=> SELECT user_name,jvm_memory_kb FROM V_MONITOR.SESSIONS;
user_name | jvm_memory_kb
-----------+--------------dbadmin
|
0
(1 row)
See Also
l
RELEASE_JVM_MEMORY
RELEASE_JVM_MEMORY
Terminates a Java Virtual Machine (JVM), making available the memory the JVM was using.
Syntax
RELEASE_JVM_MEMORY();
Privileges
None.
Examples
User session opened. RECORD 2 shows the user session running COPY DIRECT statement.
=> SELECT RELEASE_JVM_MEMORY();
SQLReference Manual
SQL Functions
release_jvm_memory
----------------------------------------Java process killed and memory released
(1 row)
See Also
l
RELEASE_ALL_JVM_MEMORY
SQLReference Manual
SQL Functions
ANALYZE_EXTERNAL_ROW_COUNT
ANALYZE_EXTERNAL_ROW_COUNTcalculates the exact number of rows in an external table.
ANALYZE_EXTERNAL_ROW_COUNTruns in the background. To cancel row count analysis,
press Ctrl+C in a vsql shell, or call the INTERRUPT_STATEMENT() function.
You cannot calculate the row count on external tables using DO_TM_TASK('ANALYZE_ROW_
COUNT').
Syntax
ANALYZE_STATISTICS [ ('') ... | ( '[ [ db-name.]schema.]table' ) ]
Parameters
''
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Specifies the name of the external table for which to calculate the exact
row count.
Privileges
Any INSERT/UPDATE/DELETE privilege on the external table
Examples
The following queries show how ANALYZE_EXTERNAL_ROW_COUNT calculates the exact row
count for all external tables.The function then calculates the exact row count for the loader_
rejects table:
SQLReference Manual
SQL Functions
See Also
l
ANALYZE_HISTOGRAM
ANALYZE_STATISTICS
ANALYZE_WORKLOAD
DROP_STATISTICS
DROP_EXTERNAL_ROW_COUNT
EXPORT_STATISTICS
IMPORT_STATISTICS
INTERRUPT_STATEMENT
VALIDATE_STATISTICS
ANALYZE_HISTOGRAM
Collects and aggregates data samples and storage information from all nodes that store projections
associated with the specified table or column.
If the function returns successfully, HP Vertica writes the statistics to the catalog. The query
optimizer uses this collected data to recommend the best possible plan to execute a query. Without
analyzing table statistics, the query optimizer assumes uniform distribution of data values and
equal storage usage for all projections.
ANALYZE_HISTOGRAM is a DDL operation that auto-commits the current transaction, if any. The
ANALYZE_HISTOGRAM function reads a variable amount of disk contents to aggregate sample
data for statistical analysis. Use the function's percent float parameter to specify the total disk
space from which HP Vertica collects sample data. The ANALYZE_STATISTICS function returns
similar data but uses a fixed disk space amount (10 percent). Analyzing more than 10 percent disk
space takes proportionally longer to process, but produces a higher level of sampling accuracy.
ANALYZE_HISTOGRAM is supported on local temporary tables, but not on global temporary
tables.
SQLReference Manual
SQL Functions
Syntax
ANALYZE_HISTOGRAM ('') ... | ( '[ [ db-name.]schema.]table [.column-name ]' [, percent ] )
Return Value
0Success. If an error occurs, refer to vertica.log for details.
Parameters
''
[[db-name.]schema.]
table
Specifies the name of the table and collects statistics for all projections of
that table. If you are using more than one schema, specify the schema that
contains the projection, as noted in the [[db-name.]schema.] entry.
[.column-name]
percent
[Optional] Specifies what percentage of data to read from disk (not the
amount of data to analyze). Specify a float from 1100, such as 33.3. By
default, the function reads 10% of the table data from disk.
For more information, see Collecting Statistics in the Administrator's
Guide.
SQLReference Manual
SQL Functions
Privileges
l
To obtain...
ANALYZE_
A fixed-size statistical data sampling (10 percent per disk). This function returns
STATISTICS
ANALYZE_
A specified percentage of disk data sampling (from 1100). If you analyze more
HISTOGRAM than 10 percent data per disk, this function is more accurate than ANALYZE_
STATISTICS, but requires proportionately longer to return statistics.
ANALYZE_
EXTERNAL_
ROW_
COUNT
Analyzing Results
To retrieve hints about underperforming queries and the associated root causes, use the
ANALYZE_WORKLOAD function. This function runs the Workload Analyzer and returns tuning
recommendations, such as "run analyze_statistics on schema.table.column". You or your
database administrator should act upon the tuning recommendations.
You can also find database tuning recommendations on the Management Console.
Canceling ANALYZE_HISTOGRAM
You can cancel this function during analysis by issuing CTRL-C in a vsql shell or by invoking the
INTERRUPT_STATEMENT() function.
SQLReference Manual
SQL Functions
Usage Considerations
By default, HP Vertica analyzes more than one column (subject to resource limits) in a single-query
execution plan to:
l
Help speed up analysis of relatively small tables that have a large number of columns
Examples
In this example, the ANALYZE_STATISTICS() function reads 10 percent of the disk data. This is
the static default value for this function. The function returns 0 for success:
=> SELECT ANALYZE_STATISTICS('shipping_dimension.shipping_key');
ANALYZE_STATISTICS
-------------------0
(1 row)
This example uses ANALYZE_HISTOGRAM () without specifying a percentage value. Since this
function has a default value of 10 percent, it returns the identical data as the ANALYZE_
STATISTICS() function, and returns 0 for success:
=> SELECT ANALYZE_HISTOGRAM('shipping_dimension.shipping_key');
ANALYZE_HISTOGRAM
------------------0
This example uses ANALYZE_HISTOGRAM (), specifying its percent parameter as 100, indicating
to read the entire disk to gather data. After the function performs a full column scan, it returns 0 for
success:
=> SELECT ANALYZE_HISTOGRAM('shipping_dimension.shipping_key', 100);
ANALYZE_HISTOGRAM
------------------0
SQLReference Manual
SQL Functions
------------------0
The following query calculates the exact number of rows in the external table loader_rejects:
=> SELECT ANALYZE_EXTERNAL_ROW_COUNT('loader_rejects');
ANALYZE_EXTERNAL_ROW_COUNT
---------------------------0
See Also
l
ANALYZE_STATISTICS
ANALYZE_WORKLOAD
DROP_STATISTICS
EXPORT_STATISTICS
IMPORT_STATISTICS
INTERRUPT_STATEMENT
ANALYZE_STATISTICS
Collects and aggregates data samples and storage information from all nodes that store projections
associated with the specified table or column.
If the function returns successfully, HP Vertica writes the statistics to the catalog. The query
optimizer uses this collected data to recommend the best possible plan to execute a query. Without
analyzing table statistics, the query optimizer assumes uniform distribution of data values and
equal storage usage for all projections.
ANALYZE_STATISTICS is a DDL operation that auto-commits the current transaction, if any. The
ANALYZE_STATISTICS function reads a fixed, 10 percent of disk contents to aggregate sample
data for statistical analysis. To obtain a larger (or smaller) data sampling, use the ANALYZE_
HISTOGRAM function, which lets you specify the percent of disk to read. Analyzing more that 10
percent disk space takes proportionally longer to process but results in a higher level of sampling
accuracy. ANALYZE_STATISTICSis supported on local temporary tables, but not on global
temporary tables.
SQLReference Manual
SQL Functions
Syntax
ANALYZE_STATISTICS [ ('') ... | ( '[ [ db-name.]schema.]table [.column-name ]' ) ]
Parameters
''
[[db-name.]schema.]
table
Specifies the name of the table and collects statistics for all projections of
that table.
If you are using more than one schema, specify the schema that contains
the projection, as notes in the [[db-name.]schema.] entry.
[.column-name]
Privileges
l
SQLReference Manual
SQL Functions
Use this
function...
To obtain...
ANALYZE_
A fixed-size statistical data sampling (10 percent per disk). This function returns
STATISTICS
ANALYZE_
A specified percentage of disk data sampling (from 1100). If you analyze more
HISTOGRAM than 10 percent data per disk, this function is more accurate than ANALYZE_
STATISTICS, but requires proportionately longer to return statistics.
ANALYZE_
EXTERNAL_
ROW_
COUNT
Analyzing Results
To retrieve hints about underperforming queries and the associated root causes, use the
ANALYZE_WORKLOAD function. This function runs the Workload Analyzer and returns tuning
recommendations, such as "run analyze_statistics on schema.table.column". You or your
database administrator should act upon the tuning recommendations.
You can also find database tuning recommendations on the Management Console.
Usage Considerations
l
You cannot run ANALYZE_STATISTICSon a anchor table for a live aggregate projection or
Top-K projection.
By default, HP Vertica analyzes more than one column (subject to resource limits) in a singlequery execution plan to:
SQLReference Manual
SQL Functions
Help speed up analysis of relatively small tables that have a large number of columns
Examples
The following examples show you how to compute statistics using the ANALYZE_STATISTICS
function.
Compute statistics on all projections in the VMart database:
=> SELECT ANALYZE_STATISTICS ('');
analyze_statistics
-------------------0
(1 row)
See Also
l
ANALYZE_HISTOGRAM
ANALYZE_WORKLOAD
SQLReference Manual
SQL Functions
ANALYZE_EXTERNAL_ROW_COUNT
DROP_STATISTICS
DROP_EXTERNAL_ROW_COUNT
EXPORT_STATISTICS
IMPORT_STATISTICS
INTERRUPT_STATEMENT
VALIDATE_STATISTICS
DROP_EXTERNAL_ROW_COUNT
Removes the exact row count statistic for the specified external table.
DROP_EXTERNAL_ROW_COUNTruns in the background. To cancel row count analysis, press
Ctrl+C in a vsql shell or call the INTERRUPT_STATEMENT() function.
It can be time consuming to regenerate statistics once they have been dropped.
Syntax
DROP_EXTERNAL_ROW_COUNT [ ('') | ('[[db-name.]schema-name.]table' ];
Parameters
''
Empty string. Specifies that HP Vertica drop the exact row count statistic
for all external tables.
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Specifies the name of the external table for which to remove the exact row
count.
SQLReference Manual
SQL Functions
Privileges
l
Examples
This example shows how you use the command to drop base statistics for the external table in the
current schema, loader_rejects:
=> SELECT DROP_EXTERNAL_ROW_COUNT('loader_rejects');
See Also
l
ANALYZE_STATISTICS
ANALYZE_EXTERNAL_ROW_COUNT
DROP_STATISTICS
EXPORT_STATISTICS
IMPORT_STATISTICS
VALIDATE_STATISTICS
DROP_STATISTICS
Removes statistics for the specified table and lets you optionally specify the category of statistics
to drop.
Syntax
DROP_STATISTICS { ('') | ('[[db-name.]schema-name.]table' [, {'BASE' | 'HISTOGRAMS' | 'ALL'}
])};
SQLReference Manual
SQL Functions
Parameters
''
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Drops statistics for all projections within the specified table. When using
more than one schema, specify the schema that contains the table with
the projections you want to delete, as noted in the syntax.
CATEGORY
Privileges
l
Usage Considerations
Once dropped, statistics can be time consuming to regenerate.
If you want the query optimizer to use the default statistics instead of the statistics that ANALYZE_
STATISTICSgenerates, use DROP_STATISTICSto drop the generated statistics for one more
projections.
Examples
The following command analyzes all statistics on all tables in the database:
SQLReference Manual
SQL Functions
This command drops base statistics for the table store_sales_fact in the store schema:
=> SELECT DROP_STATISTICS('store.store_sales_fact', 'BASE');
DROP_STATISTICS
----------------0
(1 row)
See Also
l
ANALYZE_STATISTICS
ANALYZE_EXTERNAL_ROW_COUNT
DROP_EXTERNAL_ROW_COUNT
EXPORT_STATISTICS
IMPORT_STATISTICS
VALIDATE_STATISTICS
SQLReference Manual
SQL Functions
EXPORT_STATISTICS
Generates an XML file that contains statistics for the database. You can optionally export statistics
on a single database object (table, projection, or table column).
Before you export statistics for the database, run ANALYZE_STATISTICS() to automatically
collect the most up to date statistics information.
Syntax
EXPORT_STATISTICS ( 'destination' [, '[[ db-name.]schema.]object [.column-name ]'])
Parameters
destination
Specifies the path and name of the XML output file. An empty string
returns the script to the screen.If you do not use an absolute path, the path
you give will be interpreted relative to the database's catalog directory.
(For example, if you just give a file name, the file will be written there.)
[[db-name.]schema.]
object
Specifies the name of the object (table or projection) to export and exports
statistics for that object. If the object is a table, this function exports
statistics for all projections of that table.
Note: If you are using more than one schema, specify the schema
that contains the table, as noted in the [[db-name.]schema.] entry.
[.column-name]
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Examples
The following statement exports statistics on the VMart example database to a file:
vmart=> SELECT EXPORT_STATISTICS('/opt/vertica/examples/VMart_Schema/vmart_stats.xml');
EXPORT_STATISTICS
----------------------------------Statistics exported successfully
(1 row)
The next statement exports statistics on a single column (price) from a table called food:
=> SELECT EXPORT_STATISTICS('/opt/vertica/examples/VMart_Schema/price.xml',
'food.price');
----------------------------------EXPORT_STATISTICS
----------------------------------Statistics exported successfully
(1 row)
See Also
l
ANALYZE_STATISTICS
DROP_STATISTICS
IMPORT_STATISTICS
VALIDATE_STATISTICS
IMPORT_STATISTICS
Imports statistics from the XML file generated by the EXPORT_STATISTICS command.
SQLReference Manual
SQL Functions
Syntax
IMPORT_STATISTICS ( 'XML_statistics_file' )
Parameters
XML_statistics_file
Specifies the path and name of the XML input file (which is the output of
EXPORT_STATISTICS function), type VARCHAR.
Privileges
Must be a superuser.
Usage Considerations
l
Imported statistics override existing statistics for all projections on the table referenced in the
XMLfile.
IMPORT_STATISTICS imports only valid statistics. If the source file has invalid statistics for a
specific column, those statistics are not imported and a warning occurs. If the statistics file has
an invalid structure, the import operation fails. To check a statistics file for validity, run
VALIDATE_STATISTICS.
Example
Import the statistics for the VMart database that EXPORT_STATISTICSsaved.
=> SELECT IMPORT_STATISTICS('/opt/vertica/examples/VMart_Schema/vmart_stats.xml');
IMPORT_STATISTICS
---------------------------------------------------------------------------Importing statistics for projection date_dimension_super column date_key failure (stats
did not contain row counts)
Importing statistics for projection date_dimension_super column date failure (stats did
not contain row counts)
Importing statistics for projection date_dimension_super column full_date_description
failure (stats did not contain row counts)
...
(1 row)
SQLReference Manual
SQL Functions
See Also
l
ANALYZE_STATISTICS
DROP_STATISTICS
EXPORT_STATISTICS
VALIDATE_STATISTICS
Validates statistics in the XML file generated by the EXPORT_STATISTICS command.
Syntax
VALIDATE_STATISTICS ( 'XML_statistics_file' )
Parameters
XML_statistics_file
Specifies the path and name of the XML file that contains the statistics
you want to validate, type VARCHAR.
Privileges
Must be a superuser.
Usage Considerations
l
IMPORT_STATISTICS imports only valid statistics. If the source file has invalid statistics for a
specific column, those statistics are not imported and a warning occurs. To identify the invalid
statistics, run VALIDATE_STATISTICS.
Example:Valid Statistics
The following example shows the results when the statistics are valid:
=> SELECT EXPORT_STATISTICS('cust_dim_stats.xml','customer_dimension');
EXPORT_STATISTICS
----------------------------------Statistics exported successfully
SQLReference Manual
SQL Functions
(1 row)
=> SELECT VALIDATE_STATISTICS('cust_dim_stats.xml');
VALIDATE_STATISTICS
--------------------(1 row)
---------------------
(1 row)
SQLReference Manual
SQL Functions
See Also
l
ANALYZE_STATISTICS
DROP_STATISTICS
EXPORT_STATISTICS
IMPORT_STATISTICS
SQLReference Manual
SQL Functions
ADD_LOCATION
Adds a storage location to the cluster. Use this function to add a new location, optionally with a
location label. You can also add a location specifically for user access, and then grant one or more
users access to the location.
Deprecated: ADD_LOCATIONhas been deprecated and will be removed in a future release.
Use the CREATE LOCATIONstatement instead.
Syntax
ADD_LOCATION ( 'path'
Parameters
path
node
[Optional] Indicates the cluster node on which a storage location resides. If you
omit this parameter, the function adds the location to only the initiator node.
Specifying the node parameter as an empty string ('') adds a storage location
to all cluster nodes in a single transaction.
Note: If you specify a node, you must also add a usage parameter.
SQLReference Manual
SQL Functions
usage
DATA: Stores only data files. Use this option for labeled storage locations.
USER: Allows non-dbadmin users access to the storage location for data
files (not temp files), once they are granted privileges. DO NOT create a
storage location for later use in a storage policy. Storage locations with
policies must be for DATA usage. Also, note that this keyword is orthogonal
to DATA and TEMP, and does not specify a particular usage, other than
being accessible to non-dbadmin users with assigned privileges. You cannot
alter a storage location to or from USER usage.
Note: You can use this parameter only in conjunction with the node option.
If you omit the usage parameter, the default is DATA,TEMP.
location_label
Privileges
Must be a superuser.
Example
This example adds a location that stores data and temporary files on the initiator node:
SQLReference Manual
SQL Functions
This example shows you how to add a new DATA storage location with a label, SSD. The label
identifies the location when you create storage policies. Specifying the ALLNODES keyword adds
the storage location to all nodes in a single transaction:
=> CREATE LOCATION '/home/dbadmin/SSD/schemas' ALL NODES USAGE 'DATA'
LABEL 'SSD';
See Also
l
ALTER_LOCATION_USE
DROP_LOCATION
RESTORE_LOCATION
RETIRE_LOCATION
ALTER_LOCATION_USE
Alters the type of files that can be stored at the specified storage location.
Syntax
ALTER_LOCATION_USE ( 'path' , 'node' , 'usage' )
Parameters
path
SQLReference Manual
SQL Functions
node
[Optional] The HP Vertica node with the storage location. Specifying the node parameter
as an empty string ('') alters the location across all cluster nodes in a single transaction.
usage
DATA: The storage location stores only data files. This is the supported use for both a
USER storage location, and a labeled storage location.
TEMP: The location stores only temporary files that are created during loads or
queries.
Privileges
Must be a superuser.
Example
The following example alters the storage location across all cluster nodes to store only data:
=> SELECT ALTER_LOCATION_USE ('/thirdVerticaStorageLocation/' , '' , 'DATA');
See Also
l
SQLReference Manual
SQL Functions
ADD_LOCATION
DROP_LOCATION
RESTORE_LOCATION
RETIRE_LOCATION
ALTER_LOCATION_LABEL
Alters the location label. Use this function to add, change, or remove a location label. You change a
location label only if it is not currently in use as part of a storage policy.
You can use this function to remove a location label. However, you cannot remove a location label if
the name being removed is used in a storage policy, and the location from which you are removing
the label is the last available storage for its associated objects.
Note: If you label an existing storage location that already contains data, and then include the
labeled location in one or more storage policies, existing data could be moved. If the ATM
determines data stored on a labeled location does not comply with a storage policy, the ATM
moves the data elsewhere.
Syntax
ALTER_LOCATION_LABEL ( 'path' , 'node' , 'location_label' )
Parameters
path
node
location_label
Specifies a storage label as a string, for instance SSD. You can change an
existing label assigned to a storage location, or add a new label. Specifying an
empty string ('') removes an existing label.
SQLReference Manual
SQL Functions
Privileges
Must be a superuser.
Example
The following example alters (or adds) the label SSD to the storage location at the given path on all
cluster nodes:
VMART=> select alter_location_label('/home/dbadmin/SSD/tables','', 'SSD');
alter_location_label
--------------------------------------/home/dbadmin/SSD/tables label changed.
(1 row)
See Also
l
CLEAR_OBJECT_STORAGE_POLICY
SET_OBJECT_STORAGE_POLICY
CLEAR_CACHES
Clears the HP Vertica internal cache files.
Syntax
CLEAR_CACHES ( )
Privileges
Must be a superuser.
Notes
If you want to run benchmark tests for your queries, in addition to clearing the internal HP Vertica
cache files, clear the Linux file system cache. The kernel uses unallocated memory as a cache to
hold clean disk blocks. If you are running version 2.6.16 or later of Linux and you have root access,
you can clear the kernel filesystem cache as follows:
SQLReference Manual
SQL Functions
2. Writing to the drop_caches file causes the kernel to drop clean caches, dentries, and inodes
from memory, causing that memory to become free, as follows:
n
Example
The following example clears the HP Vertica internal cache files:
=> SELECT CLEAR_CACHES();
CLEAR_CACHES
-------------Cleared
(1 row)
CLEAR_OBJECT_STORAGE_POLICY
Removes an existing storage policy. The specified object will no longer use a default storage
location. Any existing data stored currently at the labeled location in the object's storage policy is
moved to default storage during the next TM moveout operation.
Syntax
CLEAR_OBJECT_STORAGE_POLICY ( 'object_name' [,'key_min', 'key_max'] [, 'enforce_storage_move'
] )
SQLReference Manual
SQL Functions
Parameters
object_name
key_min, key_max
Specifies the table partition key value ranges stored at the labeled
location. These parameters are applicable only when object_name is a
table.
enforce_storage_move
[Optional] If true, moves the storage containers that belong to this object
to a new location immediately. If false (the default), this move occurs
automatically sometime after the next moveout operation.
Privileges
Must be a superuser.
Examples
This example shows how to clear the storage policy for the object lineorder. Changes take effect
after the next moveout:
release=> select clear_object_storage_policy('lineorder');
clear_object_storage_policy
----------------------------------Default storage policy cleared.
(1 row)
See Also
l
ALTER_LOCATION_LABEL
SET_OBJECT_STORAGE_POLICY
DROP_LOCATION
Removes the specified storage location.
Syntax
DROP_LOCATION ( 'path' , 'node' )
SQLReference Manual
SQL Functions
Parameters
path
node
The HP Vertica node where the location is available. A value of "" (an empty string) means
to perform this operation on all nodes.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Examples
The following example shows how to drop a storage location on node3, which was used to store
temp files:
=> SELECT DROP_LOCATION('/data' , 'node3');
See Also
l
ADD_LOCATION
ALTER_LOCATION_USE
RESTORE_LOCATION
RETIRE_LOCATION
ENFORCE_OBJECT_STORAGE_POLICY
Applies object storage policies immediately, instead of waiting for the Tuple Mover to perform the
next moveout. Calling this function is equivalent to setting the enforce_storage_move parameter
on related meta-functions. You typically use this function as the last step before dropping a storage
location.
This function invokes the Tuple Mover on a one-time basis.
Syntax
ENFORCE_OBJECT_STORAGE_POLICY ( 'object_name', [, 'key_min', 'key_max'] )
SQLReference Manual
SQL Functions
Parameters
object_name
Identifies the database object whose storage policies are to be applied. The
object_name parameter can resolve to a database, schema, or table.
key_min, key_max
Privileges
Must be the object owner to enforce the storage policy and have access to the storage location.
Examples
This example shows how to apply storage-policy updates to the test table:
=> select enforce_object_storage_policy("test");
See Also
l
CLEAR_OBJECT_STORAGE_POLICY
RETIRE_LOCATION
DROP_LOCATION
MEASURE_LOCATION_PERFORMANCE
Measures disk performance for the location specified.
Syntax
MEASURE_LOCATION_PERFORMANCE ( 'path'
, 'node' )
SQLReference Manual
SQL Functions
Parameters
path
node
Privileges
Must be a superuser.
Notes
l
To get a list of all node names on your cluster, query the V_MONITOR.DISK_STORAGE
system table:
=> SELECT node_name from DISK_STORAGE;
node_name
------------------v_vmartdb_node0004
v_vmartdb_node0004
v_vmartdb_node0005
v_vmartdb_node0005
v_vmartdb_node0006
v_vmartdb_node0006
(6 rows)
If you intend to create a tiered disk architecture in which projections, columns, and partitions are
stored on different disks based on predicted or measured access patterns, you need to measure
storage location performance for each location in which data is stored. You do not need to
measure storage location performance for temp data storage locations because temporary files
are stored based on available space.
The method of measuring storage location performance applies only to configured clusters. If
you want to measure a disk before configuring a cluster see Measuring Storage Performance.
Storage location performance equates to the amount of time it takes to read and write 1MB of
data from the disk. This time equates to:
IO time = Time to read/write 1MB + Time to seek = 1/Throughput + 1/Latency
Throughput is the average throughput of sequential reads/writes (units in MB per second)
SQLReference Manual
SQL Functions
Latency is for random reads only in seeks (units in seeks per second)
Note: The IO time of a faster storage location is less than a slower storage location.
Example
The following example measures the performance of a storage location on v_vmartdb_node0004:
=> SELECT MEASURE_LOCATION_PERFORMANCE('/secondVerticaStorageLocation/' , 'v_vmartdb_
node0004');
WARNING: measure_location_performance can take a long time. Please check logs for
progress
measure_location_performance
-------------------------------------------------Throughput : 122 MB/sec. Latency : 140 seeks/sec
See Also
l
CREATE LOCATION
ALTER_LOCATION_USE
RESTORE_LOCATION
RETIRE_LOCATION
MOVE_RETIRED_LOCATION_DATA
Moves all data from either a single retired storage location or all retired storage locations in the
database. This function migrates the data to non-retired storage locations based on the storage
policies of the objects whose data is stored in the location.
Syntax
MOVE_RETIRED_LOCATION_DATA(['location_path'] ['node'])
SQLReference Manual
SQL Functions
Arguments
['location_path']
['node']
Privileges
The user must be a superuser .
Usage Considerations
This function forces the Tuple Mover to move data out of the retired location or locations.
Normally, the Tuple Mover only migrates data out of retired storage locations as it consolidates data
into larger ROS containers. This function does not return until all of the data has moved off of the
retired storage location or locations.
Examples
The following example:
1. Queries the STORAGE_LOCATIONS system table to show which storage locations are
retired.
2. Queries the STORAGE_CONTAINERS system table to show the current location of the
messages table, which is currently stored in the retired storage location named ssd.
3. Calls MOVE_RETIRED_LOCATION_DATA to move the data off of the ssd storage location.
4. Repeats the previous query to show the storage location of the messages table.
SQLReference Manual
SQL Functions
See Also
l
RETIRE_LOCATION
RESTORE_LOCATION
RESTORE_LOCATION
Restores a storage location that was previously retired with RETIRE_LOCATION.
SQLReference Manual
SQL Functions
Syntax
RESTORE_LOCATION ( 'path', 'node' )
Parameters
path
node
The HP Vertica node where the retired location is available. A value of "" (an empty string)
means to perform this operation on all nodes. The operation fails if you have dropped any
locations.
Privileges
Must be a superuser.
Examples
The following example shows how to restore the retired storage location on node3:
=> SELECT RESTORE_LOCATION ('/thirdHP VerticaStorageLocation/' , 'v_vmartdb_node0004');
See Also
l
CREATE LOCATION
ALTER_LOCATION_USE
SQLReference Manual
SQL Functions
DROP_LOCATION
RETIRE_LOCATION
RETIRE_LOCATION
Makes the specified storage location inactive.
Syntax
RETIRE_LOCATION ( 'path', 'node' [, 'enforce_storage_move' ] )
Parameters
path
node
enforce_storage_move
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
/data/node02. To retire a location on all nodes, use the same path that you used to create it (/data in
this example).
No new data is stored at the retired location, unless you first restore it with the RESTORE_
LOCATION() function.
By default, if the storage location being retired contains stored data, the data is not moved.
Thus, you cannot drop the storage location. Instead, HP Vertica removes the stored data
through one or more mergeouts. If you want to drop the location immediately after retiring it, add
the enforce_storage_move parameter, using a value of true.
If the storage location being retired is used only for temp files or you use enforce_storage_move,
you can drop the location. See Dropping Storage Locations in the Administrators Guide and the
DROP_LOCATION() function.
Examples
The following examples show two approaches to retiring a storage location.
You can specify that a storage location be dropped automatically at a future time:
=> SELECT RETIRE_LOCATION ('/data' , 'v_vmartdb_node0004');
SQLReference Manual
SQL Functions
See Also
l
CREATE LOCATION
ALTER_LOCATION_USE
DROP_LOCATION
RESTORE_LOCATION
SET_LOCATION_PERFORMANCE
Sets disk performance for the location specified.
Syntax
SET_LOCATION_PERFORMANCE ( 'path' , 'node' , 'throughput' , 'average_latency' )
Parameters
path
node
throughput
average_latency
Specifies the average latency for the location. The average_latency must be 1
or more.
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
To obtain the throughput and average latency for the location, run the MEASURE_LOCATION_
PERFORMANCE() function before you attempt to set the location's performance.
Example
The following example sets the performance of a storage location on node2 to a throughput of 122
megabytes per second and a latency of 140 seeks per second.
=> SELECT SET_LOCATION_PERFORMANCE('/secondVerticaStorageLocation/','node2','122','140');
See Also
l
CREATE LOCATION
MEASURE_LOCATION_PERFORMANCE
SET_OBJECT_STORAGE_POLICY
Creates or changes an object storage policy by associating a database object with a labeled
storage location.
Note: You cannot create a storage policy on a USER type storage location.
Syntax
SET_OBJECT_STORAGE_POLICY ( 'object_name', 'location_label' [, 'key_min', 'key_max'] [,
enforce_storage_move] )
Parameters
object_name
SQLReference Manual
SQL Functions
location_label
key_min, key_max
enforce_storage_move
[Optional] Applicable only when setting a storage policy for an object that
has data stored at another labeled location. Specify this parameter as
true to move all existing storage data to the target location within this
function's transaction. This function does not return until the operation is
complete.
Privileges
Must be the object owner to set the storage policy and have access to the storage location.
SQLReference Manual
SQL Functions
Examples
This example shows how to set a storage policy for the table states to use the storage labeled SSD
as its default location:
VMART=> select set_object_storage_policy ('states', 'SSD');
set_object_storage_policy
----------------------------------Default storage policy set.
(1 row)
See Also
l
ALTER_LOCATION_LABEL
CLEAR_OBJECT_STORAGE_POLICY
SQLReference Manual
SQL Functions
DO_TM_TASK
Runs a Tuple Mover operation on one or more projections defined on the specified table.
Tip: You do not need to stop the Tuple Mover to run this function.
Syntax
DO_TM_TASK ( 'task' [ , '[[db-name.]schema.]table' |
'[[db-name.]schema.]projection' ] )
Parameters
task
Note: You cannot analyze the row count of external tables with
this option. You must use ANALYZE_EXTERNAL_ROW_
COUNT.
SQLReference Manual
SQL Functions
[[db-name.]schema.]
table
Runs a tuple mover operation for all projections within the specified table.
When using more than one schema, specify the schema that contains the
table with the projections you want to affect, as noted above.
projection
Privileges
l
Notes
DO_TM_TASK() is useful for moving out all projections from a table or database without having to
name each projection individually.
Examples
The following example performs a moveout of all projections for the t1 table:
=> SELECT DO_TM_TASK('moveout', 't1');
SQLReference Manual
SQL Functions
See Also
l
COLUMN_STORAGE
DROP_PARTITION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
SQLReference Manual
SQL Functions
ANALYZE_WORKLOAD
Runs the Workload Analyzer (WLA), a utility that analyzes system information held in system
tables.
The Workload Analyzer intelligently monitors the performance of SQL queries and workload history,
resources, and configurations to identify the root causes for poor query performance. Calling the
ANALYZE_WORKLOAD function returns tuning recommendations for all events within the scope
and time that you specify.
Tuning recommendations are based on a combination of statistics, system and data collector
events, and database-table-projection design. WLA's recommendations let database
administrators quickly and easily tune query performance.
See Understanding WLA Triggering Conditions in the Administrator's Guide for the most common
triggering conditions and recommendations.
Syntax
ANALYZE_WORKLOAD ( 'scope' [, 'since_time' | , save_data ] );
Note: The since_time and save_data arguments are optional, but mutually exclusive. You
cannot specify both arguments.
Parameters
scope
SQLReference Manual
SQL Functions
since_time
[Optional] Limits the object analysis for scope to begin at a specific time, up to, and
including, the current system status. If you omit the since_time parameter,
ANALYZE_WORKLOAD returns recommendations on events since the last recorded
time that you last called this function.
Note: You must explicitly cast strings used for the since_time parameter to
TIMESTAMP or TIMESTAMPTZ. For example:
SELECT ANALYZE_WORKLOAD('T1', '2010-10-04 11:18:15'::TIMESTAMPTZ);
SELECT ANALYZE_WORKLOAD('T1', TIMESTAMPTZ '2010-10-04 11:18:15');
save_data
Return Values
Column
Data type
Description
observation_
count
INTEGER
Integer for the total number of events observed for this tuning
recommendation. For example, if you see a return value of 1,
WLA is making its first tuning recommendation for the event
in 'scope'.
first_
observation_time
TIMESTAM
PTZ
last_
observation_time
TIMESTAM
PTZ
tuning_parameter
VARCHAR
SQLReference Manual
SQL Functions
Column
Data type
Description
tuning_
description
VARCHAR
tuning_command
VARCHAR
SQLReference Manual
SQL Functions
Column
Data type
Description
tuning_cost
VARCHAR
Privileges
Must be a superuser.
Examples
See Running ANALYZE_WORKLOAD() for Recommendations in the Administrator's Guide for
examples.
See Also
l
TUNING_RECOMMENDATIONS
Analyzing Workloads
CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY
Changes the run-time priority of a query that is actively running.
SQLReference Manual
SQL Functions
Syntax
CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY(TRANSACTION_ID, 'value')
Parameters
TRANSACTION_ID
'value'
Privileges
No special privileges required. However, non-super users can change the run-time priority of their
own queries only. In addition, non-superusers can never raise the run-time priority of a query to a
level higher than that of the resource pool.
Example
=> SELECT CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY(45035996273705748, 'low');
CHANGE_RUNTIME_PRIORITY
Changes the run-time priority of a query that is actively running. Note that, while this function is still
valid, you should instead use CHANGE_CURRENT_STATEMENT_RUNTIME_PRIORITY to change run-time
priority. CHANGE_RUNTIME_PRIORITY will be deprecated in a future release of Vertica.
Syntax
CHANGE_RUNTIME_PRIORITY(TRANSACTION_ID,STATEMENT_ID, 'value')
SQLReference Manual
SQL Functions
Parameters
TRANSACTION_ID
STATEMENT_ID
'value'
Privileges
No special privileges required. However, non-super users can change the run-time priority of their
own queries only. In addition, non-superusers can never raise the run-time priority of a query to a
level higher than that of the resource pool.
Example
=> SELECT CHANGE_RUNTIME_PRIORITY(45035996273705748, NULL, 'low');
CLEAR_CACHES
Clears the HP Vertica internal cache files.
Syntax
CLEAR_CACHES ( )
Privileges
Must be a superuser.
SQLReference Manual
SQL Functions
Notes
If you want to run benchmark tests for your queries, in addition to clearing the internal HP Vertica
cache files, clear the Linux file system cache. The kernel uses unallocated memory as a cache to
hold clean disk blocks. If you are running version 2.6.16 or later of Linux and you have root access,
you can clear the kernel filesystem cache as follows:
1. Make sure that all data is the cache is written to disk:
# sync
2. Writing to the drop_caches file causes the kernel to drop clean caches, dentries, and inodes
from memory, causing that memory to become free, as follows:
n
Example
The following example clears the HP Vertica internal cache files:
=> SELECT CLEAR_CACHES();
CLEAR_CACHES
-------------Cleared
(1 row)
SLEEP
Waits a specified number of seconds before executing another statement or command.
SQLReference Manual
SQL Functions
Syntax
SLEEP( seconds )
Parameters
seconds
The wait time, specified in one or more seconds (0 or higher) expressed as a positive
integer. Single quotes are optional; for example, SLEEP(3) is the same as SLEEP
('3').
Notes
l
This function returns value 0 when successful; otherwise it returns an error message due to
syntax errors.
Example
The following command suspends execution for 100 seconds:
=> SELECT SLEEP(100);
sleep
------0
(1 row)
SQLReference Manual
SQL Functions
SQLReference Manual
SQL Statements
SQL Statements
The primary structure of a SQL query is its statement. Multiple statements are separated by
semicolons; for example:
CREATE TABLE fact ( ..., date_col date NOT NULL, ...);
CREATE TABLE fact(..., state VARCHAR NOT NULL, ...);
IMPORTANT:When you copy or rename a table, access policies associated with the original table
are not included in the copied table. You must use ALTERACCESSPOLICY to copy the access
policies to the new table.
Syntax
ALTER ACCESS POLICY ON tablename
.. .FOR COLUMN columnname
... expression
... [ENABLE | DISABLE];
... | FOR COLUMN columname
...
COPY TO tablename;
Parameters
tablename
The name of the table that contains the access policy you want to enable, disable,
or copy.
columnname
The name of the column on which to enable or disable the access policy or the
name of the column you want to copy.
SQLReference Manual
SQL Statements
expression
Indicates whether to enable or disable the access policy at the table level. See
Enable Column Access at the Table Level.
Privileges
You must be a dbadmin user to alter an access policy.
Examples
Copy Access Policy from Table to Table
=> ALTER ACCESS POLICY on customer FOR COLUMN customer_number COPY TO customer_old;
ALTERAUTHENTICATION
Modifies the settings for a specified authentication method.
Syntax
ALTER
... |
... |
... |
... |
... |
AUTHENTICATION auth_method_name {
{ ENABLE | DISABLE }
{ LOCAL | HOST [ { TLS | NO TLS } host_ip_address ] }
RENAME TO new_auth_method_name
SET param=value[, ...]
PRIORITY value
SQLReference Manual
SQL Statements
Parameters
Parameter Name
Description
auth_method_name
ENABLE | DISABLE
RENAME TO new_auth_
method_name
SET param=value
Set a parameter name and value for the authentication method that
you are creating. Required only for LDAPand Ident authentication.
ALTERAUTHENTICATIONvalidates the parameters you enter.
SQLReference Manual
SQL Statements
Parameter Name
Description
PRIORITY value
Privileges
Must have DBADMIN privileges.
Examples
Enabling and Disabling Authentication Methods
This example uses ALTERAUTHENTICATIONto disable the v_ldap authentication method and
then enable it again:
=> ALTER AUTHENTICATION v_ldap DISABLE;
=> ALTER AUTHENTICATION v_ldap ENABLE;
SQLReference Manual
SQL Statements
When you set or modify LDAPor Ident parameters using ALTERAUTHENTICATION, HP Vertica
validates them.
This example changes the IPaddress and specifies the parameters for an LDAP authentication
method named Ldap1. Specify the bind parameters for the LDAPserver. HP Vertica connects to
the LDAP server, which authenticates the database client. If authentication succeeds, HP
Verticaauthenticates any users who have been associated with (granted) the Ldap1 authentication
method on the designated LDAPserver:
=> CREATE AUTHENTICATION Ldap1 METHOD 'ldap' HOST '172.16.65.196';
=> ALTER AUTHENTICATION Ldap1 SET host='ldap://172.16.65.177',
binddn_prefix='cn=', binddn_suffix=',dc=qa_domain,dc=com';
The next example specifies the parameters for an LDAP authentication method named Ldap2.
Specify the LDAPbind and search parameters. Sometimes, HP Vertica does not have enough
information to create the distinguished name (DN)for a user attempting to authenticate. In such
cases, you must specify to use LDAP bind and search:
=> CREATE AUTHENTICATION Ldap2 METHOD 'ldap' HOST '172.16.65.196';
=> ALTER AUTHENTICATION Ldap2 SET basedn='dc=qa_domain,dc=com',
binddn='cn=Manager,dc=qa_domain,
dc=com',search_attribute='cn',bind_password='secret';
See Also
l
CREATE AUTHENTICATION
DROPAUTHENTICATION
GRANT(Authentication)
REVOKE (Authentication)
SQLReference Manual
SQL Statements
ALTER DATABASE
Use ALTERDATABASE to:
l
Drop all fault groups and their child fault groups from the specified database.
Restore down nodes, and revert active standby nodes to standby status.
Syntax
ALTER DATABASE database_name {
... DROP ALL FAULT GROUP
... | EXPORT ON { subnet_name | DEFAULT }
... | RESET STANDBY
... | SET [PARAMETER] parameter_name = value [,...]
... | CLEAR [PARAMETER] parameter_name [,...]}
Parameters
database_name
FAULT GROUPis
RESET STANDBY
SQLReference Manual
SQL Statements
Privileges
You must be a superuser to alter the database. HP Vertica displays an error message if you try to
set or clear a parameter value at an invalid level.
Examples
The following examples show how to use ALTER DATABASE in various situations.
Drop and Restore All Default Groups
Use the following command to drop all fault groups from the exampledb database:
=> ALTER DATABASE exampledb DROP ALL FAULT GROUP;
ALTER DATABASE
Next, use the following command to restore all down nodes and reverts all active standby nodes
from the exampledb database:
=> ALTER DATABASE exampledb RESET STANDBY;
ALTER DATABASE
SQLReference Manual
SQL Statements
See Also
Fault Groups in the Administrator's Guide
High Availability With Fault Groups in the Concepts Guide
Using Public and PrivateNetworks in the Administrator's Guide
ALTERNODE in the SQL Reference Manual
Add a child fault group to or drop a child fault group from a parent fault group
Syntax
ALTER
... [
... [
... [
... [
... [
Parameters
fault-group-name
node-name
The node name you want to add to or drop from the existing (parent)
fault group.
child-fault-group-name
The name of the child fault group you want to add to or remove from
an existing parent fault group.
new-fault-group-name
The new name for the fault group you want to rename.
SQLReference Manual
SQL Statements
Permissions
Must be a superuser to alter a fault group.
Example
This example renames the parent0 fault group to parent100:
exampledb=> ALTER FAULT GROUP parent0 RENAME TO parent100;
ALTER FAULT GROUP
You can verify the change by querying the V_CATALOG.FAULT_GROUPS system table:
exampledb=> SELECT member_name FROM fault_groups;
member_name
---------------------v_exampledb_node0003
parent100
mygroup
(3 rows)
See Also
V_CATALOG.FAULT_GROUPS and V_CATALOG.CLUSTER_LAYOUT
Fault Groups in the Administrator's Guide
High Availability With Fault Groups in the Concepts Guide
ALTER FUNCTION
Alters a user-defined SQL function or user defined function (UDF) by providing a new function or
different schema name or my modifying its Fenced Mode setting.
Syntax 1
ALTER FUNCTION... [[db-name.]schema.]function-name ( [ [ argname ] argtype
... RENAME TO new_name
... SET FENCED bool_val
[, ...] ] )
Syntax 2
ALTER FUNCTION... [[db-name.]schema.]function-name ( [ [ argname ] argtype
... SET SCHEMA new_schema
... SET FENCED bool_val
[, ...] ] )
SQLReference Manual
SQL Statements
Syntax 3
ALTER FUNCTION... [[db-name.]schema.]function-name ( [ [ argname ] argtype
... SET FENCED bool_val
[, ...] ] )
Parameters
[[db-name.]schema-name.]
function-name
argname
argtype
Specifies the data type for argument that is passed to the function.
Argument types must match HP Vertica type names. See SQL Data
Types.
RENAME TO new_name
SQLReference Manual
SQL Statements
Permissions
l
To rename a function (ALTER FUNCTION RENAME TO) the user must have USAGE and
CREATE privilege on schema that contains the function.
To specify a new schema (ALTER FUNCTION SET SCHEMA), the user must have USAGE
privilege on schema that currently contains the function (old schema) and CREATE privilege on
the schema to which the function will be moved (new schema).
Notes
When you alter a function you must specify the argument type, because there could be several
functions that share the same name with different argument types.
Examples
This example creates a SQL function called zerowhennull that accepts an INTEGER argument and
returns an INTEGER result.
=> CREATE FUNCTION zerowhennull(x INT) RETURN INT
AS BEGIN
RETURN (CASE WHEN (x IS NOT NULL) THEN x ELSE 0 END);
END;
This command moves the renamed function to a new schema called macros:
=> ALTER FUNCTION zeronull(x INT) SET SCHEMA macros;
ALTER FUNCTION
SQLReference Manual
SQL Statements
See Also
l
DROP FUNCTION
USER_FUNCTIONS
ALTER LIBRARY
Replaces the library file (C++.so file, Java JARfile, or Rsource file) associated with a UDx library
defined in the HP Vertica catalog. HP Vertica automatically distributes the new file throughout the
cluster. See Developing User Defined Extensions in the Extending HPVertica Guide for details.
The UDxs defined in the catalog that reference the library automatically begin using the new library
file.
Syntax
ALTER LIBRARY [[db-name.]schema.]library_name [DEPENDS 'support_path'] AS 'library_path';
Parameters
[[db-name.]schema.]
library_name
The name of the library being altered. You can only alter an existing
library.
SQLReference Manual
SQL Statements
[DEPENDS 'support_path']
library_path
Privileges
Must be a superuser to alter a library.
Usage Considerations
l
After the updated library file is distributed to all of the nodes in the HP Vertica cluster, every UDF
that reference that library begin calling the code.
Any nodes that are down or that are added to the cluster later automatically receive a copy of the
updated library file when they join the cluster.
The new library must be developed in the same programming language as the library file being
replaced. For example, you cannot use this statement to replace a C++ library file with an R
library file.
HP Vertica does not compare the functions defined in the new library to ensure they match any
currently-defined functions in the catalog. If you change the signature of a function in the library
(for example, if you change the number and data types accepted by a UDSF defined in the
library), calls to that function will likely generate errors. If your new library file changes the
definition of a function, you must remove the function using DROP FUNCTION before using
ALTER LIBRARY to load the new library. You can then recreate the function using its new
signature.
Examples
This example shows how to update an already-defined library myFunctions with a new file.
=> ALTER LIBRARY myFunctions AS '/home/dbadmin/my_new_functions.so';
SQLReference Manual
SQL Statements
ALTER NODE
When used with the EXPORTON clause, specifies the network interface of the public network on
individual nodes that are used for import and export. When used with the REPLACEor
RESETclause, deploys active standby nodes to take the place of down nodes. Use SETand
CLEAR to change configuration parameter values.
Caution: ALTER NODE is used internally by HP Vertica. Do not use ALTERNODE for any
purpose other than changing node type, setting and clearing parameters, or importing or
exporting to a public network.
Syntax
ALTER NODE node_name {
... EXPORT ON {network_interface_name|DEFAULT}
... | REPLACE
... | REPLACE WITH {standby_node_name}
... | RESET
... | node_type
... | SET [PARAMETER] parameter_name = value [,...]
... | CLEAR [PARAMETER] parameter_name [,...]}
Parameters
node_name
node_type
EXPORT ON network_interface_name
REPLACE
SQLReference Manual
SQL Statements
RESET
Privileges
You must be a superuser to alter a node. HP Vertica displays an error message if you try to set or
clear a parameter value at an invalid level.
Examples
These examples show how you can use ALTERNODE in various situations.
Set DEFAULT Network Interface on Public Network
Specify the DEFAULT network interface of the public network on node1, which is used for export.
=> ALTER NODE node1 EXPORT ON DEFAULT;
SQLReference Manual
SQL Statements
See Also
Using Public and Private Networks in the Administrator's Guide
In the SQL Reference Manual:
l
ALTERDATABASE
CREATESUBNET
V_MONITOR.NETWORK INTERFACES
Syntax
ALTER NETWORK INTERFACE network-interface-name RENAME TO new-network-interface-name
new-network-interface-name
Permissions
Must be a superuser to alter a network interface.
SQLReference Manual
SQL Statements
Examples
This example shows how to rename a network interface.
=> ALTER NETWORK INTERFACE myNetwork RENAME TO myNewNetwork;
Syntax
ALTER PROJECTION [ [db-name.]schema.]projection-name RENAME TO new-projection-name
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection-name
Specifies the projection to change. You must include the base table name
prefix that is added automatically when you create a projection.
new-projection-name
Permissions
To rename a projection, the user must own the anchor table for which the projection was created
and have USAGE and CREATE privileges on the schema that contains the projection.
Examples
This example shows how to rename a projection.
=> CREATE TABLE tbl (x integer, y integer);
CREATE TABLE
=> CREATE PROJECTION tbl_p AS SELECT x from tbl;
CREATE PROJECTION
=> ALTER PROJECTION tbl_p RENAME to new_tbl_p;
ALTER PROJECTION
SQLReference Manual
SQL Statements
Notes
The projection must exist before it can be renamed.
See Also
l
CREATE PROJECTION
ALTER PROFILE
Changes a profile. Only a database superuser can alter a profile.
Syntax
ALTER PROFILE name LIMIT
... [PASSWORD_LIFE_TIME {life-limit | DEFAULT | UNLIMITED}]
... [PASSWORD_GRACE_TIME {grace_period | DEFAULT | UNLIMITED}]
... [FAILED_LOGIN_ATTEMPTS {login-limit | DEFAULT | UNLIMITED}]
... [PASSWORD_LOCK_TIME {lock-period | DEFAULT | UNLIMITED}]
... [PASSWORD_REUSE_MAX {reuse-limit | DEFAULT | UNLIMITED}]
... [PASSWORD_REUSE_TIME {reuse-period | DEFAULT | UNLIMITED}]
... [PASSWORD_MAX_LENGTH {max-length | DEFAULT | UNLIMITED}]
... [PASSWORD_MIN_LENGTH {min-length | DEFAULT | UNLIMITED}]
... [PASSWORD_MIN_LETTERS {min-letters | DEFAULT | UNLIMITED}]
... [PASSWORD_MIN_UPPERCASE_LETTERS {min-cap-letters | DEFAULT | UNLIMITED}]
... [PASSWORD_MIN_LOWERCASE_LETTERS {min-lower-letters | DEFAULT | UNLIMITED}]
... [PASSWORD_MIN_DIGITS {min-digits | DEFAULT | UNLIMITED}]
... [PASSWORD_MIN_SYMBOLS {min-symbols | DEFAULT | UNLIMITED}]
Note: For all parameters, the special value DEFAULT means the parameter is inherited from
the DEFAULT profile.
Parameters
Name
Description
Meaning of
UNLIMITED
value
name
N/A
SQLReference Manual
SQL Statements
Name
Description
Meaning of
UNLIMITED
value
PASSWORD_LIFE_TIME life-limit
Passwords
never expire.
No grace
period (the
same as zero)
Accounts are
never locked,
no matter how
being locked.
many failed
login attempts
are made.
SQLReference Manual
SQL Statements
Name
Description
Meaning of
UNLIMITED
value
PASSWORD_LOCK_TIME lock-period
Accounts
locked
because of too
many failed
login attempts
are never
PASSWORD_LOCK_
automatically
unlocked.
account is automatically
They must be
unlocked.
manually
unlocked by
the database
superuser.
PASSWORD_REUSE_MAX reuse-limit
required to
change
passwords a
certain number
of times before
reusing an old
password.
PASSWORD_REUSE_TIMEreuse-period
Password
reuse is not
limited by time.
Passwords are
characters allowed in a
limited to 100
characters.
Equal to max-
characters required in a
length.
SQLReference Manual
SQL Statements
Name
Description
Meaning of
UNLIMITED
value
PASSWORD_MIN_LETTERSmin-of-letters
0 (no
minimum).
in a password. Valid
ranged is 0 to max-length.
PASSWORD_MIN_UPPERCASE_LETTERSmin-cap-letters
0 (no
minimum).
Minimum number of
0 (no
minimum).
must be in a password.
Valid range is is 0 to maxlength.
PASSWORD_MIN_DIGITS min-digits
0 (no
minimum).
Minimum number of
0 (no
minimum).
Permissions
Must be a superuser to alter a profile.
Note: Only the profile settings for how many failed login attempts trigger account locking and
how long accounts are locked have an effect on password authentication methods such as
LDAP or GSS. All password complexity, reuse, and lifetime settings affect only passwords
that HP Vertica manages.
SQLReference Manual
SQL Statements
Example
ALTER PROFILE sample_profile LIMIT FAILED_LOGIN_ATTEMPTS 3;
See Also
l
CREATE PROFILE
DROP PROFILE
Syntax
ALTER PROFILE name RENAME TO newname;
Parameters
name
newname
Permissions
Must be a superuser to alter a profile.
Examples
This example shows how to rename an existing profile.
ALTER PROFILE sample_profile RENAME TO new_sample_profile;
See Also
l
ALTER PROFILE
CREATE PROFILE
SQLReference Manual
SQL Statements
DROP PROFILE
Syntax
ALTER RESOURCE POOL pool-name
...
...
...
...
...
...
...
...
...
...
...
...
]
...
...
[
[
[
[
[
[
[
[
[
[
[
[
MEMORYSIZE 'sizeUnits' ]
MAXMEMORYSIZE 'sizeUnits' ]
PRIORITY {integer | HOLD | DEFAULT } ]
EXECUTIONPARALLELISM {integer | AUTO | DEFAULT } ]
RUNTIMEPRIORITY (HIGH | MEDIUM | LOW | DEFAULT)
]
RUNTIMEPRIORITYTHRESHOLD {integer |DEFAULT }]
QUEUETIMEOUT {integer | NONE |DEFAULT } ]
PLANNEDCONCURRENCY {integer | DEFAULT | AUTO } ]
RUNTIMECAP {interval | NONE |DEFAULT } ]
MAXCONCURRENCY {integer | NONE | DEFAULT } ]
SINGLEINITIATOR { bool | DEFAULT } ]
CPUAFFINITYSET { 'cpuIndex' | 'cpuIndex list' | 'integer percentage' | NONE | DEFAULT }
Parameters
If you set any of these parameters to DEFAULT, HP Vertica sets the parameter to the value stored in
RESOURCE_POOL_DEFAULTS.
pool-name
SQLReference Manual
SQL Statements
MEMORYSIZE 'sizeUnits'
KKilobytes
MMegabytes
GGigabytes
TTerabytes
SQLReference Manual
SQL Statements
MAXMEMORYSIZE'sizeUnits' | NONE
KKilobytes
MMegabytes
GGigabytes
TTerabytes
SQLReference Manual
SQL Statements
EXECUTIONPARALLELISM
RUNTIMEPRORITY
[Default: MEDIUM]
Determines the amount of run-time resources
(CPU, I/O bandwidth) the Resource Manager
should dedicate to queries already running in the
resource pool.
Default: MEDIUM
Valid values:
l
HIGH
MEDIUM
LOW
SQLReference Manual
SQL Statements
RUNTIMEPRIORITYTHRESHOLD
PRIORITY
SQLReference Manual
SQL Statements
QUEUETIMEOUT
RUNTIMECAP
SQLReference Manual
SQL Statements
PLANNEDCONCURRENCY
SINGLEINITIATOR
SQLReference Manual
SQL Statements
MAXCONCURRENCY
SQLReference Manual
SQL Statements
CPUAFFINITYSET
DEFAULTSame as NONE.
Considerations:
l
SQLReference Manual
SQL Statements
CPUAFFINITYMODE
DEFAULTSame as ANY.
SQLReference Manual
SQL Statements
CASCADE TO
Privileges
Must be a superuser on the resource pool for the following parameters:
l
MAXMEMORYSIZE
PRIORITY
QUEUETIMEOUT
CPUAFFINITYSET
CPUAFFINITYMODE
CASCADE TO
PLANNEDCONCURRENCY
SINGLEINITIATOR
MAXCONCURRENCY
Usage Considerations
l
You can create new resource pools or alter existing ones without shutting down the system. The
only exception is that changes to GENERAL.MAXMEMORYSIZE take effect only on a node restart.
When a new pool is created (or its size altered), MEMORYSIZE amount of memory is taken out of
SQLReference Manual
SQL Statements
the GENERAL pool. If the GENERAL pool does not currently have sufficient memory to create the
pool due to existing queries being processed, a request is made to the system to create a pool
as soon as resources become available. The pool is in operation as soon as the specified
amount of memory becomes available. You can monitor whether the ALTER has been
completed in the V_MONITOR.RESOURCE_POOL_STATUS system table.
l
If the GENERAL.MAXMEMORYSIZE parameter is modified while a node is down, and that node is
restarted, the restarted node sees the new setting whereas other nodes continue to see the old
setting until they are restarted. HP Vertica recommends that you do not change this parameter
unless absolutely necessary.
During CREATE/ALTER operations,HP Vertica returns an error if this size limit is violated.
If two pools have the same PRIORITY, their requests are allowed to borrow from the GENERAL
pool in the order of arrival.
You can use CPUAFFINITYSET and CPUAFFINITYMODE only with user-created resource pools.
CPUAFFINITYSET and CPUAFFINITYMODE can only be used with user-created resource pools.
See Guidelines for Setting Pool Parameters in the Administrator's Guide for details about setting
these parameters.
Examples
This example shows how to alter resource pool ceo_pool by setting the priority to 5.
=> ALTER RESOURCE POOL ceo_pool PRIORITY 5;
This example shows how to designate a secondary pool for the ceo_pool.
=> CREATE RESOURCE POOL second_pool;
=> ALTER RESOURCE POOL ceo_pool CASCADE TO second_pool;
SQLReference Manual
SQL Statements
See Also
l
CREATE USER
RESOURCE_POOL_STATUS
Managing Workloads
Syntax
ALTER ROLE name RENAME [TO] new_name;
Parameters
name
new_name
Permissions
Must be a superuser to rename a role.
Example
=> ALTER ROLE applicationadministrator RENAME TO appadmin;
ALTER ROLE
SQLReference Manual
SQL Statements
See Also
l
CREATE ROLE
DROP ROLE
ALTER SCHEMA
Renames one or more existing schemas.
Syntax
ALTER SCHEMA [db-name.]schema-name [ , ... ]
Parameters
[db-name.]
[Optional] Specifies the current database name. Using a database name prefix is
optional, and does not affect the command in any way. You must be connected to
the specified database.
schema-name
RENAME TO
The number of schemas to rename must match the number of new schema
names supplied.
The RENAME TO parameter is applied atomically. Either all the schemas are
renamed or none of the schemas are renamed. If, for example, the number of
schemas to rename does not match the number of new names supplied, none of
the schemas are renamed.
Note: Renaming a schema that is referenced by a view will cause the view to fail
unless another schema is created to replace it.
SQLReference Manual
SQL Statements
Privileges
Schema owner or user requires CREATE privilege on the database
Notes
Renaming schemas does not affect existing pre-join projections because pre-join projections refer
to schemas by the schemas' unique numeric IDs (OIDs), and the OIDs for schemas are not
changed by ALTER SCHEMA.
Tip
Renaming schemas is useful for swapping schemas without actually moving data. To facilitate the
swap, enter a non-existent, temporary placeholder schema. The following example uses the
temporary schema temps to facilitate swapping schema S1 with schema S2. In this example, S1 is
renamed to temps. Then S2 is renamed to S1. Finally, temps is renamed to S2.
ALTER SCHEMA S1, S2, temps
RENAME TO temps, S1, S2;
Examples
The following example renames schema S1 to S3 and schema S2 to S4:
=> ALTER SCHEMA S1, S2
RENAME TO S3, S4;
See Also
l
CREATE SCHEMA
DROP SCHEMA
ALTER SEQUENCE
Changes the attributes of an existing sequence. All changes take effect in the next database
session. Any parameters not set during an ALTER SEQUENCE statement retain their prior
settings. You must be a sequence owner or a superuser to use this statement.
Note: You can rename an existing sequence, or the schema of a sequence, but neither of
SQLReference Manual
SQL Statements
Syntax
ALTER
... [
... [
... |
... [
... [
... [
... [
... [
... [
SEQUENCE [[db-name.]schema.]sequence-name
RENAME TO new-name | SET SCHEMA new-schema-name]
OWNER TO new-owner-name ]
INCREMENT [ BY ] increment-value ]
MINVALUE minvalue | NO MINVALUE ]
MAXVALUE maxvalue | NO MAXVALUE ]
RESTART [ WITH ] restart ]
CACHE cache ]
CYCLE | NO CYCLE ]
Parameters
[[db-name.]schema.]
sequence-name
RENAME TO new-name
OWNER TO new-owner-name
SQLReference Manual
SQL Statements
CYCLE | NO CYCLE
SQLReference Manual
SQL Statements
Permissions
To rename a schema, the user must be the sequence owner and have USAGE and CREATE
USAGE privilege on the schema that currently contains the sequence (old schema) and
CREATE privilege on new schema to contain the sequence.
Examples
The following example modifies an ascending sequence called sequential to restart at 105:
ALTER SEQUENCE sequential RESTART WITH 105;
The following example reassigns sequence ownership from the current owner to user Bob:
ALTER SEQUENCE sequential OWNER TO Bob;
See Also
l
CREATE SEQUENCE
CURRVAL
DROP SEQUENCE
GRANT (Sequence)
NEXTVAL
l
l
SQLReference Manual
SQL Statements
ALTER SESSION
Use ALTERSESSIONto set and clear session-level configuration parameter values for the current
session.
Syntax
ALTER SESSION {
... SET [PARAMETER] parameter_name = value [,...]
... | CLEAR [PARAMETER] parameter_name [,...]}
Parameters
SET [PARAMETER] parameter_name = value
Privileges
You must be a superuser to alter the database. HP Vertica displays an error message if you try to
set or clear a parameter value at an invalid level.
Examples
The following examples show how to use ALTERSESSION in various situations.
Set a parameter at session level
Force all UDxes that support fenced mode to run in fenced mode, even if their definition specified is
NOT FENCED:
=> ALTER SESSION SET ForceUDxFencedMode = 1;
SQLReference Manual
SQL Statements
ALTER SUBNET
Renames an existing subnet.
Syntax
ALTER SUBNET subnet-name RENAME TO 'new-subnet-name'
Parameters
The parameters are defined as follows:
subnet-name
new-subnet-name
Permissions
Must be a superuser to alter a subnet.
Examples
This example renames a subnet.
=> ALTER SUBNET mysubnet RENAME TO myNewSubnet;
ALTER TABLE
Modifies an existing table with a new table definition.
You cannot modify the metadata of an anchor table for a live aggregate projection or Top-K
projection.
SQLReference Manual
SQL Statements
Syntax 1
ALTER TABLE [[db-name.]schema.]table-name {
... ADD COLUMN column-definition ( table ) [CASCADE]
... | ADD Table-Constraint
... | ALTER COLUMN column-name
| [ SET DEFAULT expression ]
| [ DROP DEFAULT ]
| [ { SET | DROP } NOT NULL]
| [ SET DATA TYPE data-type ]
... | DROP CONSTRAINT constraint-name [ CASCADE | RESTRICT ]
... | [ DROP [ COLUMN ] column-name [ CASCADE | RESTRICT ] ]
... | RENAME [ COLUMN ] column TO new-column
... | SET SCHEMA new-schema-name [ CASCADE | RESTRICT ]
... | PARTITION BY partition-clause [ REORGANIZE ]
... | REORGANIZE
... | REMOVE PARTITIONING
... | OWNER TO new-owner-name }
Syntax 2
ALTER TABLE [[db-name.]schema.]table-name [ , ... ]... RENAME TO new-table-name [ , ... ]
Parameters
[[db-name.]schema.]
SQLReference Manual
SQL Statements
table-name
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
Character typesAll
conversions allowed, even
between CHAR and VARCHAR
Restrictions
You also cannot alter a column that
is used in the CREATE
PROJECTION .. SEGMENTED
BY clause. To resize a segmented
column, you must either create new
superprojections and omit the
column in the segmentation clause,
or you can create a new table and
projections with the column size
that specifies the new size.
The following type conversions are
SQLReference Manual
SQL Statements
not allowed:
l
SQLReference Manual
SQL Statements
[ CASCADE | RESTRICT ]
SQLReference Manual
SQL Statements
Participates in a pre-join
projection or participates in the
projection's segmentation
expression. When a pre-join
projection contains a column to
be dropped with CASCADE, HP
Vertica tries to drop the
projection.
SQLReference Manual
SQL Statements
RENAME [ COLUMN ]
SQLReference Manual
SQL Statements
PARTITION BY partition-clause
[ REORGANIZE ]
SQLReference Manual
SQL Statements
REMOVE PARTITIONING
SQLReference Manual
SQL Statements
OWNER TO new-owner-name
Privileges
You must be a table owner or a superuser and have USAGE privileges on the schema that
contains the table in order to:
l
To rename a table, you must have USAGE and CREATE privilege on the schema that contains the
table.
Moving a table to a new schema requires:
l
SQLReference Manual
SQL Statements
Locked Tables
If the operation cannot obtain an O Lock on the table(s), HP Vertica attempts to close any internal
Tuple Mover (TM) sessions running on the same table(s). This step allows the operation to proceed.
Explicit TM operations that are running in user sessions are not closed. If an explicit TM operation is
running on the table, the operation cannot proceed until the explicit TM operation completes.
The following example shows how you rename a column in the Retail.Product_Dimension table
from Product_description to Item_description:
=> ALTER TABLE Retail.Product_Dimension
RENAME COLUMN Product_description TO Item_description;
SQLReference Manual
SQL Statements
Use ALTER TABLE with the ALTER COLUMN and SET NOT NULL clauses to add the constraint
on column a in table test6:
ALTER TABLE test6 ALTER COLUMN a SET NOT NULL;
Use the SET NOT NULL or DROP NOT NULL clause to add or remove a not NULL column
constraint:
=> ALTER TABLE T1 ALTER COLUMN x SET NOT NULL;
=> ALTER TABLE T1 ALTER COLUMN x DROP NOT NULL;
Use these clauses to ensure that the column has the proper constraints when you have added or
removed a primary key constraint on a column, or any time you want to add or remove the not NULL
constraint.
Note: A PRIMARY KEY constraint includes a not NULL constraint, but if you drop the
PRIMARY KEY constraint on a column, the not NULL constraint remains on that column.
SQLReference Manual
SQL Statements
After you load data into them, HP Vertica creates a superprojection for each table. The
superprojections contains all the columns in their respective tables. For this example, name them
super_t1 and super_t2.
Create two pre-join projections that join tables t1 and t2, where t2 is an anchor, or a fact table, and
t1 is a dimension table.
=> CREATE PROJECTION t_pj1 AS SELECT t1.x, t1.y, t2.x, t2.t1_x, t2.z
FROM t1 JOIN t2 ON t1.x = t2.t1_x UNSEGMENTED ALL NODES;
=> CREATE PROJECTION t_pj2 AS SELECT t1.x, t2.x
FROM t1 JOIN t2 ON t1.x = t2.t1_x UNSEGMENTED ALL NODES;
Add a new column w1 to table t1 using the CASCADE keyword. HP Vertica adds the column to:
l
Superprojection super_t1
Add a new column w2 to table t1, and specify a nonconstant default value. HP Vertica adds the
new column to the superprojection super_t1. Because the default value is not a constant, HP
Vertica does not add the new column to the pre-join projections, but displays a warning instead.
=> ALTER TABLE t1 ADD COLUMN w2 INT DEFAULT default (t1.y+1)
NOT NULL CASCADE;
WARNING: Column "w2" in table "t1" with non-constant default
will not be added to prejoin(s) t_pj1, t_pj2.
SQLReference Manual
SQL Statements
See Also
l
Table-Constraint
Adds a constraint to the metadata of a table. See Adding Constraints in the Administrator's Guide.
Syntax
[ CONSTRAINT constraint_name
... { PRIMARY KEY ( column [
... | FOREIGN KEY ( column [
REFERENCES table [( column [
]
, ... ] )
, ... ] )
, ... ] )]
Parameters
CONSTRAINT constraint-name
[ , ... ] )
[ , ... ] )
UNIQUE ( column
[ , ... ] )
Permissions
Table owner or user WITH GRANT OPTION is grantor.
SQLReference Manual
SQL Statements
REFERENCES privilege on table to create foreign key constraints that reference this table
Examples
The VMart sample database, described in the Getting Started Guide, contains a table Product_
Dimension in which products have descriptions and categories. For example, the description
"Seafood Product 1" exists only in the "Seafood" category. You can define several similar
correlations between columns in the Product Dimension table.
ALTER USER
Changes a database user account. Changes that you make to a user account with ALTER USER
do not affect current sessions.
Users can change their own user accounts with these options:
l
IDENTIFIED BY
RESOURCE POOL
SEARCH_PATH
SQLReference Manual
SQL Statements
Syntax
ALTER
... [
... [
... [
... [
... [
... [
... [
... [
... [
... [
... [
USER name
ACCOUNT { LOCK | UNLOCK } ]
DEFAULT ROLE {role [, ...] | NONE} ]
IDENTIFIED BY 'password' [ REPLACE 'old-password' ] ]
MEMORYCAP { 'memory-limit' | NONE } ]
PASSWORD EXPIRE ]
PROFILE { profile-name | DEFAULT } ]
RESOURCE POOL pool-name ]
RUNTIMECAP { 'time-limit' | NONE } ]
TEMPSPACECAP { 'space-limit' | NONE } ]
SEARCH_PATH { schema[,schema2,...] | DEFAULT } ]
SECURITY_ALGORITHM { 'NONE' | 'MD5' | 'SHA512' }
Parameters
name
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
PASSWORD EXPIRE
SQLReference Manual
SQL Statements
KKilobytes
MMegabytes
GGigabytes
TTerabytes
SQLReference Manual
SQL Statements
Privileges
Must be a superuser to alter a user account.
Examples
Change the UserPassword
This example shows how to change a user's password:
=> CREATE USER joe;
=> ALTER USER joe IDENTIFIED BY 'newpassword';
SQLReference Manual
SQL Statements
This example shows how to change the user's hash authentication to SHA-512 and password.
When you execute the ALTERUSERstatement, HP Vertica hashes the password, using the SHA512 algorithm, and saves the hashed version:
=> CREATE USER joe;
=> ALTER USER joe SECURITY_ALGORITHM 'SHA512' IDENTIFIED BY 'newpassword'
See Also
l
CREATE USER
DROP USER
Managing Workloads
ALTER VIEW
Renames a view.
Syntax
ALTER VIEW [[db-name.]schema.] current-view-name ... RENAME TO new-view-name
Parameters
viewname
RENAME TOnew-view-name
Specifies the new name of the view. The view name must be unique.
Do not use the same name as any table, view, or projection within the
database.
Notes
Views are read only. You cannot perform insert, update, delete, or copy operations on a view.
SQLReference Manual
SQL Statements
Permissions
To create a view, the user must be a superuser or have CREATE privileges on the schema in
which the view is renamed.
Example
The following command renames view1 to view2:
=> CREATE VIEW view1 AS SELECT * FROM t;
CREATE VIEW
=> ALTER VIEW view1 RENAME TO view2;
ALTER VIEW
BEGIN
Starts a transaction block.
Syntax
BEGIN [ WORK | TRANSACTION ] [ isolation_level ] [ transaction_mode ]
Parameters
WORK | TRANSACTION
SQLReference Manual
SQL Statements
ISOLATION LEVEL {
SERIALIZABLE |
REPEATABLE READ |
READ COMMITTED |
READ UNCOMMITTED
}
SQLReference Manual
SQL Statements
Permissions
No special permissions required.
Examples
This example shows how to begin a transaction and set the isolation level.
=> BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED READ WRITE;
BEGIN
=> CREATE TABLE sample_table (a INT);
CREATE TABLE
=> INSERT INTO sample_table (a) VALUES (1);
OUTPUT
-------1
(1 row)
Notes
START TRANSACTION performs the same function as BEGIN.
SQLReference Manual
SQL Statements
See Also
l
Transactions
COMMIT
END
ROLLBACK
SQLReference Manual
SQL Statements
COMMENT ON Statements
The following functions allow you to create comments associated with HP Vertica database
objects:
l
COMMENT ON COLUMN
COMMENT ON CONSTRAINT
COMMENT ON FUNCTION
COMMENT ON LIBRARY
COMMENT ON NODE
COMMENT ON PROJECTION
COMMENT ON SCHEMA
COMMENT ON SEQUENCE
COMMENT ON TABLE
COMMENT ON VIEW
COMMENT ON COLUMN
Adds, revises, or removes a projection column comment. You can only add comments to projection
columns, not to table columns. Each object can have a maximum of 1 comment (1 or 0). Comments
are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON COLUMN [[db-name.]schema.]proj_name.column_name IS {'comment' | NULL}
SQLReference Manual
SQL Statements
Parameters
[[db-name.]schema.]
proj_name.column_name
Specifies the name of the projection and column with which to associate
the comment.
comment
Specifies the comment text to add. Enclose the text of the comment
within single-quotes. If a comment already exists for this column, the
comment you enter here overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment
exceeds that limitation, HP Vertica truncates the comment and alerts
the user with a message.
You can enclose a blank value within single quotes to remove an
existing comment.
NULL
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
SQLReference Manual
SQL Statements
Example
The following example adds a comment to the customer_name column in the customer_dimension
projection:
=> COMMENT ON COLUMN customer_dimension_vmart_node01.customer_name IS 'Last name only';
The following examples remove a comment from the customer_name column in the customer_
dimension projection in two ways, using the NULL option, or specifying a blank string:
=> COMMENT ON COLUMN customer_dimension_vmart_node01.customer_name IS NULL;
=> COMMENT ON COLUMN customer_dimension_vmart_node01.customer_name IS '';
See Also
l
COMMENTS
COMMENT ON CONSTRAINT
Adds, revises, or removes a comment on a constraint. Each object can have a maximum of 1
comment (1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON CONSTRAINT constraint_name ON [ [db-name.]schema.]table_name IS ... {'comment' |
NULL };
Parameters
constraint_name
[[db-name.]schema.]
SQLReference Manual
SQL Statements
table_name
comment
Specifies the comment text to add. Enclose the text of the comment within
single-quotes. If a comment already exists for this constraint, the
comment you enter here overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds
that limitation, HP Vertica truncates the comment and alerts the user with
a message.
You can enclose a blank value within single quotes to remove an existing
comment.
NULL
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
Example
The following example adds a comment to the constraint_x constraint on the promotion_
dimension table:
=> COMMENT ON CONSTRAINT constraint_x ON promotion_dimension IS 'Primary key';
The following examples remove a comment from the constraint_x constraint on the promotion_
dimension table:
=> COMMENT ON CONSTRAINT constraint_x ON promotion_dimension IS NULL;
=> COMMENT ON CONSTRAINT constraint_x ON promotion_dimension IS '';
SQLReference Manual
SQL Statements
See Also
l
COMMENTS
COMMENT ON FUNCTION
Adds, revises, or removes a comment on a function. Each object can have a maximum of 1
comment (1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON FUNCTION [[db-name.]schema.]function_name function_arg IS { 'comment' | NULL };
Parameters
[[db-name.]schema.]
function_name
Specifies the name of the function with which to associate the comment.
function_arg
comment
Specifies the comment text to add. Enclose the comment text within
single-quotes. If a comment already exists for this function, the comment
you enter overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds
that limitation, HP Vertica truncates the comment and alerts the user with
a message.
You can enclose a blank value within single quotes to remove an existing
comment.
NULL
SQLReference Manual
SQL Statements
Notes
l
A user must own an object to be able to add or edit comments for the object.
If you drop an object, all comments associated with the object are dropped as well.
Examples
The following example adds a comment to the macros.zerowhennull (x INT) function:
=> COMMENT ON FUNCTION macros.zerowhennull(x INT) IS 'Returns a 0 if not NULL';
The following examples remove a comment from the macros.zerowhennull (x INT) function in
two ways by using the NULL option, or specifying a blank string:
=> COMMENT ON FUNCTION macros.zerowhennull(x INT) IS NULL;
=> COMMENT ON FUNCTION macros.zerowhennull(x INT) IS '';
See Also
l
COMMENTS
COMMENT ON LIBRARY
Adds, revises, or removes a comment on a library . Each object can have a maximum of 1
comment (1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON LIBRARY [ [db-name.]schema.]library_name IS {'comment' | NULL}
SQLReference Manual
SQL Statements
Parameters
[[db-name.]schema.]
library_name
comment
Specifies the comment text to add. Enclose the text of the comment within
single-quotes. If a comment already exists for this library, the comment
you enter here overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds
that limitation, HP Vertica truncates the comment and alerts the user with
a message.
You can enclose a blank value within single quotes to remove an existing
comment.
NULL
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
Examples
The following example adds a comment to the library MyFunctions:
SQLReference Manual
SQL Statements
See Also
l
COMMENTS
COMMENT ON NODE
Adds, revises, or removes a comment on a node. Each object can have a maximum of 1 comment
(1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON NODE node_name IS
{ 'comment' | NULL }
Parameters
node_name
comment
Specifies the comment text to add. Enclose the text of the comment within singlequotes. If a comment already exists for this node, the comment you enter here
overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds that
limitation, HP Vertica truncates the comment and alerts the user with a message.
You can enclose a blank value within single quotes to remove an existing comment.
NULL
Permissions
l
The object owner can add or edit comments for the object.
SQLReference Manual
SQL Statements
Notes
Dropping an object drops all comments associated with the object.
Examples
The following example adds a comment for the initiator node:
=> COMMENT ON NODE initiator IS 'Initiator node';
See Also
l
COMMENTS
COMMENT ON PROJECTION
Adds, revises, or removes a comment on a projection. Each object can have a maximum of 1
comment (1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON PROJECTION [ [db-name.]schema.]proj_name IS { 'comment' | NULL }
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
projection_name
SQLReference Manual
SQL Statements
comment
Specifies the text of the comment to add. Enclose the text of the comment
within single-quotes. If a comment already exists for this projection, the
comment you enter here overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds
that limitation, HP Vertica truncates the comment and alerts the user with
a message.
You can enclose a blank value within single quotes to remove an existing
comment.
Null
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
Examples
The following example adds a comment to the customer_dimension_vmart_node01 projection:
=> COMMENT ON PROJECTION customer_dimension_vmart_node01 IS 'Test data';
See Also
l
COMMENTS
SQLReference Manual
SQL Statements
COMMENT ON SCHEMA
Adds, revises, or removes a comment on a schema. Each object can have a maximum of 1
comment (1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON SCHEMA [db-name.]schema_name IS {'comment' | NULL}
Parameters
[db-name.]
[Optional] Specifies the database name. You must be connected to the database
you specify. You cannot make changes to objects in other databases.
schema_name
comment
Text of the comment you want to add. Enclose the text of the comment in singlequotes. If a comment already exists for this schema, the comment you enter here
overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds that
limitation, HP Vertica truncates the comment and alerts the user with a message.
You can enclose a blank value within single quotes to remove an existing
comment.
NULL
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
Examples
The following example adds a comment to the public schema:
SQLReference Manual
SQL Statements
See Also
l
COMMENTS
COMMENT ON SEQUENCE
Adds, revises, or removes a comment on a sequence. Each object can have a maximum of 1
comment (1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON SEQUENCE [[db-name.]schema.]sequence_name IS { 'comment' | NULL }
Parameters
[[db-name.]schema.]
sequence_name
SQLReference Manual
SQL Statements
comment
Specifies the text of the comment to add. Enclose the text of the comment
within single-quotes. If a comment already exists for this sequence, the
comment you enter here overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds
that limitation, HP Vertica truncates the comment and alerts the user with
a message.
You can enclose a blank value within single quotes to remove an existing
comment.
NULL
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
Examples
The following example adds a comment to the sequence called prom_seq.
=> COMMENT ON SEQUENCE prom_seq IS 'Promotion codes';
See Also
l
COMMENTS
SQLReference Manual
SQL Statements
COMMENT ON TABLE
Adds, revises, or removes a comment on a table. Each object can have a maximum of one
comment (1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON TABLE [ [db-name.]schema.]table_name IS { 'comment' | NULL }
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table_name
Specifies the name of the table with which to associate the comment.
comment
Specifies the text of the comment to add. Enclose the text of the comment
within single-quotes. If a comment already exists for this table, the
comment you enter here overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds
that limitation, HP Vertica truncates the comment and alerts the user with
a message.
You can enclose a blank value within single quotes to remove an existing
comment.
Null
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
SQLReference Manual
SQL Statements
Examples
The following example adds a comment to the promotion_dimension table:
=> COMMENT ON TABLE promotion_dimension IS '2011 Promotions';
See Also
l
COMMENTS
Syntax
COMMENT ON TRANSFORM FUNCTION [[db-name.]schema.]t_function_name
...([t_function_arg_name t_function_arg_type] [,...]) IS {'comment' | NULL}
Parameters
[[db-name.]schema.]
t_function_name
t_function_arg_name t_function_arg_type
SQLReference Manual
SQL Statements
comment
NULL
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
Examples
The following example adds a comment to the macros.zerowhennull (x INT) UTF function:
=> COMMENT ON TRANSFORM FUNCTION macros.zerowhennull(x INT) IS 'Returns a 0 if not NULL';
The following example removes a comment from the acros.zerowhennull (x INT) function by
using the NULL option:
=> COMMENT ON TRANSFORM FUNCTION macros.zerowhennull(x INT) IS NULL;
SQLReference Manual
SQL Statements
COMMENT ON VIEW
Adds, revises, or removes a comment on a view. Each object can have a maximum of 1 comment
(1 or 0). Comments are stored in the V_CATALOG.COMMENTS system table.
Syntax
COMMENT ON VIEW [ [db-name.]schema.]view_name IS { 'comment' | NULL }
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
view_name
comment
Specifies the text of the comment to add. If a comment already exists for
this view, the comment you enter here overwrites the previous comment.
Comments can be up to 8192 characters in length. If a comment exceeds
that limitation, HP Vertica truncates the comment and alerts the user with
a message.
You can enclose a blank value within single quotes to remove an existing
comment.
NULL
Permissions
l
The object owner can add or edit comments for the object.
Notes
Dropping an object drops all comments associated with the object.
SQLReference Manual
SQL Statements
Examples
The following example adds a comment to a view called curr_month_ship:
=> COMMENT ON VIEW curr_month_ship IS 'Shipping data for the current month';
See Also
l
COMMENTS
COMMIT
Ends the current transaction and makes all changes that occurred during the transaction permanent
and visible to other users.
Syntax
COMMIT [ WORK | TRANSACTION ]
Parameters
WORK | TRANSACTION
Permissions
No special permissions required.
Notes
END is a synonym for COMMIT.
Examples
This example shows how to commit an insert.
=> CREATE TABLE sample_table (a INT);
SQLReference Manual
SQL Statements
See Also
l
Transactions
BEGIN
ROLLBACK
START TRANSACTION
CONNECT
Connects to another HP Vertica database to enable data import (using the COPY FROM VERTICA
statement) or export (using the EXPORT statement). By default, invoking CONNECT occurs over
the HP Vertica private network. Creating a connection over a public network requires some
configuration. For information about using CONNECT to export data to or import data over a public
network, see Export/Import from a Public Network.
When importing from or exporting to an HP Vertica database, you can connect only to a database
that uses trusted- (username-only) or password-based authentication, as described in
Implementing Security. Neither LDAP nor SSL authentication is supported.
Syntax
CONNECT TO VERTICA database USER username PASSWORD 'password' ON 'host',port
Parameters
database
username
password
host
A string containing the host name of one of the nodes in the other database.
SQLReference Manual
SQL Statements
port
Permissions
No special permissions required.
Connection Details
Once you successfully establish a connection to another database, the connection remains open
for the current session. To disconnect a connection, use the DISCONNECT statement.
You can have only one connection to another database at a time, though you can create
connections to multiple different databases in the same session.
If the target database does not have a password, and you specify a password in the CONNECT
statement, the connection succeeds, but does not give any indication that you supplied an incorrect
password.
Example
=> CONNECT TO VERTICA ExampleDB USER dbadmin PASSWORD 'Password123' ON
'VerticaHost01',5433;
CONNECT
See Also
l
DISCONNECT
EXPORT TO VERTICA
COPY
The COPYstatement bulk-loads data into an HP Vertica database. You can initiate loading one or
more files or pipes on a cluster host or on a client system (using the COPY LOCAL option).
Privileges
You must connect to the HP Vertica database as a superuser, or, as a non-superuser, have a
USER-accessible storage location, and applicable READ or WRITE privileges granted to the storage
SQLReference Manual
SQL Statements
location from which files are read or written to. COPY LOCAL users must have INSERT privileges to
copy data from the STDIN pipe, as well as USAGE privileges on the schema.
The following permissions are required to COPY FROM STDIN:
l
Using a specific location for rejected data or exceptions files, if path resolves to a storage location,
and the user invoking COPY is not a superuser, the following privileges are required:
l
The storage location must have been created with the USER option (see CREATE LOCATION).
The user must already have been granted READ access to the storage location where the files
exist, as described in GRANT (Storage Location)
Syntax
COPY [ [db-name.]schema-name.]to_table
... [ ( { column-as-expression | column }
...... [ FILLER datatype ]
...... [ FORMAT 'format' ]
...... [ ENCLOSED [ BY ] 'char' ]
...... [ ESCAPE [ AS ] 'char' | NO ESCAPE ]
...... [ NULL [ AS ] 'string' ]
...... [ TRIM 'byte' ]
...... [ DELIMITER [ AS ] 'char' ]
... [, ... ] ) ]
... [ COLUMN OPTION ( column
...... [ FORMAT 'format' ]
...... [ ENCLOSED [ BY ] 'char' ]
...... [ ESCAPE [ AS ] 'char' | NO ESCAPE ]
...... [ NULL [ AS ] 'string' ]
...... [ DELIMITER [ AS ] 'char' ]
... [, ... ] ) ]
FROM { STDIN
...... [ BZIP | GZIP | LZO | UNCOMPRESSED ]
...| 'pathToData' [ ON nodename | ON ANY NODE ]
...... [ BZIP | GZIP | LZO | UNCOMPRESSED ] [, ...]
...| LOCAL STDIN | 'pathToData'
...... [ BZIP | GZIP | LZO | UNCOMPRESSED ] [, ...]
}
...[ NATIVE | NATIVE VARCHAR | FIXEDWIDTH COLSIZES (integer [, ....]) | ORC]
...[ WITH, AS ]
...[ WITH [ SOURCE source([arg=value [,...] ])] [ FILTER filter([arg=value [,...] ]) ] [
PARSER parser([arg=value [,...] ]) ] ]
...[ DELIMITER [ AS ] 'char' ]
...[ TRAILING NULLCOLS ]
...[ NULL [ AS ] 'string' ]
...[ ESCAPE [ AS ] 'char' | NO ESCAPE ]
...[ ENCLOSED [ BY ] 'char' ]
...[ RECORD TERMINATOR 'string' ]
...[ SKIP records ]
SQLReference Manual
SQL Statements
...[
...[
...[
...[
...[
...[
...[
...[
...[
...[
Parameters
[[db-name.]schema-name.]to_
table
column-as-expression
SQLReference Manual
SQL Statements
column
FILLER
Specifies not to load the column and its fields into the
destination table. Use this option to omit columns that you do
not want to transfer into a table.
This parameter also transforms data from a source column
and loads the transformed data to the destination table, rather
than loading the original, untransformed source column
(parsed column). (See Ignoring Columns and Fields in the
Load File in the Administrator's Guide.)
SQLReference Manual
SQL Statements
FORMAT
'octal'
'hex'
'bitstream'
SQLReference Manual
SQL Statements
pathToData
SQLReference Manual
SQL Statements
nodename
ON ANY NODE
STDIN
LOCAL
Specifies that all paths for the COPY statement are on the
client system and that all COPY variants are initiated from a
client. You can use the LOCAL and STDIN parameters
together. You can use LOCALand pathtodata (as described
earlier), to use a relative path. See Using COPY and COPY
LOCAL in the Administrator's Guide.
SQLReference Manual
SQL Statements
WITH, AS
SQLReference Manual
SQL Statements
COLUMN OPTION
DELIMITER
TRAILING NULLCOLS
SQLReference Manual
SQL Statements
ESCAPE [AS]
NO ESCAPE
ESCAPE [AS]
DELIMITER
ENCLOSED [BY]
RECORD TERMINATOR
ENCLOSED [BY]
NULL
RECORD TERMINATOR
SQLReference Manual
SQL Statements
SKIP records
TRIM
REJECTMAX
SQLReference Manual
SQL Statements
ABORT ON ERROR
SQLReference Manual
SQL Statements
NO COMMIT
SQLReference Manual
SQL Statements
Note: Always use the COPY statement REJECTED DATA and EXCEPTIONS parameters to
save load rejections, or the REJECTED DATA AS TABLE clause. Using the
RETURNREJECTED parameter is supported only for internal use by the JDBC and ODBC
drivers. HP Vertica's internal-use options can change without notice.
NATIVE
(VARCHAR)
COPY Option
DELIMITER
COLUMN OPTION
AUTO
DIRECT
TRICKLE
ENFORCELENGTH
EXCEPTIONS
FILLER
REJECTED DATA
ABORT ON ERROR
STREAM NAME
SKIP
SKIP BYTES
FIXEDWIDTH
REJECTMAX
STDIN
UNCOMPRESSED
BZIP | GZIP
SQLReference Manual
SQL Statements
COPY Option
DELIMITER
NATIVE
(BINARY)
NATIVE
(VARCHAR)
FIXEDWIDTH
NO COMMIT
FORMAT
NULL
DELIMITED
ENCLOSED BY
ESCAPE AS
TRAILING NULLCOLS
RECORD TERMINATOR
TRIM
Usage Considerations
When loading data with the COPY statement, COPY considers the following data invalid:
l
Missing columns (an input line has less columns than the recipient table).
Extra columns (an input line has more columns than the recipient table).
Empty columns for an INTEGER or DATE/TIME data type. If a column is empty for either of
these types, COPY does not use the default value that was defined by the CREATE TABLE
command. However, if you do not supply a column option as part of the COPY statement, the
default value is used.
Incorrect representation of a data type. For example, trying to load a non-numeric data into an
INTEGER column is invalid.
When COPY encounters an empty line while loading data, the line is neither inserted nor rejected,
but COPY increments the line record number. Consider this behavior when evaluating rejected
records. If you return a list of rejected records and COPYencountered an empty row while loading
data, the position of rejected records is incremented by one.
When loading compressed files, COPYmay abort and report an error if the file seems to be
corrupted. This can happen if reading the header block fails, for example.
SQLReference Manual
SQL Statements
Examples
The following example show how to load data with the COPY statement using the FORMAT,
DELIMITER, NULL and ENCLOSED BY string options, as well as a DIRECT option.
=> COPY public.customer_dimension (customer_since FORMAT 'YYYY')
FROM STDIN
DELIMITER ','
NULL AS 'null'
ENCLOSED BY '"'
=> COPY a
FROM STDIN
DELIMITER ','
NULL E'\\\N'
DIRECT;
=> COPY store.store_dimension
FROM :input_file
DELIMITER '|'
NULL ''
RECORD TERMINATOR E'\f'
SQLReference Manual
SQL Statements
This statement copies a BZIP file from a named pipe and then uncompresses it:
\! bzip2 pf1.dat
\! cat pf1.dat.bz2 > pipe1 &
COPY large_tbl FROM :file ON site01 BZIP delimiter '|';
SELECT * FROM large_tbl;
COMMIT;
bunzip2 pf1.dat.bz2
This statement copies an LZOfile from a named pipe and then uncompresses it:
\! lzop pf1.dat
\! cat pf1.dat.lzo > pipe1 &
COPY large_tbl FROM :file ON site01 LZO delimiter '|';
SELECT * FROM large_tbl;
COMMIT;
\!lzop -d pf1.dat.lzo
SQLReference Manual
SQL Statements
See Also
l
ANALYZE_CONSTRAINTS
Directory.getFiles Method
Ignoring Columns and Fields in the Load File in the Administrator's Guide
COPY LOCAL
Using the COPY statement with its LOCAL option lets you load a data file on a client system, rather
than on a cluster host. COPY LOCAL supports the STDIN and 'pathToData' parameters, but not
the [ON nodename] clause. COPY LOCAL does not support NATIVE or NATIVE VARCHAR
formats.
The COPY LOCAL option is platform independent. The statement works in the same way across all
supported HP Vertica platforms and drivers. For more details about using COPY LOCAL with
supported drivers, see the Connecting to HP Vertica Guide section for your platform.
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.
SQLReference Manual
SQL Statements
Invoking COPY LOCAL does not automatically create exceptions and rejections files, even if
exceptions occur. You cannot save exceptions and rejections to a table with the rejected data
as table parameter. For information about saving such files, see Capturing Load Exceptions and
Rejections in the Administrator's Guide.
Permissions
User must have INSERT privilege on the table and USAGE privilege on the schema.
SQLReference Manual
SQL Statements
.
.
.
10[label = "Load-Client-File(/tmp/diff) \nOutBlk=[UncTuple]",
color = "green", shape = "ellipse"];
Syntax
COPY [target_schema.]target_table
... [( target_column_name[, target_column_name2,...])]
... FROM VERTICA database.[source_schema.]source_table
... [(source_column_name[, source_column_name2,...])]
... [AUTO | DIRECT | TRICKLE]
... [STREAM NAME 'stream name']
... [NO COMMIT]
Parameters
[target_schema.]target_table
(target_column_name[, target_
column_name2,...])
SQLReference Manual
SQL Statements
database
[source_schema.]source_table
(source_column_name[, source_
column_name2,...])
STREAM NAME
NO COMMIT
SQLReference Manual
SQL Statements
Permissions
l
Notes
Importing and exporting data fails if either side of the connection is a single-node cluster installed
to localhost, or you do not specify a host name or IP address.
l
If you do not supply a list of source and destination columns, COPY FROM VERTICA attempts
to match columns in the source table with corresponding columns in the destination table. See
the following section for details.
Matches all columns in the source Copies content only from the supplied list of
table to columns in the destination source table columns. Matches columns in
table. The number of columns in
the two tables need not match,
Omit
but the destination table must not
Destination
have fewer columns than the
Column
source.
List
SQLReference Manual
SQL Statements
The COPY FROM VERTICA statement needs to map columns in the source table to columns in
the destination table.
Example
This example demonstrates connecting to another database, copying the contents of an entire table
from the source database to an identically-defined table in the current database directly into ROS,
and then closing the connection.
=> CONNECT TO VERTICA vmart USER dbadmin PASSWORD '' ON 'VertTest01',5433;
CONNECT
=> COPY customer_dimension FROM VERTICA vmart.customer_dimension DIRECT;
Rows Loaded
------------500000
(1 row)
=> DISCONNECT vmart;
DISCONNECT
This example demonstrates copying several columns from a table in the source database into a
table in the local database.
=> CONNECT TO VERTICA vmart USER dbadmin PASSWORD '' ON 'VertTest01',5433;
CONNECT
=> COPY people (name, gender, age) FROM VERTICA
-> vmart.customer_dimension (customer_name, customer_gender,
-> customer_age);
Rows Loaded
------------500000
(1 row)
=> DISCONNECT vmart;
DISCONNECT
You can copy tables (or columns) containing Identity and Auto-increment values, but the sequence
values are not incremented automatically at their destination.
SQLReference Manual
SQL Statements
See Also
l
CONNECT
DISCONNECT
EXPORT TO VERTICA
CREATE ACCESSPOLICY
Creates a secure access policy to prevent unauthorized users from accessing potentially sensitive
information.
Syntax
CREATE ACCESS POLICY ON [schema][tablename]
FOR COLUMN columnname
expression
[ENABLE/DISABLE];
Parameters
schema
The name of the schema that contains the table to which access policies areapplied.
If you have not been granted privileges to the schema, you must include the schema
name.
tablenam
e
The name of the table that contains any column to which access policies will be
columnna
me
expressi
on
An expression that provides further information to limit column access. For example,
defined.
the expression:
=> CREATE ACCESS POLICY on customer_dimension for column customer_key
('xxxxx') enable;
length
Privileges
You must be a dbadmin user to create access policies.
SQLReference Manual
SQL Statements
Examples
Create Access Policy in Customer Table on the Column customer_number
=> CREATE ACCESS POLICY on customer FOR column customer_number customer_number enable;
Create Access Policy per Role in Customer Table on the Column customer_number
You add an expression to the policy to specify the access each role receives. A manager can
access the complete customer number, while an operator can only see a portion of the number:
=>
=>
=>
=>
Create Access Policy for Table and Column in Public Schema Without User Privileges
=> CREATE ACCESS POLICY on public.customer for column customer_number length('xxxxx')
enable;
CREATE AUTHENTICATION
Creates and enables an authentication method associated with users or roles. When you create an
authentication method using CREATEAUTHENTICATION, HP Vertica enables it automatically.
Syntax
CREATE AUTHENTICATION auth_method_name
METHOD auth_type
{ LOCAL | HOST [ { TLS | NO TLS } ] } [ host_ip_address ] }
SQLReference Manual
SQL Statements
Parameters
Name
Data Type
Description
auth_method_name
VARCHAR
auth_type
VARCHAR
'gss'
'ident'
'ldap'
'hash'
'reject'
'trust'
'tls'
SQLReference Manual
SQL Statements
Name
Data Type
Description
N/A
host_ip_address
VARCHAR
Privileges
Must have DBADMIN privileges.
Examples
This example creates an authentication method named localpwd to authenticate users who are
trying to log in from a local host using a password:
=> CREATE AUTHENTICATION localpwd METHOD 'hash' LOCAL;
This example creates an authentication method named v_ldap that uses LDAP over TLSto
authenticate users logging in from the host with the IPv4 address 10.0.0.0/23:
SQLReference Manual
SQL Statements
This example creates an authentication method named v_kerberos to authenticate users that are
trying to connect from any host in the networks 2001:0db8:0001:12xx:
=> CREATE AUTHENTICATION v_kerberos METHOD 'gss' HOST '2001:db8:1::1200/56';
This example creates an authentication method named, RejectNoSSL, that rejects users from any
IPaddress that are trying to authenticate without SSL/TLS:
=> CREATE AUTHENTICATION RejectNoSSL METHOD 'reject' HOST NO TLS '0.0.0.0/0';
--IPv4
--IPv6
See Also
l
ALTERAUTHENTICATION
DROPAUTHENTICATION
GRANT(Authentication)
REVOKE (Authentication)
Privileges
Must be a database superuser to create external tables, unless the superuser has created a useraccessible storage location to which the COPY refers, as described in CREATE LOCATION. Once
SQLReference Manual
SQL Statements
external tables exist, you must also be a database superuser to access them through a select
statement.
Permission requirements for external tables differ from other tables. To gain full access (including
SELECT) to an external table that a user has privileges to create, the database superuser must also
grant READ access to the USER-accessible storage location, see GRANT (Storage Location).
Syntax
CREATE EXTERNAL TABLE [ IF NOT EXISTS ] [schema.]table-name {
... ( Column-Definition (table) [ , ... ] )
... | [ column-name-list (create table) ]
} AS COPY
[FROM {
...| 'pathToData' [ ON nodename | ON ANY NODE ]
...... [ BZIP | GZIP | LZO | UNCOMPRESSED ] [, ...]
}
...[ NATIVE
...| NATIVE VARCHAR
...| FIXEDWIDTH { COLSIZES (integer [, ....])
...| ORC} ]
]
...... [ FILLER datatype ]
...... [ FORMAT 'format' ]
...... [ ENCLOSED BY 'char' ]
...... [ ESCAPE AS 'char' | NO ESCAPE ]
...... [ NULL [ AS ] 'string' ]
...... [ TRIM 'byte' ]
...... [ DELIMITER [ AS ] 'char' ]
... [, ... ] ) ]
... [ COLUMN OPTION ( column
...... [ FORMAT 'format' ]
...... [ ENCLOSED BY 'char' ]
...... [ ESCAPE AS 'char' | NO ESCAPE ]
...... [ NULL [ AS ] 'string' ]
...... [ DELIMITER [ AS ] 'char' ]
... [, ... ] ) ]
...[ WITH ]
...[ WITH [ SOURCE source(arg='value')]
[ FILTER filter(arg='value') ] [ PARSER parser
(arg='value') ]]
...[ DELIMITER [ AS ] 'char' ]
...[ TRAILING NULLCOLS ]
...[ NULL [ AS ] 'string' ]
...[ ESCAPE AS 'char' | NO ESCAPE ]
...[ ENCLOSED BY 'char' [ AND 'char' ] ]
...[ RECORD TERMINATOR 'string' ]
...[ SKIP integer ]
...[ SKIP BYTES integer ]
...[ TRIM 'byte' ]
...[ REJECTMAX integer ]
...[ EXCEPTIONS 'path' [ ON nodename ] [, ...] ]
...[ REJECTED DATA 'path' [ ON nodename ]
[, ...] ]
...[ ENFORCELENGTH ]
...[ ABORT ON ERROR ]
SQLReference Manual
SQL Statements
Parameters
The following parameters from the parent statements are not supported in the CREATE EXTERNAL
TABLE AS COPY statement:
CREATE TABLE
COPY
AS AT EPOCH LAST
FROM STDIN
AT TIME 'timestamp'
FROM LOCAL
DIRECT
ENCODED BY
TRICKLE
hash-segmentation-clause
NO COMMIT
For all supported parameters, see the CREATE TABLE and COPY statements.
Usage Considerations
Canceling a CREATE EXTERNAL TABLE AS COPY statement can cause unpredictable results.
HP recommends that you allow the statement to finish, then use DROP TABLE once the table
exists.
When creating an external table, do not specify a column constraint of NOTNULLunless you are
sure that the data does not contain null values. Otherwise, you may see unexpected query
results.For example, rejected rows might still be included in a SELECT statement.
Examples
Examples of external table definitions:
CREATE EXTERNAL TABLE ext1 (x integer) AS COPY FROM '/tmp/ext1.dat' DELIMITER ',';
CREATE EXTERNAL TABLE ext1 (x integer) AS COPY FROM '/tmp/ext1.dat.bz2' BZIP DELIMITER
',';
CREATE EXTERNAL TABLE ext1 (x integer, y integer) AS COPY (x as '5', y) FROM
'/tmp/ext1.dat.bz2' BZIP DELIMITER ',';
SQLReference Manual
SQL Statements
See Also
l
Physical Schema
CREATE TABLE
SELECT
The CREATE FAULT GROUPstatement creates an empty fault group. You must run the ALTER FAULT
GROUP statement to add nodes or other fault groups to an existing fault group.
Syntax
CREATE FAULT GROUP name
Parameters
name
Specifies the name of the fault group to create. Name follows the conventions described in
Identifiers. You must provide distinct names for each fault group you create.
Permissions
Must be a superuser to create a fault group.
Example
The following command creates a fault group called parent0:
SQLReference Manual
SQL Statements
To add nodes or other fault groups to the parent0 fault group, run the ALTER FAULT GROUP
statement.
See Also
l
V_CATALOG.FAULT_GROUPS
V_CATALOG.CLUSTER_LAYOUT
Both the flex table and its associated _keys table are required to use flex tables successfully. The _
keys table and _view are subservient objects of the flex table, which cannot exist if the table does
not. However, you can drop either the _keys table or _view independently.
Declaring columns (or other supported parameters) is optional. CREATE FLEX TABLE supports many
of the parameters available when creating columnar tables, but not all. This section presents the
optional use of column definitions, and the subset of supported parameters.
SQLReference Manual
SQL Statements
You can also create flex external tables, with some syntactical variations, as described in
CREATE FLEX EXTERNAL TABLE AS COPY .
Note: HP Vertica does not support flexible global temporary tables.
Syntax
CREATE {FLEX | FLEXIBLE} TABLE [ IF NOT EXISTS ] [[db-name.]schema.]table-name {
... ( [ Column-Definition (table) [ , ... ]] )
... | [ table-constraint ( column_name, ... )]
... | [ column-name-list (create table) ]
}
... [ ORDER BY table-column [ , ... ] ]
... [ ENCODED BY column-definition [ , ... ]
... [ Hash-Segmentation-Clause
..... | UNSEGMENTED { NODE node | ALL NODES } ]
... [ KSAFE [k_num] ]
... [ PARTITION BY partition-clause ]
Parameters
See the CREATE TABLE statement for all parameter descriptions.
order_by
encoded_by
Segmentation
Ksafe
flexible table
__identity__
none
by hash __identity__
keys_table
frequency
none
Note: When you build a view for a flex table (see BUILD_FLEXTABLE_VIEW), the view is
SQLReference Manual
SQL Statements
Permissions
To create a flex table, you must have CREATE privileges on the table schema.
Examples
The following example creates a flex table named darkdata without specifying any column
information. HP Vertica creates a default superprojection and buddy projection as part of creating
the table:
=> CREATE FLEXIBLE TABLE darkdata();
CREATE TABLE
The following example creates a table called darkdata1 with one column (date_col) and specifies
the partition by clause to partition the data by year. HP Vertica creates a default superprojection
and buddy projections as part of creating the table:
=> CREATE FLEX TABLE darkdata1 (date_col date NOT NULL) partition by extract('year' from
date_col);
CREATE TABLE
See Also
l
Physical Schema
COPY
CREATE TABLE
PARTITION_PROJECTION
PARTITION_TABLE
SELECT
SQLReference Manual
SQL Statements
Auto Partitioning
Privileges
Must be a database superuser to create external tables, unless the superuser has created a useraccessible storage location to which the COPY refers, as described in CREATE LOCATION. If
external tables exist, you must also be a database superuser to access them through a select
statement.
Permission requirements for external tables differ from other tables. You must have full access
(including SELECT) to an external table that a user has privileges to create.The database superuser
must also grant READ access to the USER-accessible storage location, see GRANT (Storage
Location).
Syntax
CREATE {FLEX | FLEXIBLE} EXTERNAL TABLE [ IF NOT EXISTS ] [schema.]table-name {
... ( [ Column-Definition (table) [ , ... ] ] )
} AS COPY
[ FROM {
...| 'pathToData' [ ON nodename | ON ANY NODE ]
...... [ BZIP | GZIP | LZO | UNCOMPRESSED ] [, ...]
}
...[ NATIVE
...| NATIVE VARCHAR
...| FIXEDWIDTH { COLSIZES (integer [, ....]) }
...]
]
...[ WITH ]
...[ WITH [ SOURCE source(arg='value')] [ FILTER filter(arg='value') ] [ PARSER parser
(arg='value') ]]
SQLReference Manual
SQL Statements
...[
...[
...[
...[
...[
...[
...[
...[
...[
...[
...[
...[
...[
...[
DELIMITER [ AS ] 'char' ]
TRAILING NULLCOLS ]
NULL [ AS ] 'string' ]
ESCAPE AS 'char' | NO ESCAPE ]
ENCLOSED BY 'char' [ AND 'char' ] ]
RECORD TERMINATOR 'string' ]
SKIP integer ]
SKIP BYTES integer ]
TRIM 'byte' ]
REJECTMAX integer ]
EXCEPTIONS 'path' [ ON nodename ] [, ...] ]
REJECTED DATA 'path' [ ON nodename ] [, ...] ]
ENFORCELENGTH ]
ABORT ON ERROR ]
Parameters
The following parameters from the parent statements are not supported in the CREATE FLEXIBLE
EXTERNAL TABLE AS COPY statement:
CREATE TABLE
COPY
AS AT EPOCH LAST
FROM STDIN
AT TIME 'timestamp'
FROM LOCAL
DIRECT
ENCODED BY
TRICKLE
hash-segmentation-clause
NO COMMIT
For all supported parameters, see the CREATE TABLE and COPY statements.
Notes
Canceling a CREATE FLEXEXTERNAL TABLE AS COPY statement can cause unpredictable
results. HP Vertica recommends that you allow the statement to finish, then use DROP TABLE
once the table exists.
Examples
To create an external flex table:
SQLReference Manual
SQL Statements
As with other flex tables, creating an external flex table produces two regular tables: the named
table and its associated _keys table. The keys table is not an external table:
=> \dt mountains
List of tables
Schema |
Name
| Kind | Owner | Comment
--------+-----------+-------+---------+--------public | mountains | table | release |
(1 row)
1. Check the keys from the _keys table for the results of running the helper application:
=> select * from appLog_keys;
key_name
| frequency |
data_type_
guess
----------------------------------------------------------+-----------+----------------contributors
|
8 | varchar(20)
coordinates
|
8 | varchar(20)
created_at
|
8 | varchar(60)
entities.hashtags
|
8 | long varbinary
(186)
.
.
.
retweeted_status.user.time_zone
|
1 | varchar(20)
retweeted_status.user.url
|
1 | varchar(68)
retweeted_status.user.utc_offset
|
1 | varchar(20)
retweeted_status.user.verified
|
1 | varchar(20)
(125 rows)
SQLReference Manual
SQL Statements
See Also
l
CREATE TABLE
SELECT
User-Defined SQL functions--User defined SQL functions let you define and store commonlyused SQL expressions as a function. User defined SQL functions are useful for executing
complex queries and combining HP Vertica built-in functions. You simply call the function name
you assigned in your query.
User defined scalar functions (UDSFs) take in a single row of data and return a single value.
These functions can be used anywhere a native HP Vertica function or statement can be used,
except CREATE TABLE with its PARTITION BY or any segmentation clause.
While you use CREATE FUNCTION to create both SQL and scalar functions, you use a different
syntax for each function type. For more information, see:
l
SQLReference Manual
SQL Statements
Syntax
CREATE [ OR REPLACE ] AGGREGATE FUNCTION [[db-name.]schema.]function-name
... AS LANGUAGE 'language' NAME 'factory' LIBRARY library_name;
Parameters
[ OR REPLACE ]
[[db-name.]schema.]
SQLReference Manual
SQL Statements
function-name
The name of the function to create. If the function name is schemaqualified (as above), the function is created in the specified schema. This
name does not need to match the name of the factory, but it is less
confusing if they are the same or similar.
LANGUAGE 'language'
NAME 'factory'
The name of the factory class in the shared library that generates the
object to handle the function's processing.
LIBRARY library_name
The name of the shared library that contains the C++ object to perform
the processing for this function. This library must have been previously
loaded using the CREATE LIBRARY statement.
Notes
l
The parameters and return value for the function are automatically determined by the CREATE
AGGREGATE FUNCTION statement, based on data supplied by the factory class.
When a User Defined Aggregate function that is defined multiple times with arguments of
different data types is called, HP Vertica selects the function whose input parameters match the
parameters in the function call to perform the processing.
You can return a list of all SQL functions and User Defined Functions (including aggregates) by
querying the system table V_CATALOG.USER_FUNCTIONS or executing the vsql meta-command
\df. Users see only the functions on which they have EXECUTE privileges.
Permissions
l
To create a User Defined Aggregate function, the user must have CREATE and USAGE
privileges on the schema and USAGE privileges on the library.
To use a User Defined Aggregate, the user must have USAGE privileges on the schema and
EXECUTE privileges on the defined function. See GRANT (User Defined Extension) and
REVOKE (User Defined Extension).
SQLReference Manual
SQL Statements
Examples
The following example demonstrates loading a library named AggregateFunctions then defining a
function named ag_avg and ag_cat that are mapped to the ag_cat AverageFactory and
ConcatenateFactory classes in the library:
=> CREATE LIBRARY AggregateFunctions AS
'/opt/vertica/sdk/examples/build/AggregateFunctions.so';
CREATE LIBRARY
=> CREATE AGGREGATE FUNCTION ag_avg AS LANGUAGE 'C++' NAME 'AverageFactory'
library AggregateFunctions;
CREATE AGGREGATE FUNCTION
=> CREATE AGGREGATE FUNCTION ag_cat AS LANGUAGE 'C++' NAME 'ConcatenateFactory'
library AggregateFunctions;
CREATE AGGREGATE FUNCTION
=> \x
Expanded display is on.
select * from user_functions;
-[ RECORD 1 ]----------+----------------------------------------------------------------schema_name
| public
function_name
| ag_avg
procedure_type
| User Defined Aggregate
function_return_type
| Numeric
function_argument_type | Numeric
function_definition
| Class 'AverageFactory' in Library 'public.AggregateFunctions'
volatility
|
is_strict
| f
is_fenced
| f
comment
|
-[ RECORD 2 ]----------+----------------------------------------------------------------schema_name
| public
function_name
| ag_cat
procedure_type
| User Defined Aggregate
function_return_type
| Varchar
function_argument_type | Varchar
function_definition
| Class 'ConcatenateFactory' in Library
'public.AggregateFunctions'
volatility
|
is_strict
| f
is_fenced
| f
comment
|
See Also
l
CREATE LIBRARY
SQLReference Manual
SQL Statements
USER_FUNCTIONS
Syntax
CREATE [ OR REPLACE ] ANALYTIC FUNCTION function-name
... AS [ LANGUAGE 'language' ] NAME 'factory'
... LIBRARY library_name
... [ FENCED | NOT FENCED ];
Parameters
function-name
The name to assign to the UDAnF. This is the name you use in your
SQL statements to call the function.
LANGUAGE 'language'
NAME 'factory'
The name of the C++ factory class in the shared library that generates
the object to handle the function's processing.
LIBRARY library_name
The name of the shared library that contains the C++ object to perform
the processing for this function. This library must have been
previously loaded using the CREATE LIBRARY statement.
SQLReference Manual
SQL Statements
Privileges
l
To CREATE a function, the user must have CREATE privilege on the schema to contain the
function and USAGE privilege on the library containing the function.
To use a function, the user must have USAGE privilege on the schema that contains the
function and EXECUTE privileges on the function.
To DROP a function, the user must either be a superuser, the owner of the function, or the owner
of the schema which contains the function.
Usage Considerations
l
The parameters and return value for the function are automatically determined by the CREATE
ANALYTIC FUNCTION statement, based on data supplied by the factory class.
You can assign multiple functions the same name if they accept different sets of arguments.
See User Defined Function Overloading in the Extending HPVertica Guide for more information.
You can return a list of all UDFs by querying the system table V_CATALOG.USER_
FUNCTIONS. Users see only the functions on which they have EXECUTE privileges.
Examples
This example shows how to create an analytic function named an_rank based on the factory class
named RankFactory in the AnalyticFunctions library..
=> CREATE ANALYTIC FUNCTION an_rank AS LANGUAGE 'C++'
NAME 'RankFactory' LIBRARY AnalyticFunctions;
See Also
Developing a User Defined Analytic Function
CREATE FILTER
Adds a User Defined Load FILTER function. You must have already loaded this library using the
CREATE LIBRARY statement. When you call the SQL function, HP Vertica passes the
parameters to the function in the library to process it.
SQLReference Manual
SQL Statements
Syntax
CREATE [ OR REPLACE ] FILTER [[db-name.]schema.]function-name
... AS LANGUAGE 'language' NAME 'factory' LIBRARY library_name
... [ FENCED | NOT FENCED ];
Parameters
[ OR REPLACE ]
[[db-name.]schema.]
function-name
The name of the filter function to create. If the filter function name is
schema-qualified (as above), the function is created in the specified
schema. This name does not need to match the name of the factory,
but it is less confusing if they are the same or similar.
LANGUAGE 'language'
NAME 'factory'
The name of the factory class in the shared library that generates the
object to handle the filter function's processing.
This is the same name used by the RegisterFactory class.
LIBRARY library_name
The name of the shared library that contains the C++ object to perform
the processing for this filter function. This library must have been
previously loaded using the CREATE LIBRARY statement.
SQLReference Manual
SQL Statements
Notes
l
The parameters and return value for the filter function are automatically determined by the
CREATE FILTER statement, based on data supplied by the factory class.
You can return a list of all SQL functions and User Defined Functions by querying the system
table V_CATALOG.USER_FUNCTIONS or executing the vsql meta-command \df. Users see only
the functions on which they have EXECUTE privileges.
Permissions
l
Only a superuser can create or drop a function that uses a UDx library.
To use a User Defined Filter, the user must have USAGE privileges on the schema and
EXECUTE privileges on the defined filter function. See GRANT (User Defined Extension) and
REVOKE (User Defined Extension).
Important: Installing an untrusted UDL function can compromise the security of the server.
UDx's can contain arbitrary code. In particular, UD Source functions can read data from any
arbitrary location. It is up to the developer of the function to enforce proper security limitations.
Superusers must not grant access to UDx's to untrusted users.
Example
The following example demonstrates loading a library named iConverterLib, then defining a function
named Iconverter that is mapped to the iConverterFactory factory class in the library:
=> CREATE LIBRARY iConverterLib as '/opt/vertica/sdk/examples/build/IconverterLib.so';
CREATE LIBRARY
=> CREATE FILTER Iconverter AS LANGUAGE 'C++' NAME 'IconverterFactory' LIBRARY
IconverterLib;
CREATE FILTER FUNCTION
=> \x
Expanded display is on.
=> SELECT * FROM user_functions;
-[ RECORD 1 ]----------+-------------------schema_name
| public
function_name
| Iconverter
procedure_type
| User Defined Filter
function_return_type
|
function_argument_type |
function_definition
|
volatility
|
is_strict
| f
is_fenced
| f
SQLReference Manual
SQL Statements
comment
See Also
l
CREATE LIBRARY
DROP FILTER
USER_FUNCTIONS
Syntax
CREATE [ OR REPLACE ] FUNCTION
... [[db-name.]schema.]function-name ( [ argname argtype
... RETURN rettype
... AS
... BEGIN
...... RETURN expression;
... END;
[, ...] ] )
SQLReference Manual
SQL Statements
Parameters
[[db-name.]schema.]
function-name
Specifies a name for the SQL function to create. Name follows the
conventions described in Identifiers. When using more than one schema,
specify the schema that contains the function, as noted above.
argname
argtype
Specifies the data type for argument that is passed to the function.
Argument types must match HP Vertica type names. See SQL Data
Types.
rettype
RETURN expression;
Specifies the SQL function (function body), which must be in the form of
RETURN expression. expression can contain built-in functions,
operators, and argument names specified in the CREATE FUNCTION
statement.
A semicolon at the end of the expression is required.
Note: Only one RETURN expression is allowed in the CREATE FUNCTION
definition. FROM, WHERE, GROUP BY, ORDER BY, LIMIT, aggregation,
analytics, and meta function are not allowed.
Permissions
l
To CREATE a function, the user must have CREATE privilege on the schema to contain the
function and USAGE privilege on the library containing the function.
SQLReference Manual
SQL Statements
To use a function, the user must have USAGE privilege on the schema that contains the
function and EXECUTE privileges on the function.
To DROP a function, the user must either be a superuser, the owner of the function, or the owner
of the schema which contains the function.
See GRANT (User Defined Extension) and REVOKE (User Defined Extension).
Notes
l
A SQL function can be used anywhere in a query where an ordinary SQL expression can be
used, except in the table partition clause or the projection segmentation clause.
You can create views on the queries that use SQL functions and then query the views. When
you create a view, a SQL function replaces a call to the user-defined function with the function
body in a view definition. Therefore, when the body of the user-defined function is replaced, the
view should also be replaced.
If you want to change the body of a SQL function, use the CREATE OR REPLACE syntax. The
command replaces the function with the new definition. If you change only the argument name or
argument type, the system maintains both versions under the same function name. See
Examples section below.
If multiple SQL functions with same name and argument type are in the search path, the first
match is used when the function is called.
The strictness and volatility (stable, immutable, or volatile) of a SQL Macro are automatically
inferred from the function's definition. HP Vertica then determines the correctness of usage,
such as where an immutable function is expected but a volatile function is provided.
You can return a list of all SQL functions by querying the system table V_CATALOG.USER_
FUNCTIONS and executing the vsql meta-command \df. Users see only the functions on which
they have EXECUTE privileges.
Example
This following statement creates a SQL function called myzeroifnull that accepts an INTEGER
argument and returns an INTEGER result.
=> CREATE FUNCTION myzeroifnull(x INT) RETURN INT
SQLReference Manual
SQL Statements
AS BEGIN
RETURN (CASE WHEN (x IS NOT NULL) THEN x ELSE 0 END);
END;
You can use the new SQL function (myzeroifnull) anywhere you use an ordinary SQL expression.
For example, create a simple table:
=> CREATE
=> INSERT
=> INSERT
=> INSERT
=> SELECT
a
--1
0
(3 rows)
Use the myzeroifnull function in a SELECT statement, where the function calls col1 from table
tabwnulls:
=> SELECT myzeroifnull(col1) FROM tabwnulls;
myzeroifnull
-------------1
0
0
(3 rows)
If you want to change a SQL function's body, use the CREATE OR REPLACE syntax. The following
command modifies the CASE expression:
=> CREATE OR REPLACE FUNCTION zerowhennull(x INT) RETURN INT
RETURN (CASE WHEN (x IS NULL) THEN 0 ELSE x END);
END;
AS BEGIN
To see how this information is stored in the HP Vertica catalog, see Viewing Information About SQL
Functions in the Extending HPVertica Guide.
SQLReference Manual
SQL Statements
See Also
l
ALTER FUNCTION
DROP FUNCTION
USER_FUNCTIONS
Syntax
CREATE [ OR REPLACE ] FUNCTION [[db-name.]schema.]function-name
... AS LANGUAGE 'language' NAME 'factory' LIBRARY library_name
... [ FENCED | NOT FENCED ];
Parameters
[ OR REPLACE ]
SQLReference Manual
SQL Statements
[[db-name.]schema.]
function-name
LANGUAGE 'language'
NAME 'factory'
The name of the factory class in the shared library that generates the
object to handle the function's processing.
LIBRARY library_name
The name of the file that contains the C++ library, Java Jar file, or R
functions file to perform the processing for this function. This library
must have been previously loaded using the CREATE LIBRARY
statement.
Permissions
l
To CREATE a function, the user must have CREATE privilege on the schema to contain the
function and USAGE privilege on the library containing the function.
To use a function, the user must have USAGE privilege on the schema that contains the
function and EXECUTE privileges on the function.
To DROP a function, the user must either be a superuser, the owner of the function, or the owner
of the schema which contains the function.
Notes
l
The parameters and return value for the function are automatically determined by the CREATE
FUNCTION statement, based on data supplied by the factory class.
SQLReference Manual
SQL Statements
Multiple functions can share the same name if they have different parameters. When you call a
multiply-defined function, HP Vertica selects the UDF function whose input parameters match
the parameters in the function call to perform the processing. This behavior is similar to having
multiple signatures for a method or function in other programming languages.
You can return a list of all SQL functions and UDFs by querying the system table V_
CATALOG.USER_FUNCTIONS or executing the vsql meta-command \df. Users see only the
functions on which they have EXECUTE privileges.
Examples
The following example demonstrates loading a library named scalarfunctions, then defining a
function named Add2ints that is mapped to the Add2intsInfo factory class in the library:
=> CREATE LIBRARY ScalarFunctions AS
'/opt/vertica/sdk/examples/build/ScalarFunctions.so';
CREATE LIBRARY
SQLReference Manual
SQL Statements
See Also
l
CREATE LIBRARY
DROP FUNCTION
USER_FUNCTIONS
CREATE PARSER
Adds a User Defined Load PARSER function. You must have already loaded this library using the
CREATE LIBRARY statement. When you call the SQL function, HP Vertica passes the
parameters to the function in the library to process it.
Syntax
CREATE [ OR REPLACE ] PARSER [[db-name.]schema.]function-name
... AS LANGUAGE 'language' NAME 'factory' LIBRARY library_name
... [ FENCED | NOT FENCED ];
Parameters
[ OR REPLACE ]
SQLReference Manual
SQL Statements
[[db-name.]schema.]
function-name
The name of the parser function to create. If the parser function name is
schema-qualified (as above), the function is created in the specified
schema. This name does not need to match the name of the factory,
but it is less confusing if they are the same or similar.
LANGUAGE 'language'
NAME 'factory'
The name of the factory class in the shared library that generates the
object to handle the parser function's processing.
This is the same name used by the RegisterFactory class.
LIBRARY library_name
The name of the shared library that contains the C++ object to perform
the processing for this parser function. This library must have been
previously loaded using the CREATE LIBRARY statement.
[ FENCED
NOT FENCED ]
Notes
l
The parameters and return value for the parser function are automatically determined by the
CREATE PARSER statement, based on data supplied by the factory class.
You can return a list of all SQL functions and User Defined Functions by querying the system
table V_CATALOG.USER_FUNCTIONS or executing the vsql meta-command \df. Users see only
the functions on which they have EXECUTE privileges.
SQLReference Manual
SQL Statements
Permissions
l
Only a superuser can create or drop a function that uses a UDx library.
To use a User Defined Parser, the user must have USAGE privileges on the schema and
EXECUTE privileges on the defined parser function. See GRANT (User Defined Extension) and
REVOKE (User Defined Extension).
Important: Installing an untrusted UDL function can compromise the security of the server.
UDx's can contain arbitrary code. In particular, UD Source functions can read data from any
arbitrary location. It is up to the developer of the function to enforce proper security limitations.
Superusers must not grant access to UDx's to untrusted users.
Example
The following example demonstrates loading a library named BasicIntegrerParserLib, then defining
a function named BasicIntegerParser that is mapped to the BasicIntegerParserFactory factory
class in the library:
=> CREATE LIBRARY BasicIntegerParserLib as
'/opt/vertica/sdk/examples/build/BasicIntegerParser.so';
CREATE LIBRARY
=> CREATE PARSER BasicIntegerParser AS LANGUAGE 'C++' NAME 'BasicIntegerParserFactory'
LIBRARY BasicIntegerParserLib;
CREATE PARSER FUNCTION
=> \x
Expanded display is on.
=> SELECT * FROM user_functions;
-[ RECORD 1 ]----------+-------------------schema_name
| public
function_name
| BasicIntegerParser
procedure_type
| User Defined Parser
function_return_type
|
function_argument_type |
function_definition
|
volatility
|
is_strict
| f
is_fenced
| f
comment
|
See Also
l
CREATE LIBRARY
DROP PARSER
SQLReference Manual
SQL Statements
GRANT (UserDefinedExtension)
USER_FUNCTIONS
CREATE SOURCE
Adds a User Defined Load SOURCE function. You must have already loaded this library using the
CREATE LIBRARY statement. When you call the SQL function, HP Vertica passes the
parameters to the function in the library to process it.
Syntax
CREATE [ OR REPLACE ] SOURCE [[db-name.]schema.]function-name
... AS LANGUAGE 'language' NAME 'factory' LIBRARY library_name
... [ FENCED | NOT FENCED ];
Parameters
[ OR REPLACE ]
[[db-name.]schema.]
SQLReference Manual
SQL Statements
function-name
The name of the source function to create. If the source function name
is schema-qualified (as above), the function is created in the specified
schema. This name does not need to match the name of the factory,
but it is less confusing if they are the same or similar.
LANGUAGE 'language'
NAME 'factory'
The name of the factory class in the shared library that generates the
object to handle the source function's processing.
This is the same name used by the RegisterFactory class.
LIBRARY library_name
The name of the shared library that contains the C++ object to perform
the processing for this source function. This library must have been
previously loaded using the CREATE LIBRARY statement.
Notes
l
The parameters and return value for the source function are automatically determined by the
CREATE SOURCE statement, based on data supplied by the factory class.
You can return a list of all SQL functions and User Defined Functions by querying the system
table V_CATALOG.USER_FUNCTIONS or executing the vsql meta-command \df. Users see only
the functions on which they have EXECUTE privileges.
Permissions
l
Only a superuser can create or drop a function that uses a UDx library.
To use a User Defined Source, the user must have USAGE privileges on the schema and
EXECUTE privileges on the defined source function. See GRANT (User Defined Extension)
and REVOKE (User Defined Extension).
Important: Installing an untrusted UDL function can compromise the security of the server.
UDx's can contain arbitrary code. In particular, UD Source functions can read data from any
arbitrary location. It is up to the developer of the function to enforce proper security limitations.
Superusers must not grant access to UDx's to untrusted users.
SQLReference Manual
SQL Statements
Example
The following example demonstrates loading a library named curllib, then defining a function named
curl that is mapped to the CurlSourceFactory factory class in the library:
=> CREATE LIBRARY curllib as '/opt/vertica/sdk/examples/build/cURLLib.so';
CREATE LIBRARY
=> CREATE SOURCE curl AS LANGUAGE 'C++' NAME 'CurlSourceFactory' LIBRARY curllib;
CREATE SOURCE
=> \x
Expanded display is on.
=> SELECT * FROM user_functions;
-[ RECORD 1 ]----------+-------------------schema_name
| public
function_name
| curl
procedure_type
| User Defined Source
function_return_type
|
function_argument_type |
function_definition
|
volatility
|
is_strict
| f
is_fenced
| f
comment
|
See Also
l
CREATE LIBRARY
DROP SOURCE
USER_FUNCTIONS
SQLReference Manual
SQL Statements
(UDF), see CREATE FUNCTION (UDF). If you want to create a SQL function, see CREATE
FUNCTION (SQL).
Syntax
CREATE TRANSFORM FUNCTION function-name
... [ AS LANGUAGE 'language' ] NAME 'factory'
... LIBRARY library_name
... [ FENCED | NOT FENCED ];
Parameters
function-name
The name to assign to the UDTF. This is the name you use in your
SQL statements to call the function.
LANGUAGE 'language'
NAME 'factory'
The name of the C++ factory class or R factory function in the shared
library that generates the object to handle the function's processing.
LIBRARY library_name
The name of the shared library that contains the C++ object to perform
the processing for this function. This library must have been
previously loaded using the CREATE LIBRARY statement.
Permissions
l
To CREATE a function, the user must have CREATE privilege on the schema to contain the
function and USAGE privilege on the library containing the function.
To use a function, the user must have USAGE privilege on the schema that contains the
function and EXECUTE privileges on the function.
To DROP a function, the user must either be a superuser, the owner of the function, or the owner
of the schema which contains the function.
SQLReference Manual
SQL Statements
Any statements other than the SELECT statement containing the call to the UDTF and a
PARTITION BY expression
A TIMESERIES clause
Notes
l
The parameters and return values for the function are automatically determined by the CREATE
TRANSFORM FUNCTION statement, based on data supplied by the factory class.
You can assign multiple functions the same name if they have different parameters. When you
call a multiply-defined function, HP Vertica selects the UDF function whose input parameters
match the parameters in the function call to perform the processing. This behavior is similar to
having multiple signatures for a method or function in other programming languages.
You can return a list of all UDFs by querying the system table V_CATALOG.USER_
FUNCTIONS. Users see only the functions on which they have EXECUTE privileges.
Examples
This example shows how to add a UDTF to the catalog.
=> CREATE TRANSFORM FUNCTION transFunct AS LANGUAGE 'C++' NAME 'myFactory' LIBRARY
myFunction;
See Also
l
DROP FUNCTION
SQLReference Manual
SQL Statements
USER_FUNCTIONS
CREATEHCATALOGSCHEMA
Define a schema for data stored in a Hive data warehouse using the HCatalog Connector. For more
information, see Using the HCatalog Connector in the Hadoop Integration Guide.
Syntax
CREATE HCATALOG SCHEMA [IF NOT EXISTS] schemaName
[AUTHORIZATION user-id]
[[WITH] HOSTNAME='metastore-host']
[PORT=hiveMetastore-port]
[WEBSERVICE_HOSTNAME='webHCat-hostname']
[WEBSERVICE_PORT=webHCat-port]
[HCATALOG_SCHEMA='hive-schema-name']
[HCATALOG_USER='hcat-username']
[HCATALOG_CONNECTION_TIMEOUT=timeout]
[HCATALOG_SLOW_TRANSFER_LIMIT=xfer-limit]
[HCATALOG_SLOW_TRANSFER_TIME=xfer-time]
Parameters
Parameter
Description
Default
Value
N/A
none
current
username
none
SQLReference Manual
SQL Statements
9083
webHCathostname
metastorehost
webHCat-port
50111
hive-schemaname
schemaName
hcat-username
current
username
See notes
timeout
The lowest data transfer rate (in bytes per second) from the
See notes
See notes
enforcing the data transfer rate lower limit. After this time has
passed, the HCatalog Connector tests whether the data
transfer rate from theWebHCat server is at least as fast as the
value set in xfer-limit. If it is not, then the HCatalog
Connector breaks the connection and terminates the query.
Notes
The default values for timeout, xfer-limit, and xfer-time values are set by the configuration
parameters HCatConnectionTimeout, HCatSlowTransferLimit, and HCatSlowTransferTime. See
HCatalog Connector Parameters in the Administrator's Guide for more information.
If using Kerberos authentication, the current user name is always used and the
AUTHORIZATIONparameter is ignored.
If you copied the Hadoop configuration files as described in Configuring HP Vertica for HCatalog,
you can omit most parameters here. By default this statement uses the values specified in those
configuration files, though you can still override them with this statement. If the configuration files
are complete, the following is a valid statement:
SQLReference Manual
SQL Statements
Permissions
The user must be a superuser or be granted all permissions on the database to use
CREATEHCATALOGSCHEMA.
Example
The following statement shows how to use CREATEHCATALOGSCHEMA to define a new
schema for tables stored in a Hive database and then query the system tables that contain
information about those tables:
=> CREATE HCATALOG SCHEMA hcat WITH hostname='hcathost' HCATALOG_SCHEMA='default'
-> HCATALOG_USER='hcatuser';
CREATE SCHEMA
=> -- Show list of all HCatalog schemas
=> \x
Expanded display is on.
=> SELECT * FROM v_catalog.hcatalog_schemata;
-[ RECORD 1 ]--------+-----------------------------schema_id
| 45035996273748980
schema_name
| hcat
schema_owner_id
| 45035996273704962
schema_owner
| dbadmin
create_time
| 2013-11-04 15:09:03.504094-05
hostname
| hcathost
port
| 9933
webservice_hostname | hcathost
webservice_port
| 50111
hcatalog_schema_name | default
hcatalog_user_name
| hcatuser
metastore_db_name
| hivemetastoredb
=> -- List the tables in all HCatalog schemas
=> SELECT * FROM v_catalog.hcatalog_table_list;
-[ RECORD 1 ]------+-----------------table_schema_id
| 45035996273748980
table_schema
| hcat
hcatalog_schema
| default
table_name
| messages
hcatalog_user_name | hcatuser
-[ RECORD 2 ]------+-----------------table_schema_id
| 45035996273748980
table_schema
| hcat
hcatalog_schema
| default
table_name
| weblog
hcatalog_user_name | hcatuser
-[ RECORD 3 ]------+-----------------table_schema_id
| 45035996273748980
table_schema
| hcat
SQLReference Manual
SQL Statements
hcatalog_schema
| default
table_name
| tweets
hcatalog_user_name | hcatuser
CREATE LIBRARY
Loads a library containing User Defined Extensions (UDxs) into the HP Vertica catalog. After
loading a library in the catalog, you can use statements such as CREATEFUNCTIONto define the
extensions contained in the library. See Developing and Using User Defined Extensions in the
Extending HPVertica Guide for details.
Warning: You can choose to run UDxs developed in C++in unfenced mode. Unfenced UDxs
run directly in the HP Vertica process. If the UDx you run in unfenced mode has bugs, it can
negatively impact the database, causing instability or even crashes. To avoid these issues, run
your UDx only in fenced mode. A few UDx types can only be run in unfenced mode.
Syntax
CREATE [OR REPLACE] LIBRARY
[[db-name.]schema.]library_name
AS 'library_path'
[ DEPENDS 'support_path' ]
[ LANGUAGE 'language' ]
Parameters
[ OR REPLACE ]
Replaces the old library with the new one. If you do not supply this
parameter, the CREATE LIBRARY statement fails when an existing
library matches the name the library you are trying to define.
[[db-name.]schema.]
SQLReference Manual
SQL Statements
library_name
'library_path'
The absolute path and file name of the library to load. This file must
be located in the initiator node's filesystem.
[DEPENDS 'support_path']
[LANGUAGE 'language']
'C++'
'Java'
'R'
Privileges
Must be a superuser to create or drop a library.
Usage Considerations
l
As part of the loading process, HP Vertica distributes the library file and any supporting libraries
to all nodes in the database. cluster. Any nodes that are down or that are added to the cluster
later automatically receive a copy of the files when they join the cluster.
SQLReference Manual
SQL Statements
HP Vertica makes its own copies of the library files. Later modification or deletion of the original
files specified in the statement does not effect the library defined in the catalog. To update the
library, use the ALTERLIBRARYstatement.
Simply loading the library is no guarantee that it functions correctly. CREATE LIBRARY
performs some basic checks on the library file to verify it is compatible with HP Vertica. The
statement fails if it detects that the library was not correctly compiled or it finds other basic
incompatibilities. However, there are many issues in shared libraries that CREATE LIBRARY
cannot detect.
Libraries are added to the database catalog, and therefore persist across database restarts.
If your Java library depends on native libraries (SO files), use DEPENDSto specify the path and
call System.loadLibrary() in your UDx to load the native libraries from that path.
Examples
To load a library in the home directory of the dbadmin account with the name MyFunctions:
=> CREATE LIBRARY MyFunctions AS 'home/dbadmin/my_functions.so';
To load a Java library named JavaLib.jar that depends on multiple support JARfiles in the
/home/dbamin/mylibs subdirectory:
=> CREATE LIBRARY DeleteVowelsLib AS '/home/dbadmin/JavaLib.jar'
DEPENDS '/home/dbadmin/mylibs/*' LANGUAGE 'JAVA';
See Also
l
DROP LIBRARY
ALTER LIBRARY
SQLReference Manual
SQL Statements
Syntax
CREATE [ OR REPLACE ] LOCAL {TEMPORARY | TEMP} VIEW [viewname] [ ( column-name [, ...] ) ]
AS query ]
Parameters
[ OR REPLACE ]
viewname
[Optional] Specifies the name of the local temporary view to create. Name
follows the conventions described in Identifiers. The temporary view name must
be unique among all existing tables, views, or projections in the database. If you
do not supply a name for the temporary view, the statement uses the current
user name.
column-name
[Optional] Specifies the list of names to use as column names for the temporary
view. Columns are presented from left to right in the order given. If you do not
specify one or more column names, HP Vertica automatically deduces the
column names from the query.
query
Specifies the SELECT query that the temporary view executes. HP Vertica
also uses the query to deduce the list of names to be used as columns names
for the temporary view if you do not specify them.
Use a SELECT statement to specify the query, which can refer to tables, temp
tables, and other views.
Permissions
The following permissions apply to local temporary views:
SQLReference Manual
SQL Statements
To create a local temporary view, the user must have usage permissions on any base object
from which the view pulls.
Privileges required on base objects for the view owner must be granted directly; you cannot
grant privileges on these objects using roles.
Since local temporary entities are session scoped, local temporary views are visible only to their
creator in the current session.
Example
=> CREATE LOCAL TEMP VIEW myview AS
SELECT SUM(annual_income), customer_state
FROM public.customer_dimension
WHERE customer_key IN
(SELECT customer_key
FROM store.store_sales_fact)
GROUP BY customer_state
ORDER BY customer_state ASC;
The following example uses the myview temporary view with a WHERE clause that limits the
results to combined salaries of greater than 2,000,000,000.
=> SELECT * FROM myview WHERE SUM > 2000000000;
SUM
| customer_state
-------------+---------------2723441590 | AZ
29253817091 | CA
4907216137 | CO
3769455689 | CT
3330524215 | FL
4581840709 | IL
3310667307 | IN
2793284639 | MA
5225333668 | MI
2128169759 | NV
2806150503 | PA
2832710696 | TN
14215397659 | TX
SQLReference Manual
SQL Statements
2642551509 | UT
(14 rows)
See Also
l
ALTER VIEW
SELECT
CREATE VIEW
SELECT
DROP VIEW
GRANT (View)
REVOKE (View)
CREATE LOCATION
Creates a new storage location where HP Vertica can store data. After you create the location, you
create storage policies that assign the storage location to the database objects that will store data
in the location.
Syntax
CREATE LOCATION 'path'
{NODE 'nodename' | ALL NODES}
[SHARED]
[USAGE 'usetype']
[LABEL 'labelname']
SQLReference Manual
SQL Statements
Arguments
path
Where HP Vertica will store this location's data. The type of filesystem on
which the location is based determines the format of this argument:
l
[NODE
nodename |
ALL NODES]
NODE Use this keyword to create the storage location on a single node.
Specify the node using its name as it appears in the NODES system table.
ALL NODESUse this keyword to create the storage location on all nodes
Indicates the location set by the path is shared (used by all of the nodes)
rather than local to each node. See below for details.
[USAGE
'usetype']
'USER'User who have been granted access to the storage location can
store data there.
A label for the storage location. You use this name later when assigning the
storage location to data objects.
SQLReference Manual
SQL Statements
WebHDFS URIs
The URIs you supply in the path argument are similar to the URLs for accessing files through
WebHDFS, with a few differences:
l
The path portion of the URI does not include the /webhdfs/v1/ portion of the path. Instead, after
the hostname and port, specify the HDFSpath from the root directory.
For example, suppose you can access the HDFSdirectory you want to use as a storage location
using the URL http://hadoop:50070/webhdfs/v1/user/dbadmin. Then the URI you supply to
the CREATELOCATIONstatement is webhdfs://hadoop:50070/user/dbadmin.
For more information about WebHDFSURIs, see the WebHDFS RESTAPIpage.
Privileges
The user must be a superuser to use CREATELOCATION.
In addition, the HP Vertica process must have read and write permissions to the location where
date will be stored. Each type of filesystem has its own requirements:
l
LinuxThe database administrator account (usually named dbadmin)must have full read and
write access to the directory in the path argument.
SQLReference Manual
SQL Statements
HDFS without KerberosRequires a Hadoop user whose username matches the HP Vertica
database administrator username (usually dbadmin). This Hadoop user must have read and
write access to the HDFSdirectory specified in the path argument.
HDFS with KerberosRequires a Hadoop user whose username matches the principal in the
keytab file on each HP Vertica node. This is not the same as the database administrator
username. This Hadoop user must have read and write access to the HDFS directory stored in
the path argument.
Examples
The following example shows how to create a storage location in the local Linux filesystem for
temporary data storage.
=> CREATE LOCATION '/home/dbadmin/testloc' USAGE 'TEMP' LABEL 'tempfiles';
The following example shows how to create a storage location on the HDFS available from the
Hadoop name node hadoop.example.com in the /user/dbadmin directory. The HDFS cluster does
not use Kerberos.
=> CREATE LOCATION 'webhdfs://hadoop.example.com:50070/user/dbadmin' ALL NODES SHARED
USAGE 'data' LABEL 'coldstorage';
The following example shows how to create the same storage location, but on a Hadoop cluster
that uses Kerberos. Note the output that reports the principal being used.
=> CREATE LOCATION 'webhdfs://hadoop.example.com:50070/user/dbadmin' ALL NODES SHARED
USAGE 'data' LABEL 'coldstorage';
NOTICE 0: Performing HDFS operations using kerberos principal
[vertica/hadoop.example.com]
CREATE LOCATION
Usage Considerations
This statement replaces the ADD_LOCATION function, which is now deprecated and may be
removed in a future version.
See Also
l
SQLReference Manual
SQL Statements
ALTER_LOCATION_LABEL
ALTER_LOCATION_USE
DROP_LOCATION
SET_OBJECT_STORAGE_POLICY
Syntax
CREATE NETWORK INTERFACE network-interface-name ON node-name WITH 'ip address of node'
network-interface-name
The name you assign to the network interface. Name follows the
conventions described in Identifiers.
node-name
IP address of node
Permissions
You must be a dbadmin user to create a network interface.
Examples
This example shows how to create a network interface.
=> CREATE NETWORK INTERFACE mynetwork ON node1 WITH '123.4.5.6';
CREATE PROCEDURE
Adds an external procedure to HP Vertica. See Implementing External Procedures in the Extending
HPVertica Guide for more information about external procedures.
SQLReference Manual
SQL Statements
Syntax
CREATE PROCEDURE [[db-name.]schema.]procedure-name (
... [ argname ] [ argtype [,...] ] )
... AS 'exec-name'
... LANGUAGE 'language-name'
... USER 'OS-user'
Parameters
[[db-name.]schema.]
procedure-name
argname
argtype
[Optional] Specifies the data type for argument(s) that will be passed to the
procedure. Argument types must match HP Vertica type names. See SQL
Data Types.
AS
LANGUAGE
USER
Specifies the user executed as. The user is the owner of the file. The user
cannot be root.
Note: The external program must allow execute privileges for this user.
Permissions
To create a procedure a superuser must have CREATE privilege on schema to contain procedure.
SQLReference Manual
SQL Statements
Notes
l
A procedure file must be owned by the database administrator (OS account) or by a user in the
same group as the administrator. (The procedure file owner cannot be root.) The procedure file
must also have the set UID attribute enabled, and allow read and execute permission for the
group.
By default, only a database superuser can execute procedures. However, a superuser can grant
the right to execute procedures to other users. See GRANT (Procedure).
Example
This example illustrates how to create a procedure named helloplanet for the helloplanet.sh external
procedure file. This file accepts one varchar argument.
Sample file:
#!/bin/bashecho "hello planet argument: $1" >> /tmp/myprocedure.log
exit 0
See Also
l
DROP PROCEDURE
CREATE PROFILE
Creates a profile that controls password requirements for users.
Syntax
CREATE PROFILE name LIMIT
... [PASSWORD_LIFE_TIME {life-limit | DEFAULT | UNLIMITED}]
... [PASSWORD_GRACE_TIME {grace_period | DEFAULT | UNLIMITED}]
... [FAILED_LOGIN_ATTEMPTS {login-limit | DEFAULT | UNLIMITED}]
... [PASSWORD_LOCK_TIME {lock-period | DEFAULT | UNLIMITED}]
... [PASSWORD_REUSE_MAX {reuse-limit | DEFAULT | UNLIMITED}]
... [PASSWORD_REUSE_TIME {reuse-period | DEFAULT | UNLIMITED}]
SQLReference Manual
SQL Statements
...
...
...
...
...
...
Note: For all parameters, the special DEFAULT value means that the parameter's value is
inherited from the DEFAULT profile. Any changes to the parameter in the DEFAULT profile is
reflected by all of the profiles that inherit that parameter. Any parameter not specified in the
CREATE PROFILE command is set to DEFAULT.
Parameters
Name
Description
Meaning of
UNLIMITED
value
name
N/A
Passwords
never expire.
SQLReference Manual
SQL Statements
Name
Description
Meaning of
UNLIMITED
value
PASSWORD_GRACE_TIMEgrace-period
No grace
period (the
same as zero)
Accounts are
never locked,
no matter how
being locked.
many failed
login attempts
are made.
PASSWORD_LOCK_TIME lock-period
Accounts
locked
because of too
many failed
login attempts
are never
PASSWORD_LOCK_
automatically
unlocked.
account is automatically
They must be
unlocked.
manually
unlocked by
the database
superuser.
SQLReference Manual
SQL Statements
Name
Description
Meaning of
UNLIMITED
value
PASSWORD_REUSE_MAX reuse-limit
required to
change
passwords a
certain number
of times before
reusing an old
password.
PASSWORD_REUSE_TIMEreuse-period
Password
reuse is not
limited by time.
Passwords are
characters allowed in a
limited to 100
characters.
Equal to max-
characters required in a
length.
0 (no
minimum).
in a password. Valid
ranged is 0 to max-length.
PASSWORD_MIN_UPPERCASE_LETTERSmin-cap-letters
0 (no
minimum).
SQLReference Manual
SQL Statements
Name
Description
Meaning of
UNLIMITED
value
PASSWORD_MIN_LOWERCASE_LETTERSmin-lower-letters
Minimum number of
0 (no
minimum).
must be in a password.
Valid range is is 0 to maxlength.
PASSWORD_MIN_DIGITS min-digits
0 (no
minimum).
Minimum number of
0 (no
minimum).
Permissions
Must be a superuser to create a profile.
Note: Only the profile settings for how many failed login attempts trigger account locking and
how long accounts are locked have an effect on password authentication methods such as
LDAP or GSS. All password complexity, reuse, and lifetime settings affect only passwords
that HP Vertica manages.
Example
=> CREATE PROFILE sample_profile LIMIT PASSWORD_MAX_LENGTH 20;
SQLReference Manual
SQL Statements
See Also
l
ALTER PROFILE
DROP PROFILE
CREATE PROJECTION
Creates metadata for a projection in the HP Vertica catalog.
Note: For detailed information about using CREATEPROJECTIONto create live aggregate
projections and Top-K projections, see CREATEPROJECTION(Live Aggregate Projections).
Syntax
CREATE PROJECTION [ IF NOT EXISTS ]
...[[db-name.]schema.]projection-name
...[ ( { projection-column ... | GROUPED ( column-reference1, column-reference2 [ ,... ])}
......... [ ACCESSRANK integer ]
......... [ ENCODING encoding-type ] } [ ,... ] )
...]
AS SELECT {table-column | expr_with_columns } [ , ... ] FROM table-reference [ , ... ]
... [ WHERE join-predicate [ AND join-predicate ] ...
... [ ORDER BY table-column [ , ... ] ]
... [ hash-segmentation-clause
... | UNSEGMENTED { NODE node | ALL NODES } ]
... [ KSAFE [ k-num ] ]
Parameters
[ IF NOT EXISTS ]
SQLReference Manual
SQL Statements
[[db-name.]schema.]
projection-name
{table-column | expr_with_columns }
[ ENCODING encoding-type ]
SQLReference Manual
SQL Statements
[ ACCESSRANK integer ]
SELECT table-column
table-reference
[ WHERE join-predicate ]
SQLReference Manual
SQL Statements
[ ORDER BY table-column ]
hash-segmentation-clause
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
KSAFE [ k-num ]
Privileges
When you insert data into a table, HP Vertica automatically creates a superprojection for the
table.
Superprojections do not require any additional privileges to create or drop, other than privileges for
table creation. Users who can create a table or drop a table can also create and drop the associated
superprojection.
To explicitly create a projection using the CREATE PROJECTION statement, a user must be a
superuser or owner of the anchor table or have the following privileges:
l
USAGE privilege on all the schemas that contain the base tables referenced by the projection
Only the anchor table owner can drop explicitly created projections or pre-join projections.
Explicitly created projections can be live aggregate projections, including Top-K projections and
projections with expressions.
To prevent data loss and inconsistencies, tables must contain one superprojection. You cannot
drop a projection if that projection is the table's only superprojection.
SQLReference Manual
SQL Statements
You cannot drop a buddy projection if dropping that projection violates the system K-safety .
Projection Naming
There are several ways that projections are named when you execute CREATEPROJECTION:
l
When you insert data into the table, HP Vertica automatically creates a superprojection and as
many buddy projections that are needed to satisfy the system K-safety. Those projections have
the name: tablename_b0, tablename_b1, and so on.
When you create an unsegmented projection with CREATE PROJECTION ... ALL NODES, the
To create a projection that calculates the product of a and b, use a statement like the following:
=> CREATE PROJECTION values_product (a, b, product_value)
AS SELECT a, b, a*b FROM values
SEGMENTED BY HASH(a) ALL NODES KSAFE;
To query that projection, you must use the name that HP Vertica assigned to it:
=> SELECT * FROM values_product_b0;
or
=> SELECT * FROM values_product_b1;
SQLReference Manual
SQL Statements
=> CREATE TABLE trades (stock CHAR(5), bid INT, ask INT);
=> CREATE PROJECTION tradeproj (stock ENCODING RLE,
GROUPED(bid ENCODING DELTAVAL, ask))
AS (SELECT * FROM trades) KSAFE 1;
The following example show how to create a projection that uses expressions in the column
definition. The projection contains three columns, two integers, and a third column that stores the
product of those two integers:
=> CREATE TABLE values (a INT, b INT
=> CREATE PROJECTION product (a, b, product_value) AS
SELECT a, b, a*b FROM values ORDER BY a KSAFE;
See Also
l
Projection Basics
Encoding-Type
HP Vertica supports the following encoding and compression types:
ENCODING BLOCK_DICT
For each block of storage, HP Vertica compiles distinct column values into a dictionary and then
stores the dictionary and a list of indexes to represent the data block.
SQLReference Manual
SQL Statements
BLOCK_DICT is ideal for few-valued, unsorted columns in which saving space is more important
than encoding speed. Certain kinds of data, such as stock prices, are typically few-valued within a
localized area once the data is sorted, such as by stock symbol and timestamp, and are good
candidates for BLOCK_DICT. Long CHAR/VARCHAR columns are not good candidates for
BLOCK_DICT encoding.
CHAR and VARCHAR columns that contain 0x00 or 0xFF characters should not be encoded with
BLOCK_DICT. Also, BINARY/VARBINARY columns do not support BLOCK_DICT encoding.
The encoding CPU for BLOCK_DICT is significantly higher than for default encoding schemes. The
maximum data expansion is eight percent (8%).
ENCODING BLOCKDICT_COMP
This encoding type is similar to BLOCK_DICT except that dictionary indexes are entropy coded.
This encoding type requires significantly more CPU time to encode and decode and has a poorer
worst-case performance. However, if the distribution of values is extremely skewed, using
BLOCKDICT_COMP encoding can lead to space savings.
ENCODING BZIP_COMP
This encoding type uses the bzip2 compression algorithm on the block contents. See bzip web site
for more information. This algorithm results in higher compression than the automatic LZOand gzip
encoding. However, it requires more CPUtime to compress than these other methods. This
algorithm is best used on large string columns such as VARCHAR, VARBINARY, CHAR, and
BINARY. Choose this encoding type when you are willing to trade slower load speeds for higher
data compression.
ENCODING COMMONDELTA_COMP
This compression scheme builds a dictionary of all the deltas in the block and then stores indexes
into the delta dictionary using entropy coding.
This scheme is ideal for sorted FLOAT and INTEGER-based
(DATE/TIME/TIMESTAMP/INTERVAL) data columns with predictable sequences and only the
occasional sequence breaks, such as timestamps recorded at periodic intervals or primary keys.
For example, the following sequence compresses well: 300, 600, 900, 1200, 1500, 600, 1200, 1800,
2400. The following sequence does not compress well: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55.
If the delta distribution is excellent, columns can be stored in less than one bit per row. However,
this scheme is very CPU intensive. If you use this scheme on data with arbitrary deltas, it can lead
to significant data expansion.
SQLReference Manual
SQL Statements
ENCODING DELTARANGE_COMP
This compression scheme is primarily used for floating-point data, and it stores each value as a
delta from the previous one.
This scheme is ideal for many-valued FLOAT columns that are either sorted or confined to a range.
Do not use this scheme for unsorted columns that contain NULL values, as the storage cost for
representing a NULL value is high. This scheme has a high cost for both compression and
decompression.
To determine if DELTARANGE_COMP is suitable for a particular set of data, compare it to other
schemes. Be sure to use the same sort order as the projection, and select sample data that will be
stored consecutively in the database.
ENCODING DELTAVAL
For INTEGER and DATE/TIME/TIMESTAMP/INTERVAL columns, data is recorded as a
difference from the smallest value in the data block. This encoding has no effect on other data
types.
DELTAVAL is best used for many-valued, unsorted integer or integer-based columns. The CPU
requirements for this encoding type are minimal, and the data never expands.
ENCODING GCDDELTA
For INTEGER and DATE/TIME/TIMESTAMP/INTERVAL columns, and NUMERIC columns with
18 or fewer digits, data is recorded as the difference from the smallest value in the data block
divided by the greatest common divisor (GCD) of all entries in the block.This encoding has no
effect on other data types.
ENCODING GCDDELTA is best used for many-valued, unsorted, integer columns or integerbased columns, when the values are a multiple of a common factor.For example, timestamps are
stored internally in microseconds, so data that is only precise to the millisecond are all multiples of
1000. The CPU requirements for decoding GCDDELTA encoding are minimal, and the data never
expands, but GCDDELTA may take more encoding time than DELTAVAL.
ENCODINGGZIP_COMP
This encoding type uses the gzip compression algorithm. See gzip web site for more information.
This algorithm results in better compression than the automatic LZOcompression, but lower
compression than BZIP_COMP. It requires more CPUtime to compress than LZO but less
CPUtime than BZIP_COMP. This algorithm is best used on large string columns such as
SQLReference Manual
SQL Statements
VARCHAR, VARBINARY, CHAR, and BINARY. Use this encoding when you want a better
compression than LZO, but at less CPUtime than bzip2.
ENCODING RLE
Run Length Encoding (RLE) replaces sequences (runs) of identical values with a single pair that
contains the value and number of occurrences. Therefore, it is best used for low cardinality columns
that are present in the ORDER BY clause of a projection.
The HP Vertica execution engine processes RLE encoding run-by-run and the HP Vertica optimizer
gives it preference. Use it only when the run length is large, such as when low-cardinality columns
are sorted.
The storage for RLE and AUTO encoding of CHAR/VARCHAR and BINARY/VARBINARY is
always the same.
ENCODING NONE
Do not specify this value. It is obsolete and exists only for backwards compatibility. The result of
ENCODING NONE is the same as ENCODING AUTO except when applied to CHAR and
VARCHAR columns. Using ENCODING NONE on these columns increases space usage,
increases processing time, and leads to problems if 0x00 or 0xFF characters are present in the
data.
Hash-Segmentation-Clause
Allows you to segment a projection based on a built-in hash function. The built-in hash function
provides even data distribution across some or all nodes in a cluster, resulting in optimal query
execution.
Note: Hash segmentation is the preferred method of segmentation. The Database Designer
uses hash segmentation by default.
Syntax
SEGMENTED BY expression { ALL NODES [ OFFSET offset ] | NODES node [ ,... ] }
SQLReference Manual
SQL Statements
Parameters
SEGMENTED BY expression
ALL NODES
Automatically distributes data evenly across all nodes at the time the
CREATE PROJECTION statement is run. The ordering of the nodes is
fixed.
OFFSET offset
NODES node
[ ,... ]
Notes
l
CREATE PROJECTION accepts the deprecated syntax SITES node for compatibility with
previous releases.
You must use the table column names in the expression, not the new projection column names.
An elastic projection (a segmented projection created when Elastic Cluster is enabled) created
with a modularhash segmentation expression uses hash instead.
SQLReference Manual
SQL Statements
The expression must return the same value over the life of the database.
The expression must return non-negative INTEGER values in the range 0 <= x < 263 (two to
the sixty-third power or 2^63), and values are generally distributed uniformly over that range.
If expression produces a value outside of the expected range (a negative value for example),
no error occurs, and the row is added to the first segment of the projection.
Examples
=> CREATE PROJECTION ... SEGMENTED BY HASH(C1,C2) ALL NODES;
=> CREATE PROJECTION ... SEGMENTED BY HASH(C1,C2) ALL NODES OFFSET 1;
The example produces two hash-segmented buddy projections that form part of a K-Safe design.
The projections can use different sort orders.
=> CREATE PROJECTION fact_ts_2 (
f_price,
f_cid,
f_tid,
f_cost,
f_date) AS (
SELECT price, cid, tid, cost, dwdate FROM fact)
SEGMENTED BY MODULARHASH(dwdate) ALL NODES OFFSET 2;
See Also
l
HASH
MODULARHASH
GROUPED Clause
Groups two or more columns into a single disk file. This minimizes file I/O for work loads that:
l
SQLReference Manual
SQL Statements
If you have data that is always accessed together and it is not used in predicates, you can increase
query performance by grouping these columns. Once grouped, queries can no longer independently
retrieve from disk all records for an individual column independent of the other columns within the
group.
Note: RLE encoding is reduced when an RLE column is grouped with one or more non-RLE
columns.
When grouping columns you can:
l
SQLReference Manual
SQL Statements
Note: The information in this topic is unique to creating live aggregate projections. For details
about creating other types of projections, including projections with expressions, see CREATE
PROJECTION.
Syntax
CREATE PROJECTION [ IF NOT EXISTS ]
...[[db-name.]schema.]projection-name
...[ ( { projection-column ...| {
GROUPED ( column-reference1, column-reference2 [ ,... ])}
......... [ ACCESSRANK integer ]
......... [ ENCODING Encoding-Type ] } [ ,... ] )
...]
AS SELECT {table-column | expr_with_columns } [ , ... ] FROM table-reference [ , ... ]
... [ WHERE Join-Predicate [ AND join-predicate ] ...
... [ GROUP BY expression ]
... [ KSAFE [ k-num ] ]
Parameters
[ IF NOT EXISTS ]
[[db-name.]schema.]
projection-name
SQLReference Manual
SQL Statements
{table-column | expr_with_columns }
[ ENCODING encoding-type ]
[ ACCESSRANK integer ]
SQLReference Manual
SQL Statements
SELECT table-column
table-reference
[ WHERE join-predicate ]
GROUP BY expression
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
KSAFE [ k-num ]
If you specify a value less than the system Ksafety or greater than the anchor projection Ksafety, an error occurs.
If you specify a value between the system Ksafety and the anchor projection K-safety, HP
Vertica sets the live aggregate projection Ksafety to the anchor projection K-safety.
Permissions
To explicitly create a projection using the CREATE PROJECTION statement, a user must be a
superuser or owner of the anchor table or have the following privileges:
l
USAGE privilege on all the schemas that contain the base tables referenced by the projection
Only the anchor table owner can drop explicitly created projections or pre-join projections.
Explicitly created projections can be live aggregate projections, including Top-K projections and
projections with expressions.
SQLReference Manual
SQL Statements
To prevent data loss and inconsistencies, tables must contain one superprojection. You cannot
drop a projection if that projection is the table's only superprojection.
You cannot drop a buddy projection if dropping that projection violates the system K-safety .
Important: You must create an anchor projection before you create a live aggregate projection.
After an anchor projection has been associated with a live aggregate projection, you cannot
perform any delete, update, or merge operations on the anchor projection.
The anchor projection must specify a segmentation that is a subset of the live aggregate
projection's segmentation.
The following example shows how to create a live aggregate projection that counts the number of
clicks per user:
=> CREATE PROJECTION clicks_agg
AS SELECT user_id, page_id, click_time::DATE click_date,
COUNT(*) num_clicks FROM clicks
GROUP BY user_id, page_id, click_time::DATE;
After the data is loaded, you can query data directly from the live aggregate projection:
=> SELECT * FROM clicks_agg;
SQLReference Manual
SQL Statements
Important: You must create an anchor projection before you create a live aggregate projection.
After an anchor projection has been associated with a live aggregate projection, you cannot
perform any delete, update, or merge operations on the anchor projection.
The anchor projection must specify a segmentation that is a subset of the live aggregate
projection's segmentation.
Suppose you want to retrieve the five more recent meter readings for each gas meter. You might
enter the following:
=> SELECT meter_id, reading_date, reading_value
FROM ( SELECT meter_id, reading_date, reading_value, ROW_NUMBER()
OVER (PARTITION BY meter_id ORDER BY reading_date DESC) rn FROM readings) sq
WHERE rn <= 5;
Because you cannot use subqueries when defining a projection, HP Vertica supports a simplified
Top-K syntax:
=> SELECT meter_id, reading_date, reading_value FROM readings LIMIT 5
OVER (PARTITION BY meter_id ORDER BY reading_date DESC);
Important: You can use either form of the syntax in a Top-K query, but you can only use the
simplified syntax to create a Top-Kprojection. When you use the simplified syntax to query a
table, you do not have the same restrictions as when you use the simplified syntax when
creating a Top-K projection.
Use this query to create a Top-K projection that is organized by meter_id and stores the five most
recent meter readings for each gas meter:
=> CREATE PROJECTION readings_topk (meter_id, recent_date, recent_value)
AS
SQLReference Manual
SQL Statements
See Also
l
Top-K Projections
CREATE PROJECTION
Syntax
CREATE RESOURCE POOL pool-name
... [ MEMORYSIZE {'sizeUnits' |DEFAULT }]
... [ MAXMEMORYSIZE {'sizeUnits' | NONE |DEFAULT }]
... [ EXECUTIONPARALLELISM {int | AUTO | DEFAULT} ]
... [ PRIORITY {integer | HOLD | DEFAULT}]
... [ RUNTIMEPRIORITY { HIGH | MEDIUM | LOW |DEFAULT} ]
... [ RUNTIMEPRIORITYTHRESHOLD { integer |DEFAULT }]
... [ QUEUETIMEOUT {integer | NONE |DEFAULT}]
... [ PLANNEDCONCURRENCY {integer | DEFAULT |AUTO }]
... [ MAXCONCURRENCY {integer | NONE |DEFAULT }]
... [ RUNTIMECAP {interval | NONE | DEFAULT} ]
... [ SINGLEINITIATOR { bool | DEFAULT }]
... [ CPUAFFINITYSET { 'cpuIndex' | 'cpuIndex list' | 'integer percentage' | NONE | DEFAULT }
]
... [ CPUAFFINITYMODE { SHARED | EXCLUSIVE | ANY | DEFAULT } ]
... [ CASCADE TO {secondary_pool | DEFAULT} ]
Parameters
Note: If you specify DEFAULT for any parameter when creating a resource pool, HP Vertica
uses the default value for the user-defined pool, stored in the RESOURCE_POOL_
DEFAULTS table.
SQLReference Manual
SQL Statements
pool-name
MEMORYSIZE 'sizeUnits'
KKilobytes
MMegabytes
GGigabytes
TTerabytes
SQLReference Manual
SQL Statements
MAXMEMORYSIZE'sizeUnits' | NONE
KKilobytes
MMegabytes
GGigabytes
TTerabytes
SQLReference Manual
SQL Statements
EXECUTIONPARALLELISM
PRIORITY
When set to HOLD, pool priority is 999 and query remains queued until
QUEUETIMEOUT is reached.
SQLReference Manual
SQL Statements
RUNTIMEPRIORITY
HIGH
MEDIUM
LOW
SQLReference Manual
SQL Statements
RUNTIMEPRIORITYTHRESHOLD
[Default 2]
Specifies a time limit (in seconds) by
which a query must finish before the
Resource Manager assigns to it the
RUNTIMEPRIORITY of the resource
pool. All queries begin running at a
HIGH priority. When a query's
duration exceeds this threshold, it is
assigned the RUNTIMEPRIORITY of
the resource pool.
Note: If upgrading from an HP
Vertica version prior to 6.0,
RUNTIMEPRIORITYTHRESH
OLD gets set to 0. If upgrading
from version 6.0 or higher,
RUNTIMEPRIORITYTHRESH
OLD retains its value.
QUEUETIMEOUT
SQLReference Manual
SQL Statements
PLANNEDCONCURRENCY
SQLReference Manual
SQL Statements
MAXCONCURRENCY
RUNTIMECAP
SINGLEINITIATOR
SQLReference Manual
SQL Statements
CPUAFFINITYSET
'cpuIndex'Index of a specific
CPU on which to run the queries
for this pool. Queries in this pool
are not run on any other CPUs
besides the CPU defined.
'integer percentage'Percentage
of all available CPUs to use for
this query. You must define this
setting in whole percentages. HP
Vertica rounds the percentages
down to account for whole CPU
units.
SQLReference Manual
SQL Statements
DEFAULTSame as NONE.
Considerations:
l
SQLReference Manual
SQL Statements
CPUAFFINITYMODE
DEFAULTSame as ANY.
SQLReference Manual
SQL Statements
CASCADE TO
Privileges
Must be a superuser to create a resource pool.
Usage Considerations
l
Resource pool names are subject to the same rules as HP Vertica Identifiers. Built-in pool
names cannot be used for user-defined pools.
You can create new resource pools or alter existing ones without shutting down the system.
When you create a new pool is created (or alter a pool's memory size), a MEMORYSIZE amount of
memory is taken out of the GENERAL pool. Sometimes, however, the GENERAL pool does not
currently have sufficient memory to create the pool because of existing queries being
processed. In such cases:
n
A request is made to the system to create a pool as soon as resources become available.
The pool is created immediately and memory is moved to the pool as it becomes available.
The pool is in operation as soon as the specified amount of memory becomes available. You can
monitor whether ALTER has completed in the V_MONITOR.RESOURCE_POOL_STATUS system
table.
SQLReference Manual
SQL Statements
During CREATE/ALTER operations,HP Vertica returns an error if this size limit is violated.
If two pools have the same PRIORITY, their requests are allowed to borrow from the GENERAL
pool in the order of arrival.
See Guidelines for Setting Pool Parameters in the Administrator's Guide for details about setting
these parameters.
Examples
This example shows how to create a resource pool with MEMORYSIZE of 1800 MB.
=> CREATE RESOURCE POOL ceo_pool MEMORYSIZE '1800M' PRIORITY 10;
CREATE RESOURCE POOL
Assuming the CEO report user already exists, associate this user with the preceding resource pool
using ALTER USER statement.
=> GRANT USAGE ON RESOURCE POOL ceo_pool to ceo_user;
GRANT PRIVILEGE
=> ALTER USER ceo_user RESOURCE POOL ceo_pool;
ALTER USER
Issue the following command to confirm that the ceo_user is associated with the ceo_pool:
=> SELECT * FROM users WHERE user_name ='ceo_user';
-[ RECORD 1 ]-----+-------------------------------------------------user_id
| 45035996273733402
user_name
| ceo_user
is_super_user
| f
profile_name
| default
is_locked
| f
lock_time
|
resource_pool
| ceo_pool
memory_cap_kb
| unlimited
temp_space_cap_kb | unlimited
run_time_cap
| unlimited
all_roles
|
default_roles
|
search_path
| "$user", public, v_catalog, v_monitor, v_internal
This example shows how to create and designate secondary resource pools.
SQLReference Manual
SQL Statements
=>
=>
=>
=>
See Also
l
CREATE USER
Managing Workloads
Built-In Pools
HP Vertica is preconfigured with built-in pools for various system tasks. The built-in pools can be
reconfigured to suit your usage. The following sections describe the purpose of built-in pools and
the default settings.
Built-In
Pool
Settings
SQLReference Manual
SQL Statements
GENERAL
A special, catch-all pool used to answer requests that have no specific resource
pool associated with them. Any memory left over after memory has been allocated
to all other pools is automatically allocated to the GENERAL pool. The MEMORYSIZE
parameter of the GENERAL pool is undefined (variable), however, the GENERAL pool
must be at least 1GB in size and cannot be smaller than 25% of the memory in the
system.
The MAXMEMORYSIZE parameter of the GENERAL pool has special meaning; when set
as a % value it represents the percent of total physical RAM on the machine that the
Resource Manager can use for queries. By default, it is set to 95%. The
GENERAL.MAXMEMORYSIZE governs the total amount of RAM that the Resource
Manager can use for queries, regardless of whether it is set to a percent or to a
specific value (for example, '10GB')
Any user-defined pool can borrow memory from the GENERAL pool to satisfy
requests that need extra memory until the MAXMEMORYSIZE parameter of that pool is
reached. If the pool is configured to have MEMORYSIZE equal to MAXMEMORYSIZE, it
cannot borrow any memory from the GENERAL pool and is said to be a standalone
resource pool. When multiple pools request memory from the GENERAL pool, they
are granted access to general pool memory according to their priority setting. In this
manner, the GENERAL pool provides some elasticity to account for point-in-time
deviations from normal usage of individual resource pools.
HP recommends reducing the GENERALpool MAXMEMORYSIZE if your catalog uses
over 5% of overall memory.
SYSQUERY
The pool that runs queries against system monitoring and catalog tables.The
SYSQUERY pool reserves resources for system table queries so that they are never
blocked by contention for available resources.
SYSDATA
The pool reserved for temporary storage of intermediate results of queries against
system monitoring and catalog tables. If the SYSDATA pool size is too low, HP Vertica
cannot execute queries for large system tables or during high concurrent access to
system tables.
SQLReference Manual
SQL Statements
WOSDATA
The Write Optimized Store (WOS) resource pool. Data loads to the WOS
automatically spill to the ROS once it exceeds a certain amount of WOS usage; the
PLANNEDCONCURRENCY parameter of the WOS is used to determine this spill
threshold. For instance, if PLANNEDCONCURRENCY of the WOSDATA pool is set to 4, once
a load has occupied one quarter of the WOS, it spills to the ROS.
Notes:
l
The WOSDATA pool is limited to a size of 2GB or 25% of the GENERAL pool's limits,
whichever is less. However, when the GENERAL pool has a limit of 20GB or higher,
the WOSDATA pool will instead have 2GB of dedicated memory.
See Scenario: Tuning for Continuous Load and Query in the Administrator's Guide.
TM
The Tuple Mover (TM) pool. You can use the MAXCONCURRENCY parameter for the TM
pool to allow more than one concurrent TM operation to occur.
See Scenario: Tuning Tuple Mover Pool Settings in the Administrator's Guide.
RECOVERY
The pool used by queries issued when recovering another node of the database. The
MAXCONCURRENCY parameter is used to determine how many concurrent recovery
threads to use. You can use the PLANNEDCONCURRENCY parameter (by default, set to
twice the MAXCONCURRENCY) to tune how to apportion memory to recovery queries.
See Scenario: Tuning for Recovery in the Administrator's Guide.
REFRESH
SQLReference Manual
SQL Statements
DBD
The Database Designer pool, used to control resource usage for the DBD internal
processing. When a user runs Database Designer, either using the Administration
Tools or programmatically, its execution is mostly contained by the user's resource
pool, but may spill over into some system resource pools for less-intensive tasks. To
use the DBD pool for database designer usage, enable the
DBDUseOnlyDesignerResourcePool configuration parameter.
If you enable the DBDUseOnlyDesignerResourcePool configuration parameter, note
that the DBD pool is configured with a zero (0) second QUEUETIMEOUT value.
Whenever resources are under pressure, this timeout setting causes the DBD to time
out immediately, and not be queued to run later. The Database Designer then
requests the user to run the designer later, when resources are more available. HP
recommends that you do not reconfigure this pool.
JVM
The JVMpool controls Java Virtual Machine resources used by Java User Defined
Extensions. When a Java UDx starts the JVM, it draws resources from the those
specified in the JVM resource pool. HP Vertica does not reserve memory in advance
for the JVM pool. When needed, the pool can expand to 10% of physical memory or 2
GB of memory, whichever is smaller. If you are buffering large amounts of data, you
may need to increase the size of the JVM resource pool.
You can adjust the size of your JVMresource pool by changing its configuration
settings. Unlike other resource pools, the JVM resource pool does not release
resources until a session is closed.
See Also
l
RESOURCE_ACQUISITIONS
SQLReference Manual
SQL Statements
Note: Some of the built-in resource pool parameter values have restrictions, which are noted in
the tables.
GENERAL
Setting
Value
MEMORYSIZE
MAXMEMORYSIZE
Default: 95% of Total RAM on the node. Setting this value to 100%
generates warnings that swapping could result. MAXMEMORYSIZE
has the following restrictions:
l
PRIORITY
RUNTIMEPRIORITY
Medium
RUNTIMEPRIORITYTHRESHOLD
QUEUETIMEOUT
300
RUNTIMECAP
NONE
SQLReference Manual
SQL Statements
Setting
Value
PLANNEDCONCURRENCY
# of cores
Memory/2GB
Unlimited
Restrictions: Setting to 0 generates warnings that no system queries
may be able to run in the system.
SINGLEINITIATOR
SQLReference Manual
SQL Statements
SYSQUERY
Setting
Value
MEMORYSIZE
64M
Restrictions: Setting to <20M generates warnings because it could
prevent system queries from running and make problem diagnosis
difficult.
MAXMEMORYSIZE
Unlimited
EXECUTIONPARALLELISM
AUTO
PRIORITY
110
RUNTIMEPRIORITY
HIGH
RUNTIMEPRIORITYTHRESHOLD
QUEUETIMEOUT
300
RUNTIMECAP
NONE.
PLANNEDCONCURRENCY
See GENERAL
MAXCONCURRENCY
Unlimited
Restrictions: Setting to 0 generates warnings that no system queries
may be able to run in the system.
SINGLEINITIATOR
SYSDATA
Setting
Value
MEMORYSIZE
100m
MAXMEMORYSIZE
10%
Restriction: Setting To <4m generates warnings that no system
queries may be able to run in the system.
SQLReference Manual
SQL Statements
Setting
Value
EXECUTIONPARALLELISM
PRIORITY
RUNTIMEPRIORITY
RUNTIMEPRIORITYTHRESHOLD
QUEUETIMEOUT
RUNTIMECAP
PLANNEDCONCURRENCY
MAXCONCURRENCY
SINGLEINITIATOR
WOSDATA
Setting
Value
MEMORYSIZE
0%
MAXMEMORYSIZE
EXECUTIONPARALLELISM
PRIORITY
RUNTIMEPRIORITY
RUNTIMEPRIORITYTHRESHOLD
QUEUETIMEOUT
RUNTIMECAP
NONE
PLANNEDCONCURRENCY
2*# nodes
MAXCONCURRENCY
SINGLEINITIATOR
SQLReference Manual
SQL Statements
TM
Setting
Value
MEMORYSIZE
100M
MAXMEMORYSIZE
Unlimited
EXECUTIONPARALLELISM
AUTO
PRIORITY
105
RUNTIMEPRIORITY
MEDIUM
RUNTIMEPRIORITYTHRESHOLD
60
QUEUETIMEOUT
300
RUNTIMECAP
NONE
PLANNEDCONCURRENCY
MAXCONCURRENCY
2
Restrictions: Cannot set to 0 or NONE (unlimited)
SINGLEINITIATOR
REFRESH
Setting
Value
MEMORYSIZE
0%
MAXMEMORYSIZE
Unlimited
EXECUTIONPARALLELISM
AUTO
PRIORITY
-10
RUNTIMEPRIORITY
MEDIUM
RUNTIMEPRIORITYTHRESHOLD
60
QUEUETIMEOUT
300
SQLReference Manual
SQL Statements
Setting
Value
RUNTIMECAP
NONE
PLANNEDCONCURRENCY
MAXCONCURRENCY
Unlimited
Restrictions: cannot set to 0
SINGLEINITIATOR
RECOVERY
Setting
Value
MEMORYSIZE
0%
MAXMEMORYSIZE
Unlimited
Restrictions: cannot set to < 25%.
EXECUTIONPARALLELISM
AUTO
PRIORITY
107
RUNTIMEPRIORITY
MEDIUM
RUNTIMEPRIORITYTHRESHOLD
60
QUEUETIMEOUT
300
RUNTIMECAP
NONE
PLANNEDCONCURRENCY
Twice MAXCONCURRENCY
MAXCONCURRENCY
(# of cores / 2) + 1
Restrictions: Cannot set to 0 or NONE (unlimited)
SINGLEINITIATOR
SQLReference Manual
SQL Statements
DBD
Setting
Value
MEMORYSIZE
0%
MAXMEMORYSIZE
Unlimited
EXECUTIONPARALLELISM
AUTO
PRIORITY
RUNTIMEPRIORITY
MEDIUM
RUNTIMEPRIORITYTHRESHOLD
QUEUETIMEOUT
RUNTIMECAP
NONE
PLANNEDCONCURRENCY
See GENERAL
MAXCONCURRENCY
Unlimited
SINGLEINITIATOR
JVM
Setting
Value
MEMORYSIZE
0%
MAXMEMORYSIZE
EXECUTIONPARALLELISM
AUTO
PRIORITY
RUNTIMEPRIORITY
MEDIUM
RUNTIMEPRIORITYTHRESHOLD
QUEUETIMEOUT
300
RUNTIMECAP
NONE
SQLReference Manual
SQL Statements
Setting
Value
PLANNEDCONCURRENCY
AUTO
MAXCONCURRENCY
SINGLEINITIATOR
CREATE ROLE
Creates a new, empty role. You must then add permissions to the role using one of the GRANT
statements.
Syntax
CREATE ROLE role;
Parameters
role
The name for the new role. Name follows the conventions described in Identifiers.
Permissions
Must be a superuser to create a role.
Examples
This example shows to create an empty role called roleA.
=> CREATE ROLE roleA;
CREATE ROLE
See Also
l
DROP ROLE
CREATE SCHEMA
Defines a new schema.
SQLReference Manual
SQL Statements
Syntax
CREATE SCHEMA [ IF NOT EXISTS ] [db-name.]schema [ AUTHORIZATION user-name ]
Parameters
[ IF NOT EXISTS ]
[db-name.]
schema
AUTHORIZATION user-name
Privileges
To create a schema, the user must either be a superuser or have CREATE privilege for the
database. See GRANT (Database).
Optionally, CREATE SCHEMA could include the following sub-statements to create tables within
the schema:
l
CREATE TABLE
GRANT
With the following exceptions, these sub-statements are treated as if they have been entered as
individual commands after the CREATE SCHEMA statement has completed:
SQLReference Manual
SQL Statements
If the AUTHORIZATION statement is used, all tables are owned by the specified user.
The CREATE SCHEMA statement and all its associated sub-statements are completed as one
transaction. If any of the statements fail, the entire CREATE SCHEMA statement is rolled
back.
Examples
The following example creates a schema named s1 with no objects.
=> CREATE SCHEMA s1;
The following series of commands create a schema named s1 with a table named t1 and grants
Fred and Aniket access to all existing tables and ALL privileges on table t1:
=> CREATE SCHEMA s1;=> CREATE TABLE t1 (c INT);
=> GRANT USAGE ON SCHEMA s1 TO Fred, Aniket;
=> GRANT ALL ON TABLE t1 TO Fred, Aniket;
See Also
l
ALTER SCHEMA
SET SEARCH_PATH
DROP SCHEMA
CREATE SEQUENCE
Defines a new named sequence number generator object.
Use sequences or auto-incrementing columns for primary key columns. For example, to generate
only even numbers in a sequence, specify a start value of 2, and increment the sequence by 2. For
SQLReference Manual
SQL Statements
more information see Using Sequences in the Administrator's Guide. Sequences guarantee
uniqueness and avoid constraint enforcement problems and their associated overhead.
Syntax
CREATE SEQUENCE [[db-name.]schema.]sequence_name
... [ INCREMENT [ BY ] positive_or_negative ]
... [ MINVALUE minvalue | NO MINVALUE ]
... [ MAXVALUE maxvalue | NO MAXVALUE ]
... [ START [ WITH ] start ]
... [ CACHE cache ]
... [ CYCLE | NO CYCLE ]
Parameters
[[db-name.]schema.]
sequence_name
SQLReference Manual
SQL Statements
CACHE cache
CYCLE | NO CYCLE
Permissions
To create a sequence, the user must have CREATE privilege on the schema to contain the
sequence. Only the owner and superusers can initially access the sequence. All other users must
be granted access to the sequence by a superuser or the owner.
SQLReference Manual
SQL Statements
To create a table with a sequence, the user must have SELECT privilege on the sequence and
USAGE privilege on the schema that contains the sequence.
Note: Referencing a named sequence in a CREATE TABLE statement requires SELECT
privilege on the sequence object and USAGE privilege on the schema of the named sequence.
in a WHERE clause
in a DISTINCT clause
in a subquery
a view
You can use subqueries to work around some of these restrictions. For example, to use sequences
with a DISTINCT clause:
=> SELECT t.col1, shift_allocation_seq.nextval
SELECT DISTINCT col1 FROM av_temp1) t;
FROM (
Removing a Sequence
Use the DROP SEQUENCE function to remove a sequence. You cannot drop a sequence upon
which other objects depend. Sequences used in a default expression of a column cannot be
dropped until all references to the sequence are removed from the default expression.
DROP SEQUENCE ... CASCADE is not supported.
Examples
HP Vertica Analytic Database (7.1.x)
SQLReference Manual
SQL Statements
The following example creates an ascending sequence called my_seq, starting at 100:
dbt=> create sequence my_seq START 100;
CREATE SEQUENCE
After creating a sequence, you must call the NEXTVAL function at least once in a session to create
a cache for the sequence and its initial value. Subsequently, use NEXTVAL to increment the
sequence. Use the CURRVAL function to get the current value.
The following NEXTVAL function instantiates the newly-created my_seq sequence and sets its first
number:
=> SELECT NEXTVAL('my_seq');
nextval
--------100
(1 row)
The following command returns the current value of this sequence. Since no other operations have
been performed on the newly-created sequence, the function returns the expected value of 100:
=> SELECT CURRVAL('my_seq');
currval
--------100
(1 row)
Calling the CURRVAL again function returns only the current value:
=> SELECT CURRVAL('my_seq');
currval
--------101
(1 row)
The following example shows how to use the my_seq sequence in an INSERT statement.
SQLReference Manual
SQL Statements
Now query the table you just created to confirm that the ID column has been incremented to 102:
=> SELECT * FROM customer;
lname | fname | membership_card | id
---------+-------+-----------------+----Hawkins | John |
72753 | 102
(1 row)
The following example shows how to use a sequence as the default value for an INSERT
command:
=> CREATE TABLE customer2(
id INTEGER DEFAULT NEXTVAL('my_seq'),
lname VARCHAR(25),
fname VARCHAR(25),
membership_card INTEGER
);
=> INSERT INTO customer2 VALUES (default,'Carr', 'Mary', 87432);
Now query the table you just created. The ID column has been incremented again to 103:
=> SELECT * FROM customer2;
id | lname | fname | membership_card
-----+-------+-------+----------------103 | Carr | Mary |
87432
(1 row)
As you can see, each time you call NEXTVAL(), the value increments.
The CURRVAL() function returns the current value.
SQLReference Manual
SQL Statements
See Also
l
ALTER SEQUENCE
Column-Constraint
CURRVAL
DROP SEQUENCE
GRANT (Sequence)
NEXTVAL
Sequence Privileges
CREATE SUBNET
Identifies the subnet to which the nodes of an HP Vertica database belong. Use this statement
when you want to configure import/export from a database to other HP Vertica clusters.
Syntax
CREATE SUBNET subnet-name WITH'subnet prefix'
Parameters
subnet-name
A name of your choosing to assign to the subnet. Name follows the conventions
described in Identifiers.
subnet prefix
You can then configure the database to use the subnet for import/export. (See Identify the
Database or Node(s) used for Import/Export for more information.)
Permissions
You must be a dbadmin user to create a subnet.
SQLReference Manual
SQL Statements
Examples
This example shows how to create a subnet.
=> CREATE SUBNET mySubnet WITH '123.4.5.6';
CREATE TABLE
Creates a table in the logical schema or an external table definition.
Syntax
CREATE TABLE [ IF NOT EXISTS ] [[db-name.]schema.]table-name {
... ( Column-Definition (table) [ , ... ] )
... | [ table-constraint ( column_name, ... )]
... | [ column-name-list (create table) ] AS [COPY] [ [ AT EPOCH LATEST ]
... | [ AT TIME 'timestamp' ] ] [ /*+ direct */ ] query
... | [ LIKE [[db-name.]schema.]existing-table [ {INCLUDING | EXCLUDING} PROJECTIONS ] ]
}
... [ ORDER BY table-column [ , ... ] ]
... [ ENCODED BY column-definition [ , ... ]
... [ Hash-Segmentation-Clause
... | UNSEGMENTED { NODE node_name | ALL NODES } ]
... [ KSAFE [k_num] ]
... [ PARTITION BY partition-clause ]
Parameters
[ IF NOT EXISTS ]
[[db-name.]schema.]
SQLReference Manual
SQL Statements
table-name
column-definition
column-name-list
AT EPOCH LATEST | AT
TIME'timestamp'
/*+ direct */
SQLReference Manual
SQL Statements
AS query
Creates a new table from the results of a query and fills it with
data from the query. For example:
CREATE TABLE promo AS SELECT ... ;
SQLReference Manual
SQL Statements
[LIKE existing-table
[INCLUDING | EXCLUDING
PROJECTIONS]]
[ ORDER BY table-column ]
SQLReference Manual
SQL Statements
ENCODED BY column-definition
hash-segmentation-clause
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
KSAFE [ k ]
SQLReference Manual
SQL Statements
Permissions
l
To create a table, you must have CREATE privilege on the table schema.
To create a table with a named sequence, you must have SELECT privilege on the sequence
object and USAGE privilege on the schema associated with the sequence.
To create a table with the LIKE clause, you must have owner permissions on the source table
If you create a table without providing the projection-related clauses, HP Vertica automatically
creates a superprojection for the table when you use an INSERT INTO or COPY statement to
load data into the table for the first time. The projection is created in the same schema as the
table. Once HP Vertica has created the projection, it loads the data.
If you use CREATE TABLE AS SELECT to create a table from the results of a query, the table
is created first and a projection is created immediately after, using some of the properties of the
underlying SELECT query.
(Advanced users only) If you use any of the following parameters, the default projection is
created immediately upon table creation using the specified properties:
n
ORDER BY table-column
SQLReference Manual
SQL Statements
hash-segmentation-clause
KSAFE
Note: Before you define a superprojection in the above manner, read Creating Custom
Designs in the Administrator's Guide.
Partition Clauses
Creating a table with a partition clause causes all projections anchored on that table to be
partitioned according to the clause. For each partitioned projection, logically, there are as many
partitions as the number of unique values returned by the partitioned expression applied over the
rows of the projection.
All projections include a base projection name prefix, which HP Vertica adds automatically. To
ensure a unique projection name, HP Vertica adds a version number within the name if necessary.
You use projection names to drop or rename a projection.
Note: Due to the impact on the number of ROS containers, explicit and implicit upper limits are
imposed on the number of partitions a projection can have; these limits, however, are detected
during the course of operation, such as during COPY.
Creating a partitioned table does not necessarily force all data feeding into a tables projection to be
segmented immediately. Logically, the partition clause is applied after the segmented by clause.
Partitioning specifies how data is organized at individual nodes in a cluster and after projection data
is segmented; only then is the data partitioned at each node based on the criteria in the partitioning
clause.
SQL functions used in the partitioning expression must be immutable, which means they return the
exact same value whenever they are invoked and independently of session or environment
settings, such as LOCALE. For example, the TO_CHAR function is dependent on locale settings
and cannot be used. The RANDOM function also produces different values on each invocation, so
cannot be used.
Data loaded with the COPY command is automatically partitioned according to the table's
PARTITION BY clause.
For more information, see "Restrictions on Partitioning Expressions" in Defining Partitions in the
Administrator's Guide
SQLReference Manual
SQL Statements
Examples
The following example creates a table named Product_Dimension in the Retail schema. HP
Vertica creates a default superprojection when data is loaded into the table:
=> CREATE TABLE Retail.Product_Dimension (
Product_Key
integer NOT NULL,
Product_Description
varchar(128),
SKU_Number
char(32) NOT NULL,
Category_Description
char(32),
Department_Description
char(32) NOT NULL,
Package_Type_Description
char(32),
Package_Size
char(32),
Fat_Content
integer,
Diet_Type
char(32),
Weight
integer,
Weight_Units_of_Measure
char(32),
Shelf_Width
integer,
Shelf_Height
integer,
Shelf_Depth
integer
);
The following example creates a table named Employee_Dimension. HP Vertica creates its
associated superprojection in the Public schema when data is loaded into the table. Instead of
using the sort order from the column definition, the superprojection uses the sort order specified by
the ORDER BY clause:
=> CREATE TABLE Public.Employee_Dimension (
Employee_key
integer PRIMARY KEY NOT NULL,
Employee_gender
varchar(8) ENCODING RLE,
Courtesy_title
varchar(8),
Employee_first_name
varchar(64),
Employee_middle_initial
varchar(8),
Employee_last_name
varchar(64), )
ORDER BY Employee_gender, Employee_last_name, Employee_first_name;
The following example creates a table called time and partitions the data by year. HP Vertica
creates a default superprojection when data is loaded into the table:
=> CREATE TABLE time( ..., date_col date NOT NULL, ...) => PARTITION BY extract('year'
FROM date_col);
The following example creates a table named location and partitions the data by state. HP Vertica
creates a default superprojection when data is loaded into the table:
=> CREATE TABLE location(..., state VARCHAR NOT NULL, ...)
PARTITION BY state;
SQLReference Manual
SQL Statements
The following statement uses SELECT AS to create a table called promo and load data from columns
in the existing customer_dimension table in which the customer's annual_income is greater than
$1,000,000. The data is ordered by state and annual income.
=> CREATE TABLE promo
AS SELECT
customer_name,
customer_address,
customer_city,
customer_state,
annual_income
FROM customer_dimension
WHERE annual_income>1000000
ORDER BY customer_state, annual_income;
The following table uses SELECT AS to create a table called promo and load data from the latest
committed DML transaction (AT EPOCH LATEST).
=> CREATE TABLE promo
AS AT EPOCH LATEST SELECT
customer_name,
customer_address,
customer_city,
customer_state,
annual_income
FROM customer_dimension;
The next example creates a new table (date_dimcopy) based on the VMart database date_
dimension table, and including projections.
VMart=> create table date_dimcopy like date_dimension including projections;
CREATE TABLE
The new table, date_dimcopy, has the same definitions as the original date_dimension table.
VMart=> select ordinal_position,column_name, data_type FROM columns where table_
name='date_dimcopy' ORDER BY ordinal_position;
ordinal_position |
column_name
| data_type
-----------------+-------------------------------+------------1 | date_key
| int
2 | date
| date
3 | full_date_description
| varchar(18)
4 | day_of_week
| varchar(9)
5 | day_number_in_calendar_month | int
6 | day_number_in_calendar_year
| int
7 | day_number_in_fiscal_month
| int
8 | day_number_in_fiscal_year
| int
9 | last_day_in_week_indicator
| int
10 | last_day_in_month_indicator
| int
11 | calendar_week_number_in_year | int
12 | calendar_month_name
| varchar(9)
SQLReference Manual
SQL Statements
13
14
15
16
17
18
19
20
21
|
|
|
|
|
|
|
|
|
calendar_month_number_in_year
calendar_year_month
calendar_quarter
calendar_year_quarter
calendar_half_year
calendar_year
holiday_indicator
weekday_indicator
selling_season
|
|
|
|
|
|
|
|
|
int
char(7)
int
char(7)
int
int
varchar(10)
char(7)
varchar(32)
(21 rows)
The following examples illustrate creating a table, and then attempting to create the same table,
with and without the IF NOT EXISTS argument, to show the results.
1. Create a simple table:
=> CREATE TABLE t (a INT);
CREATE TABLE
2. Try to create the same table, without IF NOT EXISTS, so a rollback occurs:
=> CREATE TABLE t (a INT, b VARCHAR(256));
ROLLBACK: object "t" already exists
3. Try again to create the table, using the IF NOT EXISTS clause, so a notice occurs:
=> CREATE TABLE IF NOT EXISTS t (a INT, b VARCHAR(256));
NOTICE: object "t" already exists; nothing was done
CREATE TABLE
The IF NOT EXISTS argument is useful for SQL scripts where you want to create a table if it does
not already exist, and reuse the existing table if it does.
See Also
l
Physical Schema
COPY
SQLReference Manual
SQL Statements
DROP_PARTITION
DROP PROJECTION
DUMP_PARTITION_KEYS
DUMP_PROJECTION_PARTITION_KEYS
DUMP_TABLE_PARTITION_KEYS
PARTITION_PROJECTION
PARTITION_TABLE
SELECT
Auto Partitioning
Column-Definition (table)
A column definition specifies the name, data type, and constraints to be applied to a column.
Syntax
column-name data-type { ... [ Column-Constraint ]
... [ ENCODING encoding-type ]
... [ ACCESSRANK integer ] }
Parameters
column-name
SQLReference Manual
SQL Statements
data-type
column-constraint
ENCODING encoding-type
ACCESSRANK integer
[Optional] Overrides the default access rank for a column. Use this
parameter to increase or decrease the speed at which HP Vertica
accesses a column. See Creating and Configuring Storage Locations
and Prioritizing Column Access Speed.
Example
The following example creates a table named Employee_Dimension and its associated
superprojection in the Public schema. The Employee_key column is designated as a primary key,
and RLE encoding is specified for the Employee_gender column definition:
=> CREATE TABLE Public.Employee_Dimension (
Employee_key
integer PRIMARY KEY NOT NULL,
Employee_gender
varchar(8) ENCODING RLE,
Courtesy_title
varchar(8),
Employee_first_name
varchar(64),
Employee_middle_initial
varchar(8),
SQLReference Manual
SQL Statements
Employee_last_name
varchar(64),
);
Column-Name-List (table)
Is used to rename columns when creating a table from a query (CREATE TABLE AS SELECT). It can
also be used to specify the Encoding-Type and access rank of the column.
Syntax
column-name-list
... [ ENCODING encoding-type ]
... [ ACCESSRANK integer ] [ , ... ]
... [ GROUPED ( projection-column-reference [,...] ) ]
Parameters
column-name
ENCODING encoding-type
ACCESSRANK integer
Overrides the default access rank for a column. This is useful if you
want to increase or decrease the speed at which a column is accessed.
See Creating and Configuring Storage Locations and Prioritizing
Column Access Speed in the Administrator's Guide.
GROUPED
SQLReference Manual
SQL Statements
The following statement is not allowed because encoding is specified in both column-name-list and
ENCODED BY clause:
=> CREATE TABLE promo (state ENCODING RLE ACCESSRANK 1, zip ENCODING RLE, ...)
AS SELECT * FROM customer_dimension
ORDER BY customer_state
ENCODED BY customer_state ENCODING RLE ACCESSRANK 1, customer_zip ENCODING RLE ...;
Example
The following example creates a table named employee_dimension and its associated
superprojection in the public schema. Note that encoding-type RLE is specified for the employee_
gender column definition:
=> CREATE TABLE public.employee_dimension (
employee_key
INTEGER PRIMARY KEY NOT NULL,
employee_gender
VARCHAR(8) ENCODING RLE,
courtesy_title
VARCHAR(8),
employee_first_name
VARCHAR(64),
employee_middle_initial VARCHAR(8),
employee_last_name
VARCHAR(64)
);
Using the VMart schema, the following example creates a table named promo from a query that
selects data from columns in the customer_dimension table. RLE encoding is specified for the
state column in the column name list.
=> CREATE TABLE promo (
name,
address,
city,
state ENCODING RLE, income )
AS SELECT customer_name,
customer_address,
customer_city,
customer_state,
annual_income
FROM customer_dimension
WHERE annual_income > 1000000
SQLReference Manual
SQL Statements
Column-Constraint
Adds a referential integrity constraint to the metadata of a column. See Adding Constraints in the
Administrator's Guide.
Syntax
[ CONSTRAINT constraint-name ] {
...[ NULL | NOT NULL ]
...| PRIMARY KEY
...| REFERENCES table-name [( column [ , ... ] )]
...| UNIQUE
...[ DEFAULT default ]
...[ AUTO_INCREMENT ]
...[ IDENTITY [ ( cache ) | ( start, increment[, cache ] ) ] ]
}
Parameters
CONSTRAINT constraint-name
PRIMARY KEY
SQLReference Manual
SQL Statements
REFERENCES table-name
[column]
UNIQUE
SQLReference Manual
SQL Statements
DEFAULT default
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
IDENTITY [ ( cache ) |
( start, increment[, cache ] ) ]
Permissions
Table owner or user WITH GRANT OPTION is grantor.
l
REFERENCES privilege on table to create foreign key constraints that reference this table
Notes
l
HP Vertica supports only one IDENTITY or one AUTO_INCREMENT column per table.
When you use ALTER TABLE to change the table owner, HP Vertica transfers ownership of the
associated IDENTITY/AUTO_INCREMENT sequences but not other REFERENCES
sequences.
SQLReference Manual
SQL Statements
You can specify a FOREIGN KEY constraint explicitly by using the FOREIGN KEY parameter,
or implicitly, using a REFERENCES parameter to the table with the PRIMARY KEY. If you omit
the column in the referenced table, HP Vertica uses the primary key:
=> CREATE TABLE fact(c1 INTEGER PRIMARY KEY NOT NULL);
=> CREATE TABLE dim (c1 INTEGER REFERENCES fact NOT NULL);
Columns that are given a PRIMARY constraint must also be set NOT NULL. HP Vertica
automatically sets these columns to be NOT NULL if you do not do so explicitly.
HP Vertica supports variable-free expressions in the column DEFAULT clause. See COPY
[Column as Expression].
If you are using a CREATE TABLE AS SELECT statement, the column-constraint parameter
does not apply. Constraints are set by the columns in the query table identified in the FROM
clause.
An AUTO-INCREMENT or IDENTITY value is never rolled back, even if a transaction that tries
to insert a value into a table is not committed.
Example
The following command creates the store_dimension table and sets the default column value for
store_state to MA:
=> CREATE TABLE store_dimension (store_state CHAR (2) DEFAULT MA);
The following command creates the public.employee_dimension table and sets the default
column value for hire_date to current_date():
=> CREATE TABLE public.employee_dimension (hire_date DATE DEFAULT current_date());
The following example uses the IDENTITY column-constraint to create a table with an ID column
that has an initial value of 1. It is incremented by 1 every time a row is inserted.
=> CREATE TABLE Premium_Customer(
ID IDENTITY(1,1),
lname VARCHAR(25),
fname VARCHAR(25),
store_membership_card INTEGER
);
=> INSERT INTO Premium_Customer (lname, fname, store_membership_card )
VALUES ('Gupta', 'Saleem', 475987);
SQLReference Manual
SQL Statements
Calling the LAST_INSERT_ID function returns value 2 because you previously inserted a new
customer (Chen Lee), and this value is incremented each time a row is inserted:
=> SELECT LAST_INSERT_ID();
last_insert_id
---------------2
(1 row)
The following example uses the AUTO_INCREMENT column-constraint to create a table with an
ID column that automatically increments every time a row is inserted.
=> CREATE TABLE Premium_Customer(
ID AUTO_INCREMENT,
lname VARCHAR(25),
fname VARCHAR(25),
store_membership_card INTEGER
);
=> INSERT INTO Premium_Customer (lname, fname, store_membership_card )
VALUES ('Gupta', 'Saleem', 475987);
SQLReference Manual
SQL Statements
(1 row)
The next examples illustrate the three valid ways to use IDENTITY arguments. The first example
uses a cache of 100, and the defaults for start value (1) and increment value (1):
=> CREATE TABLE t1(x IDENTITY(100), y INT);
The second example specifies the start and increment values as 1, and defaults to a cache value of
250,000:
=> CREATE TABLE t2(y IDENTITY(1,1), x INT);
The third example specifies start and increment values of 1, and a cache value of 100:
=> CREATE TABLE t3(z IDENTITY(1,1,100), zx INT);
Table-Constraint
Adds a constraint to the metadata of a table. See Adding Constraints in the Administrator's Guide.
SQLReference Manual
SQL Statements
Syntax
[ CONSTRAINT constraint_name
... { PRIMARY KEY ( column [
... | FOREIGN KEY ( column [
REFERENCES table [( column [
]
, ... ] )
, ... ] )
, ... ] )]
Parameters
CONSTRAINT constraint-name
[ , ... ] )
[ , ... ] )
UNIQUE ( column
[ , ... ] )
Permissions
Table owner or user WITH GRANT OPTION is grantor.
l
REFERENCES privilege on table to create foreign key constraints that reference this table
SQLReference Manual
SQL Statements
You can specify a foreign key table constraint either explicitly (with the FOREIGN KEY parameter),
or implicitly using the REFERENCES parameter to reference the table with the primary key. You do
not have to explicitly specify the columns in the referenced table, for example:
CREATE TABLE fact(c1 INTEGER PRIMARY KEY);
CREATE TABLE dim (c1 INTEGER REFERENCES fact);
Examples
The VMart sample database, described in the Getting Started Guide, contains a table Product_
Dimension in which products have descriptions and categories. For example, the description
"Seafood Product 1" exists only in the "Seafood" category. You can define several similar
correlations between columns in the Product Dimension table.
Hash-Segmentation-Clause (table)
Hash segmentation allows you to segment a projection based on a built-in hash function that
provides even distribution of data across some or all of the nodes in a cluster, resulting in optimal
query execution.
Note: Hash segmentation is the preferred method of segmentation. The Database Designer
uses hash segmentation by default.
Syntax
SEGMENTED BY expression
SQLReference Manual
SQL Statements
Parameters
SEGMENTED BY expression
ALL NODES
Automatically distributes the data evenly across all nodes at the time
the projection is created. The ordering of the nodes is fixed.
NODES node
[ ,... ]
Notes
l
Table column names must be used in the expression, not the projection column names.
n
The expression must return the same value over the life of the database.
The expression must return non-negative INTEGER values in the range 0 <= x < 263 (two
to the sixty-third power or 2^63), and values are generally distributed uniformly over that
range.
SQLReference Manual
SQL Statements
If expression produces a value outside of the expected range (a negative value for
example), no error occurs, and the row is added to the first segment of the projection.
Example
This example segments the default superprojection and its buddies for the Public.Employee_
Dimension table using HASH segmentation across all nodes based on the Employee_key column:
=> CREATE TABLE Public.Employee_Dimension (
Employee_key
integer PRIMARY KEY NOT NULL,
Employee_gender
varchar(8) ENCODING RLE,
Courtesy_title
varchar(8),
Employee_first_name
varchar(64),
Employee_middle_initial
varchar(8),
Employee_last_name
varchar(64),
)
SEGMENTED BY HASH(Employee_key) ALL NODES;
See Also
l
HASH
MODULARHASH
Syntax
CREATE [ GLOBAL | LOCAL ] TEMPORARY | TEMP
... TABLE [ IF NOT EXISTS ] [[db-name.]schema.].table-name {
... ( Column-Definition (temp table) [ , ... ] )
... | [ column-name-list (create table) ] }
... [ ON COMMIT { DELETE | PRESERVE } ROWS ]
... [ AS [ { AT EPOCH { integer | LATEST } | AT TIME 'timestamp'} ]
... [ /*+ direct */ ] query ]
... [ ORDER BY table-column [ , ... ] ]
... [ ENCODED BY column-definition [ , ... ] ]
SQLReference Manual
SQL Statements
....[ Hash-Segmentation-Clause
......| UNSEGMENTED { NODE node
......| ALL NODES } ]
....[ KSAFE [ k-num ] ]
....| [ NO PROJECTION ] ]
Parameters
GLOBAL
LOCAL
TEMPORARY | TEMP
[ IF NOT EXISTS ]
[[db-name.]schema.]
table-name
column-definition
column-name-list
See column-name-list .
SQLReference Manual
SQL Statements
ON COMMIT { PRESERVE |
DELETE } ROWS
AS [ { AT EPOCH {
integer | LATEST }
| AT TIME 'timestamp'}
]
/*+ direct */
Note: If you create a temporary table using the direct hint, you
still need to use the ON COMMIT PRESERVE ROWS option for the
rows.
SQLReference Manual
SQL Statements
AS query
ENCODED BY columndefinition
SQLReference Manual
SQL Statements
hash-segmentationclause
SQLReference Manual
SQL Statements
KSAFE [ k-num ]
[Optional] Specifies the K-safety level of the projection created for the
table. The integer K determines how many unsegmented or
segmented buddy projections to create. The value must be greater
than or equal to the current K-safety level of the database, and less
than the total number of nodes. If you do not specify a KSAFE value,
the superprojection is created at the current system K-safety level.
For example: K-SAFE 1
Note: When a hash-segmentation-clause is used with KSAFE,
HP Vertica automatically creates k_num+1 buddy projections to
meet the K-safety requirement.
NO PROJECTION
Notes
l
You cannot add projections to non-empty, session-scoped temporary tables (ON COMMIT
PRESERVE ROWS). Make sure that projections exist before you load data. See the
"Automatic Projection Creation" in the CREATE TABLE statement.
Although adding projections is allowed for tables with ON COMMIT DELETE ROWS specified, be
aware that you could lose all the data.
The V_TEMP_SCHEMA namespace is automatically part of the search path. Thus, temporary table
names do not need to be preceded with the schema.
Queries that involve temporary tables have the same restrictions on SQL support as queries that
do not use temporary tables.
AT EPOCH LATEST queries that refer to session-scoped temporary tables work the same as
those for transaction-scoped temporary tables. Both return all committed and uncommitted data
SQLReference Manual
SQL Statements
regardless of epoch. For example, you can commit data from a temporary table in one epoch,
advance the epoch, and then commit data in a new epoch.
l
If you issue the TRUNCATE TABLE statement on a temporary table, only session-specific data
is truncated with no affect on data in other sessions.
The DELETE ... FROM TEMP TABLE syntax does not truncate data when the table was created
with PRESERVE; it marks rows for deletion. See DELETE for additional details.
In general, session-scoped temporary table data is not visible using system (virtual) tables.
Temporary tables do not recover. If a node fails, queries that use the temporary table also fail.
Restart the session and populate the temporary table.
Pre-join projections that refer to both temporary and non-temporary tables are not supported.
You cannot use temporary tables as dimensions when the fact table is non-temporary in pre-join
projections. All small tables in a pre-join projection must be at least as persistent as the large
table and other small tables. The persistence scale is: Normal > session-scoped temporary
table > transaction-scoped temporary table.
n
If the anchor table of a pre-join projection is a transaction-scoped temp table, you can use
any type of table (temp or normal) in the pre-join.
If the anchor table of a pre-join is a normal table, you can use only normal tables as dimension
tables.
If there is a snowflake dimension session-scoped temporary table, its dimension tables may
not be a transaction-scoped temporary tables.
SQLReference Manual
SQL Statements
Examples
This example shows how to create a temporary table with one column of type INT.
=> CREATE TEMPORARY TABLE temp_table (temp_col INT);
CREATE TABLE
See Also
l
ALTER TABLE
CREATE TABLE
DELETE
DROP TABLE
Subqueries
Transactions
Syntax
column-name data-type [ DEFAULT ] [ NULL | NOT NULL ]
[ ENCODING encoding-type ] [ ACCESSRANK integer ] ]
Parameters
column-name
SQLReference Manual
SQL Statements
data-type
BINARY
BOOLEAN
CHARACTER
DATE/TIME
NUMERIC
SQLReference Manual
SQL Statements
DEFAULT default
The return data type of the default expression after evaluation either
matches that of the column for which it is defined, or an implicit cast
between the two data types is possible. For example, a character
value cannot be cast to a numeric data type implicitly, but a number
data type can be cast to character data type implicitly.
SQLReference Manual
SQL Statements
NOT NULL
Specifies that the column must receive a value during INSERT and
UPDATE operations. If no DEFAULT value is specified and no value is
provided, the INSERT or UPDATE statement returns an error because
no default value exists.
ENCODING encoding-type
ACCESSRANK integer
[Optional] Overrides the default access rank for a column. Use this
parameter to increase or decrease the speed at which HP Vertica
accesses a column. See Creating and Configuring Storage Locations
and Prioritizing Column Access Speed.
Syntax
column-name-list [ ENCODING encoding-type ] [ ACCESSRANK integer ] [ , ... ]
projection-column-reference [,...] ) ]
[ GROUPED(
Parameters
column-name-list
ENCODING encoding-type
ACCESSRANK integer
SQLReference Manual
SQL Statements
GROUPED
Groups two or more columns into a single disk file. This minimizes file
I/O for work loads that:
l
If you have data that is always accessed together and it is not used in
predicates, you can increase query performance by grouping these
columns. Once grouped, queries can no longer independently retrieve
from disk all records for an individual column independent of the other
columns within the group.
Note: RLE encoding is reduced when an RLE column is grouped
with one or more non-RLE columns.
When grouping columns you can:
l
(GROUPED(a, b, c, d))
Notes
If you are using a CREATE TEMPORARY TABLE AS SELECT statement:
SQLReference Manual
SQL Statements
The data-type cannot be specified for a column in the column name list. It is derived by the
column in the query table identified in the FROM clause
You can supply the encoding type and access rank in either the column name list or the column
list in the query, but not both.
The following statements are both allowed:
=> CREATE TEMPORARY TABLE temp_table1 (state ENCODING RLE ACCESSRANK 1, zip ENCODING
RLE, ...)
AS SELECT * FROM customer_dimension
ORDER BY customer_state, ... ;
=> CREATE TEMPORARY TABLE temp_table1
AS SELECT * FROM customer_dimension
ORDER BY customer_state
ENCODED BY customer_state ENCODING RLE ACCESSRANK 1, customer_zip ENCODING RLE ...;
Example
The following example creates a temporary table named temp_table2 and its associated
superprojection. Note that encoding-type RLE is specified for the y column definition:
=> CREATE
x
y
b
z
The following example creates a table named temp_table3 from a query that selects data from
columns in the customer_dimension table. RLE encoding is specified for the state column in the
column name list.
=> CREATE TABLE temp_table3 (name, address, city, state ENCODING RLE, income)
SELECT
customer_name,
customer_address,
customer_city,
customer_state,
AS
SQLReference Manual
SQL Statements
annual_income
FROM customer_dimension
WHERE annual_income > 1000000
ORDER BY customer_state, annual_income;
Syntax
SEGMENTED BY expression
Parameters
SEGMENTED BY expression
ALL NODES
Automatically distributes the data evenly across all nodes at the time
the projection is created. The ordering of the nodes is fixed.
NODES node
[ ,... ]
SQLReference Manual
SQL Statements
Notes
l
You must use the table column names in the expression, not the projection column names.
The expression must return the same value over the life of the database.
The expression must return non-negative INTEGER values in the range 0 <= x < 263 (two to
the sixty-third power or 2^63), and values are generally distributed uniformly over that range.
If expression produces a value outside of the expected range (a negative value for example),
no error occurs, and the row is added to the first segment of the projection.
The hash-segmentation-clause within the CREATE TABLE or CREATE TEMP TABLE statement
does not support the OFFSET keyword (available in the CREATE PROJECTION statement). The
OFFSET is set to zero (0).
Example
This example segments the default superprojection and its buddies using HASH segmentation
based on column 1 (C1).
=> CREATE TEMPORARY TABLE ... SEGMENTED BY HASH(C1) ALL NODES;
See Also
l
HASH
MODULARHASH
SQLReference Manual
SQL Statements
Syntax
CREATE TEXT INDEX [[db-name.]schema.]txtindex_name ON [[db-name.]schema.]source_table (unique_
id, text_field);
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
If you do not specify a schema, the table is created in the default schema.
txtindex_name
source_table
unique_id
Specifies the name of the column in the source table containing a unique
identifier. Any data type is permissible. Column must be the primary key in
the source table.
text_field
Specifies the name of the column in the source table containing the text
field. CHAR, VARCHAR, or LONGCHAR are permissible data types.
Nulls are allowed.
Privileges
l
The index will automatically inherit the query permissions of its parent table. The table owner
and dbadmin will be allowed to create and/or modify the indices.
Important: Do not alter the contents or definitions of the text index. If the contents or
definitions of the text index are altered, then the results will not appropriately match the source
table.
Requirements
l
Requires there be a column with a unique identifier set as the primary key.
There must be a projection associated with the source table and it must be both sorted and
segmented by the primary key.
SQLReference Manual
SQL Statements
Behavior
l
If data within a table is partitioned, then an extra column will be displayed in the text index
showing the partition.
Examples
The following example shows how to create a text index on the table t_log using the
CREATE TEXT INDEX statement:
=> CREATE TEXT INDEX t_log_index ON t_log (id, text);
CREATE INDEX
=> SELECT * FROM t_log_index;
select * from t_log_index;
word
| doc_id
-----------------------+-------'catalog
|
1
'dbadmin'
|
2
2014-06-04
|
1
2014-06-04
|
2
2014-06-04
|
3
2014-06-04
|
4
2014-06-04
|
5
2014-06-04
|
6
2014-06-04
|
7
2014-06-04
|
8
45035996273704962(2)
|
2
45035996273704962(2)
|
3
45035996273704962(2)
|
4
45035996273704962(2)
|
5
45035996273704966
|
3
45035996273704968
|
4
<INFO>
|
1
<INFO>
|
6
<INFO>
|
7
<INFO>
|
8
<WARNING>
|
2
<WARNING>
|
3
<WARNING>
|
4
<WARNING>
|
5
...
(97 rows)
The following example shows a text index, tpart_index, created from a partitioned source table:
=> SELECT * FROM tpart_index;
word
| doc_id | partition
SQLReference Manual
SQL Statements
------------------------+--------+----------0
|
4 |
2014
0
|
5 |
2014
11:00:49.568
|
4 |
2014
11:00:49.568
|
5 |
2014
11:00:49.569
|
6 |
2014
<INFO>
|
6 |
2014
<WARNING>
|
4 |
2014
<WARNING>
|
5 |
2014
Database
|
6 |
2014
Execute:
|
6 |
2014
Object
|
4 |
2014
Object
|
5 |
2014
[Catalog]
|
4 |
2014
[Catalog]
|
5 |
2014
'catalog
|
1 |
2013
'dbadmin'
|
2 |
2013
0
|
3 |
2013
11:00:49.568
|
1 |
2013
11:00:49.568
|
2 |
2013
11:00:49.568
|
3 |
2013
11:00:49.570
|
7 |
2013
11:00:49.571
|
8 |
2013
45035996273704962(2)
|
2 |
2013
45035996273704962(2)
|
3 |
2013
45035996273704966
|
3 |
2013
...
(89 rows)
CREATE USER
Adds a name to the list of authorized database users.
Syntax
CREATE USER name
... [ ACCOUNT {LOCK | UNLOCK} ]
... [ IDENTIFIED BY 'password' ]
... [ MEMORYCAP {'memory-limit' | NONE} ]
... [ PASSWORD EXPIRE ]
... [ PROFILE {profile | DEFAULT} ]
... [ RESOURCE POOL pool-name ]
... [ RUNTIMECAP {'time-limit' | NONE} ]
... [ TEMPSPACECAP {'space-limit' | NONE} ]
... [ SEARCH_PATH {schema[,schema2,...]} | DEFAULT ]
SQLReference Manual
SQL Statements
Parameters
name
SQLReference Manual
SQL Statements
IDENTIFIED BY 'password'
PASSWORD EXPIRE
SQLReference Manual
SQL Statements
K Kilobytes
MMegabytes
GGigabytes
TTerabytes
SQLReference Manual
SQL Statements
SEARCH_PATH schema[,schema2,...] |
DEFAULT
Permissions
Must be a superuser to create a user.
SQLReference Manual
SQL Statements
Notes
l
User names created with double-quotes are case sensitive. For example:
=> CREATE USER "FrEd1";
In the above example, the login name must be an exact match. If the user name was created
without double-quotes (for example, FRED1), then the user can log in as FRED1, FrEd1, fred1,
and so on.
Newly-created users do not have access to schema PUBLIC by default. Make sure to GRANT
USAGE ON SCHEMA PUBLIC to all users you create.
You can change a user password by using the ALTER USER statement. If you want to
configure a user to not have any password authentication, you can set the empty password in
CREATE or ALTER USER statements, or omit the IDENTIFIED BY parameter in CREATE
USER.
By default, users have the right to create temporary tables in the database.
Examples
=> CREATE USER Fred;
=> GRANT USAGE ON SCHEMA PUBLIC to Fred;
See Also
l
ALTER USER
DROP USER
Managing Workloads
SQLReference Manual
SQL Statements
CREATE VIEW
Defines a new view. Views are read only. You cannot perform insert, update, delete, or copy
operations on a view.
Syntax
CREATE [ OR REPLACE ] VIEW viewname [ ( column-name [, ...] ) ] AS query ]
Parameters
[ OR REPLACE ]
When you supply this option, HP Vertica overwrites any existing view with the
name viewname. If you omit this option and a view with that name already
exists, CREATE VIEW returns an error.
viewname
Specifies the name of the view to create. Name follows the conventions
described in Identifiers. Do not use the same name as any table, view, or
projection within the database. If the view name is not provided, the user name
is used as the view name.
column-name
[Optional] Specifies the list of names to be used as column names for the view.
Columns are presented from left to right in the order given. If not specified, HP
Vertica automatically uses the column names from the query. Each view
supports a maximum of 1600 columns.
query
Specifies the query that the view executes. If the column names are not
specified, HP Vertica uses the query for the column names of the view.
Use a SELECT statement to specify the query.The SELECT statement can
refer to tables, temp tables, and other views.
Permissions
To create a view, the user must be a superuser or have CREATE privileges on the schema in
which the view is created.
Privileges required on base objects for the view owner must be granted directly; you cannot grant
privileges on these objects using roles:
l
If a non-owner runs a SELECT query on the view, the view owner must also have SELECT ...
WITH GRANT OPTION privileges on the view's base tables or views. This privilege must be
SQLReference Manual
SQL Statements
If a view owner runs a SELECT query on the view, the owner must also have SELECT privilege
directly granted (not through a role) on a view's base objects (table or view).
Review the original query, and then the transformed subquery version:
SELECT * FROM ship;
SELECT * FROM (SELECT * FROM public.shipping_dimension) AS ship;
For example, suppose you create a view. The view definition contains an ORDERBYclause inside
a FROMsubquery:
=> CREATE VIEW myview AS
SELECT SUM(annual_income), customer_state
FROM public.customer_dimension
WHERE customer_key IN
(SELECT customer_key
FROM store.store_sales_fact)
GROUP BY customer_state
ORDER BY customer_state ASC;
In this example, when you query the view, HP Vertica does not sort the data because it comes from
multiple nodes:
SQLReference Manual
SQL Statements
To return sorted results, there must be an ORDERBYclause on the outer query, as in the following
example:
=> SELECT * FROM myview WHERE SUM > 2000000000 ORDER BY customer_state ASC;
SUM
| customer_state
-------------+---------------2723441590 | AZ
29253817091 | CA
4907216137 | CO
3769455689 | CT
3330524215 | FL
4581840709 | IL
3310667307 | IN
2793284639 | MA
5225333668 | MI
2128169759 | NV
2806150503 | PA
2832710696 | TN
14215397659 | TX
2642551509 | UT
(14 rows)
One other case where view data is sorted is when you use a LIMITn clause. To return correct
results, HP Vertica must sort the data before applying the LIMIT.
Dropping a View
Use the DROP VIEW statement to drop a view. Only the specified view is dropped. HP Vertica
does not support CASCADE functionality for views, and it does not check for dependencies.
Dropping a view causes any view that references it to fail.
SQLReference Manual
SQL Statements
Renaming a View
Use the ALTER VIEW statement to rename a view.
See Also
l
ALTER VIEW
SELECT
DROP VIEW
GRANT (View)
REVOKE (View)
DELETE
Marks tuples as no longer valid in the current epoch, marking the records for deletion in the WOS,
rather than deleting data from disk storage. By default, delete uses the WOS and if the WOS fills
up, overflows to the ROS. You cannot delete records from a projection.
Syntax
DELETE [ /*+ direct */ ] [ /*+ label(label-name)*/ ]
... FROM [[db-name.]schema.]table
... WHERE Clause
Parameters
/*+ direct */
/*+ label(label-name)*/
SQLReference Manual
SQL Statements
[[db-name.]schema.]
table
Permissions
Table owner or user with GRANT OPTION is grantor.
l
SELECT privilege on the referenced table when executing a DELETE statement that references
table column values in a WHERE or SET clause
SQLReference Manual
SQL Statements
If you include a WHERE clause with a DELETE statement on a temporary table, DELETE behaves the
same as for base tables, marking all delete vectors for storage, and you lose any performance
benefits. If the delete operation succeeds on temporary tables, you cannot roll back to a prior
savepoint.
To truncate a temporary table, without ending the transaction, use DELETE FROM temp_table.
Examples
To use the DELETEor UPDATE statements with a WHERE Clause, the user must have both
SELECT and DELETEprivileges on the table.
The following command truncates a temporary table called temp1:
=> DELETE FROM temp1;
The following command deletes all records from base table T where C1 = C2 - C1.
=> DELETE FROM T WHERE C1=C2-C1;
The following command deletes all records from the customer table in the retail schema where the
state attribute is in MA or NH:
=> DELETE FROM retail.customer WHERE
For examples on how to nest a subquery within a DELETE statement, see Subqueries in UPDATE
and DELETE in the Analyzing Data Guide.
See Also
l
DROP TABLE
TRUNCATE TABLE
DISCONNECT
Closes a previouslyestablished connection to another HP Vertica database. You must have
previously used the CONNECT statement to perform a COPY FROM VERTICA or EXPORT TO
VERTICA statement.
SQLReference Manual
SQL Statements
Syntax
DISCONNECT database-name
Parameters
database-name
Permissions
No special permissions required.
Example
=> DISCONNECT ExampleDB;
DISCONNECT
See Also
l
CONNECT
EXPORT TO VERTICA
Syntax
DROP ACCESS POLICY ON tablename
FOR COLUMN columnname;
SQLReference Manual
SQL Statements
Parameters
tablename
The name of the table that contains the column access policy you want to
remove.
columnname
The name of the column that contains the access policy you want to
remove.
Privileges
You must be a dbadmin user to drop an access policy.
Examples
These examples show various cases where you can drop an access policy from a customer table
or drop both the access policy and the table.
Drop Access Policy from Customer Table for a Specified Column
DROP ACCESS POLICY ON customer FOR COLUMN Customer_Number;
Drop Access Policy and Table Using the CASCADE Keyword with DROPTABLE
DROP TABLE <tablename> CASCADE;
Syntax
DROP AGGREGATE FUNCTION [[db-name.]schema.]function-name [, ...]
... ( [ [ argname ] argtype [, ...] ] )
SQLReference Manual
SQL Statements
Parameters
[[db-name.]schema.]
function-name
argname
argtype
Specifies the data type for argument(s) that are passed to the function.
Argument types must match HP Vertica type names. See SQL Data
Types.
Notes
l
To drop a function, you must specify the argument types because there could be several
functions that share the same name with different parameters.
HP Vertica does not check for dependencies, so if you drop a SQL function where other objects
reference it (such as views or other SQL functions), HP Vertica returns an error when those
objects are used and not when the function is dropped.
Permissions
Only the superuser or owner can drop the function.
SQLReference Manual
SQL Statements
Example
The following command drops the ag_avg function:
=> DROP AGGREGATE FUNCTION ag_avg(numeric);
DROP AGGREGATE FUNCTION
See Also
l
ALTER FUNCTION
GRANT (UserDefinedExtension)
USER_FUNCTIONS
DROPAUTHENTICATION
Drops an authentication method that has been created but not granted to any users. If you try to
drop an authentication method that has been granted to one or more users, the DROPoperation
fails. To successfully drop an authentication method that is currently granted to a user, use the
CASCADEkeyword.
Syntax
DROP AUTHENTICATION auth_method_name [ CASCADE ]
Parameters
auth_method_name
SQLReference Manual
SQL Statements
Privileges
Must have DBADMIN privileges.
Examples
To delete an authentication record for md5_auth, use the following command:
=> DROP AUTHENTICATION md5_auth;
To delete an authentication record for a method that has been granted to a user, use the
CASCADEkeyword:
=> CREATE AUTHENTICATION localpwd METHOD 'password' LOCAL;
=> GRANT AUTHENTICATION localpwd TO jsmith;
=> DROP AUTHENTICATION localpwd CASCADE;
ALTERAUTHENTICATION
CREATE AUTHENTICATION
GRANT(Authentication)
REVOKE (Authentication)
Syntax
DROP FAULT GROUP name
SQLReference Manual
SQL Statements
Parameters
name
Permissions
Must be a superuser to drop a fault group.
Example
The following example drops the group2 fault group from the cluster:
exampledb=> DROP FAULT GROUP group2;
DROP FAULT GROUP
See Also
l
SQLReference Manual
SQL Statements
DROP FUNCTION
Drops a SQL function or User Defined Function (UDF) from the HP Vertica catalog.
Syntax
DROP FUNCTION [[db-name.]schema.] function-name [, ...]
... ( [ [ argname ] argtype [, ...] ] )
Parameters
[[db-name.]schema.]
function-name
argname
argtype
Specifies the data type for argument(s) that are passed to the function.
Argument types must match HP Vertica type names. See SQL Data
Types.
Permissions
Must be a superuser, function owner, or schema owner to drop a function.
SQLReference Manual
SQL Statements
Notes
l
To drop a function, you must specify the argument types because there could be several
functions that share the same name with different parameters.
HP Vertica does not check for dependencies, so if you drop a SQL function where other objects
reference it (such as views or other SQL functions), HP Vertica returns an error when those
objects are used and not when the function is dropped.
Example
The following command drops the zerowhennull function in the macros schema:
=> DROP FUNCTION macros.zerowhennull(x INT);
DROP FUNCTION
See Also
l
ALTER FUNCTION
USER_FUNCTIONS
DROP SOURCE
Drops a User Defined Load Source function from the HP Vertica catalog.
Syntax
DROP SOURCE [[db-name.]schema.]source-name();
SQLReference Manual
SQL Statements
Parameters
[[db-name.]schema.]
source-name
Specifies the name of the source function to drop. If the function name is
schema-qualified, the function is dropped from the specified schema (as
noted above). You must include empty parenthesis after the function
name.
Permissions
Only the superuser or owner can drop the source function.
Example
The following command drops the curl source function:
=> drop source curl();
DROP SOURCE
See Also
l
ALTER FUNCTION
CREATE SOURCE
SQLReference Manual
SQL Statements
USER_FUNCTIONS
DROP FILTER
Drops a User Defined Load Filter function from the HP Vertica catalog.
Syntax
DROP FILTER [[db-name.]schema.]filter-name();
Parameters
[[db-name.]schema.]
filter-name
Specifies the name of the filter function to drop. If the function name is
schema-qualified, the function is dropped from the specified schema (as
noted above). You must include empty parenthesis after the function
name.
Permissions
Only the superuser or owner can drop the filter function.
SQLReference Manual
SQL Statements
Example
The following command drops the Iconverter filter function::
=> drop filter Iconverter();
DROP FILTER
See Also
l
ALTER FUNCTION
CREATE FILTER
USER_FUNCTIONS
DROP PARSER
Drops a User Defined Load Parserfunction from the HP Vertica catalog.
Syntax
DROP PARSER[[db-name.]schema.]parser-name();
SQLReference Manual
SQL Statements
Parameters
[[db-name.]schema.]
parser-name
Specifies the name of the parser function to drop. If the function name is
schema-qualified, the function is dropped from the specified schema (as
noted above). You must include empty parenthesis after the function
name.
Permissions
Only the superuser or owner can drop the parser function.
Example
The following command drops the BasicIntegerParser parser function:
=> DROP PARSER BasicIntegerParser();
DROP PARSER
See Also
l
ALTER FUNCTION
CREATE PARSER
SQLReference Manual
SQL Statements
USER_FUNCTIONS
DROP LIBRARY
Removes a shared library from the database. The user defined functions (UDFs) in the library are
no longer available. See Using User Defined Functions in the Extending HPVertica Guide for
details.
Syntax
DROP LIBRARY [[db-name.]schema.]library_name [CASCADE]
Parameters
[[db-name.]schema.]
library_name
The name of the library to drop. This must be the same name given to
CREATE LIBRARY to load the library.
[CASCADE]
Drops any functions that have been defined using the library. This
statement fails if CASCADE is not specified and there is one or more
UDFs that have been defined using the library.
Permissions
Must be a superuser to drop a library.
SQLReference Manual
SQL Statements
Notes
The library file is deleted from the managed directories on the HP Vertica nodes.
Example
To drop the library named MyFunctions:
=> DROP LIBRARY MyFunctions CASCADE;
Syntax
DROP NETWORK INTERFACE network-interface-name [CASCADE]
Parameters
The parameters are defined as follows:
network-interface-name
Permissions
Must be a superuser to drop a network interface.
Examples
This example show how to drop a network interface.
=> DROP NETWORK INTERFACE myNetwork;
DROP PROCEDURE
Removes an external procedure from HP Vertica.
SQLReference Manual
SQL Statements
Syntax
DROP PROCEDURE [[db-name.]schema.]name ( [ argname ] [ argtype ] [,...] )
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
name
argname
argtype
Optional unless an argument type was specified when the procedure was
created. The argument type or types used when creating the procedure.
Permissions
Must be a superuser or procedure owner and have USAGE privilege on schema that contain
procedure or be the schema owner.
Notes
l
Only the reference to the procedure is removed. The external file remains in the
<database>/procedures directory on each node in the database.
Example
=> DROP PROCEDURE helloplanet(arg1 varchar);
See Also
l
CREATE PROCEDURE
DROP PROFILE
Removes a profile from the database. Only the superuser can drop a profile.
SQLReference Manual
SQL Statements
Syntax
DROP PROFILE name [, ...] [ CASCADE ]
Parameters
name
CASCADE
Moves all users assigned to the profile or profiles being dropped to the DEFAULT
profile. If you do not include CASCADE in the DROP PROFILE command and a targeted
profile has users assigned to it, the command returns an error.
Permissions
Must be a superuser to drop a profile.
Notes
You cannot drop the DEFAULT profile.
Example
=> DROP PROFILE sample_profile;
See Also
l
ALTER PROFILE
CREATE PROFILE
DROP PROJECTION
Marks a projection to be dropped from the catalog so it is unavailable to user queries.
Syntax
DROP PROJECTION { base-projname |
SQLReference Manual
SQL Statements
Parameters
base-projname
Specifies the base projection to drop, along with all replicated buddies on all
nodes simultaneously. When using more than one schema, specify the schema
containing the base projection.
projname can be 'projname' or 'schema.projname'.
projname-node
Drops only the specified projection on the specified node.When using more than
one schema, specify the schema that contains the projection to drop.
projname can be 'projname' or 'schema.projname'.
RESTRICT
Drops the projection only if it does not contain any objects. RESTRICT is the
default.
CASCADE
Permissions
To drop a projection, the user must own the anchor table for which the projection was created and
have USAGE privilege on schema that contains the projection OR be the schema owner.
Restrictions
To prevent data loss and inconsistencies, tables must contain one superprojection. DROP
PROJECTION fails if the specified projection is the table's only superprojection.
You cannot drop a buddy projection if dropping that projection violates the system K-safety .
Examples
Drop all projections:
=> DROP PROJECTION prejoin_p;
SQLReference Manual
SQL Statements
Create a table and a projection, and then drop the projection. In this example, there is only one
projection. If more than one projection exists, the DROPPROJECTIONstatement fails.
=> CREATE TABLE tbl (x INT , y INT);
=> CREATE PROJECTION tbl_p AS SELECT x FROM tbl;
=> DROP PROJECTION tbl_p;
See Also
l
CREATE PROJECTION
DROP TABLE
GET_PROJECTIONS, GET_TABLE_PROJECTIONS
GET_PROJECTION_STATUS
MARK_DESIGN_KSAFE
Adding Nodes
Syntax
DROP RESOURCE POOL pool-name
SQLReference Manual
SQL Statements
Parameters
pool-name
Permissions
Must be a superuser to drop a resource pool.
DROP RESOURCE POOL returns an error if the user does not have permission to use the
GENERAL pool. Existing sessions are transferred to the GENERAL pool regardless of whether the
session's user has permission to use the GENERAL pool. This can result in additional user privileges
if the pool being dropped is more restrictive than the GENERAL pool. To prevent giving users
additional privileges, follow this procedure to drop restrictive pools:
1. Revoke the permissions on the pool for all users.
2. Close any sessions that had permissions on the pool.
SQLReference Manual
SQL Statements
Examples
The following command drops the resource pool that was created for the CEO:
=> DROP RESOURCE POOL ceo_pool;
See Also
l
Managing Workloads
DROP ROLE
Removes a role from the database. Only the database superuser can drop a role.
Use the CASCADE option to drop a role that is assigned to one or more users or roles.
Syntax
DROP ROLE role [CASCADE];
Parameters
role
CASCADE
Revoke the role from users and other roles before dropping the role
Permissions
Must be a superuser to drop a role.
Examples
=> DROP ROLE appadmin;
NOTICE: User bob depends on Role appadmin
ROLLBACK: DROP ROLE failed due to dependencies
SQLReference Manual
SQL Statements
See Also
l
CREATE ROLE
DROP SCHEMA
Permanently removes a schema from the database. Be sure that you want to remove the schema
before you drop it, because DROP SCHEMA is an irreversible process. Use the CASCADE
parameter to drop a schema containing one or more objects.
Syntax
DROP SCHEMA [db-name.]schema [, ...] [ CASCADE | RESTRICT ]
Parameters
[db-name.]
[Optional] Specifies the current database name. Using a database name prefix is
optional, and does not affect the command in any way. You must be connected to
the specified database.
schema
CASCADE
RESTRICT
Drops the schema only if it does not contain any objects (the default).
Privileges
Schema owner
Restrictions
You cannot drop the PUBLIC schema.
SQLReference Manual
SQL Statements
Notes
l
A schema owner can drop a schema even if the owner does not own all the objects within the
schema. All the objects within the schema are also dropped.
If a user is accessing an object within a schema that is in the process of being dropped, the
schema is not deleted until the transaction completes.
Examples
The following example drops schema S1 only if it doesn't contain any objects:
=> DROP SCHEMA S1;
DROP SEQUENCE
Removes the specified sequence number generator.
Syntax
DROP SEQUENCE [[db-name.]schema.]name [ , ... ]
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
When using more than one schema, specify the schema that contains the
sequence to drop.
name
SQLReference Manual
SQL Statements
Permissions
To drop a sequence, the user must be the sequence owner or schema owner.
Notes
l
For sequences specified in a table's default expression, the default expression fails the next
time you try to load data. HP Vertica does not check for these instances.
The CASCADE keyword is not supported. Sequences used in a default expression of a column
cannot be dropped until all references to the sequence are removed from the default expression.
Example
The following command drops the sequence named sequential.
=> DROP SEQUENCE sequential;
See Also
l
ALTER SEQUENCE
CREATE SEQUENCE
CURRVAL
GRANT (Sequence)
NEXTVAL
Sequence Privileges
DROP SUBNET
Removes a subnet from HP Vertica. You can use the CASCADE option to also remove the subnet
from any database definition. (See Identify the Database or Node(s) used for Import/Export for more
information.)
SQLReference Manual
SQL Statements
Syntax
DROP SUBNET subnet-name [CASCADE]
Parameters
The parameters are defined as follows:
subnet-name
If you remove a subnet, be sure your database is not configured to allow export on the public
subnet. (See Identify the Database or Node(s) used for Import/Export for more information.)
Permissions
Must be a superuser to drop a subnet.
Examples
This example shows how to remove a subnet.
=> DROP SUBNET mySubnet;
DROP TABLE
Removes a table and, optionally, its associated projections.
Syntax
DROP TABLE [ IF EXISTS ] [[db-name.]schema.]table [, ...] [ CASCADE ]
Parameters
[IF EXISTS]
If specified, DROP TABLE does not report an error if one or more of the
tables to be dropped does not exist. This clause is useful in SQL scripts
where you want to drop a table if it exists before recreating it.
SQLReference Manual
SQL Statements
[[db-name.]schema.]
table
Specifies the table name. When using more than one schema, specify the
schema that contains the table in the DROP TABLE statement.
CASCADE
Permissions
Table owner with USAGE privilege on schema that contains the table or schema owner
Note: The schema owner can drop a table but cannot truncate a table.
Notes
l
Make sure that all other users have disconnected before using DROP TABLE.
Views that reference a table that is dropped and then replaced by another table with the same
name continue to function and use the contents of the new table, as long as the new table
contains the same columns and column names.
Examples
If you try to drop a table with associated projections, a message listing the projections displays. For
example:
SQLReference Manual
SQL Statements
See Also
l
DELETE
DROP PROJECTION
TRUNCATE TABLE
Adding Nodes
Syntax
DROP TEXT INDEX [ IF EXISTS ] [[db-name.]schema.]idx_table;
Parameters
[IF EXISTS]
SQLReference Manual
SQL Statements
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
If you do not specify a schema, the table is created in the default schema.
idx_table
Specifies the text index name. When using more than one schema,
specify the schema that contains the index in the DROP TEXT INDEX
statement.
Privileges
l
Table owner and dbadmin with USAGE privilege on schema that contains the table or schema
owner.
Behavior
l
When a source table is dropped that has a text index associated with it, the text index will also
be dropped.
Examples
The following example drops the text index t_text_index:
=> DROP TEXT INDEX t_text_index;
DROP INDEX
Syntax
DROP TRANSFORM FUNCTION [[db-name.]schema.]name [, ...]
... ( [ [ argname ] argtype [, ...] ] )
SQLReference Manual
SQL Statements
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
name
argname
argtype
Specifies the data type for argument(s) that are passed to the function.
Argument types must match HP Vertica type names. See SQL Data
Types.
Permissions
Must be a superuser, function owner, or schema owner to drop a function.
Notes
To drop a transform function, you must specify the argument types because there could be several
functions that share the same name with different parameters.
Example
The following command drops the tokenize UDTF in the macros schema:
=> DROP TRANSFORM FUNCTION macros.tokenize(varchar);
DROP TRANSFORM FUNCTION
The following command drops the Pagerank polymorphic function in the online schema:
=> DROP TRANSFORM FUNCTION online.Pagerank (z float);
DROP TRANSFORM FUNCTION
SQLReference Manual
SQL Statements
See Also
l
DROP USER
Removes a name from the list of authorized database users.
Syntax
DROP USER name [, ...] [ CASCADE ]
Parameters
name
CASCADE
[Optional] Drops all user-defined objects created by the user dropped, including
schema, table and all views that reference the table, and the table's associated
projections.
Permissions
Must be a superuser to drop a user.
Examples
DROP USER <username> fails if objects exist that were created by the user, such as schemas, and
tables and their associated projections:
=> DROP USER user1;
NOTICE: Table T_tbd1 depends on User user1
ROLLBACK: DROP failed due to dependencies
DETAIL: Cannot drop User user1 because other objects depend on it
HINT: Use DROP ... CASCADE to drop the dependent objects too
DROP USER <name> CASCADE succeeds regardless of any pre-existing user-defined objects. The
statement forcibly drops all user-defined objects, such as schemas, tables and their associated
projections:
SQLReference Manual
SQL Statements
Caution: Tables owned by the user being dropped cannot be recovered after you issue DROP
USER CASCADE.
DROP USER <username> succeeds if no user-defined objects exist (no schemas, tables or
projections defined by the user):
=> CREATE USER user2;
CREATE USER
=> DROP USER user2;
DROP USER
See Also
l
ALTER USER
CREATE USER
DROP VIEW
Removes the specified view. This statement drops only the specified view. HP Vertica does not
support a cascade parameter for views, nor does it check for dependencies on the dropped view.
Any other views that reference the dropped view will fail.
If you drop a view and replace it with another view or table with the same name and column names,
any views dependent on the dropped view continue to function using the new view. If you change
the column data type in the new view, the server coerces the old data type to the new one if
possible. Otherwise, it returns an error.
Syntax
DROP VIEW name [ , ... ]
Parameters
name
SQLReference Manual
SQL Statements
Permissions
To drop a view, the user must be the view owner and have USAGE privileges on the schema or be
the schema owner.
Examples
=> DROP VIEW myview;
END
Ends the current transaction and makes all changes that occurred during the transaction permanent
and visible to other users.
Syntax
COMMIT [ WORK | TRANSACTION ]
Parameters
WORK | TRANSACTION
Permissions
No special permissions required.
Notes
COMMIT is a synonym for END.
Examples
This example shows how to end a transaction.
=> CREATE TABLE sample_table (a INT);
=> INSERT INTO sample_table (a) VALUES (1);
OUTPUT
-------1
=> END;
SQLReference Manual
SQL Statements
COMMIT
See Also
l
Transactions
BEGIN
ROLLBACK
START TRANSACTION
EXPLAIN
Returns the query plan execution strategy to standard output.
Syntax
EXPLAIN { SELECT... | INSERT... | UPDATE... COPY... | DELETE... | MERGE... | EXPORT... }
Returns
A compact representation of the query plan, laid out hierarchically. For example:
=> EXPLAIN SELECT * FROM hTicks h FULL OUTER JOIN aTicks a ON (h.time = a.time);
------------------------------ QUERY PLAN DESCRIPTION: -----------------------------Access Path:
+-JOIN HASH [FullOuter] [Cost: 31, Rows: 4 (NO STATISTICS)] (PATH ID: 1) Outer (FILTER)
Inner (FILTER)
| Join Cond: (h."time" = a."time")
| Execute on: All Nodes
| +-- Outer -> STORAGE ACCESS for h [Cost: 15, Rows: 4 (NO STATISTICS)] (PATH ID: 2)
| |
Projection: public.HTicks_node0001
| |
Materialize: h.stock, h."time", h.price
| |
Execute on: All Nodes
| +-- Inner -> STORAGE ACCESS for a [Cost: 15, Rows: 4 (NO STATISTICS)] (PATH ID: 3)
| |
Projection: public.ATicks_node0001
| |
Materialize: a.stock, a."time", a.price
| |
Execute on: All Nodes
SQLReference Manual
SQL Statements
Permissions
Privileges required to run this command are the same privileges required to run the query you
preface with the EXPLAIN keyword.
Notes
l
Query plans rely on reasonably representative statistics of your data. See Collecting Statistics
in the Administrator's Guide for details.
EXPORT TO VERTICA
Exports an entire table, columns from a table, or the results of a SELECT statement to another HP
Vertica database. Exported data is written to the target database using AUTO mode. Exporting data
to another database requires first establishing a connection to the target database using the
CONNECT statement. See Exporting Data for more setup information.
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.
You can export data from an earlier HP Vertica release, as long as the earlier release is a version of
the last major release. For instance, for Version 6.x, you can export data from any version of 5.x,
but not from 4.x.
By default, using EXPORT TO VERTICA to copy data to another database occurs over the HP
Vertica private network. Connecting to a public network requires some configuration. For
information about using this statement to copy data across a public network, see Using Public and
Private IP Networks.
Syntax
EXPORT TO VERTICA database.[dest-schema.]dest-table
... [(dest-column [,dest-column2,...])]
... { AS SELECT select-expression
... | FROM [source-schema.]source-table
... [(source-column [,source-column2,...])]};
SQLReference Manual
SQL Statements
Parameters
database
.[dest-schema.]
dest-table
dest-column
[,dest-column2,...]
AS SELECT select-expression
source-column
[,source-column2,...]
Notes
Importing and exporting data fails if either side of the connection is a single-node cluster installed to
localhost, or you do not specify a host name or IP address.
Permissions
l
SQLReference Manual
SQL Statements
You can optionally supply lists of either source columns to be copied, columns in the destination
table where data should be stored, or both. Specifying the lists lets you select a subset of source
table columns to copy to the destination table. Since source and destination lists are not required,
results differ depending on which list is present. The following table presents the results of
supplying one or more lists:
Omit Source Column List
Matches all columns in the source Copies content only from the supplied list of
table to columns in the destination source table columns. Matches columns in
table. The number of columns in
the two tables need not match,
Omit
but the destination table must not
Destination
have fewer columns than the
Column
source.
List
Examples
First, open the connection to the other database, then perform a simple export of an entire table to
an identical table in the target database.
=> CONNECT TO VERTICA testdb USER dbadmin PASSWORD '' ON 'VertTest01',5433;
CONNECT
=> EXPORT TO VERTICA testdb.customer_dimension FROM customer_dimension;
Rows Exported
--------------23416
(1 row)
The following statement demonstrates exporting a portion of a table using a simple SELECT
statement.
=> EXPORT TO VERTICA testdb.ma_customers AS SELECT customer_key, customer_name, annual_
income
-> FROM customer_dimension WHERE customer_state = 'MA';
Rows Exported
---------------
SQLReference Manual
SQL Statements
3429
(1 row)
This statement exports several columns from one table to several different columns in the target
database table using column lists. Remember that when supplying both a source and destination
column list, the number of columns must match.
=> EXPORT TO VERTICA testdb.people (name, gender, age) FROM customer_dimension
-> (customer_name, customer_gender, customer_age);
Rows Exported
--------------23416
(1 row)
You can export tables (or columns) containing Identity and Auto-increment values, but the
sequence values are not incremented automatically at their destination.
You can also use the EXPORT TO VERTICA statement with a SELECT AT EPOCH LATEST
expression to include data from the latest committed DML transaction.
See Also
l
CONNECT
DISCONNECT
SQLReference Manual
SQL Statements
GRANT Statements
GRANT statements, described in this section, allow you to grant privileges on database objects to
specific users:
l
GRANT(Authentication)
GRANT (Database)
GRANT (Procedure)
GRANT (Role)
GRANT (Schema)
GRANT (Sequence)
GRANT (Table)
GRANT (View)
GRANT (Authentication)
Associates (or grants) an authentication record to one or more users or roles.
Syntax
GRANT AUTHENTICATION auth-method-name TO
{ Public | user_or_role | user_or_role1, user_or_role2, user_or_role3,... }
Parameters
auth_method_name
SQLReference Manual
SQL Statements
user_or_role, user_or_role1,
Privileges
Must have DBADMIN privileges.
Examples
This example uses a GRANTAUTHENTICATION statement to associate v_ldap authentication
with user jsmith:
=> GRANT AUTHENTICATION v_ldap TO jsmith;
See Also
l
ALTERAUTHENTICATION
CREATE AUTHENTICATION
DROPAUTHENTICATION
REVOKE (Authentication)
GRANT (Database)
Grants the right to create schemas within the database to a user or role. By default, only the
superuser has the right to create a database schema.
SQLReference Manual
SQL Statements
Syntax
GRANT { ... { CREATE [, ...]
... | { TEMP }
... | ALL [ PRIVILEGES ]
... | CONNECT } }
... ON DATABASE database-name [, ...]
... TO { username | rolename } [, ...]
... [ WITH GRANT OPTION ]
Parameters
CREATE
TEMP
CONNECT
ALL
PRIVILEGES
database-name
username | rolename
Example
The following example grants user Fred the right to create schemas on vmartdb.
=> GRANT CREATE ON DATABASE vmartdb TO Fred;
See Also
l
REVOKE (Database)
SQLReference Manual
SQL Statements
GRANT (Procedure)
Grants privileges on a procedure to a database user or role. Only the superuser can grant privileges
to a procedure. To grant privileges to a schema containing the procedure, users must have USAGE
privileges. See GRANT (Schema).
Syntax
GRANT { EXECUTE | ALL }
ON PROCEDURE [ [ db-name.]schema.]procedure-name [, ...]
( [ argname ] argtype [,... ] )
TO { username | role | PUBLIC } [, ...]
Parameters
{ EXECUTE | ALL }
[[ db-name.]schema-name.]
procedure-name
argname
argtype
SQLReference Manual
SQL Statements
Example
The following command grants EXECUTE privileges on the tokenize procedure to users Bob and
Jules, and to the Operator role:
=> GRANT EXECUTE ON PROCEDURE tokenize(varchar) TO Bob, Jules, Operator;
See Also
l
REVOKE (Procedure)
Syntax
GRANT USAGE
ON RESOURCE POOL resource-pool [, ...]
TO { username | role | PUBLIC } [, ...]
Parameters
resource-pool
SQLReference Manual
SQL Statements
Examples
This examples shows how to grant user Joe usage on resource pool Joe_pool.
=> CREATE USER Joe;
CREATE USER
=> CREATE RESOURCE POOL Joe_pool;
CREATE RESOURCE POOL
=> GRANT USAGE ON RESOURCE POOL Joe_pool TO Joe;
GRANT PRIVILEGE
See Also
l
GRANT (Role)
Adds a predefined role to users or other roles. Granting a role does not activate the role
automatically; the user must enable it using the SET ROLE command.
Granting a privilege to a role immediately affects active user sessions. When you grant a new
privilege, it becomes immediately available to every user with the role active.
Syntax
GRANT role [,...] ... TO { user | role | PUBLIC } [, ...]
... [ WITH ADMIN OPTION ];
SQLReference Manual
SQL Statements
Parameters
role [,...]
The name of a user or other role to be granted the role. If the keyword
PUBLIC is supplied, then all users have access to the role.
Grants users and roles administrative privileges for the role. They are able
to grant the role to and revoke the role from other users or roles.
Notes
HP Vertica will return a NOTICE if you grant a role with or without admin option, to a grantee who
has already been granted that role. For example:
=> GRANT commentor to Bob;
NOTICE 4622: Role "commentor" was already granted to user "Bob"
Creating Roles
These examples create three roles, appdata, applogs, and appadmin, and grant one of the roles to
a user, bob:
=> CREATE ROLE appdata;
CREATE ROLE
=> CREATE ROLE applogs;
CREATE ROLE
=> CREATE ROLE appadmin;
CREATE ROLE
=> GRANT appdata TO bob;
GRANT ROLE
Activating a Role
After granting a role to a user, the role must be activated. You can activate a role on a session
basis, or as part of the user's login.
To activate a role for a user's session:
=> CREATE ROLE appdata;
CREATE ROLE
=> GRANT appdata TO bob;
GRANT ROLE
SQLReference Manual
SQL Statements
Now, any privileges assigned to either appdata or applogs are automatically assigned to appadmin
as well.
SQLReference Manual
SQL Statements
granting the appadmin role (with administrative privileges) to users bob and alice. After each user
has been granted the appadmin role, either use can connect as the other will full privileges.
=> GRANT appadmin TO bob, alice WITH ADMIN OPTION;
GRANT ROLE
=> \connect - bob
You are now connected as user "bob".
=> REVOKE appadmin FROM alice;
REVOKE ROLE
See Also
l
REVOKE (Role)
GRANT (Schema)
Grants privileges on a schema to a database user or role.
Syntax
GRANT { ... { CREATE | USAGE } [ , ... ]
... | ALL [ PRIVILEGES ] }
... ON SCHEMA [db-name.]schema [ , ... ]
... TO { username | role | PUBLIC } [ , ... ]
... [ WITH GRANT OPTION ]
Parameters
CREATE
Allows the user read access to the schema and the right to create tables and
views within the schema.
USAGE
Allows the user access to the objects contained within the schema. This
allows the user to look up objects within the schema. Note that the user
must also be granted access to the individual objects. See the GRANT
TABLE and GRANT VIEW statements.
ALL
PRIVILEGES
[db-name.]
SQLReference Manual
SQL Statements
schema
username
role
PUBLIC
Notes
Newly-created users do not have access to schema PUBLIC by default. Make sure to grant
USAGE on schema PUBLIC to all users you create.
Examples
This example shows how to grant user Joe usage on schema online_sales.
=> CREATE USER Joe;
CREATE USER
=> GRANT USAGE ON SCHEMA online_sales TO Joe;
GRANT PRIVILEGE
See Also
l
REVOKE (Schema)
GRANT (Sequence)
Grants privileges on a sequence generator to a user or role. Optionally grants privileges on all
sequences within one or more schemas.
Syntax
GRANT { SELECT | ALL [ PRIVILEGES ] }... ON SEQUENCE [[db-name.]schema.]sequence-name [ , ...
]
... | ON ALL SEQUENCES IN SCHEMA schema-name [, ...]
... TO { username | role | PUBLIC } [ , ... ]
... [ WITH GRANT OPTION ]
SQLReference Manual
SQL Statements
Parameters
SELECT
PRIVILEGES
[[db-name.]schema.]
sequence-name
username
role
PUBLIC
Notes
The user must also be granted USAGE on the schema that contains the sequence. See GRANT
(Schema).
Examples
This example shows how to grant user Joe all privileges on sequence my_seq.
=> CREATE SEQUENCE my_seq START 100;
CREATE SEQUENCE
=> GRANT ALL PRIVILEGES ON SEQUENCE my_seq TO Joe;
GRANT PRIVILEGE
SQLReference Manual
SQL Statements
See Also
l
REVOKE (Sequence)
Syntax
GRANT { READ | WRITE | ALL [ PRIVILEGES ] }
... ON LOCATION 'path' [, ON node ]
... TO { username | role | PUBLIC } [,
...]
...
... [ WITH GRANT OPTION ]
Parameters
READ
WRITE
ALL
PRIVILEGES
SQLReference Manual
SQL Statements
ON LOCATION 'path'
[, ON node ]
Notes
Only a superuser can add, alter, retire, drop, and restore a location. The superuser can grant only
READ and/or WRITE access privileges to storage locations for other users or roles.
Examples
In the following series of commands, a superuser creates a new storage location and grants it to
user Bob:
=> CREATE LOCATION '/home/dbadmin/UserStorage/BobStore' NODE 'v_mcdb_node0007' USAGE
'USER';
CREATE LOCATION
Now the superuser grants a user named Bob all available privileges tothe /BobStore location:
=> GRANT ALL ON LOCATION '/home/dbadmin/UserStorage/BobStore' TO Bob;
GRANT PRIVILEGE
SQLReference Manual
SQL Statements
See Also
l
GRANT (Table)
Grants privileges on a table to a user or role. Optionally grants privileges on all tables within one or
more schemas.
Note: Granting privileges on all tables within a schema includes all views in the same schema.
Syntax
GRANT { { SELECT | INSERT | UPDATE | DELETE | REFERENCES } [ ,... ] ... | ALL [ PRIVILEGES ] }
... ON [ TABLE ] [ [ db-name.]schema.]tablename [ , ... ]
... | ON ALL TABLES IN SCHEMA schema-name [, ...]
... TO { username | role | PUBLIC } [ , ... ]
... [ WITH GRANT OPTION ]
Parameters
SELECT
Allows the user to SELECT from any column of the specified table.
SQLReference Manual
SQL Statements
INSERT
Allows the user to INSERT tuples into the specified table and to use
the COPY command to load the table.
Note: COPY FROM STDIN is allowed to any user granted the
INSERT privilege, while COPY FROM <file> is an admin-only
operation.
UPDATE
DELETE
REFERENCES
ALL
PRIVILEGES
[[db-name.]schema.]
tablename
Specifies the table on which to grant the privileges. When using more
than one schema, specify the schema that contains the table on which
to grant privileges.
Grants privileges on all tables (and by default all views) within one or
more schemas to a user and/or role.
username
role
PUBLIC
SQLReference Manual
SQL Statements
Notes
l
The user must also be granted USAGE on the schema that contains the table. See GRANT
(Schema).
To use the DELETE or UPDATE commands with a WHERE Clause, a user must have both
SELECT and UPDATE and DELETE privileges on the table.
The user can be granted privileges on a global temporary table, but not a local temporary table.
Examples
This example shows how to grant user Joe all privileges on table customer_table.
=> CREATE USER Joe;
CREATE USER
=> GRANT ALL PRIVILEGES ON TABLE customer_dimension TO Joe;
GRANT PRIVILEGE
See Also
l
REVOKE (Table)
SQLReference Manual
SQL Statements
UDL Filter
UDL Parser
UDL Source
Syntax
GRANT { EXECUTE | ALL }
... ON FUNCTION [ [ db-name.]schema.]function-name [, ...]
... | ON AGGREGATE FUNCTION [ [ db-name.]schema.]function-name [, ...]
... | ON ANALYTIC FUNCTION [ [ db-name.]schema.]function-name [, ...]
... | ON TRANSFORM FUNCTION [[db-name.]schema.]function-name [, ...]
... | ON FILTER [ [ db-name.]schema.]filter-name [, ...]
... | ON PARSER [ [ db-name.]schema.]parser-name [, ...]
... | ON SOURCE [ [ db-name.]schema.]source-name [, ...]
... | ON ALL FUNCTIONS IN SCHEMA schema-name [, ...]
... ( [ argname ] argtype [, ...] )
... TO { username | role | PUBLIC } [, ...]
Parameters
{ EXECUTE | ALL }
[[ db-name.]schema-name.]
function-name
filter-name
parser-name
source-name
SQLReference Manual
SQL Statements
argname
argtype
Permissions
Only a superuser and owner can grant privileges on a UDx. To grant privileges to a specific
schema UDx or to all UDx's within one or more schemas, grantees must have USAGE privileges on
the schema. See GRANT (Schema).
Examples
The following command grants EXECUTE privileges on the myzeroifnull SQL function to users Bob
and Jules, and to the Operator role. The function takes one integer argument:
=> GRANT EXECUTE ON FUNCTION myzeroifnull (x INT) TO Bob, Jules, Operator;
The following command grants EXECUTE privileges on all functions in the zero-schema schema to
user Bob:
=> GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA zero-schema TO Bob;
The following command grants EXECUTE privileges on the tokenize transform function to user Bob
and to the Operator role:
=> GRANT EXECUTE ON TRANSFORM FUNCTION tokenize(VARCHAR) TO Bob, Operator;
The following command grants EXECUTE privileges on the ExampleSource() source to user Alice.
SQLReference Manual
SQL Statements
The next command grants ALL privileges on the ExampleSource() source to user Alice:
=> GRANT ALL ON SOURCE ExampleSource() TO Alice;
The following command grants ALL privileges on the polymorphic function Pagerank to the dbadmin
role:
=> GRANT ALL ON TRANSFORM FUNCTION Pagerank(z varchar) to dbadmin;
See Also
l
Developing and Using User Defined Functions in the Extending HPVertica Guide
GRANT (View)
Grants privileges on a view to a database user or role.
Syntax
GRANT ... { SELECT | ALL [ PRIVILEGES ] }
... ON [ [ db-name.]schema.]viewname [, ...]
... TO { username | role | PUBLIC } [, ...]
... [ WITH GRANT OPTION ]
Parameters
SELECT
ALL
Grants a user or role all privileges to a view, and any resources referenced
within it.
PRIVILEGES
SQLReference Manual
SQL Statements
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
viewname
Specifies the view on which to grant the privileges. When using more than
one schema, specify the schema that contains the view, as noted above.
username
role
PUBLIC
Note: If userA wants to grant userB access to a view, userA must specify WITH GRANT
OPTION on the base table, in addition to the view, regardless of whether userB (grantee) has
access to the base table.
Examples
This example shows how to grant user Joe all privileges on view ship.
=> CREATE VIEW ship AS SELECT * FROM public.shipping_dimension;
CREATE VIEW
=> GRANT ALL PRIVILEGES ON ship TO Joe;
GRANT PRIVILEGE
See Also
l
REVOKE (View)
INSERT
Inserts values into all projections of a table. You must insert one complete tuple at a time. By
default, INSERT first uses the WOS. When the WOS is full, the inserted tuple overflows to the
ROS.
Note: If a table has no associated projections, HP Vertica creates a default superprojection for
SQLReference Manual
SQL Statements
Syntax
INSERT [ /*+ hint[, hint] */ ]
... INTO [[db-name.]schema.]table
... [ ( column [, ...] ) ]
... { DEFAULT VALUES
... | VALUES ( { expression | DEFAULT } [, ...] )
... | SELECT... }
Parameters
/*+ hint[, hint] */
[[db-name.]schema.]
table
Specifies the name of a table in the schema. You cannot INSERT tuples
into a projection. When using more than one schema, specify the schema
that contains the table, as noted above.
SQLReference Manual
SQL Statements
column
Specifies one or more table columns. You can list the target columns in
any order. If no list of column names is given at all, the default is all the
columns of the table in their declared order; or the first N column names, if
there are only N columns supplied by the VALUES clause or query. The
values supplied by the VALUES clause or query are associated with the
explicit or implicit column list left-to-right.
DEFAULT VALUES
Fills all columns with their default values as specified in CREATE TABLE.
VALUES
expression
Specifies a value to store in the corresponding column. Do not use metafunctions in INSERT statements.
Note: This expression must not nest other expressions within it.
DEFAULT
SELECT...
Permissions
l
Examples
=>
=>
=>
=>
INSERT
INSERT
INSERT
INSERT
INTO
INTO
INTO
INTO
SQLReference Manual
SQL Statements
HP Vertica does not support subqueries or nested expressions as the target of an INSERT
statement. For example, the following query returns an error message:
INSERT INTO t1 (col1, col2) VALUES ('abc', (SELECT mycolumn FROM mytable));
ERROR 4821: Subqueries not allowed in target of insert
When doing an INSERT /*+ direct */ HP Vertica takes optional spaces before and after the plus
sign (e.g., between the /* and the +). Both of the following commands, for example, load data into
the ROS:
=>
=>
=>
=>
MERGE
The MERGE statement combines INSERT and UPDATE operations into a single operation. During a
merge, HP Vertica updates and inserts rows in the target table from rows in the source table,
depending on conditions you specify, such as whether the target table already has a row that
matches data from the source.
Note: The MERGE statement requires an exclusive lock (X lock). An X lock is also required to
complete a DELETEstatement.
By default, HP Vertica prepares an optimized query plan for a MERGE statement when the statement
and its tables meet certain conditions. See Optimized Versus Non-Optimized MERGE in the
Administrator's Guide for details.
A MERGE operation uses the WOS by default. If the WOS fills up, data overflows to the ROS.
You cannot use the MERGE statement with flex tables.
SQLReference Manual
SQL Statements
Syntax
MERGE [/*+ direct */]
... INTO [[db-name.]schema.]target-table [ alias ]
... USING [[db-name.]schema.]source-table [ alias ]
... ON ( condition )
... [ WHEN MATCHED THEN UPDATE SET
column1 = value1 [, column2 = value2 ... ] ]
... [ WHEN NOT MATCHED THEN INSERT ( column1 [, column2 ...])
VALUES ( value1 [, value2 ... ] ) ]
Returns
The returned value at the end of a MERGE operation represents the number of rows updated, plus the
number of rows inserted into the target table.
Parameters
/*+ direct */
[[db-name.]schema.]
SQLReference Manual
SQL Statements
INTO target-table
Specifies the target table name (with optional alias) that you
want to update. MERGE takes an X (exclusive) lock on the
target table during the operation.
You cannot merge into a projection or unstructured table.
USING source-table
ON condition
SQLReference Manual
SQL Statements
More than one matching value in the source join column for
a corresponding value in the target table. The source join
column does not require a unique or primary key constraint.
SQLReference Manual
SQL Statements
SQLReference Manual
SQL Statements
Privileges
A MERGE statement requires SELECT permissions on the source table and INSERT, UPDATE, and
DELETE permissions on the target table.
An optimized query plan for a MERGE statement assumes that the data you are trying to merge
conforms with any unique or primary key constraints you declare.
You cannot run a MERGE operation on identity/auto-increment columns or on columns that have
primary key or foreign key referential integrity constraints, as defined in CREATE TABLE ColumnConstraint syntax.
If you run the MERGE statement more than once using the same target and source tables, you
could introduce duplicate values into the join columns, such as when using constants in the
UPDATE/INSERT clauses.
You cannot use the LIMIT clause on unsorted data when you update or merge tables that
participate in pre-join projections.
Examples
The following example shows how to merge table target_table with table source_table. When
the id columns match, the target tables count column is updated.
=> CREATE TABLE target_table (id INT PRIMARY KEY, count INT);
CREATE TABLE
SQLReference Manual
SQL Statements
See Also
Synchronizing Table Data with MERGE in the Administrator's Guide
PROFILE
Profiles a single SQL statement.
Syntax
PROFILE { SELECT ... }
Output
Writes a hint to stderr, as described in the example below.
Permissions
Privileges required to run this command are the same privileges required to run the query being
profiled.
Notes
To profile a single statement, add the PROFILE keyword to the beginning of the statement, which
saves profiling information for future analysis:
=> PROFILE SELECT customer_name, annual_income
FROM public.customer_dimension
WHERE (customer_gender, annual_income) IN (
SELECT customer_gender, MAX(annual_income)
FROM public.customer_dimension
SQLReference Manual
SQL Statements
GROUP BY customer_gender);
While a query is executing, a notice and hint display in the terminal window. For example, the
preceding query returns the following:
NOTICE 4788: Statement is being profiled
HINT: Select * from v_monitor.execution_engine_profiles where transaction_
id=45035996273726389 and statement_id=10;
NOTICE 3557: Initiator memory for query: [on pool general: 732168 KB, minimum: 451218
KB]
NOTICE 5077: Total memory required by query: [732168 KB]
customer_name
| annual_income
-----------------+--------------James M. McNulty |
999979
Emily G. Vogel
|
999998
(2 rows)
Tip: Use the statement returned by the hint as a starting point for reviewing the query's
profiling data, such as to see what counters are available.
SQLReference Manual
SQL Statements
counter_name
----------------------------------------------------estimated rows produced
bytes spilled
rle rows produced
join inner current size of temp files (bytes)
request wait (us)
start time
intermediate rows to process
producer wait (us)
rows segmented
consumer stall (us)
bytes sent
rows sent
join inner completed merge phases
encoded bytes received
cumulative size of raw temp data (bytes)
end time
bytes read from cache
total merge phases
rows pruned by valindex
cumulative size of temp files (bytes)
output queue wait (us)
rows to process
input queue wait (us)
rows processed
memory allocated (bytes)
join inner cumulative size of temp files (bytes)
current size of temp files (bytes)
join inner cumulative size of raw temp data (bytes)
bytes received
file handles
bytes read from disk
join inner total merge phases
completed merge phases
memory reserved (bytes)
clock time (us)
response wait (us)
network wait (us)
rows received
encoded bytes sent
execution time (us)
producer stall (us)
buffers spilled
rows produced
(43 rows)
RELEASE SAVEPOINT
Destroys a savepoint without undoing the effects of commands executed after the savepoint was
established.
Syntax
RELEASE [ SAVEPOINT ] savepoint_name
SQLReference Manual
SQL Statements
Parameters
savepoint_name
Permissions
No special permissions required.
Notes
Once destroyed, the savepoint is unavailable as a rollback point.
Example
The following example establishes and then destroys a savepoint called my_savepoint. The values
101 and 102 are both inserted at commit.
=>
=>
=>
=>
=>
See Also
l
SAVEPOINT
ROLLBACK TO SAVEPOINT
SQLReference Manual
SQL Statements
REVOKE Statements
The following functions allow you to revoke privileges on database objects for specified users:
l
REVOKE (Authentication)
REVOKE (Database)
REVOKE (Procedure)
REVOKE (Role)
REVOKE (Schema)
REVOKE (Sequence)
REVOKE (Table)
REVOKE (View)
REVOKE (Authentication)
Revokes an authentication method that you have granted to (associated with) one or more users or
roles.
Syntax
REVOKE AUTHENTICATION auth-method-name FROM
{ Public | user_or_role | user_or_role1, user_or_role2, user_or_role3,... }
SQLReference Manual
SQL Statements
Parameters
auth_method_name
Name of the
authentication method
which you want to
revoke from one or
more users.
Type: VARCHAR
Privileges
Must have DBADMIN privileges.
Examples
This example revokes v_ldap authentication from user jsmith:
=> REVOKE AUTHENTICATION v_ldap FROM jsmith;
See Also
l
ALTERAUTHENTICATION
CREATE AUTHENTICATION
SQLReference Manual
SQL Statements
DROPAUTHENTICATION
GRANT(Authentication)
REVOKE (Database)
Revokes the right for the specified user or role to create schemas in the specified database.
Syntax
REVOKE [ GRANT OPTION FOR ]
... { CREATE | { TEMPORARY | TEMP } [ ,... ] }
... | CONNECT
... | ALL [ PRIVILEGES ] }
... ON DATABASE database-name [ , ... ]
... FROM { username | role }[ , ... ]
... [ CASCADE ]
Parameters
GRANT OPTION FOR
Revokes the grant option for the privilege, not the privilege itself. If omitted,
revokes both the privilege and the grant option.
CREATE
TEMPORARY | TEMP
ALL
PRIVILEGES
database-name
username
role
CASCADE
Revokes the privilege from the specified user or role and then from others.
Once a user or role has been granted a privilege, the user can grant that
privilege to other users and roles. The CASCADE keyword first revokes the
privilege from the initial user or role, and then from other grantees extended
the privilege.
SQLReference Manual
SQL Statements
Examples
The following example revokes Fred's right to create schemas on vmartdb:
=> REVOKE CREATE ON DATABASE vmartdb FROM Fred;
See Also
l
GRANT (Database)
REVOKE (Procedure)
Revokes the execute privilege on a procedure from a user or role.
Syntax
REVOKE EXECUTE
... ON [ [ db-name.]schema.]procedure-name [ , ... ]
... ( [ argname ] argtype [ ,... ] ] )
... FROM { username | PUBLIC | role } [ , ... ]
...[ CASCADE ]
Parameters
[[db-name.]schema.]
SQLReference Manual
SQL Statements
procedure-name
argname
argtype
username
PUBLIC
role
CASCADE
Revokes the privilege from the specified user or role and then from others.
Once a user or role has been granted a privilege, the user can grant that
privilege to other users and roles. The CASCADE keyword first revokes
the privilege from the initial user or role, and then from other grantees
extended the privilege.
Notes
Only a superuser can revoke USAGE on a procedure.
Examples
This example revokes Bob's execute privilege on the tokenize(varchar) procedure.
=> REVOKE EXECUTE ON tokenize(varchar) FROM Bob;
See Also
l
GRANT (Procedure)
SQLReference Manual
SQL Statements
Syntax
REVOKE USAGE... ON RESOURCE POOL resource-pool
... FROM { username | PUBLIC | role } [ , ... ]
...[ CASCADE ]
Parameters
resource-pool
Specifies the resource pool from which to revoke the usage privilege.
username
PUBLIC
role
CASCADE
Revokes the privilege from the specified user or role and then from others. Once
a user or role has been granted a privilege, the user can grant that privilege to
other users and roles. The CASCADE keyword first revokes the privilege from
the initial user or role, and then from other grantees extended the privilege.
Notes
l
HP Vertica checks resource pool permissions when a user initially switches to the pool, rather
than on each access. Revoking a user's permission to use a resource pool does not affect
existing sessions. You need to close the user's open sessions that are accessing the resource
pool if you want to prevent them from continuing to use the pool's resources.
It is an error to revoke a user's access permissions for the resource pool to which they are
assigned (their default pool). You must first change the pool they are assigned to using ALTER
USER ... RESOURCE POOL (potentially using GRANT USAGE ON RESOURCE POOL first
to allow them to access the new pool) before revoking their access.
Examples
This example shows how to revoke user Joe's usage privilege on the Joe_pool resource pool.
=> REVOKE USAGE ON RESOURCE POOL Joe_pool FROM Joe;
REVOKE PRIVILEGE
SQLReference Manual
SQL Statements
See Also
l
REVOKE (Role)
Revokes a role (and administrative access, applicable) from a grantee. A user that has
administrator access to a role can revoke the role for other users.
If you REVOKE role WITH ADMIN OPTION, HP Vertica revokes only the ADMIN OPTION from
the grantee, not the role itself.
You can also remove a role's access to another role.
Syntax
REVOKE [ ADMIN OPTION FOR ] role [, ...]
... FROM { user | role | PUBLIC } [, ...]
...[ CASCADE ];
Parameters
ADMIN OPTION FOR
role
The name of one or more roles from which you want to revoke access.
The name of a user or role whose permission you want to revoke. You
can use the PUBLIC option to revoke access to a role that was
previously made public.
CASCADE
Revokes the privilege from the specified user or role and then from
others. Once a user or role has been granted a privilege, the user can
grant that privilege to other users and roles. The CASCADE keyword first
revokes the privilege from the initial user or role, and then from other
grantees extended the privilege.
Examples
This example shows the revocation of the pseudosuperuser role from the dbadmin user:
=> REVOKE pseudosuperuser from dbadmin;
SQLReference Manual
SQL Statements
This example shows the revocation of administration access from the dbadmin user for the
pseudosuperuser role. The ADMINOPTIONcommand does not remove the pseudosuperuser role.
=> REVOKE ADMIN OPTION FOR pseudosuperuser FROM dbadmin;
Notes
If the role you are trying to revoke was not already granted to the user, HP Vertica returns a
NOTICE:
=> REVOKE commentor FROM Sue;
NOTICE 2022: Role "commentor" was not already granted to user "Sue"
REVOKE ROLE
See Also
l
GRANT (Role)
REVOKE (Schema)
Revokes privileges on a schema from a user or role.
Note: In a database with trust authentication, the GRANT and REVOKE statements appear to
work as expected but have no actual effect on the security of the database.
Syntax
REVOKE [ GRANT OPTION FOR ] {
... { CREATE | USAGE } [ ,... ]
... | ALL [ PRIVILEGES ] }
... ON SCHEMA [db-name.] schema [ , ... ]
... FROM { username | PUBLIC | role } [ , ... ]
...[ CASCADE ]
Parameters
GRANT OPTION FOR
Revokes the grant option for the privilege, not the privilege itself. If omitted,
revokes both the privilege and the grant option.
CREATE
Revokes the user read access to the schema and the right to create tables
and views within the schema.
SQLReference Manual
SQL Statements
USAGE
Revokes user access to the objects contained within the schema. Note that
the user can also have access to the individual objects revoked. See the
GRANT TABLE and GRANT VIEW statements.
ALL
PRIVILEGES
[db-name.]
schema
username
PUBLIC
role
CASCADE
Revokes the privilege from the specified user or role and then from others.
Once a user or role has been granted a privilege, the user can grant that
privilege to other users and roles. The CASCADE keyword first revokes the
privilege from the initial user or role, and then from other grantees extended
the privilege.
Examples
This example shows how to revoke user Joe's usage privileges on the online_sales schema.
=> REVOKE USAGE ON SCHEMA online_sales FROM Joe;
REVOKE PRIVILEGE
See Also
l
GRANT (Schema)
REVOKE (Sequence)
Revokes privileges on a sequence generator from a user or role. Optionally revokes privileges on
all sequences within one or more schemas.
SQLReference Manual
SQL Statements
Syntax
REVOKE [ GRANT OPTION FOR ]
... { SELECT | ALL [ PRIVILEGES ] }
... ON SEQUENCE [ [ db-name.]schema.]sequence-name [ , ... ]
... | ON ALL SEQUENCES IN SCHEMA schema-name [, ...]
... FROM { username | PUBLIC | role } [ , ... ]
...[ CASCADE ]
Parameters
SELECT
ALL
PRIVILEGES
[[db-name.]schema.]
sequence-name
username
PUBLIC
role
SQLReference Manual
SQL Statements
CASCADE
Revokes the privilege from the specified user or role and then from
others. Once a user or role has been granted a privilege, the user
can grant that privilege to other users and roles. The CASCADE
keyword first revokes the privilege from the initial user or role, and
then from other grantees extended the privilege.
Examples
This example shows how to revoke user Joe's privileges on the my_seq sequence.
=> REVOKE ALL PRIVILEGES ON SEQUENCE my_seq FROM Joe;
REVOKE PRIVILEGE
See Also
l
GRANT (Sequence)
Syntax
REVOKE [ GRANT OPTION FOR ]
... { READ | WRITE | ALL [ PRIVILEGES ] }
... ON LOCATION [ 'path' , [ ON node ] ]
... FROM { username | role | PUBLIC } [, ...]
... [ CASCADE ]
Parameters
REVOKE OPTION FOR
READ
SQLReference Manual
SQL Statements
WRITE
ALL
PRIVILEGES
ON LOCATION ( 'path' ,
[ ON node ] )
CASCADE
Examples
For examples, see GRANT (Storage Location)
See Also
l
SQLReference Manual
SQL Statements
REVOKE (Table)
Revokes privileges on a table from a user or role. Optionally revokes privileges on all tables within
one or more schemas.
Note: Revoking privileges on all tables within a schema includes all views in the same
schema.
In a database with trust authentication, the GRANT and REVOKE statements appear to work as
expected but have no actual effect on the security of the database.
Syntax
REVOKE [ GRANT OPTION FOR ]... {
......{ SELECT | INSERT | UPDATE | DELETE | REFERENCES } [ ,... ]
......| ALL [ PRIVILEGES ]
... }
... ON [ TABLE ] [ [ db-name.]schema.]tablename [ , ... ]
... | ON ALL TABLES IN SCHEMA schema-name [, ...]
... FROM { username | PUBLIC | role } [ , ... ]
... [ CASCADE ]
Parameters
GRANT OPTION FOR
Revokes the grant option for the privilege, not the privilege itself. If
omitted, revokes both the privilege and the grant option.
SELECT
INSERT
Revokes the user from being able to INSERT tuples into the specified
table and to use the COPY command to load the table.
Note: COPY FROM STDIN is allowed to any user granted the
INSERT privilege, while COPY FROM <file> is an admin-only
operation.
UPDATE
DELETE
Revokes user from being able to DELETE a row from the specified
table.
SQLReference Manual
SQL Statements
REFERENCES
ALL
PRIVILEGES
[[db-name.]schema.]
tablename
Specifies the table from which to remove privileges. When using more
than one schema, specify the schema that contains the table on which
to revoke privileges, as noted above.
username
PUBLIC
role
CASCADE
Revokes the privilege from the specified user or role and then from
others. Once a user or role has been granted a privilege, the user can
grant that privilege to other users and roles. The CASCADE keyword
first revokes the privilege from the initial user or role, and then from
other grantees extended the privilege.
Examples
This example shows how to revoke user Joe's privileges on the customer_dimension table.
=> REVOKE ALL PRIVILEGES ON TABLE customer_dimension FROM Joe;
SQLReference Manual
SQL Statements
REVOKE PRIVILEGE
See Also
l
GRANT (Table)
UDL Filter
UDL Parser
UDL Source
Syntax
REVOKE EXECUTE
...ON FUNCTION [ [ db-name.]schema.]function-name [, ...]
... | ON AGGREGATE FUNCTION [ [ db-name.]schema.]function-name [, ...]
... | ON ANALYTIC FUNCTION [ [ db-name.]schema.]function-name [, ...]
... | ON TRANSFORM FUNCTION [[db-name.]schema.]function-name [, ...]
... | ON FILTER [ [ db-name.]schema.]filter-name [, ...]
... | ON PARSER [ [ db-name.]schema.]parser-name [, ...]
... | ON SOURCE [ [ db-name.]schema.]source-name [, ...]
... | ON ALL FUNCTIONS IN SCHEMA schema-name [, ...]
... ( [ argname ] argtype [, ...] )
SQLReference Manual
SQL Statements
Parameters
[[ db-name.]schema-name.]
function-name
filter-name
parser-name
source-name
argname
argtype
CASCADE
Permissions
Only a superuser and owner can revoke EXECUTEprivileges on a UDx.
SQLReference Manual
SQL Statements
Examples
The following command revokes EXECUTE privileges from user Bob on the myzeroifnull function:
> REVOKE EXECUTE ON FUNCTION myzeroifnull (x INT) FROM Bob;
The following command revokes ALL privileges from user Doug on the Pagerank polymorphic
function:
> REVOKE ALL ON TRANSFORM FUNCTION Pagerank (t float) FROM Doug;
The following command revokes EXECUTE privileges on all functions in the zero-schema schema
from user Bob:
> REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA zero-schema FROM Bob;
The following command revokes EXECUTE privileges from user Bob on the tokenize function:
> REVOKE EXECUTE ON TRANSFORM FUNCTION tokenize(VARCHAR) FROM Bob;
The following command revokes ALL privileges on the ExampleSource() source from user Alice:
> REVOKE ALL ON SOURCE ExampleSource() FROM Alice;
See Also
l
Developing and Using User Defined Functions in the Extending HPVertica Guide
REVOKE (View)
Revokes user privileges on a view.
Note: In a database with trust authentication, the GRANT and REVOKE statements appear to
work as expected but have no actual effect on the security of the database.
SQLReference Manual
SQL Statements
Syntax
REVOKE [ GRANT OPTION FOR ]... { SELECT | ALL [ PRIVILEGES ] }
... ON [ VIEW ] [ [ db-name.]schema.]viewname [ , ... ]
... FROM { username | PUBLIC } [ , ... ]
... [ CASCADE ]
Parameters
GRANT OPTION FOR
Revokes the grant option for the privilege, not the privilege itself. If
omitted, revokes both the privilege and the grant option.
SELECT
PRIVILEGES
[[db-name.]schema.]
viewname
Specifies the view on which to revoke the privileges. When using more
than one schema, specify the schema that contains the view, as noted
above.
username
PUBLIC
CASCADE
Revokes the privilege from the specified user or role and then from others.
Once a user or role has been granted a privilege, the user can grant that
privilege to other users and roles. The CASCADE keyword first revokes
the privilege from the initial user or role, and then from other grantees
extended the privilege.
SQLReference Manual
SQL Statements
Examples
This example shows how to revoke user Joe's privileges on view ship.
=> REVOKE ALL PRIVILEGES ON ship FROM Joe;
REVOKE PRIVILEGE
See Also
l
GRANT (View)
ROLLBACK
Ends the current transaction and discards all changes that occurred during the transaction.
Syntax
ROLLBACK [ WORK | TRANSACTION ]
Parameters
WORK | TRANSACTION
Permissions
No special permissions required.
Notes
When an operation is rolled back, any locks that are acquired by the operation are also rolled back.
ABORT is a synonym for ROLLBACK.
Examples
This example shows how to roll back from a DELETE transaction.
=> SELECT * FROM sample_table;
SQLReference Manual
SQL Statements
a
--1
(1 row)
=> DELETE FROM sample_table WHERE a = 1;
=> SELECT * FROM sample_table;
a
--(0 rows)
=> ROLLBACK;
=> SELECT * FROM sample_table;
a
--1
(1 row)
This example shows how to roll back the changes you made since the BEGIN statement.
=> BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY;
BEGIN
=> ROLLBACK TRANSACTION;
ROLLBACK
See Also
l
Transactions
BEGIN
COMMIT
END
START TRANSACTION
ROLLBACK TO SAVEPOINT
Rolls back all commands that have been entered within the transaction since the given savepoint
was established.
Syntax
ROLLBACK TO [SAVEPOINT] savepoint_name
SQLReference Manual
SQL Statements
Parameters
savepoint_name
Permissions
No special permissions required.
Notes
l
The savepoint remains valid and can be rolled back to again later if needed.
When an operation is rolled back, any locks that are acquired by the operation are also rolled
back.
ROLLBACK TO SAVEPOINT implicitly destroys all savepoints that were established after the
named savepoint.
Example
The following example rolls back the values 102 and 103 that were entered after the savepoint, my_
savepoint, was established. Only the values 101 and 104 are inserted at commit.
=>
=>
=>
=>
=>
=>
=>
See Also
l
RELEASE SAVEPOINT
SAVEPOINT
SAVEPOINT
Creates a special mark, called a savepoint, inside a transaction. A savepoint allows all commands
that are executed after it was established to be rolled back, restoring the transaction to the state it
SQLReference Manual
SQL Statements
Syntax
SAVEPOINT savepoint_name
Parameters
savepoint_name
Permissions
No special permissions required.
Notes
l
Savepoints are local to a transaction and can only be established when inside a transaction
block.
If a savepoint with the same name already exists, it is replaced with the new savepoint.
Example
The following example illustrates how a savepoint determines which values within a transaction
can be rolled back. The values 102 and 103 that were entered after the savepoint, my_savepoint,
was established are rolled back. Only the values 101 and 104 are inserted at commit.
=>
=>
=>
=>
=>
=>
=>
=>
.
.
(101);
(102);
(103);
(104);
SQLReference Manual
SQL Statements
.
101
104
(2 rows)
See Also
l
RELEASE SAVEPOINT
ROLLBACK TO SAVEPOINT
SELECT
Retrieves a result set from one or more tables.
Syntax
[{ AT EPOCH {LATEST | epoch-number} | AT TIME 'timestamp'}]
select [ /*+ label(label-name)*/ ] [ ALL | DISTINCT ]
... { * | expression [[AS] output-name]} [ , ... ]
... [ INTO ]
... [ FROM [, ...] ]
... [ WHERE condition ]
... [ TIMESERIES slice-time ]
... [ GROUP BY expression [ , ... ] ]
... [ HAVING condition [ , ... ] ]
... [ MATCH ]... [ UNION { ALL | DISTINCT } ]
... [ EXCEPT ]
... [ INTERSECT ]
... [ ORDER BY expression { ASC | DESC } [ ,... ] ]
... [ LIMIT { count | ALL } ]
... [ OFFSET start ]
... [ FOR UPDATE [ OF table-name [ , ... ] ] ]
SQLReference Manual
SQL Statements
Parameters
AT EPOCH LATEST
Queries all data in the database up to but not including the current
epoch without holding a lock or blocking write operations. See
Snapshot isolation for more information. AT EPOCH LATEST is ignored
when applied to temporary tables (all rows are returned).
By default, queries run under the READ COMMITTED isolation level,
which means:
l
epoch-number
Queries all data in the database up to and including the current epoch
without holding a lock or blocking write operations.
AT TIME 'timestamp'
/*+ label(label-name)*/
DISTINCT
Removes duplicate rows from the result set (or group).The DISTINCT
set quantifier must immediately follow the SELECT keyword. Only one
DISTINCT keyword can appear in the select list.
SQLReference Manual
SQL Statements
expression
Forms the output rows of the SELECT statement. The expression can
contain:
output-name
Literals (constants)
Mathematical Operators
Aggregate Expressions
CASE Expressions
SQL Functions
FOR UPDATE
Privileges
Table owner or user with GRANT OPTION is grantor.
l
Privileges required on base objects for the view owner must be granted directly; you cannot grant
privileges on these objects using roles:
SQLReference Manual
SQL Statements
If a non-owner runs a SELECT query on the view, the view owner must also have SELECT ...
WITH GRANT OPTION privileges on the view's base tables or views. This privilege must be
directly granted to the owner; it should not be granted through a role.
If a view owner runs a SELECT query on the view, the owner must also have SELECT privilege
directly granted (not through a role) on a view's base objects (table or view).
Example
When multiple clients run transactions like in the following example query, deadlocks can occur if
FOR UPDATE is not used. Two transactions acquire an S lock, and when both attempt to upgrade to
an X lock, they encounter deadlocks:
=> SELECT balance FROM accounts WHERE account_id=3476 FOR UPDATE;
...
=> UPDATE accounts SET balance = balance+10 WHERE account_id=3476;
=> COMMIT;
See Also
l
LOCKS
Analytic Functions
Subqueries
Joins
EXCEPT Clause
Combines two or more SELECT queries. EXCEPT returns distinct results of the left-hand query
that are not also found in the right-hand query.
Note: MINUS is an alias for EXCEPT.
SQLReference Manual
SQL Statements
Syntax
SELECT
... EXCEPT select
... [ EXCEPT select ]...
... [ ORDER BY { column-name
... | ordinal-number }
... [ ASC | DESC ] [ , ... ] ]
... [ LIMIT { integer | ALL } ]
... [ OFFSET integer ]
Notes
l
Use the EXCEPT clause to filter out specific results from a SELECT statement. The EXCEPT
query operates on the results of two or more SELECT queries. It returns only those rows in the
left-hand query that are not also present in the right-hand query.
HP Vertica evaluates multiple EXCEPT clauses in the same SELECT query from left to right,
unless parentheses indicate otherwise.
The results of each SELECT statement must be union compatible. Each statement must return
the same number of columns, and the corresponding columns must have compatible data types.
For example, you cannot use the EXCEPT clause on a column of type INTEGER and a column
of type VARCHAR. If statements do not meet these criteria, HP Vertica returns an error.
Note: The Data Type Coercion Chart lists the data types that can be cast to other data
types. If one data type can be cast to the other, those two data types are compatible.
You can order the results of an EXCEPT operation by including an ORDER BY operation in the
statement. When you write the ORDER BY list, specify the column names from the leftmost
SELECT statement, or specify integers that indicate the position of the columns by which to
sort.
The rightmost ORDER BY, LIMIT, or OFFSET clauses in an EXCEPT query do not need to be
enclosed in parentheses, because the rightmost query specifies that HP Vertica perform the
operation on the results of the EXCEPT operation. Any ORDER BY, LIMIT, or OFFSET clauses
contained in SELECT queries that appear earlier in the EXCEPT query must be enclosed in
parentheses.
SQLReference Manual
SQL Statements
Examples
Consider the following three tables:
Company_A
Id | emp_lname |
dept
| sales
------+-----------+----------------+------1234 | Stephen
| auto parts
| 1000
5678 | Alice
| auto parts
| 2500
9012 | Katherine | floral
|
500
3214 | Smithson | sporting goods | 1500
(4 rows)
Company_B
Id | emp_lname |
dept
| sales
------+-----------+-------------+------4321 | Marvin
| home goods |
250
8765 | Bob
| electronics | 20000
9012 | Katherine | home goods |
500
3214 | Smithson | home goods | 1500
(4 rows)
Company_C
Id | emp_lname |
dept
| sales
------+-----------+----------------+------3214 | Smithson | sporting goods | 1500
5432 | Madison
| sporting goods |
400
7865 | Cleveland | outdoor
| 1500
1234 | Stephen
| floral
| 1000
(4 rows)
The following query returns the IDs and last names of employees that exist in Company_A, but not
in Company_B:
=> SELECT id, emp_lname FROM Company_A
EXCEPT
SQLReference Manual
SQL Statements
The following query sorts the results of the previous query by employee last name:
=> SELECT id, emp_lname FROM Company_A
EXCEPT
SELECT id, emp_lname FROM Company_B
ORDER BY emp_lname ASC;
id | emp_lname
------+----------5678 | Alice
1234 | Stephen
(2 rows)
If you order by the column position, the query returns the same results:
=> SELECT id, emp_lname FROM Company_A
EXCEPT
SELECT id, emp_lname FROM Company_B
ORDER BY 2 ASC;
id | emp_lname
------+----------5678 | Alice
1234 | Stephen
(2 rows)
The following query returns the IDs and last names of employees that exist in Company_A, but not
in Company_B or Company_C:
=> SELECT id, emp_lname FROM Company_A
EXCEPT
SELECT id, emp_lname FROM Company_B
EXCEPT
SELECT id, emp_lname FROM Company_C;
id | emp_lname
------+----------5678 | Alice
(1 row)
SQLReference Manual
SQL Statements
Using the VMart example database, the following query returns information about all Connecticutbased customers who bought items through stores and whose purchases amounted to more than
$500, except for those customers who paid cash:
=> SELECT customer_key, customer_name FROM public.customer_dimension
WHERE customer_key IN (SELECT customer_key FROM store.store_sales_fact
WHERE sales_dollar_amount > 500
EXCEPT
SELECT customer_key FROM store.store_sales_fact
WHERE tender_type = 'Cash')
AND customer_state = 'CT';
customer_key |
customer_name
--------------+---------------------15084 | Doug V. Lampert
21730 | Juanita F. Peterson
24412 | Mary U. Garnett
25840 | Ben Z. Taylor
29940 | Brian B. Dobisz
32225 | Ruth T. McNulty
33127 | Darlene Y. Rodriguez
40000 | Steve L. Lewis
44383 | Amy G. Jones
46495 | Kevin H. Taylor
(10 rows)
See Also
l
SELECT
INTERSECT Clause
UNION Clause
Subqueries
FROM Clause
Specifies one or more source tables from which to retrieve rows.
Syntax
FROM Table-Reference [ , ... ] ... [ subquery ] [AS] name ...
Parameters
table-reference
Is a Table-Primary or a Joined-Table.
SQLReference Manual
SQL Statements
Example
The following example returns all records from the customer_dimension table:
=> SELECT * FROM customer_dimension
Table-Reference
Syntax
Table-Primary | Joined-Table
Parameters
table-primary
Specifies an optionally qualified table name with optional table aliases, column
aliases, and outer joins.
joined-table
Table-Primary
Syntax
{ table-name [ AS ] alias
| ( Joined-Table ) }
Parameters
table-name
alias
column-alias
joined-table
SQLReference Manual
SQL Statements
Joined-Table
Syntax
table-reference join-type table-referenceON Join-Predicate
Parameters
table-reference
join-type
join-predicate
Notes
A query that uses INNER JOIN syntax in the FROM clause produces the same result set as a
query that uses the WHERE clause to state the join-predicate. See Joins in the Analyzing Data
Guide for more information.
GROUP BY Clause
Use the GROUPBY clause with aggregate functions in a SELECT statement to collect data
across multiple records. HP Vertica groups the results into one or more sets of rows that match an
expression.
The GROUP BY clause without aggregates is similar to using SELECT DISTINCT.
ROLLUP is an extension to the GROUPBYclause. ROLLUP performs subtotal aggregations.
Syntax
GROUP BY expression [ ,... ] [ aggregate_expression [,... ])
SQLReference Manual
SQL Statements
Parameters
GROUP BY expression
aggregate_expression
Usage Considerations
l
The expression cannot include aggregate functions. However, you can use the GROUP BY
clause with CUBE, GROUPINGSETS, and ROLLUP to return summary values for each group.
When you create a GROUP BY clause, you must include all non-aggregated columns that
appear in the SELECT list.
You can use the WHEREclause with GROUPBY clause. When you do so, HP Vertica ignores
all rows that do not satisfy the WHEREclause.
SQLReference Manual
SQL Statements
Examples
This example shows how to use the WHEREclause with GROUPBY. In this case, the example
retrieves all employees whose last name begins with S, and ignores all rows that do not meet this
criteria. The GROUP BY clause uses the ILIKE function to retrieve only last names beginning with
S. The SUM aggregate function computes the total vacation days for each group.
=> SELECT employee_last_name, SUM(vacation_days)
FROM employee_dimension
WHERE employee_last_name ILIKE 'S%'
GROUP BY employee_last_name;
employee_last_name | SUM
--------------------+-----Sanchez
| 2892
Smith
| 2672
Stein
| 2660
(3 rows)
The GROUPBYclause in the following example shows groups the results first by vendor region,
and then by the vendor region's biggest deal.
=> SELECT vendor_region, MAX(deal_size) AS "Biggest Deal"
FROM vendor_dimension
GROUP BY vendor_region;
vendor_region | Biggest Deal
---------------+-------------East
|
990889
MidWest
|
699163
NorthWest
|
76101
South
|
854136
SouthWest
|
609807
West
|
964005
(6 rows)
The only difference between the following query and the preceding one is that the HAVING clause
filters the groups to deal sizes greater than $900,000:
=> SELECT vendor_region, MAX(deal_size) as "Biggest Deal"
FROM vendor_dimension
GROUP BY vendor_region
HAVING MAX(deal_size) > 900000;
vendor_region | Biggest Deal
---------------+-------------East
|
990889
West
|
964005
(2 rows)
The GROUP BY clause without aggregates is similar to using SELECT DISTINCT. For example,
the following two queries return the same results:
SQLReference Manual
SQL Statements
See Also
l
CUBE Aggregate
GROUP_ID
GROUPING
GROUPING_ID
ROLLUP Aggregate
Automatically performs subtotal aggregations as an extension to the GROUPBYclause.
ROLLUPperforms these aggregations across multiple dimensions, at different levels, within a
single SQL query. You can use the ROLLUP clause with the grouping functions, GROUPING,
GROUP_ID, and GROUPING_ID.
l
GROUP BY ROLLUP does not sort the results. To sort data, use the ORDER BY Clause. The
ORDERBYclause must come after the GROUP BY clause.
If you enclose two or more columns in parentheses, GROUPBY treats them as a single entity.
Syntax
GROUP BY group_expression [, group_expression, ...]
SQLReference Manual
SQL Statements
Parameters
expression
multi-level_aggregate_expression
group_expression
Levels of Aggregation
If n is the number of grouping columns, ROLLUP creates n+1 levels of subtotals (including a grand
total). Because ROLLUP removes the right-most column at each step, specify column order
carefully.
Suppose that ROLLUP(A, B, C) creates four groups:
l
(A, B, C)
(A, B)
(A)
()
Because ROLLUP removes the right-most column at each step, there are no groups for (A, C) and
(B, C).
l
If you enclose two or more columns in parentheses, GROUPBY treats them as a single entity.
For example:
n
ROLLUP(A, B, C) creates four groups: (A, B, C), (A, B), (A), ().
ROLLUP((A, B), C) treats (A, B) as a single entity and only creates three groups: (A, B, C),
(A, B), ()
SQLReference Manual
SQL Statements
For the expenses table, ROLLUP computes the subtotals in each category from 20052007: $99.96
for books and $449.96 for electricity, with a grand total of $549.92. Use the ORDERBY clause to
sort the results:
SQLReference Manual
SQL Statements
ORDER BY 1, 2, GROUPING_ID();
Category
| Year | SUM
-------------+------+-------Books
|
| 99.96
Electricity |
| 449.96
|
| 549.92
The next example rolls up on (Category, Year), but not on the full results. The GROUPING_
IDfunction specifies to aggregate less than three levels:
=> SELECT Category, Year, SUM(Amount) FROM expenses
GROUP BY ROLLUP(Category,Year) HAVING GROUPING_ID(Category,Year)<3
ORDER BY 1, 2, GROUPING_ID();
Category
| Year | SUM
-------------+------+-------Books
| 2005 | 39.98
Books
| 2007 | 29.99
Books
| 2008 | 29.99
Books
|
| 99.96
Electricity | 2005 | 109.99
Electricity | 2006 | 109.99
Electricity | 2007 | 229.98
Electricity |
| 449.96
See Also
l
CUBE Aggregate
GROUPING
GROUP_ID
GROUPING_ID
GROUP BY Clause
GROUP_ID
Uniquely identifies duplicate sets for GROUP BY queries that return duplicate grouping sets. This
function returns one or more integers, starting with zero (0), as identifiers.
For the number of duplicates n for a particular grouping, GROUP_ID returns a range of sequential
numbers, 0 to n1. For the first each unique group it encounters, GROUP_ID returns the value 0. If
SQLReference Manual
SQL Statements
GROUP_IDfinds the same grouping again, the function returns 1, then returns 2 for the next found
grouping, and so on.
Note: GROUP_IDis applicable only in SELECT statements that contain a multi-level GROUP
BY extension: CUBE, GROUPINGSETS, and ROLLUP.
Behavior Type
Immutable
Syntax
GROUP_ID ()
Examples
This example shows how GROUP_ID creates unique identifiers when a query produces duplicate
groupings. For an expenses table, the following query groups the results by category of expense
and year and rolls up the sum for those two columns. The results have duplicate groupings for
category and NULL. The first grouping has a GROUP_ID of 0, and the second grouping has a
GROUP_IDof 1.
=> SELECT Category, Year, SUM(Amount), GROUPING_ID(Category, Year),
GROUP_ID() FROM expenses GROUP BY Category, ROLLUP(Category,Year)
ORDER BY Category, Year, GROUPING_ID();
Category
| Year | SUM
| GROUPING_ID | GROUP_ID
-------------+------+--------+-------------+---------Books
| 2005 | 39.98 |
0 |
0
Books
| 2007 | 29.99 |
0 |
0
Books
| 2008 | 29.99 |
0 |
0
Books
|
| 99.96 |
1 |
0
Books
|
| 99.96 |
1 |
1
Electricity | 2005 | 109.99 |
0 |
0
Electricity | 2006 | 109.99 |
0 |
0
Electricity | 2007 | 229.98 |
0 |
0
Electricity |
| 449.96 |
1 |
1
Electricity |
| 449.96 |
1 |
0
See Also
l
CUBE Aggregate
GROUPING
GROUPING_ID
SQLReference Manual
SQL Statements
GROUP BY Clause
ROLLUP Aggregate
GROUPING
Disambiguates the use of NULL values when GROUP BY queries with multi-level aggregates
generate NULL values to identify subtotals in grouping columns. Such NULL values from the
original data can also occur in rows. GROUPING returns 1, if the value of expression is:
l
Note: You can use GROUPING only in SELECT statements that contain a GROUP BY
aggregate: CUBE, GROUPINGSETS, or ROLLUP.
Behavior Type
Immutable
Syntax
GROUPING (expression)
Parameters
expression
Examples
This example shows a query that uses the GROUPING function. This query takes one of the
GROUP BY expressions as an argument. For each row, the function returns either:
l
SQLReference Manual
SQL Statements
The 1 in the GROUPING(Year) column for electricity and books indicates that these values are
subtotals. The right-most column values for both GROUPING(Category) and GROUPING(Year)
are 1. This value indicates that neither column contributed to the GROUP BY. The final row
represents the total sales.
=> SELECT Category, Year, SUM(Amount),
GROUPING(Category), GROUPING(Year) FROM expenses
GROUP BY ROLLUP(Category, Year) ORDER BY Category, Year, GROUPING_ID();
Category | Year | SUM
| GROUPING | GROUPING
-------------+------+--------+----------+---------Books
| 2005 | 39.98 |
0 |
0
Books
| 2007 | 29.99 |
0 |
0
Books
| 2008 | 29.99 |
0 |
0
Books
|
| 99.96 |
0 |
1
Electricity | 2005 | 109.99 |
0 |
0
Electricity | 2006 | 109.99 |
0 |
0
Electricity | 2007 | 229.98 |
0 |
0
Electricity |
| 449.96 |
0 |
1
|
| 549.92 |
1 |
1
See Also
l
CUBE Aggregate
GROUP_ID
GROUPING_ID
GROUP BY Clause
ROLLUP Aggregate
GROUPING_ID
Concatenates the set of Boolean values generated by the GROUPING function into a bit vector.
The GROUPING_ID function treats the bit vector as a binary number and returns it as a base-10
value that identifies the grouping set combination.
By using GROUPING_ID you avoid the need for multiple, individual GROUPING functions.
GROUPING_ID simplifies row-filtering conditions, because the rows of interest are identified using
a single return from GROUPING_ID = n. Use GROUPING_ID to identify grouping combinations.
SQLReference Manual
SQL Statements
Behavior Type
Immutable
Syntax
GROUPING_ID (expression[, expression]...) | GROUPING_ID()
Parameters
expression
Examples
This example shows how calling GROUPING_ID without an expression returns the GROUPING
bit vector associated with a full set of multi-level aggregate expressions. The GROUPING_ID
value is comparable to GROUPING_ID(a,b) because GROUPING_ID()includes all columns in the
GROUPBYROLLUP:
=> SELECT a,b,COUNT(*), GROUPING_ID() FROM T GROUP BY ROLLUP(a,b);
In the following query, the GROUPING(Category) and GROUPING(Year) columns have three
combinations:
l
0,0
0,1
1,1
=> SELECT Category, Year, SUM(Amount),
GROUPING(Category), GROUPING(Year) FROM expenses
GROUP BY ROLLUP(Category, Year) ORDER BY Category, Year, GROUPING_ID();
Category
| Year | SUM
| GROUPING | GROUPING
-------------+------+--------+----------+---------Books
| 2005 | 39.98 |
0 |
0
Books
| 2007 | 29.99 |
0 |
0
SQLReference Manual
SQL Statements
Books
Books
Electricity
Electricity
Electricity
Electricity
|
|
|
|
|
|
|
2008 |
|
2005 |
2006 |
2007 |
|
|
29.99
99.96
109.99
109.99
229.98
449.96
549.92
|
|
|
|
|
|
|
0
0
0
0
0
0
1
|
|
|
|
|
|
|
0
1
0
0
0
1
1
Decimal Equivalents
00
01
11
Category, Year
The following query returns the single number for each GROUP BY level that appears in the gr_id
column:
=> SELECT Category, Year, SUM(Amount),
GROUPING(Category),GROUPING(Year),GROUPING_ID(Category,Year) AS gr_id
FROM expenses GROUP BY ROLLUP(Category, Year);
Category
| Year | SUM
| GROUPING | GROUPING | gr_id
-------------+------+--------+----------+----------+------Books
| 2008 | 29.99 |
0 |
0 |
0
Books
| 2005 | 39.98 |
0 |
0 |
0
Electricity | 2007 | 229.98 |
0 |
0 |
0
Books
| 2007 | 29.99 |
0 |
0 |
0
Electricity | 2005 | 109.99 |
0 |
0 |
0
Electricity |
| 449.96 |
0 |
1 |
1
|
| 549.92 |
1 |
1 |
3
Electricity | 2006 | 109.99 |
0 |
0 |
0
Books
|
| 99.96 |
0 |
1 |
1
The gr_id value determines the GROUP BY level for each row:
GROUPBYLevel
GROUPBYRow Level
Total sum
Category
Category, year
You can also use the DECODE function to give the values more meaning by comparing each
search value individually:
SQLReference Manual
SQL Statements
See Also
l
CUBE Aggregate
GROUP_ID
GROUPING
GROUP BY Clause
ROLLUP Aggregate
CUBE Aggregate
Automatically performs all possible aggregations of the specified columns, as an extension to the
GROUP BY clause.
You can use with the CUBE clause with the grouping functions GROUPING, GROUP_ID, and
GROUPING_ID.
l
GROUP BY CUBE does not order data. If you want to sort data, use the ORDER BY Clause.
The ORDERBYclause must come after the GROUP BY clause.
SQLReference Manual
SQL Statements
Syntax
GROUP BY group_expression [, group_expression, ...]
Parameters
expression
multi-level_aggregate_expression
group_expression
Levels of CUBEAggregation
If n is the number of grouping columns, CUBEcreates 2n levels of aggregations. For example:
CUBE (A, B, C) creates all possible permutations, resulting in eight groups:
l
(A, B, C)
(A, B)
(A, C)
(B, C)
(A)
(B)
(C)
()
If you increase the number of CUBEcolumns, the number of CUBE groupings increases
exponentially. TheCUBEquery may be resource intensive and produce combinations that are not
SQLReference Manual
SQL Statements
of interest. In that case, consider using the GROUPING SETS Aggregate , which allows you to
choose specific groupings.
To aggregate the data by both Category and Year using the CUBEaggregate:
=> SELECT Category, Year, SUM(Amount) FROM expenses
GROUP BY CUBE(Category, Year) ORDER BY 1, 2, GROUPING_ID();
Category
| Year | SUM
-------------+------+-------Books
| 2005 | 39.98
Books
| 2007 | 29.99
Books
| 2008 | 29.99
Books
|
| 99.96
Electricity | 2005 | 109.99
Electricity | 2006 | 109.99
Electricity | 2007 | 229.98
Electricity |
| 449.96
| 2005 | 149.97
| 2006 | 109.99
| 2007 | 259.97
| 2008 | 29.99
|
| 549.92
The results include subtotals for each category and year, and a grand total ($549.92).
SQLReference Manual
SQL Statements
Electricity |
|
| 449.96
| 549.92
The next query returns only the aggregations for the two categories for each year.
TheGROUPINGIDfunction specifies to omit the grand total ($549.92):
=> SELECT Category, Year, SUM (Amount) FROM expenses
GROUP BY CUBE(Category,Year) HAVING GROUPING_ID(Category,Year)<2
ORDER BY 1, 2, GROUPING_ID();
Category
| Year | SUM
------------+------+-------Books
| 2005 | 39.98
Books
| 2007 | 29.99
Books
| 2008 | 29.99
Books
|
| 99.96
Electrical | 2005 | 109.99
Electrical | 2006 | 109.99
Electrical | 2007 | 229.98
Electrical |
| 449.96
See Also
l
GROUP BY Clause
GROUP_ID
GROUPING
GROUPING_ID
You can use the GROUPING SETS clause with the GROUPING, GROUP_ID, and
GROUPING_ID functions.
To sort data, use the ORDER BY Clause. The ORDERBYclause must come after the GROUP
BY clause.
SQLReference Manual
SQL Statements
Syntax
GROUP BY group_expression [, group_expression, ...]
Parameters
expression
multi-level_aggregate_expression
group_expression
Defining theGroupings
GROUPING SETS allows you to specify exactly which groupings you want in the results. You can
also concatenate the groupings as follows:
The following example clauses result in the groupings shown.
The Clause...
(A, B, C, D)
SQLReference Manual
SQL Statements
The Clause...
Example:Selecting Groupings
This example shows how to select only those groupings you want. Suppose you want to aggregate
on columns only, and you do not need the grand total. The first query omits the total. In the second
query, you add () to the GROUPINGSETSlist to get the total. Use the ORDERBYclause to sort
the results by grouping:
=> SELECT Category, Year, SUM(Amount) FROM expenses
GROUP BY GROUPING SETS((Category, Year), (Year))
ORDER BY 1, 2, GROUPING_ID();
Category | Year | SUM
------------+------+-------Books
| 2005 | 39.98
Books
| 2007 | 29.99
Books
| 2008 | 29.99
Electrical | 2005 | 109.99
Electrical | 2006 | 109.99
Electrical | 2007 | 229.98
| 2005 | 149.97
| 2006 | 109.99
| 2007 | 259.97
| 2008 | 29.99
=> SELECT Category, Year, SUM(Amount) FROM expenses
GROUP BY GROUPING SETS((Category, Year), (Year), ())
ORDER BY 1, 2, GROUPING_ID();
Category | Year | SUM
------------+------+-------Books
| 2005 | 39.98
Books
| 2007 | 29.99
Books
| 2008 | 29.99
Electrical | 2005 | 109.99
Electrical | 2006 | 109.99
Electrical | 2007 | 229.98
| 2005 | 149.97
| 2006 | 109.99
| 2007 | 259.97
SQLReference Manual
SQL Statements
| 2008 | 29.99
|
| 549.92
See Also
l
CUBE Aggregate
GROUPING
GROUP_ID
GROUPING_ID
GROUP BY Clause
ROLLUP Aggregate
HAVING Clause
Restricts the results of a GROUP BY Clause.
Syntax
HAVING condition [, ...]
Parameters
condition
Notes
l
The HAVING clause was added to the SQL standard because you cannot use WHERE with
Aggregate Functions.
SQLReference Manual
SQL Statements
Example
The following example returns the employees with salaries greater than $50,000:
=> SELECT employee_last_name, MAX(annual_salary) as "highest_salary"
FROM employee_dimension
GROUP BY employee_last_name
HAVING MAX(annual_salary) > 50000;
employee_last_name | highest_salary
--------------------+---------------Bauer
|
920149
Brown
|
569079
Campbell
|
649998
Carcetti
|
195175
Dobisz
|
840902
Farmer
|
804890
Fortin
|
481490
Garcia
|
811231
Garnett
|
963104
Gauthier
|
927335
(10 rows)
INTERSECT Clause
Calculates the intersection of the results of two or more SELECT queries. INTERSECT returns
distinct values by both the query on the left and right sides of the INTERSECT operand.
Syntax
select
... INTERSECT select
... [ INTERSECT select ]...
... [ ORDER BY { column-name | ordinal-number }
[ ASC | DESC ]
... [ , ... ] ]
... [ LIMIT { integer | ALL } ]
... [ OFFSET integer ]
Notes
l
Use the INTERSECT clause to return all elements that are common to the results of all the
SELECT queries. The INTERSECT query operates on the results of two or more SELECT
queries. INTERSECT returns only the rows that are returned by all the specified queries.
The results of each SELECT query must be union compatible; they must return the same
SQLReference Manual
SQL Statements
number of columns, and the corresponding columns must have compatible data types. For
example, you cannot use the INTERSECT clause on a column of type INTEGER and a column
of type VARCHAR. If the SELECT queries do not meet these criteria, HP Vertica returns an
error.
Note: The Data Type Coercion Chart lists the data types that can be cast to other data
types. If one data type can be cast to the other, those two data types are compatible.
Order the results of an INTERSECT operation by using an ORDER BY clause. In the ORDER
BY list, specify the column names from the leftmost SELECT statement or specify integers that
indicate the position of the columns by which to sort.
The rightmost ORDER BY, LIMIT, or OFFSET clauses in an INTERSECT query do not need to
be enclosed in parentheses because the rightmost query specifies that HP Vertica perform the
operation on the results of the INTERSECT operation. Any ORDER BY, LIMIT, or OFFSET
clauses contained in SELECT queries that appear earlier in the INTERSECT query must be
enclosed in parentheses.
Examples
Consider the following three tables:
Company_A
id
emp_lname
dept
sales
------+------------+----------------+------1234 | Stephen
| auto parts
| 1000
5678 | Alice
| auto parts
| 2500
9012 | Katherine | floral
| 500
SQLReference Manual
SQL Statements
3214
| Smithson
Company_B
id
emp_lname
dept
sales
------+------------+-------------+------4321 | Marvin
| home goods |
250
9012 | Katherine | home goods |
500
8765 | Bob
| electronics | 20000
3214 | Smithson
| home goods | 1500
Company_C
id | emp_lname |
dept
| sales
------+-----------+----------------+------3214 | Smithson | sporting goods | 1500
5432 | Madison
| sporting goods |
400
7865 | Cleveland | outdoor
| 1500
1234 | Stephen
| floral
| 1000
The following query returns the IDs and last names of employees that exist in both Company_A and
Company_B:
=> SELECT id, emp_lname FROM Company_A
INTERSECT
SELECT id, emp_lname FROM Company_B;
id
| emp_lname
------+----------3214 | Smithson
9012 | Katherine
(2 rows)
The following query returns the same two employees in descending order of sales:
=> SELECT id, emp_lname, sales FROM Company_A
INTERSECT
SELECT id, emp_lname, sales FROM Company_B
ORDER BY sales DESC;
id | emp_lname | sales
------+-----------+------3214 | Smithson | 1500
9012 | Katherine |
500
(2 rows)
You can also use the integer that represents the position of the sales column (3) to return the same
result:
=> SELECT id, emp_lname, sales FROM Company_A
INTERSECT
SQLReference Manual
SQL Statements
The following query returns the employee who works for both companies whose sales in Company_
B are greater than 1000:
=> SELECT id, emp_lname, sales FROM Company_A
INTERSECT
(SELECT id, emp_lname, sales FROM company_B WHERE sales > 1000)
ORDER BY sales DESC;
id | emp_lname | sales
------+-----------+------3214 | Smithson | 1500
(1 row)
In the following query returns the ID and last name of the employee who works for all three
companies:
=> SELECT id, emp_lname FROM Company_A
INTERSECT
SELECT id, emp_lname FROM Company_B
INTERSECT
SELECT id, emp_lname FROM Company_C;
id | emp_lname
------+----------3214 | Smithson
(1 row)
The following query shows the results of a mismatched data types; these two queries are not union
compatible:
=> SELECT id, emp_lname FROM Company_A
INTERSECT
SELECT emp_lname, id FROM Company_B;
ERROR 3429: For 'INTERSECT', types int and varchar are inconsistent
DETAIL: Columns: id and emp_lname
Using the VMart example database, the following query returns information about all Connecticutbased customers who bought items online and whose purchase amounts were between $400 and
$500:
=> SELECT customer_key, customer_name from public.customer_dimension
WHERE customer_key IN (SELECT customer_key
FROM online_sales.online_sales_fact
SQLReference Manual
SQL Statements
See Also
l
SELECT
EXCEPT Clause
UNION Clause
Subqueries
INTO Clause
Creates a new table from the results of a query and fills it with data from the query.
Syntax
INTO [ { GLOBAL | LOCAL } { TEMPORARY | TEMP } ]
... [ TABLE ] table-name
SQLReference Manual
SQL Statements
Parameters
GLOBAL
LOCAL
TABLE
table-name
DELETE marks a temporary table for transactionscoped data. HP Vertica truncates the table (delete
all its rows) after each commit. DELETE ROWS is
the default.
PRESERVE marks a temporary table for sessionscoped data, which is preserved beyond the lifetime
of a single transaction. HP Vertica truncates the table
(delete all its rows) when you terminate a session.
Examples
The following statement creates a table called newtable and fills it with the data from customer_
dimension:
=> SELECT * INTO newtable FROM customer_dimension;
The following statement creates a temporary table called newtable and fills it with the data from
customer_dimension:
=> SELECT * INTO temp TABLE newtable FROM customer_dimension;
The following example creates a local temporary table and inserts the contents from mytable into it:
SQLReference Manual
SQL Statements
See Also
l
LIMIT Clause
Specifies the maximum number of result set rows to return.
Syntax
LIMIT { rows | ALL }
Parameters
rows
ALL
Considerations
l
When both LIMIT and OFFSET are used, HP Vertica skips the specified number of rows before
it starts to count the rows to be returned.
You cannot use the LIMIT clause on unsorted data when you update or merge tables that
participate in pre-join projections.
You can use LIMIT without an ORDER BY Clause that includes all columns in the select list,
but the query could produce nondeterministic results.
Nondeterministic: Omits the ORDER BY
ORDER BY clause:
customer_dimension table:
SQLReference Manual
SQL Statements
Examples
The following examples illustrate the LIMIT clause queries that HP Vertica supports:
=>
=>
=>
=>
=>
=>
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
*
*
*
*
*
*
FROM
FROM
FROM
FROM
FROM
FROM
MATCH Clause
A SQL extension that lets you screen large amounts of historical data in search of event patterns,
the MATCH clause provides subclasses for analytic partitioning and ordering and matches rows
from the result table based on a pattern you define.
You specify a pattern as a regular expression, which is composed of event types defined in the
DEFINE subclause, where each event corresponds to a row in the input table. Then you can search
for the pattern within a sequence of input events. Pattern matching returns the contiguous
sequence of rows that conforms to PATTERN subclause. For example, pattern P (A B* C) consist
of three event types: A, B, and C. When HP Vertica finds a match in the input table, the associated
pattern instance must be an event of type A followed by 0 or more events of type B, and an event of
type C.
Pattern matching is particularly useful for clickstream analysis where you might want to identify
users' actions based on their Web browsing behavior (page clicks). A typical online clickstream
funnel is:
Company home page -> product home page -> search -> results -> purchase online
Using the above clickstream funnel, you can search for a match on the user's sequence of web
clicks and identify that the user:
SQLReference Manual
SQL Statements
Ran a search
Made a purchase
For examples that use this clickstream model, see Event Series Pattern Matching in the Analyzing
Data Guide.
Syntax
MATCH ( [ PARTITION BY table_column ] ORDER BY table_column
... DEFINE event_name AS boolean_expr [, ...]
... PATTERN pattern_name AS ( regexp )
... [ ROWS MATCH { ALL EVENTS | FIRST EVENT } ] )
Parameters
PARTITION BY
[Optional] Defines the window data scope in which the pattern, defined in
the PATTERN subclause, is matched. The partition clause partitions the
data by matched patterns defined in the PATTERN subclause. For each
partition, data is sorted by the ORDER BY clause. If the partition clause
is omitted, the entire data set is considered a single partition.
ORDER BY
Defines the window data scope in which the pattern, defined in the
PATTERN subclause, is matched. For each partition, the order clause
specifies how the input data is ordered for pattern matching.
Note: The ORDER BY clause is mandatory.
SQLReference Manual
SQL Statements
DEFINE
Defines the boolean expressions that make up the event types in the
regular expressions. For example:
DEFINE
Entry
Onsite
AS RefURL
Is the name of the event to evaluate for each row; for example, Entry,
Onsite, Purchase.
Note: Event names are case insensitive and follow the same
naming conventions as those used for tables and columns.
boolean_expr
PATTERN pattern_name
Is the name of the pattern, which you define in the PATTERN subclause;
for example, P is the pattern name defined below:
PATTERN P AS (...)
SQLReference Manual
SQL Statements
regexp
Is the pattern that is composed of the event types defined in the DEFINE
subclause and which returns the contiguous sequence of rows that
conforms to the PATTERN subclause.
*
*?
+?
Match 0 or 1 time
??
*+
++
?+
[Optional] Defines how to resolve more than one event evaluating to true
for a single row.
l
For ROWS MATCH FIRST EVENT, if more than one event evaluates
to true for a single row, HP Vertica chooses the event defined first in
the SQL statement to be the event it uses for the row.
SQLReference Manual
SQL Statements
The semantic evaluating ordering of the SQL clauses is: FROM -> WHERE -> PATTERN
MATCH -> SELECT.
Data is partitioned as specified in the PARTITION BY clause. If the partition clause is omitted,
the entire data set is considered a single partition.
For each partition, the order clause specifies how the input data is ordered for pattern matching.
Events are evaluated for each row. A row could have 0, 1, or N events evaluate to true. If more
than one event evaluates to true for the same row, HP Vertica returns a run-time error unless you
specify ROWS MATCH FIRST EVENT. If you specify ROWS MATCH FIRST EVENT and
more than one event evaluates to TRUE for a single row, HP Vertica chooses the event that
was defined first in the SQL statement to be the event it uses for the row.
HP Vertica performs pattern matching by finding the contiguous sequence of rows that conforms
to the pattern defined in the PATTERN subclause.
For each match, HP Vertica outputs the rows that contribute to the match. Rows not part of the
match (do not satisfy one or more predicates) are not output.
l
HP Vertica reports only non-overlapping matches. If an overlap occurs, HP Vertica chooses the
first match found in the input stream. After finding the match, HP Vertica looks for the next
match, starting at the end of the previous match.
HP Vertica reports the longest possible match, not a subset of a match. For example, consider
pattern: A*B with input: AAAB. Because A uses the greedy regular expression quantifier (*), HP
Vertica reports all A inputs (AAAB), not AAB, AB, or B.
DISTINCT and GROUP BY/HAVING clauses are not allowed in pattern match queries.
SQLReference Manual
SQL Statements
You cannot use the same pattern name to define a different event; for example, the following is
not allowed for X:
DEFINE
X AS c1 <
X AS c1 >= 3
Used with MATCH clause, HP Vertica Pattern Matching Functions provide additional data about
the patterns it finds. For example, you can use the functions to return values representing the
name of the event that matched the input row, the sequential number of the match, or a partitionwide unique identifier for the instance of the pattern that matched.
Examples
For examples, see Event Series Pattern Matching in the Analyzing Data Guide.
See Also
l
EVENT_NAME
MATCH_ID
PATTERN_ID
MINUS Clause
MINUS is an alias for EXCEPT.
OFFSET Clause
Omits a specified number of rows from the beginning of the result set.
Syntax
OFFSET rows
Parameters
rows
SQLReference Manual
SQL Statements
Notes
l
When both LIMIT and OFFSET are specified, specified number of rows are skipped before
starting to count the rows to be returned.
When using OFFSET, use an ORDER BY Clause. Otherwise the query returns an undefined
subset of the result set.
Example
The following example is similar to the example used in the LIMIT Clause. If you want to see just
records 610, however, use the OFFSET clause to skip over the first five cities:
=> SELECT customer_city
FROM customer_dimension
WHERE customer_name = 'Metamedia'
ORDER BY customer_city
OFFSET 5;
customer_city
-----------------El Monte
Fontana
Hartford
Joliet
Peoria
Rancho Cucamonga
Ventura
Waco
Wichita Falls
(9 rows)
SQLReference Manual
SQL Statements
ORDER BY Clause
Sorts a query result set on one or more columns.
Syntax
ORDER BY expression [ ASC | DESC ] [, ...]
Parameters
expression
Can be:
l
The name or ordinal number of a SELECT list item. You cannot use an integer
value if you use the ORDERBY clause inside OVER().
An arbitrary expression formed from columns that do not appear in the SELECT
list
A CASE expression
Notes
l
The ordinal number refers to the position of the result column, counting from the left beginning at
one. This makes it possible to order by a column that does not have a unique name. (You can
assign a name to a result column using the AS clause.)
While the user's current locale and collation sequence are used to compare strings and
determine the results of the ORDER BY clause of a query, data in HP Vertica projections is
always stored sorted by the ASCII (binary) collating sequence.
For INTEGER, INT, and DATE/TIME data types, NULL appears first (smallest) in ascending
order.
For FLOAT, BOOLEAN, CHAR, and VARCHAR, NULL appears last (largest) in ascending
order.
Example
The follow example returns all the city and deal size for customer Metamedia, sorted by deal size in
descending order.
SQLReference Manual
SQL Statements
TIMESERIES Clause
Provides gap-filling and interpolation (GFI) computation, an important component of time series
analytics computation. See Using Time Series Analytics in the Analyzing Data Guide for details
and examples.
Syntax
TIMESERIES slice_time AS 'length_and_time_unit_expression' OVER (
... [ window_partition_clause [ , ... ] ]
... ORDER BY time_expression )
... [ ORDER BY table_column [ , ... ] ]
Parameters
slice_time
'length_and_time_unit_expression'
SQLReference Manual
SQL Statements
OVER()
PARTITION BY
expression
ORDER BY
time_expression
Notes
If the window_partition_clause is not specified in TIMESERIES OVER(), for each defined time
slice, exactly one output record is produced; otherwise, one output record is produced per partition
per time slice. Interpolation is computed there.
Given a query block that contains a TIMESERIES clause, the following are the semantic phases of
execution (after evaluating the FROM and the optional WHERE clauses):
1. Compute time_expression.
2. Perform the same computation as the TIME_SLICE() function on each input record based on
the result of time_expression and 'length_and_time_unit_expression'.
a. Perform gap filling to generate time slices missing from the input.
b. Name the result of this computation as slice_time, which represents the generated time
series column (alias) after gap filling.
SQLReference Manual
SQL Statements
TIMESERIES only supports the DAY TO SECOND Interval-Qualifier (does not allow YEAR TO
MONTH).
Unlike TIME_SLICE, the time slice length and time unit expressed in length_and_time_unit_
expr must be constants so gaps in the time slices are well-defined.
TIME_SLICE can return the start or end time of a time slice, depending on the value of its fourth
input parameter (start_or_end). TIMESERIES, on the other hand, always returns the start time
of each time slice. To output the end time of each time slice, you can write a SELECT statement
like the following:
SELECT slice_time + <slice_length>;
Restrictions
l
When the TIMESERIES clause occurs in a SQL query block, only SELECT, FROM, WHERE,
and ORDER BY clauses can be used in that same query block. GROUP BY and HAVING
clauses are not allowed.
If a GROUP BY operation is needed before or after gap-filling and interpolation (GFI), use a
subquery and place the GROUP BY In the outer query. For example:
=> SELECT symbol, AVG(first_bid) as avg_bid FROM (
SELECT symbol, slice_time, TS_FIRST_VALUE(bid1) AS first_bid
FROM Tickstore
WHERE symbol IN ('MSFT', 'IBM')
TIMESERIES slice_time AS '5 seconds' OVER (PARTITION BY symbol ORDER BY ts)
) AS resultOfGFI
GROUP BY symbol;
When the TIMESERIES clause is present in the SQL query block, only time series aggregate
functions (such as TS_FIRST_VALUE and TS_LAST_VALUE), the slice_time column,
PARTITION BY expressions, and TIME_SLICE are allowed in the SELECT list. For example,
SQLReference Manual
SQL Statements
the following two queries would return a syntax error because bid1 was not a PARTITION BY or
GROUP BY column:
=> SELECT bid, symbol, TS_FIRST_VALUE(bid) FROM Tickstore
TIMESERIES slice_time AS '5 seconds' OVER (PARTITION BY symbol ORDER BY ts);
ERROR: column "Tickstore.bid" must appear in the PARTITION BY list of Timeseries
clause or be used in a Timeseries Output function
=> SELECT bid, symbol, AVG(bid) FROM Tickstore
GROUP BY symbol;
ERROR: column "Tickstore.bid" must appear in the GROUP BY clause or be used in an
aggregate function
Examples
For examples, see Gap Filling and Interpolation (GFI) in the Analyzing Data Guide.
See Also
l
TIME_SLICE
TS_FIRST_VALUE
TS_LAST_VALUE
UNION Clause
Combines the results of two or more SELECT statements.
The results of a UNION query contains only distinct rows. If you write the ALLkeyword, the query
retains all duplicate rows. If you do not care about eliminating duplicate rows, use UNION ALL for
best performance.
Syntax
SELECT ... UNION { ALL | DISTINCT } select
... [ UNION { ALL | DISTINCT } select ]...
... [ ORDER BY { column-name | ordinal-number }
... [ ASC | DESC ] [ , ... ] ]
... [ LIMIT { integer | ALL } ]
... [ OFFSET integer ]
SQLReference Manual
SQL Statements
Notes
l
The UNION operation combines the results of several SELECT statements into a single result.
All rows in a UNION result must exist in the results of at least one of the SELECT statements.
The results of each SELECT statement must return the same number of columns, and the
corresponding columns must have compatible data types. For example, you cannot use the
UNION clause on a column of type INTEGER and a column of type VARCHAR. If the
UNIONtypes do not meet these criteria, HP Vertica returns an error.
Note: The Data Type Coercion Chart lists the data types that can be cast to other data
types. If one data type can be cast to the other, those two data types are compatible.
You can use UNION [ALL] in FROM, WHERE, and HAVING clauses.
Order the results of an UNION operation with an ORDER BY clause. In the ORDER BY list,
specify the column names from the leftmost SELECT statement, or specify integers that
indicate the position of the columns by which to sort.
The rightmost ORDER BY, LIMIT, or OFFSET clauses in a UNION query do not need to be
enclosed in parentheses because the rightmost query specifies that HP Vertica perform the
operation on the results of the UNION operation. Any ORDER BY, LIMIT, or OFFSET clauses
contained in SELECT queries that appear earlier in the UNION query must be enclosed in
parentheses.
Examples
Consider the following two tables:
Company_A
Id
emp_lname
dept
sales
------+------------+-------------+-------
SQLReference Manual
SQL Statements
1234
5678
9012
| Stephen
| Alice
| Katherine
| auto parts
| auto parts
| floral
| 1000
| 2500
| 500
Company_B
Id
emp_lname
dept
sales
------+------------+-------------+------4321 | Marvin
| home goods |
250
9012 | Katherine | home goods |
500
8765 | Bob
| electronics | 20000
The following query lists all distinct IDs and last names of employees; Katherine works for both
companies, so she appears once in the results only. Distinct results is the default behavior for a
UNIONoperation. If you omit the DISTINCT keyword, the query returns the same results:
=> SELECT id, emp_lname FROM Company_A
UNION DISTINCT
SELECT id, emp_lname FROM Company_B;
id | emp_lname
------+----------1234 | Stephen
4321 | Marvin
5678 | Alice
8765 | Bob
9012 | Katherine
(5 rows)
The following query lists all IDs and surnames of employees. Katherine works for both companies
A and B, so her records appear in the results twice:
=> SELECT id, emp_lname FROM Company_A
UNION ALL
SELECT id, emp_lname FROM Company_B;
id | emp_lname
------+----------1234 | Stephen
5678 | Alice
9012 | Katherine
4321 | Marvin
9012 | Katherine
8765 | Bob
(6 rows)
The next example returns the top two top performing salespeople in each company. The query
orders the full results in descending order of sales:
=> (SELECT id, emp_lname, sales FROM Company_A
ORDER BY sales DESC LIMIT 2)
UNION ALL
SQLReference Manual
SQL Statements
The following query returns all employee orders by sales. The rightmost clause (ORDER BY) is
applied to the entire result, listing the sales in ascending order:
=> SELECT id, emp_lname, sales FROM Company_A
UNION
SELECT id, emp_lname, sales FROM Company_B
ORDER BY sales;
id | emp_lname | sales
------+-----------+------4321 | Marvin
|
250
9012 | Katherine |
500
1234 | Stephen
| 1000
5678 | Alice
| 2500
8765 | Bob
| 20000
(5 rows)
To calculate the sum of the sales for each company grouped by department, use this query:
=> (SELECT 'Company A' as company, dept, SUM(sales) FROM Company_A
GROUP BY dept)
UNION
(SELECT 'Company B' as company, dept, SUM(sales) FROM Company_B
GROUP BY dept)
ORDER BY 1;
company
|
dept
| sum
-----------+-------------+------Company A | auto parts | 3500
Company A | floral
|
500
Company B | electronics | 20000
Company B | home goods |
750
(4 rows)
SQLReference Manual
SQL Statements
Using the VMart example database, the following query returns information about all Connecticutbased customers who bought items through either stores or online sales channels and whose
purchases totaled more than $500:
=> SELECT DISTINCT customer_key, customer_name FROM public.customer_dimension
customer_key IN (SELECT customer_key FROM store.store_sales_fact
WHERE sales_dollar_amount > 500
UNION ALL
SELECT customer_key FROM online_sales.online_sales_fact
WHERE sales_dollar_amount > 500)
AND customer_state = 'CT';
customer_key |
customer_name
--------------+-----------------------955 | Darlene N. Vu
48916 | Tanya H. Wilson
43123 | Luigi I. Fortin
33780 | Ben T. Nielson
24827 | Luigi . Kramer
21631 | Jack R. Perkins
31493 | Matt E. Miller
12438 | Samantha Q. Campbell
7021 | Luigi T. Dobisz
5229 | Julie V. Garcia
1971 | Betty V. Dobisz
...
WHERE
See Also
l
SELECT
EXCEPT Clause
INTERSECT Clause
Subqueries
WHERE Clause
Eliminates rows from the result table that do not satisfy one or more predicates.
Syntax
WHERE boolean-expression
[ subquery ] ...
Parameters
boolean-expression
Is an expression that returns true or false. Only rows for which the
expression is true become part of the result set.
SQLReference Manual
SQL Statements
The boolean-expression can include Boolean Operators and the following elements:
l
BETWEEN-predicate
Boolean-Predicate
Column-Value-Predicate
IN-predicate
Join-Predicate
LIKE-predicate
NULL-predicate
Notes
You can use parentheses to group expressions, predicates, and boolean operators. For example:
=> ... WHERE NOT (A=1 AND B=2) OR C=3;
Example
The following example returns the names of all customers in the Eastern region whose name starts
with 'Amer'. Without the WHERE clause filter, the query returns all customer names in the
customer_dimension table.
=> SELECT DISTINCT customer_name
FROM customer_dimension
WHERE customer_region = 'East'
AND customer_name ILIKE 'Amer%';
customer_name
--------------Americare
Americom
Americore
Americorp
Ameridata
Amerigen
Amerihope
Amerimedia
Amerishop
Ameristar
Ameritech
(11 rows)
SQLReference Manual
SQL Statements
WINDOW Clause
Creates a named window for an analytics query so you can avoid typing long OVER() clause
syntax.
Syntax
WINDOW window_name AS ( window_definition_clause );
[ window_partition_clause ] [ window_order_clause ]
Parameters
WINDOW window_name
AS window_definition_clause
Examples
This example shows how to create the myWindow window for an analytics query.
=> SELECT customer_name, occupation, annual_income, RANK() OVER myWindow AS RANK FROM
customer_dimension WINDOW myWindow AS (PARTITION BY occupation ORDER BY annual_income);
customer_name
| occupation | annual_income | RANK
-----------------------+------------+---------------+-----Jose I. Brown
| Accountant |
11371 |
1
Jessica O. Nguyen
| Accountant |
12374 |
4
James B. Winkler
| Accountant |
12740 |
7
See Also
l
Analytic Functions
Naming Windows
WITH Clause
WITH clauses are individually-evaluated SELECT statements for use in a larger, container query.
You can use WITH clauses to simplify complicated queries and reduce statement repetition.
SQLReference Manual
SQL Statements
WITH clauses can be evaluated using inline expansion or using a materialization approach for more
complex situations. For a detailed distinction, see WITH Clauses in SELECT.
Important: Each WITH clause query must have a unique name. Attempting to use same-name
aliases for WITH clause query names causes an error.
Syntax
This syntax statement is illustrative, rather than syntactically exact, to show the possibility of
numerous successive WITH queries in use with others:
WITH... with_query_1 [(col_name[,...])]AS (SELECT ...),
... with_query_2 [(col_name[,...])]AS (SELECT ...[with_query_1]),
.
.
.
... with_query_n [(col_name[,...])]AS (SELECT ...[with_query1, with_query_2, with_query_n
[,...]])
SELECT
.
.
.
Restrictions
l
If the primary query errors, then temporary tables may not get dropped until the clients session
closes.
WITH statements with materialization enabled will perform an auto-commit of the user
transaction. This occurs even when using EXPLAIN on the WITH statement.
Examples
The following example shows how to use the default inline expansion.
Suppose you want to obtain order information for all orders shipped between December 15, 2007
and December 31, 2007.
-- Disable the materialization method if previously enabled
SELECT clr_vertica_options('OPT', 'ENABLE_WITH_CLAUSE_MATERIALIZATION');
SQLReference Manual
SQL Statements
The following example shows a situation where you would benefit from enabling the materialization
method. Suppose you want to find information about the vendor whose combined total order cost for
all orders is the highest.
-- Enable materialization
SELECT add_vertica_options('OPT', 'ENABLE_WITH_CLAUSE_MATERIALIZATION');
-- Begin WITH clause,revenue
WITH
revenue AS (
SELECT vendor_key, SUM(total_order_cost) AS total_revenue
FROM store.store_orders_fact
GROUP BY vendor_key ORDER BY 1)
-- End defining WITH clause statement
-- Begin main primary query
SELECT vendor_name,
vendor_address,
vendor_city,
total_revenue
FROM vendor_dimension v, revenue r
WHERE v.vendor_key = r.vendor_key AND total_revenue = (
SELECT MAX(total_revenue)
FROM revenue)
ORDER BY vendor_name;
See Also
l
SELECT
Subqueries
SQLReference Manual
SQL Statements
SET DATESTYLE
Specifies the format of date/time output for the current session.
Syntax
SET DATESTYLE TO { value | 'value' } [ ,... ]
Parameters
The DATESTYLE parameter can have multiple, non-conflicting values:
Value
Interpretation
Example
MDY
month-day-year
12/16/2011
DMY
day-month-year
16/12/2011
YMD
year-month-day
2011-12-16
ISO
POSTGRES
verbose style
SQL
traditional style
GERMAN
regional style
In the SQL style, if DMY field ordering has been specified, the day appears before the month.
Otherwise, the month appears before the day. (To see how this setting also affects interpretation of
input values, see Date/Time Literals.) The following table shows an example.
DATESTYLE Input Ordering Example Output
SQL, DMY
day/month/year
SQL, MDY
month/day/year
Permissions
No special permissions required.
SQLReference Manual
SQL Statements
Notes
l
HP Vertica ISO output for DATESTYLE is ISO long form, but several input styles are accepted. If
the year appears first in the input, YMD is used for input and output, regardless of the DATESTYLE
value.
The SQL standard requires the use of the ISO 8601 format.
INTERVAL output looks like the input format, except that units like CENTURY or WEEK are converted
to years and days, and AGO is converted to the appropriate sign. In ISO mode, the output looks
like
[ quantity unit [ ... ] ] [ days ] [ hours:minutes:seconds ]
Example
The following examples show how the DATESTYLE parameter affects the output of the SELECT
INTERVAL command:
=>SHOW DATESTYLE;
name
| setting
-----------+---------datestyle | ISO, MDY
=> SELECT INTERVALYM '-12-11', INTERVAL '-10 15:05:1.234567';
?column? |
?column?
----------+---------------------12-11
| -10 15:05:01.234567
=> SET INTERVALSTYLE TO UNITS;
SET
=> SELECT INTERVALYM '-12-11', INTERVAL '-10 15:05:1.234567';
?column?
|
?column?
---------------------+--------------------------12 years 11 months | -10 days 15:05:01.234567
=> SET DATESTYLE TO SQL;;
SET
=> SELECT INTERVALYM '-12-11', INTERVAL '-10 15:05:1.234567';
?column? |
?column?
----------+---------------------12-11
| -10 15:05:01.234567
=> SET DATESTYLE TO POSTGRES;
SET
=> SELECT INTERVALYM '-12-11', INTERVAL '-10 15:05:1.234567';
?column?
|
?column?
--------------------------+--------------------------------------------@ 12 years 11 months ago | @ 10 days 15 hours 5 mins 1.234567 secs ago
=> SET DATESTYLE TO GERMAN;
SQLReference Manual
SQL Statements
SET
=> SELECT INTERVALYM '-12-11', INTERVAL '-10 15:05:1.234567';
?column?
|
?column?
---------------------+--------------------------12 years 11 months | -10 days 15:05:01.234567
SET ESCAPE_STRING_WARNING
Issues a warning when a backslash is used in a string literal during the current session.
Syntax
SET ESCAPE_STRING_WARNING TO { ON | OFF }
Parameters
ON
OFF
Permissions
No special permissions required.
Notes
l
Turn off standard conforming strings before you turn on this parameter.
Tip: To set escape string warnings across all sessions, use the EscapeStringWarnings
configuration parameter. See the Internationalization Parameters in the Administrator's Guide.
Examples
The following example shows how to turn OFF escape string warnings for the session.
SQLReference Manual
SQL Statements
See Also
l
SET STANDARD_CONFORMING_STRINGS
SET INTERVALSTYLE
Specifies whether to include units in interval output for the current session.
Syntax
SET INTERVALSTYLE TO [ plain |
units
Parameters
plain
Sets the default interval output to omit units. PLAIN is the default value.
units
Enables interval output to include units. When you enable interval units, the DATESTYLE
parameter controls the output. If you enable units and they do not display in the output,
check the DATESTYLE parameter value, which must be set to ISO or POSTGRES for
interval units to display.
Permissions
No special permissions required.
SQLReference Manual
SQL Statements
See Also
l
INTERVAL
SET LOCALE
Specifies the locale for the current session.
Syntax
SET LOCALE TO < ICU-locale-identifier >
Parameters
< ICU-locale-identifier >
SQLReference Manual
SQL Statements
Permissions
No special permissions required.
Notes
Though not inclusive, the following are some commonly-used locales:
l
Session related:
l
The locale setting is session scoped and applies only to queries (no DML/DDL) executed in that
session. You cannot specify a locale for an individual query.
You can set the default locale for new sessions using the DefaultSessionLocale configuration
parameter
Query related:
The following restrictions apply when queries are run with locale other than the default en_
US@collation=binary:
l
When one or more of the left-side NOT IN columns is CHAR or VARCHAR, multicolumn NOT
IN subqueries are not supported . For example:
SQLReference Manual
SQL Statements
Note: Even if columns test.x and test.y have a NOT NULL constraint, an error occurs.
Subqueries that use analytic functions in the HAVING clause are not supported. For example:
=> DROP TABLE test CASCADE;
=> CREATE TABLE test (x VARCHAR(10));
=> SELECT MAX(x)OVER(PARTITION BY 1 ORDER BY 1)
FROM test GROUP BY x HAVING x IN (SELECT MAX(x) FROM test);
ERROR: Analytics query with having clause expression that involves aggregates and
subquery
is not supported
DML/DDL related:
l
SQL identifiers (such as table names and column names) can use UTF-8 Unicode characters.
For example, the following CREATE TABLE statement uses the (German eszett) in the table
name:
=> CREATE TABLE strae(x int, y int);
CREATE TABLE
Projection sort orders are made according to the default en_US@collation=binary collation.
Thus, regardless of the session setting, issuing the following command creates a projection
sorted by col1 according to the binary collation:
=> CREATE PROJECTION p1 AS SELECT * FROM table1 ORDER BY col1;
SQLReference Manual
SQL Statements
In such cases, strae and strasse are not stored near each other on disk.
Sorting by binary collation also means that sort optimizations do not work in locales other than
binary. HP Vertica returns the following warning if you create tables or projections in a nonbinary locale:
WARNING: Projections are always created and persisted in the default HP Vertica
locale. The current locale is de_DE
When creating pre-join projections, the projection definition query does not respect the locale or
collation setting. When you insert data into the fact table of a pre-join projection, referential
integrity checks are not locale or collation aware.
For example:
\locale LDE_S1
-- German
=> CREATE TABLE dim (col1 varchar(20) primary key);
=> CREATE TABLE fact (col1 varchar(20) references dim(col1));
=> CREATE PROJECTION pj AS SELECT * FROM fact JOIN dim
ON fact.col1 = dim.col1 UNSEGMENTED ALL NODES;
=> INSERT INTO dim VALUES('');
=> COMMIT;
The following INSERT statement fails with a "nonexistent FK" error even though '' is in the dim
table, and in the German locale 'SS' and '' refer to the same character.
=> INSERT INTO fact VALUES('SS');
ERROR: Nonexistent foreign key value detected in FK-PK join (fact x dim)
using subquery and dim_node0001; value SS
=> => ROLLBACK;
=> DROP TABLE dim, fact CASCADE;
When the locale is non-binary, HP Vertica uses the COLLATION function to transform the input
to a binary string that sorts in the proper order.
This transformation increases the number of bytes required for the input according to this
formula:
result_column_width = input_octet_width * CollationExpansion + 4
CHAR fields are displayed as fixed length, including any trailing spaces. When CHAR fields are
processed internally, they are first stripped of trailing spaces. For VARCHAR fields, trailing
SQLReference Manual
SQL Statements
spaces are usually treated as significant characters; however, trailing spaces are ignored when
sorting or comparing either type of character string field using a non-BINARY locale.
Examples
This example sets the locale for the session to en_GB (English as in Great Britain).
SET LOCALE TO en_GB;
INFO: Locale: 'en_GB'
INFO:
English (United Kingdom)
INFO: Short form: 'LEN'
You can also use the short form of a locale in this command:
SET LOCALE TO LEN;
INFO: Locale: 'en'
INFO:
English
INFO: Short form: 'LEN'
See Also
l
About Locales
SET ROLE
Enables a role for the current user's current session. The user will gain the permissions that have
been granted to the role.
Syntax
SET ROLE { role [, ...] | NONE | ALL | DEFAULT }
SQLReference Manual
SQL Statements
Parameters
role [, ...] | NONE | ALL | DEFAULT
Permissions
You can only set a role that has been granted to you. Run the SHOW AVAILABLE_ROLES
command to get a list of the roles available to the user.
Notes
l
The default role is the first role that was assigned to the user or set by the superuser via the
ALTER USER statement's DEFAULT ROLE argument.
Enabling a role does not affect any other roles that are currently enabled. A user session can
have more than one role enabled at a time. The user's permissions are the union of all the roles
that are currently active, plus any permissions granted directly to the user.
Example
=> SHOW ENABLED_ROLES; -- Which roles are active now.
name
|
setting
---------------+---------------------------enabled roles |
(1 row)
=> SHOW AVAILABLE_ROLES; -- All roles the user can access
name
|
setting
-----------------+---------------------------available roles | applogs, appadmin, appuser
(1 row)
=> SET ROLE applogs;
SET
=> SHOW ENABLED_ROLES;
name
| setting
SQLReference Manual
SQL Statements
SET SEARCH_PATH
Specifies the order in which HP Vertica searches schemas when a SQL statement contains an
unqualified table name.
HP Vertica provides the SET search_path statement instead of the CURRENT_SCHEMA
statement found in some other databases.
Syntax 1
SET SEARCH_PATH [ TO | = ] schemaname [ , ... ]
Syntax 2
SET SEARCH_PATH [ TO | = ] default
SQLReference Manual
SQL Statements
Parameters
schemaname
$user is the schema with the same name as the current user. If the schema does
not exist, $user is ignored.
default
Permissions
No special permissions required.
Notes
The first schema named in the search path is called the current schema. The current schema is the
first schema that HP Vertica searches. It is also the schema in which HP Vertica creates new
tables if the CREATE TABLE command does not specify a schema name.
Examples
The following example shows the current search path settings:
=> SHOW SEARCH_PATH;
name
|
setting
-------------+--------------------------------------------------search_path | "$user", public, v_catalog, v_monitor, v_internal
(1 row)
This command sets the order in which HP Vertica searches schemas to T1, U1, and V1:
=> SET SEARCH_PATH TO T1, U1, V1;
This command returns the search path to the default of '"$user", public':
SQLReference Manual
SQL Statements
Syntax
SET SESSION AUTOCOMMIT TO { ON | OFF }
Parameters
ON
OFF
Disable autocommit. Transactions are not automatically committed. This is the default for
interactive sessions (connections made through vsql).
Permissions
No special permissions required.
Examples
This examples show how to set AUTOCOMMIT to 'on' and then to 'off'.
=> SET SESSION AUTOCOMMIT TO on;
SET
=> SET SESSION AUTOCOMMIT TO off;
SET
See Also
l
SQLReference Manual
SQL Statements
Syntax
SET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]where transaction_mode is
one of:
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
READ { ONLY | WRITE }
Parameters
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.
Isolation level, described in the following table, determines what data the transaction can access
when other transactions are running concurrently. The isolation level cannot be changed after the
first query (SELECT) or DML statement (INSERT, DELETE, UPDATE) if a transaction has run.
ISOLATION LEVEL SERIALIZABLE
SQLReference Manual
SQL Statements
Permissions
No special permissions required.
SQLReference Manual
SQL Statements
Syntax
SET SESSION MEMORYCAP 'memory-limit' | = default
Parameters
memory-limit | = default
KKilobytes
MMegabytes
GGigabytes
TTerabytes
If you use the value = default the session's MEMORYCAP is set to the
user's MEMORYCAP value.
SQLReference Manual
SQL Statements
Permissions
l
This command requires superuser privileges if the MEMORYCAP is being increased over the
user's MEMORYCAP limit (see CREATE USER for details).
Non-superusers can change this value to anything below or equal to their MEMORYCAP limit.
Notes
The MEMORYCAP limit is per user session, not an overall cap on the user's memory usage. A user
could spawn multiple sessions, each of which could use up to the limit set by the MEMORYCAP.
Examples
The following command sets a memorycap of 4 gigabytes on the session:
=> SET SESSION MEMORYCAP '4G';
See Also
l
CREATE USER
Managing Workloads
SQLReference Manual
SQL Statements
Syntax
SET SESSION RESOURCE_POOL = { pool-name | default }
Parameters
pool-name | default
Permissions
l
This command requires non-superusers to have USAGE privileges for the resource pool.
Superusers can assign their session to any resource pool they want.
To set the resource pool session, the user needs USAGE privilege on the resource pool.
Notes
The resource pool must exist.
Examples
This examples show how to set the session resource pool to the ceo_pool resource pool.
=> SET SESSION RESOURCE_POOL = ceo_pool;
SET
See Also
l
CREATE USER
SQLReference Manual
SQL Statements
Managing Workloads
Syntax
SET SESSION RUNTIMECAP [ 'duration' | NONE | = default ]
Parameters
'duration' | NONE | DEFAULT
Notes
l
If RUNTIMECAP is also set for the user or the resource pool, HP Vertica uses the shortest limit.
This command requires superuser privileges if the RUNTIMECAP is being increased over the
user's RUNTIMECAP limit.
SQLReference Manual
SQL Statements
Normal users can change the RUNTIMECAP of their own sessions to any value below their
own RUNTIMECAP. They cannot increase the RUNTIMECAP beyond any limit set for them by
the superuser.
The timeout is not precise, so a query may run a little longer than the value set in
RUNTIMECAP.
Queries that violate the RUNTIMECAP are terminated with the error message Execution time
exceeded run time cap of <cap_duraation>.
SHOW RUNTIMECAP (below) shows only the session RUNTIMECAP; it does not show the user or
resource pool RUNTIMECAP.
Examples
The following command sets the session's RUNTIMECAP to 10 minutes:
=> SET SESSION RUNTIMECAP '10 minutes';
See Also
l
CREATE USER
ALTER USER
Managing Workloads
SQLReference Manual
SQL Statements
Syntax
SET SESSION TEMPSPACECAP 'space-limit' | = default | NONE
Parameters
'space-limit'
The maximum amount of temporary file space the session can use. To set a
limit, use a numeric value followed by a unit (for example: '10G'). The unit can be
one of the following:
l
% percentage of total temporary storage space available. (In this case, the
numeric value must be 0-100).
KKilobytes
MMegabytes
GGigabytes
TTerabytes
Permissions
l
This command requires superuser privileges to increase the TEMPSPACECAP over the user's
TEMPSPACECAP limit.
Regular users can change the TEMPSPACECAP associated with their own sessions to any
value less than or equal to their own TEMPSPACECAP. They cannot increase its value beyond
their own TEMPSPACECAP value.
Notes
l
This limit is per session, not per user. A user could open multiple sessions, each of which could
use up to the TEMPSPACECAP.
SQLReference Manual
SQL Statements
Any execution plan that exceeds its TEMPSPACECAP usage results in the error:
ERROR: Exceeded temp space cap.
Examples
The following command sets a TEMPSPACECAP of 20gigabytes on the session:
=> SET SESSION TEMPSPACECAP '20G';
SET
=> SHOW TEMPSPACECAP;
name
| setting
--------------+---------tempspacecap | 20971520
(1 row)
See Also
l
ALTER USER
CREATE USER
Managing Workloads
SET STANDARD_CONFORMING_STRINGS
Treats backslashes as escape characters for the current session.
Syntax
SET STANDARD_CONFORMING_STRINGS TO { ON | OFF }
SQLReference Manual
SQL Statements
Parameters
ON
Makes ordinary string literals ('...') treat back slashes (\) literally. This means that back
slashes are treated as string literals, not escape characters. (This is the default.)
OFF
Permissions
No special permissions required.
Notes
l
When standard conforming strings are on, HP Vertica supports SQL:2008 string literals within
Unicode escapes.
Examples
The following example shows how to turn off conforming strings for the session.
=> SET STANDARD_CONFORMING_STRINGS TO OFF;
The following example shows how to turn on conforming strings for the session.
=> SET STANDARD_CONFORMING_STRINGS TO ON;
SQLReference Manual
SQL Statements
See Also
l
SET ESCAPE_STRING_WARNING
Syntax
SET TIME ZONE TO { value | 'value' }
Parameters
value
One of the time zone names specified in the tz database, as described in Sources for
Time Zone and Daylight Saving Time Data. Time Zone Names for Setting TIME
ZONE listed in the next section are for convenience only and could be out of date.
An interval value
Permissions
No special permissions required.
Notes
l
TIME ZONE is a synonym for TIMEZONE. Both are allowed in HP Vertica syntax.
The built-in constants LOCAL and DEFAULT, which set the time zone to the one specified in the
TZ environment variable or, if TZ is undefined, from the operating system time zone. See TZ
Environment Variable and Using Time Zones with HP Vertica in the Installation Guide.
When using a Country/City name, do not omit the country or the city. For example:
=> SET TIME ZONE TO 'Africa/Cairo';
SQLReference Manual
SQL Statements
-- valid
=> SET TIME ZONE TO 'Cairo';
-- invalid
If you set the timezone using POSIX format, the timezone abbreviation you use overrides the
default timezone abbreviation. If the DATESTYLE is set to POSTGRES, the timezone
abbreviation you use is also used when converting a timestamp to a string.
Examples
=>
=>
=>
=>
=>
SET
SET
SET
SET
SET
TIME
TIME
TIME
TIME
TIME
ZONE
ZONE
ZONE
ZONE
ZONE
TO
TO
TO
TO
TO
DEFAULT;
'PST8PDT'; -- Berkeley, California
'Europe/Rome'; -- Italy
'-7'; -- UDT offset equivalent to PDT
INTERVAL '-08:00 HOURS';
See Also
l
SQLReference Manual
SQL Statements
In addition to the names listed in the table, HP Vertica accepts time zone names of the form
STDoffset or STDoffsetDST, where STD is a zone abbreviation, offset is a numeric offset in hours
west from UTC, and DST is an optional daylight-savings zone abbreviation, assumed to stand for
one hour ahead of the given offset. For example, if EST5EDT were not already a recognized zone
name, it would be accepted and would be functionally equivalent to USA East Coast time. When a
daylight-savings zone name is present, it is assumed to be used according to USA time zone rules,
so this feature is of limited use outside North America. Be wary that this provision can lead to
silently accepting bogus input, since there is no check on the reasonableness of the zone
abbreviations. For example, SET TIME ZONE TO FOOBANKO works, leaving the system effectively
using a rather peculiar abbreviation for GMT.
Time Zone
Africa
America
Antarctica
Asia
Atlantic
Australia
CET
EET
Etc/GMT
Europe
Factory
GMT GMT+0 GMT-0 GMT0 Greenwich Etc/GMT Etc/GMT+0 Etc/GMT-0 Etc/GMT0
Etc/Greenwich
Indian
MET
Pacific
UCT Etc/UCT
SQLReference Manual
SQL Statements
SHOW
Displays run-time parameters for the current session.
Syntax
SHOW { setting_name | ALL }
Parameters
AUTOCOMMIT
AVAILABLE_ROLES
DATESTYLE
ENABLED_ROLES
Displays the roles enabled for the current session. See SET
ROLE.
ESCAPE_STRING_WARNING
INTERVALSTYLE
LOCALE
MEMORYCAP
RESOURCE_POOL
Displays the resource pool that the session is using. See SET
RESOURCE POOL.
RUNTIMECAP
Displays the maximum amount of time that queries can run in the
session. See SET RUNTIMECAP
SQLReference Manual
SQL Statements
SEARCH_PATH
STANDARD_CONFORMING_STRINGS
TEMPSPACECAP
TIMEZONE
TRANSACTION_ISOLATION
TRANSACTION_READ_ONLY
ALL
Permissions
No special permissions required.
SQLReference Manual
SQL Statements
enabled roles
available roles
(15 rows)
|
| applogs, appadmin
The next command returns the setting for SESSION CHARACTERISTICS AS TRANSACTION.
False indicates that the default read/write is the current setting:
=> SHOW TRANSACTION_READ_ONLY;
name
| setting
-----------------------+--------transaction_read_only | false
(1 row)
SQLReference Manual
SQL Statements
SHOW CURRENT
Displays active configuration parameter values that are set at all levels. HP Vertica first checks
values set at the session level. If a value is not set for a configuration parameter at the session
level, HP Vertica next checks if the value is set for the node where you are logged in, and then
checks the database level. If no values are set, SHOW CURRENT shows the default value for the
configuration parameter. If the configuration parameter requires a restart to take effect, the active
values shown might differ from the set values.
Syntax
SHOW CURRENT { name [,...]| ALL }
Parameters
name
ALL
Privileges
l
You must have superuser privileges to view some values. If you are not the superuser, and you
use the the keyword 'ALL', parameter values are masked with ****. If the parameter is
specifically listed, an error message appears.
Examples
This example shows configuration parameters and their settings at all levels.
=> SHOW CURRENT ALL;
level
|
name
|setting
---------+---------------------------+--------DEFAULT | ActivePartitionCount
| 1
DEFAULT | AdvanceAHMInterval
| 180
DEFAULT | AHMBackupManagement
| 0
DATABASE | AnalyzeRowCountInterval
| 3600
SESSION | ForceUDxFencedMode
| 1
NODE
| MaxClientSessions
| 0
.
.
.
SQLReference Manual
SQL Statements
SHOW DATABASE
Displays configuration parameter values that are set for the database. If a configuration parameter
is not set at the database level,SHOW DATABASEdoes not return a row for that parameter. If the
configuration parameter requires a restart to take effect, the values shown might differ from the
active values.
Syntax
SHOW DATABASE dbname { parameter_name [,...]| ALL }
Parameters
dbname
parameter_name
ALL
Privileges
l
You must have superuser privileges to view some values. If you are not the superuser, and you
use the the keyword 'ALL', parameter values are masked with ****. If the parameter is
specifically listed, an error message appears.
Examples
The following example shows how to display all configuration parameters that are set at the
database level.
=> SHOW DATABASE VMart ALL;
name
|
setting
-------------------------+-----------------------AnalyzeRowCountInterval | 3600
DefaultSessionLocale
| en_US@collation=binary
JavaBinaryForUDx
| /usr/bin/java
(3 rows)
SQLReference Manual
SQL Statements
SHOW NODE
Displays configuration parameter values that are set for a node. If a configuration parameter is not
set at the node level, SHOW NODEdoes not return a row for that parameter. If the configuration
parameter requires a restart to take effect, the values shown might differ from the active values.
Syntax
SHOW NODE node_name { parameter_name [,...]| ALL }
Parameters
node_name
parameter_name
ALL
Shows all configuration parameters that are set at the node level.
Privileges
l
You must have superuser privileges to view some values. If you are not the superuser, and you
use the the keyword 'ALL', parameter values are masked with ****. If the parameter is
specifically listed, an error message appears.
Examples
The following example shows how display all values set for v_vmart_node0001:
=> SHOW NODE v_vmart_node0001 ALL;
name
| setting
------------------+--------MaxClientSessions | 0
(1 row)
SHOW SESSION
Displays set configuration parameter values for the current session. If the configuration parameter
is not set at the session level,SHOW SESSIONdoes not return a row for that parameter. If the
SQLReference Manual
SQL Statements
configuration parameter requires a restart to take effect, the values shown might differ from the
active values.
Syntax
SHOW SESSION { name [,...]| ALL }
Parameters
name
ALL
Privileges
You must have superuser privileges to view some values. If you are not the superuser, and you use
the keyword 'ALL', parameter values are masked with ****. If the parameter is specifically listed, an
error message appears.
Examples
The following example shows how to view all configuration parameters and their settings for the
current session.
=> SHOW SESSION ALL:
name
|
setting
----------------------------+--------------------------------------------------locale
| en_US@collation=binary (LEN_KBINARY)
autocommit
| off
standard_conforming_strings | on
escape_string_warning
| on
datestyle
| ISO, MDY
intervalstyle
| plain
timezone
| America/New_York
search_path
| "$user", public, v_catalog, v_monitor, v_internal
transaction_isolation
| READ COMMITTED
transaction_read_only
| false
resource_pool
| general
memorycap
| UNLIMITED
tempspacecap
| UNLIMITED
runtimecap
| UNLIMITED
enabled roles
| dbduser*, dbadmin*, pseudosuperuser*
available roles
| dbduser*, dbadmin*, pseudosuperuser*
ForceUDxFencedMode
| 1
(17 rows)
SQLReference Manual
SQL Statements
START TRANSACTION
Starts a transaction block.
Syntax
START TRANSACTION [ isolation_level ]
Parameters
Isolation level, described in the following table, determines what data the transaction can access
when other transactions are running concurrently. The isolation level cannot be changed after the
first query (SELECT) or DML statement (INSERT, DELETE, UPDATE) has run. A transaction retains its
isolation level until it completes, even if the session's transaction isolation level changes midtransaction. 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.
WORK | TRANSACTION
ISOLATION LEVEL {
SERIALIZABLE |
REPEATABLE READ |
READ COMMITTED |
READ UNCOMMITTED
}
SQLReference Manual
SQL Statements
INSERT, UPDATE, DELETE, and COPY if the table they would write
to is not a temporary table
Permissions
No special permissions required.
Notes
BEGIN performs the same function as START TRANSACTION.
Examples
This example shows how to start a transaction.
= > START TRANSACTION ISOLATION LEVEL READ COMMITTED READ WRITE;
START TRANSACTION
=> CREATE TABLE sample_table (a INT);
CREATE TABLE
=> INSERT INTO sample_table (a) VALUES (1);
OUTPUT
-------1
(1 row)
See Also
l
Transactions
SQLReference Manual
SQL Statements
COMMIT
END
ROLLBACK
TRUNCATE TABLE
Removes all storage associated with a table, while preserving the table definitions. TRUNCATE
TABLE auto-commits the current transaction after statement execution and cannot be rolled back.
Syntax
TRUNCATE TABLE [[db-name.]schema.]table
Parameters
[[db-name.]schema.]
[Optional] Specifies the database name and optional schema name, for
example, mydb.myschema. The database name identifies objects that are
not unique within the current search path. (See Setting Search Paths.)
table
Permissions
Superuser or table owner. A schema owner can drop a table but cannot truncate a table.
Notes
l
To truncate an ON COMMIT DELETE ROWS temporary table without ending the transaction, use
DELETE FROM temp_table syntax.
Note: The effect of DELETE FROM depends on the table type. If the table is specified as
ON COMMIT DELETE ROWS, then DELETE FROM works like TRUNCATE TABLE;
otherwise it behaves like a normal delete in that it does not truncate the table.
After truncate operations complete, the data recovers from that current epoch onward. Because
TRUNCATE TABLE removes table history, AT EPOCH queries return nothing. TRUNCATE
TABLE behaves the same when you have data in WOS, ROS, or both, as well as for
SQLReference Manual
SQL Statements
unsegmented/segmented projections.
If the operation cannot obtain an O Lock on the table(s), HP Vertica attempts to close any
internal Tuple Mover (TM) sessions running on the same table(s). This step allows the operation
to proceed. Explicit TM operations that are running in user sessions are not closed. If an explicit
TM operation is running on the table, the operation cannot proceed until the explicit TM operation
completes.
Examples
This example shows how to truncate a table.
=> INSErT INTO sample_table (a) VALUES (3);
=> SELECT * FROM sample_table;
a
--3
(1 row)
=> TRUNCATE TABLE sample_table;
TRUNCATE TABLE
=> SELECT * FROM sample_table;
a
--(0 rows)
For more examples about how to use TRUNCATE, see Dropping and Truncating Tables in the
Administrator's Guide.
See Also
l
DELETE
DROP TABLE
LOCKS
Transactions
UPDATE
Replaces the values of the specified columns in all rows for which a specific condition is true. All
other columns and rows in the table are unchanged. By default, UPDATE uses the WOS and if the
SQLReference Manual
SQL Statements
Syntax
UPDATE [ /*+ direct */ ] [ /*+ label(label-name)*/ ]
... [[db-name.]schema.]Table-Reference [AS] alias
... SET column =
... { expression | DEFAULT } [ , ... ]
... [ FROM from-list ]
... [ WHERE Clause ]
Parameters
/*+ direct */
Note: If you update using the direct hint, you still need to issue a
COMMIT or ROLLBACK command to finish the transaction.
/*+ label(labelname)*/
[[db-name.]
schema.]
SQLReference Manual
SQL Statements
table-reference
table-primary or joined-table:
tableprimary
joinedtable
column
expression
Specifies a value to assign to the column. The expression can use the
current values of this and other columns in the table. For example:
UPDATE T1 SET C1 = C1+1;
from-list
Permissions
Table owner or user with GRANT OPTION is grantor.
l
SELECT privilege on the table when executing an UPDATE statement that references table
column values in a WHERE or SET clause
Considerations
l
Subqueries and joins are permitted in UPDATE statements, which is useful for updating values
in a table based on values that are stored in other tables. UPDATE changes the values of the
specified columns in all rows that satisfy the condition. Only the columns to be modified need to
be specified in the SET clause. Columns that are not explicitly modified retain their previous
values. On successful completion, an UPDATE operation returns a count, which represents the
number of rows updated. A count of 0 is not an error; it means that no rows matched the
condition.
SQLReference Manual
SQL Statements
See Subqueries in UPDATE and DELETE Statements in the Analyzing Data Guide.
l
The table you specify in the UPDATE list cannot also appear in the FROM list (no self joins); for
example, the following UPDATE statement is not allowed:
=> BEGIN;
=> UPDATE result_table
SET address='new' || r2.address
FROM result_table r2
WHERE r2.cust_id = result_table.cust_id + 10;
ERROR: Self joins in UPDATE statements are not allowed
DETAIL: Target relation result_table also appears in the FROM list
If the joins specified in the WHERE predicate produce more than one copy of the row in the table
to be updated, the new value of the row in the table is chosen arbitrarily.
UPDATE inserts new records into the WOS and marks the old records for deletion.
You cannot UPDATE columns that have primary key or foreign key referential integrity
constraints.
To use the DELETE or UPDATE commands with a WHERE Clause, you must have both
SELECT and DELETE privileges on the table.
You cannot use the LIMIT clause on unsorted data when you update or merge tables that
participate in pre-join projections.
Examples
In the FACT table, modify the PRICE column value for all rows where the COST column value is
greater than 100:
=> UPDATE FACT SET PRICE = PRICE - COST * 80 WHERE COST > 100;
In the Retail.CUSTOMER table, set the STATE column to 'NH' when the CID column value is
greater than 100:
=> UPDATE Retail.CUSTOMER SET STATE = 'NH' WHERE CID > 100;
To use table aliases in UPDATE queries, consider the following two tables:
=> SELECT * FROM Result_Table;
cust_id |
address
SQLReference Manual
SQL Statements
The following query and subquery use table aliases to update the address column in Result_Table
(alias r) with the new address from the corresponding column in the New_Addresses table (alias n):
=> UPDATE Result_Table r
SET address=n.new_address
FROM New_Addresses n
WHERE r.cust_id = n.new_cust_id;
The Result_Table table reflects the address field updates made for customer IDs 20 and 30:
=> SELECT * FROM Result_Table ORDER BY cust_id;
cust_id |
address
---------+-----------------20 | Infinite Loop
30 | Loop Infinite
30 | Loop Infinite
40 | Mt. Vernon Street
50 | Hillside Avenue
(5 rows)
For more information about nesting subqueries within an UPDATE statement, see Subqueries in
UPDATE and DELETE in the Analyzing Data Guide.
SQLReference Manual
SQL Statements
SQLReference Manual
HP Vertica System Tables
Monitoring Vertica
SQLReference Manual
HP Vertica System Tables
V_CATALOG Schema
The system tables in this section reside in the v_catalog schema. These tables provide
information (metadata) about the objects in a database; for example, tables, constraints, users,
projections, and so on.
ACCESS_POLICY
The ACCESS_POLICYsystem table provides information about the access policies associated
with specific tables.
Column Name
Data Type
Description
ACCESS_POLICY_OID
INTEGER
TABLE_NAME
VARCHAR
IS_POLICY_ENABLED
BOOLEAN
POLICY_TYPE
VARCHAR
EXPRESSION
VARCHAR
TRIGGERED_BY
VARCHAR
COLUMN_NAME
VARCHAR
Example
This example shows how to display a list of the access policies on your system:
=> SELECT * FROM access_policy;
access_policy_oid
| table_name
| is_policy_enabled | policy_type
| expression | triggered_
by | column_name
---------------+-----------------+----------------+---------------------+-------------------------------------------------45035996278650744
| public.employee_data|
ENABLED
| Column Policy | employee_id | Select
| employee_id
45035996278650745
| public.customer
|
ENABLED
| Column Policy | customer_id | Select
| customer_id
45035996278650746
| public.customer_data|
DISABLED
| Column Policy | customer_ssn| Select
| customer_ssn
SQLReference Manual
HP Vertica System Tables
45035996278650747
| store_id
| public.store_locale |
ENABLED
| Select
(4 rows)
ALL_TABLES
Provides summary information about the tables in HP Vertica.
Column
Name
Data Type
Description
SCHEMA_NAME
VARCHAR
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
TABLE_TYPE
VARCHAR
REMARKS
VARCHAR
TABLE
SYSTEM TABLE
VIEW
GLOBAL TEMPORARY
LOCAL TEMPORARY
A brief comment about the table. You define this field by using the
COMMENT ON TABLE and COMMENT ON VIEW commands.
Example
onenode=> SELECT DISTINCT table_name, table_type FROM all_tables
WHERE table_name ILIKE 't%';
SQLReference Manual
HP Vertica System Tables
table_name
| table_type
------------------------+-------------types
| SYSTEM TABLE
trades
| TABLE
tuple_mover_operations | SYSTEM TABLE
tables
| SYSTEM TABLE
tuning_recommendations | SYSTEM TABLE
testid
| TABLE
table_constraints
| SYSTEM TABLE
transactions
| SYSTEM TABLE
(8 rows)
onenode=> SELECT table_name, table_type FROM all_tables
WHERE table_name ILIKE 'my%';
table_name | table_type
------------+-----------mystocks
| VIEW
(1 row)
=> SELECT * FROM all_tables LIMIT 4;
-[ RECORD 1 ]------------------------------------------schema_name | v_catalog
table_id
| 10206
table_name | all_tables
table_type | SYSTEM TABLE
remarks
| A complete listing of all tables and views
-[ RECORD 2 ]------------------------------------------schema_name | v_catalog
table_id
| 10000
table_name | columns
table_type | SYSTEM TABLE
remarks
| Table column information
-[ RECORD 3 ]------------------------------------------schema_name | v_catalog
table_id
| 10054
table_name | comments
table_type | SYSTEM TABLE
remarks
| User comments on catalog objects
-[ RECORD 4 ]------------------------------------------schema_name | v_catalog
table_id
| 10134
table_name | constraint_columns
table_type | SYSTEM TABLE
remarks
| Table column constraint information
CLIENT_AUTH
The CLIENT_AUTHsystem table provides information about the client authentication methods that
you have created for your HP Vertica database.
Column Name
Data Type
Description
AUTH_OID
INTEGER
AUTH_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
IS_AUTH_ENABLED
BOOLEAN
AUTH_HOST_TYPE
VARCHAR
AUTH_HOST_ADDRESS
VARCHAR
LOCAL
HOST
HOSTSSL
HOSTNOSSL
AUTH_METHOD
VARCHAR
AUTH_PARAMETERS
VARCHAR
IDENT
GSS
HASH
LDAP
REJECT
TLS
TRUST
AUTH_CONTINUE_TO
N/A
Unused.
SQLReference Manual
HP Vertica System Tables
Examples
This example shows how you can use a statement to retrieve s information about each client
authentication method you have created:
=> SELECT auth_name, is_auth_enabled, auth_host_type, auth_host_address,
auth_method FROM CLIENT_AUTH;
auth_name
| is_auth_enabled | auth_host_type | auth_host_address
| auth_method
---------------+-----------------+----------------+---------------------+------------v_ident
| True
| LOCAL
|
| IDENT
v_gss
| True
| HOST
| 0.0.0.0/0
| GSS
v_trust
| False
| LOCAL
|
| TRUST
v_ldap
| True
| HOST
| 10.19.133.123/
| LDAP
RejectNoSSL
| True
| HOSTNOSSL
| 0.0.0.0/0
| REJECT
RejectWithSSL | True
| HOSTSSL
| 0.0.0.0/0
| REJECT
v_hash
| False
| LOCAL
|
| HASH
v_tls
| True
| HOSTSSL
| 1.1.1.1/0
| TLS
v_trust
| True
| HOSTSSL
| 2001:db8:ab:123/128 | TLS
(9 rows)
CLIENT_AUTH_PARAMS
The CLIENT_AUTH_PARAMSsystem table provides information about the client authentication
methods that have parameter values assigned:
Column Name
Data Type
Description
AUTH_OID
INTEGER
AUTH_NAME
VARCHAR
AUTH_PARAMETER_NAME
VARCHAR
AUTH_PARAMETER_VALUE
VARCHAR
system_users
binddn_prefix
host
SQLReference Manual
HP Vertica System Tables
Examples
This example shows how you use a statement to retrieve the parameter names and values for all
authentication methods you have created. The authentication methods that have parameters are:
l
v_ident
v_ldap
v_ldap1
=> SELECT * FROM CLIENT_AUTH_PARAMS;
auth_oid
|
auth_name
| auth_parameter_name |
auth_parameter_value
-------------------+---------------+---------------------+-----------------------------45035996273741304 | v_ident
| system_users
| root
45035996273741332 | v_gss
|
|
45035996273741350 | v_password
|
|
45035996273741368 | v_trust
|
|
45035996273741388 | v_ldap
| host
| ldap://172.16.65.177
45035996273741388 | v_ldap
| binddn_prefix
| cn=
45035996273741388 | v_ldap
| binddn_suffix
| ,dc=qa_domain,dc=com
45035996273741406 | RejectNoSSL
|
|
45035996273741424 | RejectWithSSL |
|
45035996273741450 | v_md5
|
|
45035996273904044 | l_tls
|
|
45035996273906566 | v_hash
|
|
45035996273910432 | v_ldap1
| host
| ldap://172.16.65.177
45035996273910432 | v_ldap1
| basedn
| dc=qa_domain,dc=com
45035996273910432 | v_ldap1
| binddn
| cn=Manager,dc=qa_domain,dc=com
45035996273910432 | v_ldap1
| bind_password
| secret
45035996273910432 | v_ldap1
| search_attribute
| cn
(17 rows)
CLUSTER_LAYOUT
Shows the relative position of the actual arrangement of the nodes participating in the cluster and
the fault groups that affect them. Ephemeral nodes are not shown in the cluster layout ring because
they hold no resident data.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CLUSTER_POSITION
INTEGER
NODE_ID
INTEGER
NODE_NAME
VARCHAR
FAULT_GROUP_ID
INTEGER
FAULT_GROUP_NAME
VARCHAR
FAULT_GROUP_TIER
INTEGER
The node's depth in the fault group tree hierarchy. For example
is the node:
l
Example
=> SELECT cluster_position FROM cluster_layout;
cluster_position
------------------
SQLReference Manual
HP Vertica System Tables
0
1
2
3
4
5
6
7
(8 rows)
See Also
Large Cluster in the Administrator's Guide
COLUMNS
Provides table column information.
Column Name
Data Type
Description
TABLE_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_NAME
VARCHAR
IS_SYSTEM_TABLE
BOOLEAN
COLUMN_ID
VARCHAR
COLUMN_NAME
VARCHAR
DATA_TYPE
VARCHAR
DATA_TYPE_ID
INTEGER
DATA_TYPE_LENGTH
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CHARACTER_MAXIMUM_LENGTH
VARCHAR
NUMERIC_PRECISION
INTEGER
NUMERIC_SCALE
INTEGER
DATETIME_PRECISION
INTEGER
INTERVAL_PRECISION
INTEGER
ORDINAL_POSITION
INTEGER
IS_NULLABLE
BOOLEAN
COLUMN_DEFAULT
VARCHAR
IS_IDENTITY
BOOLEAN
Example
Retrieve table and column information from the COLUMNS table:
=> SELECT table_schema, table_name, column_name, data_type, is_nullable
FROM columns WHERE table_schema = 'store'
AND data_type = 'Date';
table_schema |
table_name
|
column_name
| data_type | is_nullable
--------------+-------------------+------------------------+-----------+------------store
| store_dimension
| first_open_date
| Date
| f
store
| store_dimension
| last_remodel_date
| Date
| f
store
| store_orders_fact | date_ordered
| Date
| f
store
| store_orders_fact | date_shipped
| Date
| f
store
| store_orders_fact | expected_delivery_date | Date
| f
store
| store_orders_fact | date_delivered
| Date
| f
6 rows)
NULL results indicate that those columns were not defined. For example, given the following table,
the result for the DATETIME_PRECISION column is NULL because no precision was declared:
=> CREATE TABLE c (c TIMESTAMP);
SQLReference Manual
HP Vertica System Tables
CREATE TABLE
=> SELECT table_name, column_name, datetime_precision FROM columns
WHERE table_name = 'c';
table_name | column_name | datetime_precision
------------+-------------+-------------------c
| c
|
(1 row)
In this example, the DATETIME_PRECISION column returns 4 because the precision was declared as
4 in the CREATE TABLE statement:
=> DROP TABLE c;
=> CREATE TABLE c (c TIMESTAMP(4));
CREATE TABLE
=> SELECT table_name, column_name, datetime_precision FROM columns
WHERE table_name = 'c';
table_name | column_name | datetime_precision
------------+-------------+-------------------c
| c
|
4
An identity column is a sequence available only for numeric column types. To identify what column
in a table, if any, is an identity column, search the COLUMNS table to find the identity column in a
table testid:
=> CREATE TABLE testid (c1 IDENTITY(1, 1, 1000), c2 INT);
=> \x
Expanded display is on.
=> SELECT * FROM COLUMNS WHERE is_identity='t' AND table_name='testid';
-[ RECORD 1 ]------------+-------------------table_id
| 45035996273719486
table_schema
| public
table_name
| testid
is_system_table
| f
column_id
| 45035996273719486-1
column_name
| c1
data_type
| int
data_type_id
| 6
data_type_length
| 8
character_maximum_length |
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 1
is_nullable
| f
column_default
|
is_identity
| t
Use the SEQUENCES table to get detailed information about the sequence in testid:
=> SELECT * FROM sequences WHERE identity_table_name='testid';
SQLReference Manual
HP Vertica System Tables
-[ RECORD 1 ]-------+-------------------sequence_schema
| public
sequence_name
| testid_c1_seq
owner_name
| dbadmin
identity_table_name | testid
session_cache_count | 1000
allow_cycle
| f
output_ordered
| f
increment_by
| 1
minimum
| 1
maximum
| 9223372036854775807
current_value
| 0
sequence_schema_id | 45035996273704976
sequence_id
| 45035996273719488
owner_id
| 45035996273704962
identity_table_id
| 45035996273719486
For more information about sequences and identity columns, see Using Named Sequences.
COMMENTS
Returns information about comments associated with objects in the database.
Column Name
Data Type
Description
COMMENT_ID
INTEGER
OBJECT_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
OBJECT_TYPE
VARCHAR
COLUMN
CONSTRAINT
FUNCTION
LIBRARY
NODE
PROJECTION
SCHEMA
SEQUENCE
TABLE
VIEW
OBJECT_SCHEMA
VARCHAR
OBJECT_NAME
VARCHAR
OWNER_ID
VARCHAR
OWNER_NAME
VARCHAR
CREATION_TIME
LAST_MODIFIED_TIME
COMMENT
VARCHAR
CONSTRAINT_COLUMNS
Records information about table column constraints.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CONSTRAINT_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
COLUMN_NAME
VARCHAR
CONSTRAINT_NAME
VARCHAR
CONSTRAINT_TYPE
CHAR
Is one of:
REFERENCE_TABLE_ID
INTEGER
f foreign
n not null
p primary
u unique
d determines
REFERENCE_TABLE_SCHEMA
VARCHAR
REFERENCE_TABLE_NAME
VARCHAR
REFERENCE_COLUMN_NAME
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
SQLReference Manual
HP Vertica System Tables
DATABASES
Provides information about the databases in this HP Vertica installation.
Column Name
Data Type
Description
DATABASE_ID
INTEGER
DATABASE_NAME
VARCHAR
OWNER_ID
INTEGER
OWNER_NAME
INTEGER
START_TIME
TIMESTAMPTZ
COMPLIANCE_MESSAGE
VARCHAR
EXPORT_SUBNET
VARCHAR
LOAD_BALANCE_POLICY
VARCHAR
DUAL
DUAL is a single-column "dummy" table with one record whose value is X; for example:
=> SELECT * FROM DUAL;
dummy
------X
(1 row)
SQLReference Manual
HP Vertica System Tables
(1 row)
=> SELECT current_timestamp, current_user FROM dual;
?column?
| current_user
-------------------------------+-------------2010-03-08 12:57:32.065841-05 | release
(1 row)
=> CREATE TABLE t1(col1 VARCHAR(20), col2 VARCHAR(2));
=> INSERT INTO T1(SELECT 'hello' AS col1, 1 AS col2 FROM dual);)
=> SELECT * FROM t1;
col1 | col2
-------+-----hello | 1
(1 row
Because DUAL is a system table, you cannot create projections for it. You also cannot use it in
pre-join projections for table objects. For example, assuming the following table schema (CREATE
TABLE t1 (col1 varchar(20), col2 varchar(2));) both of the following statements are not
permitted and will return errors:
=> CREATE PROJECTION t1_prejoin AS SELECT * FROM t1 JOIN dual
ON t1.col1 = dual.dummy;
ERROR: Virtual tables are not allowed in FROM clause of projection
=> CREATE PROJECTION dual_proj AS SELECT * FROM dual;
ERROR: Virtual tables are not allowed in FROM clause of projection
ELASTIC_CLUSTER
Returns information about cluster elasticity, such as whether Elastic Cluster is running.
Column Name
Data Type
Description
SCALING_FACTOR
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
MAXIMUM_SKEW_PERCENT
INTEGER
SEGMENT_LAYOUT
VARCHAR
LOCAL_SEGMENT_LAYOUT
VARCHAR
VERSION
INTEGER
IS_ENABLED
BOOLEAN
IS_LOCAL_SEGMENT_ENABLED
BOOLEAN
IS_REBALANCE_RUNNING
BOOLEAN
Permissions
Must be a superuser.
Example
=> SELECT * FROM elastic_cluster;
-[ RECORD 1 ]------------+------------------------------------------------scaling_factor
| 4
maximum_skew_percent
| 15
segment_layout
| v_myvdb_node0004[33.3%] v_myvdb_node0005[33.3%]
| v_myvdb_node0006[33.3%]
SQLReference Manual
HP Vertica System Tables
local_segment_layout
|
|
|
|
|
|
version
|
is_enabled
|
is_local_segment_enabled |
is_rebalance_running
|
v_myvdb_node0004[8.3%]
v_myvdb_node0004[8.3%]
v_myvdb_node0005[8.3%]
v_myvdb_node0005[8.3%]
v_myvdb_node0006[8.3%]
v_myvdb_node0006[8.3%]
1
t
f
f
v_myvdb_node0004[8.3%]
v_myvdb_node0004[8.3%]
v_myvdb_node0005[8.3%]
v_myvdb_node0005[8.3%]
v_myvdb_node0006[8.3%]
v_myvdb_node0006[8.3%]
See Also
l
ENABLE_ELASTIC_CLUSTER
DISABLE_ELASTIC_CLUSTER
Elastic Cluster
EPOCHS
For all epochs, provides the date and time of the close and the corresponding epoch number of the
closed epoch. This information lets you determine which time periods pertain to which epochs.
Column Name
Data Type
Description
EPOCH_CLOSE_TIME
EPOCH_NUMBER
INTEGER
Example
=> SELECT * FROM epochs;
epoch_close_time
| epoch_number
-------------------------------+-------------2012-11-14 09:26:10.696296-05 |
0
2012-11-14 10:04:55.668457-05 |
1
2012-11-14 10:08:05.963606-05 |
2
(3 rows)
See Also
l
SQLReference Manual
HP Vertica System Tables
FAULT_GROUPS
View the fault groups and their hierarchy in the cluster.
Column Name
Data Type
Description
MEMBER_ID
INTEGER
MEMBER_TYPE
VARCHAR
MEMBER_NAME
VARCHAR
PARENT_ID
INTEGER
PARENT_TYPE
VARCHAR
Nodes
PARENT_NAME
VARCHAR
FAULTGROUP
DATABASE
IS_AUTOMATICALLY_GENERATED
BOOLEAN
SQLReference Manual
HP Vertica System Tables
Example
The following example shows the current hierarchy of the fault groups in the cluster:
vmartdb=> SELECT member_type, member_name, parent_type, CASE
WHEN parent_type = 'DATABASE' THEN ''
ELSE parent_name END FROM fault_groups
ORDER BY member_name;
member_type | member_name | parent_type | parent_name
-------------+-------------+-------------+------------NODE
| node01
| FAULT GROUP | two
NODE
| node02
| FAULT GROUP | two
NODE
| node03
| FAULT GROUP | three
FAULT GROUP | one
| DATABASE
|
FAULT GROUP | three
| DATABASE
|
FAULT GROUP | two
| FAULT GROUP | one
This example queries the ELASTIC_CLUSTER system table to view the distribution of the
segment layout.
vmartdb=> SELECT segment_layout from elastic_cluster;
segment_layout
------------------------------------------------------------------------v_vmart_node0001[33.3%] v_vmart_node0003[33.3%] v_vmart_node0004[33.3%]
(1 row)
See Also
High Availability With Fault Groups in the Concepts Guide
Fault Groups in the Administrator's Guide
FOREIGN_KEYS
Provides foreign key information.
Column Name
Data Type
Description
CONSTRAINT_ID
INTEGER
CONSTRAINT_NAME
VARCHAR
COLUMN_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ORDINAL_POSITION
VARCHAR
TABLE_NAME
VARCHAR
REFERENCE_TABLE_NAME
VARCHAR
CONSTRAINT_TYPE
VARCHAR
REFERENCE_COLUMN_NAME
VARCHAR
TABLE_SCHEMA
VARCHAR
REFERENCE_TABLE_SCHEMA
VARCHAR
Example
mydb=> SELECT
constraint_name,
table_name,
ordinal_position,
reference_table_name
FROM foreign_keys ORDER BY 3;
constraint_name
|
table_name
| ordinal_position | reference_table_name
---------------------------+-------------------+------------------+---------------------fk_store_sales_date
| store_sales_fact |
1 | date_dimension
fk_online_sales_saledate | online_sales_fact |
1 | date_dimension
fk_store_orders_product
| store_orders_fact |
1 | product_dimension
fk_inventory_date
| inventory_fact
|
1 | date_dimension
fk_inventory_product
| inventory_fact
|
2 | product_dimension
fk_store_sales_product
| store_sales_fact |
2 | product_dimension
fk_online_sales_shipdate | online_sales_fact |
2 | date_dimension
fk_store_orders_product
| store_orders_fact |
2 | product_dimension
fk_inventory_product
| inventory_fact
|
3 | product_dimension
fk_store_sales_product
| store_sales_fact |
3 | product_dimension
fk_online_sales_product
| online_sales_fact |
3 | product_dimension
fk_store_orders_store
| store_orders_fact |
3 | store_dimension
fk_online_sales_product
| online_sales_fact |
4 | product_dimension
fk_inventory_warehouse
| inventory_fact
|
4 | warehouse_dimension
fk_store_orders_vendor
| store_orders_fact |
4 | vendor_dimension
fk_store_sales_store
| store_sales_fact |
4 | store_dimension
fk_store_orders_employee | store_orders_fact |
5 | employee_dimension
fk_store_sales_promotion | store_sales_fact |
5 | promotion_dimension
fk_online_sales_customer | online_sales_fact |
5 | customer_dimension
fk_store_sales_customer
| store_sales_fact |
6 | customer_dimension
SQLReference Manual
HP Vertica System Tables
fk_online_sales_cc
fk_store_sales_employee
fk_online_sales_op
fk_online_sales_shipping
fk_online_sales_warehouse
fk_online_sales_promotion
(26 rows)
|
|
|
|
|
|
online_sales_fact
store_sales_fact
online_sales_fact
online_sales_fact
online_sales_fact
online_sales_fact
|
|
|
|
|
|
6
7
7
8
9
10
|
|
|
|
|
|
call_center_dimension
employee_dimension
online_page_dimension
shipping_dimension
warehouse_dimension
promotion_dimension
GRANTS
Provides information about privileges granted on various objects, the granting user, and grantee
user. The order of columns in the table corresponds to the order in which they appear in the GRANT
command. The GRANTS table does not retain the role grantor.
Column Name
Data Type
Description
GRANT_ID
INTEGER
GRANTOR_ID
INTEGER
GRANTOR
VARCHAR
PRIVILEGES_DESCRIPTION
VARCHAR
OBJECT_SCHEMA
VARCHAR
OBJECT_NAME
VARCHAR
OBJECT_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
OBJECT_TYPE
VARCHAR
GRANTEE_ID
INTEGER
GRANTEE
VARCHAR
Notes
The vsql commands \dp and \z both include the schema name in the output; for example:
=> \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
| dbadmin | USAGE
|
| v_internal
| dbadmin | USAGE
|
| v_catalog
| dbadmin | USAGE
|
| v_monitor
| dbadmin | USAGE
|
| v_internal
| dbadmin | USAGE
|
| designer_system
(9 rows)
The vsql command \dp *.tablename displays table names in all schemas. This command lets
you distinguish grants for same-named tables in different schemas:
=> \dp *.events
Access privileges for database "dbadmin"
Grantee | Grantor |
Privileges
| Schema | Name
---------+---------+--------------------------------------------+---------+-------user2
| dbadmin | INSERT, SELECT, UPDATE, DELETE, REFERENCES | schema1 | events
user1
| dbadmin | SELECT
| schema1 | events
user2
| dbadmin | INSERT, SELECT, UPDATE, DELETE, REFERENCES | schema2 | events
user1
| dbadmin | INSERT, SELECT
| schema2 | events
(4 rows)
The vsql command \dp schemaname.* displays all tables in the named schema:
=> \dp schema1.*
SQLReference Manual
HP Vertica System Tables
Examples
This example shows CREATE and USAGE privileges granted to Bob in the fictitious apps
database:
=> SELECT grantor, privileges_description, object_schema, object_name, grantee
FROM grants;
grantor | privileges_description | object_schema | object_name | grantee
---------+------------------------+---------------+-------------+--------dbadmin | USAGE
|
| general
| Bob
dbadmin | CREATE
|
| schema2
| Bob
(2 rows)
This next query looks for privileges granted to a particular set of grantees. The asterisk in
privileges_description column for User1 means that user has WITH GRANT OPTION privileges.
=> SELECT grantor, privileges_description, object_schema, object_name, grantee
FROM grants WHERE grantee ILIKE 'User%';
grantor |
privileges_description | object_schema | object_name | grantee
---------+---------------------------+---------------+-------------+--------release | USAGE
|
| general
| User1
release | USAGE
|
| general
| User2
release | USAGE
|
| general
| User3
release | USAGE
|
| s1
| User1
release | USAGE
|
| s1
| User2
release | USAGE
|
| s1
| User3
User1
| INSERT*, SELECT*, UPDATE* | s1
| t1
| User1
(7 rows)
In the following example, online_sales is the schema that first gets privileges, and then inside that
schema the anchor table gets SELECT privileges:
=> SELECT grantee, grantor, privileges_description, object_schema, object_name
FROM grants WHERE grantee='u1' ORDER BY object_name;
SQLReference Manual
HP Vertica System Tables
SQLReference Manual
HP Vertica System Tables
See Also
l
HAS_ROLE
ROLES
USERS
HCATALOG_COLUMNS
Describes the columns of all tables available through the HCatalog Connector. Each row in this
table corresponds to to a column in a table accessible through the HCatalog Connector. See About
the HCatalog Connector in the Hadoop Integration Guide for more information.
Column Name
Data Type
Description
TABLE_SCHEMA
VARCHAR
(128)
HCATALOG_
VARCHAR
SCHEMA
(128)
TABLE_NAME
VARCHAR
(128)
IS_PARTITION_
BOOLEAN
VARCHAR
COLUMN
COLUMN_NAME
(128)
HCATALOG_DATA_
VARCHAR
TYPE
(128)
DATA_TYPE
VARCHAR
(128)
DATA_TYPE_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
DATA_TYPE_
INTEGER
INTEGER
LENGTH
CHARACTER_
MAXIMUM_LENGTH
NUMERIC_
it can hold
INTEGER
PRECISION
NUMERIC_SCALE
INTEGER
DATETIME_
INTEGER
PRECISION
INTERVAL_
column
INTEGER
PRECISION
ORDINAL_
INTEGER
POSITION
Permissions
No explicit permissions are required; however, users see only the records that correspond to
schemata they have permissions to access.
Notes
l
Querying this table results in one web service call to the WebHCat server for each table in each
HCatalog schema. Depending on the number of tables available through the HCatalog
Connector, querying this table takes a while.
If you need to perform multiple queries on this table in a short period of time, consider creating a
copy of the table using a CREATETABLEAS statement. The copy does not reflect any
changes made to the schema of the Hive tables after it was created, but it is much faster to
query.
Example
The following example demonstrates finding the column information for a specific table:
SQLReference Manual
HP Vertica System Tables
SQLReference Manual
HP Vertica System Tables
data_type_id
| 9
data_type_length
| 65000
character_maximum_length | 65000
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 4
-[ RECORD 5 ]------------+----------------table_schema
| hcat
hcatalog_schema
| default
table_name
| hcatalogtypes
is_partition_column
| f
column_name
| varcharcol
hcatalog_data_type
| string
data_type
| varchar(65000)
data_type_id
| 9
data_type_length
| 65000
character_maximum_length | 65000
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 5
-[ RECORD 6 ]------------+----------------table_schema
| hcat
hcatalog_schema
| default
table_name
| hcatalogtypes
is_partition_column
| f
column_name
| boolcol
hcatalog_data_type
| boolean
data_type
| boolean
data_type_id
| 5
data_type_length
| 1
character_maximum_length |
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 6
-[ RECORD 7 ]------------+----------------table_schema
| hcat
hcatalog_schema
| default
table_name
| hcatalogtypes
is_partition_column
| f
column_name
| timestampcol
hcatalog_data_type
| string
data_type
| varchar(65000)
data_type_id
| 9
data_type_length
| 65000
character_maximum_length | 65000
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 7
-[ RECORD 8 ]------------+----------------table_schema
| hcat
SQLReference Manual
HP Vertica System Tables
hcatalog_schema
| default
table_name
| hcatalogtypes
is_partition_column
| f
column_name
| varbincol
hcatalog_data_type
| binary
data_type
| varbinary(65000)
data_type_id
| 17
data_type_length
| 65000
character_maximum_length | 65000
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 8
-[ RECORD 9 ]------------+----------------table_schema
| hcat
hcatalog_schema
| default
table_name
| hcatalogtypes
is_partition_column
| f
column_name
| bincol
hcatalog_data_type
| binary
data_type
| varbinary(65000)
data_type_id
| 17
data_type_length
| 65000
character_maximum_length | 65000
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 9
See Also
l
HCATALOG_SCHEMATA
HCATALOG_TABLES
HCATALOG_TABLE_LIST
HCATALOG_SCHEMATA
Lists all of the schemata (plural of schema) defined using the HCatalog Connector. See Using the
HCatalog Connector in the Hadoop Integration Guide.
Column Name
Data Type
Description
SCHEMA_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SCHEMA_NAME
VARCHAR
(128)
Database catalog
INTEGER
SCHEMA_
OWNER_ID
SCHEMA_
VARCHAR
OWNER
(128)
schema's owner
CREATE_TIME
HOSTNAME
VARCHAR
(128)
INTEGER
PORT
VARCHAR
HOSTNAME
(128)
WEBSERVICE_
INTEGER
PORT
for connections
HCATALOG_
VARCHAR
SCHEMA_NAME
(128)
HCATALOG_
VARCHAR
USER_NAME
(128)
METASTORE_
VARCHAR
DB_NAME
(128)
Permissions
No explicit permissions are required; however, users see only the records that correspond to
schemata they have permissions to access.
Notes
Unlike other HCatalog Connector-related system tables, this table does not make any calls to the
WebHCat server. Therefore querying incurs very little overhead.
SQLReference Manual
HP Vertica System Tables
Example
=> \x
Expanded display is on.
dbadmin=> SELECT * FROM HCATALOG_SCHEMATA;
-[ RECORD 1 ]--------+----------------------------schema_id
| 45035996273864536
schema_name
| hcat
schema_owner_id
| 45035996273704962
schema_owner
| dbadmin
create_time
| 2013-11-05 10:19:54.70965-05
hostname
| hcathost
port
| 9083
webservice_hostname | hcathost
webservice_port
| 50111
hcatalog_schema_name | default
hcatalog_user_name
| hive
metastore_db_name
| hivemetastoredb
See Also
l
HCATALOG_COLUMNS
HCATALOG_TABLE_LIST
HCATALOG_TABLES
HCATALOG_TABLES
Detailed list of all tables made available through the HCatalog Connector. See Using the HCatalog
Connector in the Hadoop Integration Guide.
Column Name
Data Type
Description
TABLE_
INTEGER
VARCHAR
(128)
HCATALOG_
VARCHAR
SCHEMA
(128)
the table
TABLE_NAME
VARCHAR
SCHEMA_ID
TABLE_SCHEMA
(128)
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
HCATALOG_
VARCHAR
USER_NAME
(128)
MIN_FILE_SIZE_
INTEGER
INTEGER
BYTES
TOTAL_
NUMBER_FILES
LOCATION
LAST_UPDATE_
HDFS
VARCHAR
(8192)
normally an HDFSURI
TIME
OUTPUT_
VARCHAR
FORMAT
(128)
table
LAST_ACCESS_
TIME
MAX_FILE_SIZE_
INTEGER
IS_PARTITIONED
BOOLEAN
PARTITION_
VARCHAR
EXPRESSION
(128)
TABLE_OWNER
VARCHAR
BYTES
The Hive user that owns this table in the Hive database
(128)
INPUT_FORMAT
VARCHAR
The SerDe class used to read the data from this table
(128)
TOTAL_FILE_
INTEGER
SIZE_BYTES
HCATALOG_
VARCHAR
GROUP
(128)
PERMISSION
VARCHAR
(128)
the ls -l command
SQLReference Manual
HP Vertica System Tables
Permissions
No explicit permissions are required; however, users see only the records that correspond to
schemata they have permissions to access.
Notes
Querying this table results in Vertica Analytic Database making one REST function call to
WebHCatfor each table in all of the schemata available through the HCatalog Connector. This
means that querying this table may take a long while, depending on the number tables and number
of HCatalog schemata.
Example
The following example demonstrates querying HCATALOG_TABLES to view a single table's
details:
=> \x
Expanded display is on.
=> SELECT * FROM HCATALOG_TABLES WHERE table_name = 'msgjson';
-[ RECORD 1 ]---------+----------------------------------------------------------table_schema_id
| 45035996273864536
table_schema
| hcat
hcatalog_schema
| default
table_name
| msgjson
hcatalog_user_name
| hcatuser
min_file_size_bytes
| 13524
total_number_files
| 10
location
| hdfs://hive.example.com:8020/user/exampleuser/msgjson
last_update_time
| 2013-11-05 14:18:07.625-05
output_format
| org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
last_access_time
| 2013-11-11 13:21:33.741-05
max_file_size_bytes
| 45762
is_partitioned
| f
partition_expression |
table_owner
| hcatuser
input_format
| org.apache.hadoop.mapred.TextInputFormat
total_file_size_bytes | 453534
hcatalog_group
| supergroup
permission
| rwxr-xr-x
See Also
l
HCATALOG_SCHEMATA
HCATALOG_COLUMNS
SQLReference Manual
HP Vertica System Tables
HCATALOG_TABLE_LIST
HCATALOG_TABLE_LIST
A concise list of all tables contained in all Hive schemata and databases available through the
HCatalog Connector. See Using the HCatalog Connector in the Hadoop Integration Guide.
Column Name
Data Type
Description
TABLE_SCHEMA_
INTEGER
VARCHAR
(128)
HCATALOG_
VARCHAR
SCHEMA
(128)
TABLE_NAME
VARCHAR
ID
TABLE_SCHEMA
(128)
HCATALOG_
VARCHAR
USER_NAME
(128)
Permissions
No explicit permissions are required; however, users see only the records that correspond to
schemata they have permissions to access.
Notes
l
Querying this table results in one call to WebHCat for each Hive schema defined using the
HCatalog Connector. This means that the query usually takes longer than querying other
system tables.
SQLReference Manual
HP Vertica System Tables
Example
The following example demonstrates defining a new HCatalog schema then querying HCATALOG_
TABLE_LIST. Note that one table defined in a different HCatalog schema also appears. The
HCATALOGTABLE_LISTlists all of the tables available in any of the HCatalog schemata:
=> CREATE HCATALOG SCHEMA hcat WITH hostname='hcathost'
-> HCATALOG_SCHEMA='default' HCATALOG_DB='default' HCATALOG_USER='hcatuser';
CREATE SCHEMA
=> \x
Expanded display is on.
=> SELECT * FROM v_catalog.hcatalog_table_list;
-[ RECORD 1 ]------+-----------------table_schema_id
| 45035996273748980
table_schema
| hcat
hcatalog_schema
| default
table_name
| weblogs
hcatalog_user_name | hcatuser
-[ RECORD 2 ]------+-----------------table_schema_id
| 45035996273748980
table_schema
| hcat
hcatalog_schema
| default
table_name
| tweets
hcatalog_user_name | hcatuser
-[ RECORD 3 ]------+-----------------table_schema_id
| 45035996273748980
table_schema
| hcat
hcatalog_schema
| default
table_name
| messages
hcatalog_user_name | hcatuser
-[ RECORD 4 ]------+-----------------table_schema_id
| 45035996273864948
table_schema
| hiveschema
hcatalog_schema
| default
table_name
| weblogs
hcatalog_user_name | hcatuser
See Also
l
HCATALOG_COLUMNS
HCATALOG_SCHEMATA
HCATALOG_TABLES
LARGE_CLUSTER_CONFIGURATION_STATUS
Shows the current cluster nodes and control node (spread hosts) designations in the Catalog so you
can see if they match.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SPREAD_HOST_NAME
VARCHAR
CONTROL_NODE_NAME
VARCHAR
See Also
Large Cluster in the Administrator's Guide
LICENSE_AUDITS
Lists the results of HP Vertica's license automatic compliance audits. See How HP Vertica
Calculates Database Size in the Administrator's Guide.
Column Name
Data Type
Description
DATABASE_SIZE_BYTES
INTEGER
LICENSE_SIZE_BYTES
INTEGER
USAGE_PERCENT
FLOAT
AUDIT_START_TIMESTAMP
TIMESTAMPTZ
AUDIT_END_TIMESTAMP
TIMESTAMPTZ
CONFIDENCE_LEVEL_PERCENT
FLOAT
ERROR_TOLERANCE_PERCENT
FLOAT
USED_SAMPLING
BOOLEAN
CONFIDENCE_INTERVAL_LOWER_BOUND_BYTES
INTEGER
CONFIDENCE_INTERVAL_UPPER_BOUND_BYTES
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SAMPLE_COUNT
INTEGER
CELL_COUNT
INTEGER
LICENSE_NAME
VARCHAR
LICENSES
For all licenses, provides information information on license types, the dates for which licenses are
valid, and the limits the licenses impose.
Column Name
Data Type
Description
LICENSE_ID
INTEGER
NAME
VARCHAR
LICENSEE
VARCHAR
START_DATE
VARCHAR
END_DATE
VARCHAR
The end date until which the license is valid (or "Perpetual"
if the license has no expiration).
SIZE
VARCHAR
IS_COMMUNITY_EDITION
BOOLEAN
NODE_RESTRICTION
VARCHAR
Example
=> \x
Expanded display is on.
=> SELECT * FROM licenses;
-[ RECORD 1 ]--------+---------------------------------------license_id
| 45035996273704986
name
| vertica
SQLReference Manual
HP Vertica System Tables
licensee
| Vertica Community Edition
start_date
| 2011-11-22
end_date
| Perpetual
size
| 1TB
is_community_edition | t
node_restriction
| 3
-[ RECORD 2 ]--------+---------------------------------------license_id
| 45035996274085644
name
| com.vertica.flextable
licensee
| Vertica Community Edition, Flextable
start_date
| 2013-10-29
end_date
| Perpetual
size
| 1TB
is_community_edition | t
node_restriction
|
MATERIALIZE_FLEXTABLE_COLUMNS_RESULTS
Returns the results after you run the flex table function, MATERIALIZE_FLEXTABLE_COLUMNS.
The system table includes the following information:
Column
Name
Data Type
Description
TABLE_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_NAME
VARCHAR
CREATION_TIME
VARCHAR
KEY_NAME
VARCHAR
The end date until which the license is valid (or "Perpetual" if the
license has no expiration).
STATUS
VARCHAR
ADDED
EXISTS
ERROR
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
MESSAGE
BOOLEAN
Added successfully
Column of same name already exists in table
definition
Add operation failed
--or-l
Example
ddbt=> SELECT table_name, creation_time, key_name, status, message
FROM v_catalog.materialize_flextable_columns_results WHERE table_name = 'twitter_r';
table_name |
creation_time
|
key_name
| status |
message
------------+-------------------------------+-------------------+--------+------------------------------------------------------twitter_r | 2013-11-20 17:00:27.945484-05 | contributors
| ADDED | Added
successfully
twitter_r | 2013-11-20 17:00:27.94551-05 | entities.hashtags | ADDED | Added
successfully
twitter_r | 2013-11-20 17:00:27.945519-05 | entities.urls
| ADDED | Added
successfully
twitter_r | 2013-11-20 17:00:27.945532-05 | created_at
| EXISTS | Column of same
name already exists in table definition
(4 rows)
NODES
Lists details about the nodes in the database.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
(128)
NODE_ID
INT
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_STATE
VARCHAR
(128)
NODE_ADDRESS
VARCHAR
(80)
NODE_ADDRESS_FAMILY
EXPORT_ADDRESS
VARCHAR
(10)
ipv4.
VARCHAR
(8192)
EXPORT_ADDRESS_FAMILY
CATALOG_PATH
VARCHAR
(10)
ipv4.
VARCHAR
(8192)
NODE_TYPE
VARCHAR(9)
IS_EPHEMERAL
BOOLEAN
STANDING_IN_FOR
NODE_DOWN_SINCE
VARCHAR
(128)
replacing.
TIMESTAMPZ The amount of time that the replaced node has been
unavailable.
Examples
This example shows a typical list of nodes and their settings.
dbadmin=> \x
Expanded display is on.
dbadmin=> select * from nodes;
-[ RECORD 1 ]---------+----------------------------------------------------node_name
| v_vmart_node0001
node_id
| 45035996273704980
node_state
| UP
SQLReference Manual
HP Vertica System Tables
node_address
| 10.20.100.247
node_address_family
| ipv4
export_address
| 10.20.100.247
export_address_family | ipv4
catalog_path
| /home/dbadmin/VMart/v_vmart_node0001_catalog/Catalog
node_type
| PERMANENT
is_ephemeral
| f
standing_in_for
|
node_down_since
|
-[ RECORD 2 ]---------+----------------------------------------------------node_name
| v_vmart_node0002
node_id
| 45035996273723010
node_state
| UP
node_address
| 10.20.100.248
node_address_family
| ipv4
export_address
| 10.20.100.248
export_address_family | ipv4
catalog_path
| /home/dbadmin/VMart/v_vmart_node0002_catalog/Catalog
node_type
| PERMANENT
is_ephemeral
| f
standing_in_for
|
node_down_since
|
-[ RECORD 3 ]---------+----------------------------------------------------node_name
| v_vmart_node0003
node_id
| 45035996273723014
node_state
| UP
node_address
| 10.20.100.249
node_address_family
| ipv4
export_address
| 10.20.100.249
export_address_family | ipv4
catalog_path
| /home/dbadmin/VMart/v_vmart_node0003_catalog/Catalog
node_type
| PERMANENT
is_ephemeral
| f
standing_in_for
|
node_down_since
|
ODBC_COLUMNS
Provides table column information. The format is defined by the ODBC standard for the ODBC
SQLColumns metadata. Details on the ODBC SQLColumns format are available in the ODBC
specification: http://msdn.microsoft.com/enus/library/windows/desktop/ms711683%28v=vs.85%29.aspx.
Column Name
Data Type
Description
SCHEMA_NAME
VARCHAR
TABLE_NAME
VARCHAR
COLUMN_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
DATA_TYPE
INTEGER
The data type of the column. This can be an ODBC SQL data
type or a driver-specific SQL data type. This column
corresponds to the ODBC_TYPE column in the TYPES table.
DATA_TYPE_NAME
VARCHAR
COLUMN_SIZE
INTEGER
BUFFER_LENGTH
INTEGER
DECIMAL_DIGITS
INTEGER
NUM_PREC_RADIX
INTEGER
NULLABLE
BOOLEAN
REMARKS
VARCHAR
COLUMN_DEFAULT
VARCHAR
SQL_TYPE_ID
INTEGER
SQL_DATETIME_SUB
VARCHAR
CHAR_OCTET_LENGTH
INTEGER
ORDINAL_POSITION
INTEGER
IS_NULLABLE
VARCHAR
IS_IDENTITY
BOOLEAN
SQLReference Manual
HP Vertica System Tables
Example
dbadmin=> SELECT schema_name, table_name,data_type_name
FROM odbc_columns
LIMIT 2;
schema_name |
table_name
| data_type_name
-------------+---------------------------+---------------v_monitor
| execution_engine_profiles | Boolean
v_monitor
| query_profiles
| Boolean
(2 rows)
PASSWORD_AUDITOR
This system table contains information about individual users and their password information.This
table also indicates if users are using hash authentication, which is the associated security
algorithm.
Column Name
Data Type
Description
USER_ID
INTEGER
USER_NAME
VARCHAR
PASSWORD
VARCHAR
ACCTEXPIRED
BOOLEAN
SECURITY_ALGORITHM
VARCHAR
'MD5'
'SHA512'
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SYSTEM_SECURITY_ALGORITHM
VARCHAR
System-level security
algorithm for hash
authentication.
Default value:
'NONE' (Uses MD5 algorithm.)
Valid values:
EFFECTIVE_SECURITY_ALGORITHM
VARCHAR
'MD5'
'SHA512'
Examples
This example shows all the user password information from the PASSWORD_AUDITOR table.
=> SELECT * FROM PASSWORD_AUDITOR;
-[ RECORD 1 ]----------------+-------------------------------------------------------------------------------------------------------------------------------user_id
| 45035996273704962
user_name
| dbadmin
password
|
acctexpired
| f
security_algorithm
| NONE
system_security_algorithm
| MD5
effective_security_algorithm | MD5
-[ RECORD 2 ]----------------+-------------------------------------------------------------------------------------------------------------------------------user_id
| 45035996274849932
user_name
| user1
password
| sha512ac6937e18a55e08a30cd6aef28548eee4d48f70b443
8469d2045b413fa5e6ce4811e631e5a5c4d574af85106738f4fff360d19da7a8736e7ac1626d62b
acctexpired
| f
security_algorithm
| SHA512
system_security_algorithm
| MD5
effective_security_algorithm | SHA512
-[ RECORD 3 ]----------------+-------------------------------------------------------------------------------------------------------------------------------user_id
| 45035996274849952
user_name
| user2
SQLReference Manual
HP Vertica System Tables
password
acctexpired
security_algorithm
system_security_algorithm
effective_security_algorithm
|
|
|
|
|
t
MD5
MD5
MD5
PASSWORDS
Contains user passwords information. This table stores not only current passwords, but also past
passwords if any profiles have PASSWORD_REUSE_TIME or PASSWORD_REUSE_MAX parameters set.
See CREATE PROFILE for details.
Column Name
Data Type
Description
USER_ID
INTEGER
USER_NAME
VARCHAR
PASSWORD
VARCHAR
PASSWORD_CREATE_TIME
DATETIME The date and time when the password was created.
IS_CURRENT_PASSWORD
BOOLEAN
Denotes whether this is the user's current password. Noncurrent passwords are retained to enforce password reuse
limitations.
PROFILE_ID
INTEGER
PROFILE_NAME
VARCHAR
PASSWORD_REUSE_MAX
VARCHAR
PASSWORD_REUSE_TIME
VARCHAR
PRIMARY_KEYS
Provides primary key information.
Column Name
Data Type
Description
CONSTRAINT_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CONSTRAINT_NAME
VARCHAR
COLUMN_NAME
VARCHAR
ORDINAL_POSITION
VARCHAR
TABLE_NAME
VARCHAR
CONSTRAINT_TYPE
VARCHAR
TABLE_SCHEMA
VARCHAR
Example
Request specific columns from the PRIMARY_KEYS table:
=> SELECT constraint_name, table_name, ordinal_position, table_schema
FROM primary_keys ORDER BY 3;
constraint_name |
table_name
| ordinal_position | table_schema
-----------------+-----------------------+------------------+-------------C_PRIMARY
| customer_dimension
|
1 | public
C_PRIMARY
| product_dimension
|
1 | public
C_PRIMARY
| store_dimension
|
1 | store
C_PRIMARY
| promotion_dimension
|
1 | public
C_PRIMARY
| date_dimension
|
1 | public
C_PRIMARY
| vendor_dimension
|
1 | public
C_PRIMARY
| employee_dimension
|
1 | public
C_PRIMARY
| shipping_dimension
|
1 | public
C_PRIMARY
| warehouse_dimension
|
1 | public
C_PRIMARY
| online_page_dimension |
1 | online_sales
C_PRIMARY
| call_center_dimension |
1 | online_sales
C_PRIMARY
| product_dimension
|
2 | public
(12 rows)
PROFILE_PARAMETERS
Defines what information is stored in profiles.
Column Name Data Type
Description
PROFILE_ID
INTEGER
PROFILE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Description
PARAMETER_TYPE
VARCHAR
password_security, etc.)
PARAMETER_NAME
VARCHAR
PARAMETER_LIMIT
VARCHAR
PROFILES
Provides information about password policies that you set using the CREATE PROFILE
statement.
Column Name
Data Type
Description
PROFILE_ID
INTEGER
PROFILE_NAME
VARCHAR
PASSWORD_LIFE_TIME
VARCHAR
PASSWORD_GRACE_TIME
VARCHAR
PASSWORD_REUSE_MAX
VARCHAR
PASSWORD_REUSE_TIME
VARCHAR
FAILED_LOGIN_ATTEMPTS
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PASSWORD_LOCK_TIME
VARCHAR
PASSWORD_MAX_LENGTH
VARCHAR
PASSWORD_MIN_LENGTH
VARCHAR
PASSWORD_MIN_LETTERS
VARCHAR
PASSWORD_MIN_LOWERCASE_LETTERS
VARCHAR
PASSWORD_MIN_UPPERCASE_LETTERS
VARCHAR
PASSWORD_MIN_DIGITS
VARCHAR
PASSWORD_MIN_SYMBOLS
VARCHAR
Notes
Non-superusers querying this table see only the information for the profile to which they are
assigned.
See Also
l
CREATE PROFILE
ALTER PROFILE
PROJECTION_CHECKPOINT_EPOCHS
Records when each projection checkpoint epoch changes.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_ID
INTEGER
NODE_NAME
VARCHAR
PROJECTION_SCHEMA_ID
INTEGER
PROJECTION_SCHEMA
VARCHAR
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
IS_UP_TO_DATE
BOOLEAN
CHECKPOINT_EPOCH
INTEGER
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Examples
=> SELECT epoch FROM t;
epoch
------52
52
53
(3 rows)=> SELECT node_name, projection_schema, projection_name, is_up-to-date,
checkpoint_epoch
FROM projection_checkpoint_epochs;
node_name | projection_schema | projection_name | is_up_to_date | checkpoint_epoch
SQLReference Manual
HP Vertica System Tables
-----------+-------------------+------------------+---------------+-----------------node01
| public
| t_super
| t
| 51
node01
| public
| p_super
| t
| 51
(2 rows)
=> SELECT DO_TM_TASK('moveout','');
do_tm_task
-------------------------------------------------------------------------Task: moveout
(Table: public.t) (Projection: public.t_super)
(Table: public.p) (Projection: public.p_super)
(1 row)
=> SELECT node_name, projection_schema, projection_name, is_up-to-date, checkpoint_epoch
FROM projection_checkpoint_epochs;
node_name | projection_schema | projection_name | is_up_to_date | checkpoint_epoch
-----------+-------------------+-----------------+---------------+-----------------node01
| public
| t_super
| t
| 53
node01
| public
| p_super
| t
| 53
(2 rows)
PROJECTION_COLUMNS
Provides information about projection columns, such as encoding type, sort order, type of
statistics, and the time at which columns statistics were last updated.
Column Name
Data Type
Description
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
PROJECTION_COLUMN_NAME
VARCHAR
COLUMN_POSITION
INTEGER
SORT_POSITION
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
COLUMN_ID
INTEGER
DATA_TYPE
VARCHAR
ENCODING_TYPE
VARCHAR
ACCESS_RANK
INTEGER
GROUP_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
TABLE_COLUMN_ID
VARCHAR
TABLE_COLUMN_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
STATISTICS_TYPE
VARCHAR
NONENo statistics
STATISTICS_UPDATED_TIMESTAMP
IS_EXPRESSION
BOOLEAN
IS_AGGREGATE
BOOLEAN
PARTITION_BY_POSITION
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ORDER_BY_TYPE
INTEGER
COLUMN_EXPRESSION
VARCHAR
ASCNULLSFIRST
ASCNULLSLAST
DESCNULLSFIRST
DESCNULLSLAST
Examples
On a single-node cluster, the following sample schema defines a table named trades, which groups
the highly-correlated columns bid and ask and stores the stock column separately:
=> CREATE TABLE trades (stock CHAR(5), bid INT, ask INT);
=> CREATE PROJECTION trades_p (stock ENCODING RLE, GROUPED(bid ENCODING
DELTAVAL, ask)) AS (SELECT * FROM trades) ORDER BY stock, bid;
=> INSERT INTO trades VALUES('acme', 10, 20);
=> COMMIT;
Notice that the statistics_type column returns NONE for all three columns in the trades table.
Also, there is no value in the statistics_updated_timestamp field because statistics have not
yet been run on this table.
-[ RECORD 1 ]----------------+-------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| stock
column_position
| 0
sort_position
| 0
column_id
| 45035996273718840
data_type
| char(5)
encoding_type
| RLE
access_rank
| 0
group_id
| 0
table_schema
| public
table_id
| 45035996273718836
SQLReference Manual
HP Vertica System Tables
table_name
| trades
table_column_id
| 45035996273718836-1
table_column_name
| stock
statistics_type
| NONE
statistics_updated_timestamp |
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
-[ RECORD 2 ]----------------+-------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| bid
column_position
| 1
sort_position
| 1
column_id
| 45035996273718842
data_type
| int
encoding_type
| DELTAVAL
access_rank
| 0
group_id
| 45035996273718844
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-2
table_column_name
| bid
statistics_type
| NONE
statistics_updated_timestamp |
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
-[ RECORD 3 ]----------------+-------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| ask
column_position
| 2
sort_position
|
column_id
| 45035996273718846
data_type
| int
encoding_type
| AUTO
access_rank
| 0
group_id
| 45035996273718844
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-3
table_column_name
| ask
statistics_type
| NONE
statistics_updated_timestamp |
SQLReference Manual
HP Vertica System Tables
-[ RECORD 1 ]------+-ANALYZE_STATISTICS | 0
This time, statistics_type changes to FULL for the trades.stock column (representing full
statistics were run). The statistics_updated_timestamp column returns the time the stock
columns statistics were updated. The timestamp for the bid and ask columns have not changed
because statistics were not run on those columns. Also, the bid and ask columns changed from
NONE to ROWCOUNT because HP Vertica automatically updates ROWCOUNT statistics from
time to time. The statistics are created by looking at existing catalog metadata.
-[ RECORD 1 ]----------------+-----------------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| stock
column_position
| 0
sort_position
| 0
column_id
| 45035996273718840
data_type
| char(5)
encoding_type
| RLE
access_rank
| 0
group_id
| 0
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-1
table_column_name
| stock
statistics_type
| FULL
statistics_updated_timestamp | 2012-12-08 13:52:04.178294-05
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
-[ RECORD 2 ]----------------+-----------------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| bid
column_position
| 1
sort_position
| 1
column_id
| 45035996273718842
data_type
| int
encoding_type
| DELTAVAL
access_rank
| 0
group_id
| 45035996273718844
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-2
SQLReference Manual
HP Vertica System Tables
table_column_name
| bid
statistics_type
| ROWCOUNT
statistics_updated_timestamp | 2012-12-08 13:51:20.016465-05
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
-[ RECORD 3 ]----------------+-----------------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| ask
column_position
| 2
sort_position
|
column_id
| 45035996273718846
data_type
| int
encoding_type
| AUTO
access_rank
| 0
group_id
| 45035996273718844
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-3
table_column_name
| ask
statistics_type
| ROWCOUNT
statistics_updated_timestamp | 2012-12-08 13:51:20.016475-05
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
If you run statistics on the bid column and then query this system table again, only RECORD 2 is
updated:
=> SELECT ANALYZE_STATISTICS('trades.bid');
-[ RECORD 1 ]------+-ANALYZE_STATISTICS | 0
=> SELECT * FROM PROJECTION_COLUMNS where table_name = 'trades';
-[ RECORD 1 ]----------------+-----------------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| stock
column_position
| 0
sort_position
| 0
column_id
| 45035996273718840
data_type
| char(5)
encoding_type
| RLE
access_rank
| 0
group_id
| 0
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-1
table_column_name
| stock
SQLReference Manual
HP Vertica System Tables
statistics_type
| FULL
statistics_updated_timestamp | 2012-12-08 13:52:04.178294-05
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
-[ RECORD 2 ]----------------+-----------------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| bid
column_position
| 1
sort_position
| 1
column_id
| 45035996273718842
data_type
| int
encoding_type
| DELTAVAL
access_rank
| 0
group_id
| 45035996273718844
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-2
table_column_name
| bid
statistics_type
| FULL
statistics_updated_timestamp | 2012-12-08 13:53:23.438447-05
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
-[ RECORD 3 ]----------------+-----------------------------projection_id
| 45035996273718838
projection_name
| trades_p
projection_column_name
| ask
column_position
| 2
sort_position
|
column_id
| 45035996273718846
data_type
| int
encoding_type
| AUTO
access_rank
| 0
group_id
| 45035996273718844
table_schema
| public
table_id
| 45035996273718836
table_name
| trades
table_column_id
| 45035996273718836-3
table_column_name
| ask
statistics_type
| ROWCOUNT
statistics_updated_timestamp | 2012-12-08 13:51:20.016475-05
is_expression
| f
is_aggregate
| f
partition_by_position
|
order_by_type
|
column_expression
|
SQLReference Manual
HP Vertica System Tables
You can query just the timestamp column to see when the columns were updated:
=> \x
Expanded display is off.
=> SELECT ANALYZE_STATISTICS('trades');
ANALYZE_STATISTICS
-------------------0
(1 row)
=> SELECT projection_column_name, statistics_type,
statistics_updated_timestamp
FROM PROJECTION_COLUMNS where table_name = 'trades';
projection_column_name | statistics_type | statistics_updated_timestamp
------------------------+-----------------+------------------------------stock
| FULL
| 2012-12-08 13:54:27.428622-05
bid
| FULL
| 2012-12-08 13:54:27.428632-05
ask
| FULL
| 2012-12-08 13:54:27.428639-05
(3 rows)
If you have a projection with expressions, this example shows how to get the projection ID, column
name, and column expression from PROJECTION_COLUMNS:
=> SELECT projection_id, projection_column_name, column_expression
FROM projection_columns WHERE is_expression = 't';
projection_id
| projection_column_name |
column_expression
-------------------+------------------------+--------------------------45035996274382910 | click_date
| (clicks.click_time)::date
45035996274382910 | num_clicks
| count(*)
See Also
l
PROJECTIONS
ANALYZE_STATISTICS
CREATE PROJECTION
PROJECTION_DELETE_CONCERNS
Lists projections whose design may cause performance issues when deleting data. This table is
generated by calling the EVALUATE_DELETE_PERFORMANCE function. See Optimizing
Deletes and Updates for Performance in the Administrator's Guide for more information.
Column Name
Data Type
Description
PROJECTION_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PROJECTION_SCHEMA
VARCHAR
PROJECTION_NAME
VARCHAR
CREATION_TIME
LAST_MODIFIED_TIME
COMMENT
VARCHAR
PROJECTIONS
Provides information about projections.
Column
Name
Da
ta
Ty
pe
Description
PROJECTION_
SCHEMA_ID
INT
EGE
R
A unique numeric ID that identifies the specific schema that contains the
PROJECTION_
SCHEMA
VAR
CHA
R
PROJECTION_ID
INT
EGE
R
PROJECTION_
NAME
VAR
CHA
R
PROJECTION_
BASENAME
VAR
CHA
R
The base name used for other projections. For auto-created projections,
HP Vertica catalog.
OWNER_ID
OWNER_NAME
INT
EGE
R
VAR
CHA
R
SQLReference Manual
HP Vertica System Tables
Column
Name
ANCHOR_TABLE_
ID
Da
ta
Ty
pe
INT
EGE
R
Description
For pre-join projections, the unique numeric identification (OID) of the
anchor table. If the projection is not a pre-join projection, this value is the
OID of the table from which the projection was created.
A projection has only one anchor (fact) table.
ANCHOR_TABLE_
NAME
VAR
CHA
R
For pre-join projections, the name of the anchor table. If the projection is
not a pre-join projection, the name of the table from which the projection
was created.
NODE_ID
NODE_NAME
INT
EGE
R
A unique numeric ID (OID) for any nodes that contain any unsegmented
VAR
CHA
R
projections.
This column returns information for unsegmented projections only, not for
segmented and pinned projections.
IS_PREJOIN
CREATED_EPOCH
BOO
LEA
N
INT
EGE
R
f is false.
SQLReference Manual
HP Vertica System Tables
Column
Name
CREATE_TYPE
Da
ta
Ty
pe
VAR
CHA
R
Description
The method in which the projection was created:
l
INT
EGE
R
The projection K-safe value. This value can be greater than the database
K-safety value (if more replications of a projection exist than are required
to meet the database K-safety). This value cannot be less than the
database K-safe setting.
IS_UP_TO_DATE
BOO
LEA
N
SQLReference Manual
HP Vertica System Tables
Column
Name
HAS_
STATISTICS
Da
ta
Ty
pe
BOO
LEA
N
Description
Indicates whether there are statistics for any column in the projection,
where t is true and f is false.
l
This column returns true only when all non-epoch columns for a table
have full statistics. Otherwise, the column returns false. See
ANALYZE_STATISTICS().
Projections that have no data never have full statistics. Use the
PROJECTION_STORAGE system table to determine if your
projection contains data.
IS_SEGMENTED
SEGMENT_
EXRESSION
BOO
LEA
N
VAR
CHA
R
f is not.
SEGMENT_RANGE
VAR
CHA
R
IS_SUPER_
PROJECTION
BOO
LEA
N
HAS_
EXPRESSIONS
BOO
LEA
N
Indicates if the projection has expressions that define the column values,
where t is true and f is false. HAS_EXPRESSIONSis always true for live
aggregate projections.
IS_AGGREGATE_
PROJECTION
BOO
LEA
N
SQLReference Manual
HP Vertica System Tables
Column
Name
AGGREGATE_
TYPE
Da
ta
Ty
pe
VAR
CHA
R
Description
Indicates the type of live aggregate projection:
l
GROUPBY
TOPK
Examples
The following example shows how to query the PROJECTIONS table to find a specific live aggregate
projection:
SQLReference Manual
HP Vertica System Tables
See Also
l
ANALYZE_STATISTICS
PROJECTION_COLUMNS
PROJECTION_STORAGE
RESOURCE_POOL_DEFAULTS
Provides information about the default values for resource pools. Information is for both HP Verticainternal and DBA-created pools.
For any resource pool, you can restore default values contained in this table by simply using the
DEFAULT keyword in the ALTER_RESOURCE_POOL statement.
To see default values for resource pools:
VMart= > SELECT * FROM V_CATALOG.RESOURCE_POOL_DEFAULTS;
Permissions
No explicit permissions are required.
See Also
l
RESOURCE_POOLS
RESOURCE_POOLS
Displays information about the parameters specified for the resource pool in the CREATE
RESOURCE POOL statement.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NAME
VARCHAR
IS_INTERNAL
BOOLEAN
MEMORYSIZE
VARCHAR
MAXMEMORYSIZE
VARCHAR
EXECUTIONPARALLELISM
INTEGER
PRIORITY
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RUNTIMEPRIORITY
VARCHAR
HIGH
MEDIUM (Default)
LOW
INTEGER
QUEUETIMEOUT
INTEGER
PLANNEDCONCURRENCY
INTEGER
MAXCONCURRENCY
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RUNTIMECAP
INTERVAL
SINGLEINITIATOR
BOOLEAN
CPUAFFINITYSET
VARCHAR
CPUAFFINITYMODE
VARCHAR
CASCADETO
VARCHAR
SQLReference Manual
HP Vertica System Tables
Usage Considerations
Column names in the RESOURCE_POOL table mirror syntax in the CREATE RESOURCE POOL
statement. Therefore, column names do not use underscores.
Examples
This example shows how to view values set for various resource pools.
SQLReference Manual
HP Vertica System Tables
See Also
l
ROLES
Contains the names of all roles the user can access, along with any roles that have been assigned
to those roles.
Column
Name
Data Type
Description
ROLE_ID
INTEGER
NAME
VARCHAR
ASSIGNED_ROLES
VARCHAR
The names of any roles that have been granted to this role. By
enabling the role, the user also has access to the privileges of
these additional roles.
Note: If you see an asterisk in the ASSIGNED_ROLES column
output, it means the user has roles WITH ADMIN OPTION.
Tip: You can also use the HAS_ROLE() function to see if a role is available to a user.
Example
=> SELECT * FROM roles;
role_id
|
name
| assigned_roles
-------------------+-----------------+---------------45035996273704964 | public
|
45035996273704966 | dbduser
|
45035996273704968 | dbadmin
| dbduser*
45035996273704972 | pseudosuperuser | dbadmin*
45035996273704974 | logreader
|
45035996273704976 | logwriter
|
45035996273704978 | logadmin
| logreader, logwriter
(7 rows)
SQLReference Manual
HP Vertica System Tables
See Also
l
GRANTS
HAS_ROLE
USERS
SCHEMATA
Provides information about schemas in the database.
Column Name
Data Type
Description
SCHEMA_ID
INTEGER
SCHEMA_NAME
VARCHAR
SCHEMA_OWNER_ID
INTEGER
SCHEMA_OWNER
VARCHAR
SYSTEM_SCHEMA_CREATOR
VARCHAR
CREATE_TIME
IS_SYSTEM_SCHEMA
BOOLEAN
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> SELECT * FROM schemata;
-[ RECORD 1 ]---------+-----------------------------schema_id
| 8300
SQLReference Manual
HP Vertica System Tables
schema_name
| v_internal
schema_owner_id
| 45035996273704962
schema_owner
| dbadmin
system_schema_creator | dbadmin
create_time
| 2012-03-22 11:19:46.311825-04
is_system_schema
| t
-[ RECORD 2 ]---------+-----------------------------schema_id
| 8301
schema_name
| v_catalog
schema_owner_id
| 45035996273704962
schema_owner
| dbadmin
system_schema_creator | dbadmin
create_time
| 2012-03-22 11:19:46.311905-04
is_system_schema
| t
-[ RECORD 3 ]---------+-----------------------------schema_id
| 8302
schema_name
| v_monitor
schema_owner_id
| 45035996273704962
schema_owner
| dbadmin
system_schema_creator | dbadmin
create_time
| 2012-03-22 11:19:46.31193-04
is_system_schema
| t
-[ RECORD 4 ]---------+-----------------------------schema_id
| 45035996273704968
schema_name
| public
schema_owner_id
| 45035996273704962
schema_owner
| dbadmin
system_schema_creator |
create_time
| 2012-03-22 11:19:40.75002-04
is_system_schema
| f
SEQUENCES
Displays information about the parameters specified for a sequence using the CREATE
SEQUENCE statement.
Column Name
Data Type
Description
SEQUENCE_SCHEMA
VARCHAR
SEQUENCE_NAME
VARCHAR
OWNER_NAME
VARCHAR
IDENTITY_TABLE_NAME
VARCHAR
SESSION_CACHE_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ALLOW_CYCLE
BOOLEAN
OUTPUT_ORDERED
BOOLEAN
INCREMENT_BY
INTEGER
MINIMUM
INTEGER
MAXIMUM
INTEGER
CURRENT_VALUE
INTEGER
SEQUENCE_SCHEMA_ID
INTEGER
SEQUENCE_ID
INTEGER
OWNER_ID
INTEGER
IDENTITY_TABLE_ID
INTEGER
Examples
Create a simple sequence:
=> CREATE SEQUENCE my_seq MAXVALUE 5000 START 150;
CREATE SEQUENCE
SQLReference Manual
HP Vertica System Tables
allow_cycle
output_ordered
increment_by
minimum
maximum
current_value
sequence_schema_id
sequence_id
owner_id
identity_table_id
|
|
|
|
|
|
|
|
|
|
f
f
1
1
5000
149
45035996273704966
45035996273844996
45035996273704962
0
An identity column is a sequence available only for numeric column types. To identify what column
in a table, if any, is an identity column, search the COLUMNS table to find the identity column in a
table:
=> CREATE TABLE testid (c1 IDENTITY(1, 1, 1000), c2 INT);
=> \x
Expanded display is on.
=> SELECT * FROM COLUMNS WHERE is_identity='t' AND table_name='testid';
-[ RECORD 1 ]------------+-----------------table_id
| 45035996274150730
table_schema
| public
table_name
| testid
is_system_table
| f
column_name
| c1
data_type
| int
data_type_id
| 6
data_type_length
| 8
character_maximum_length |
numeric_precision
|
numeric_scale
|
datetime_precision
|
interval_precision
|
ordinal_position
| 1
is_nullable
| f
column_default
|
is_identity
| t
Use the SEQUENCES table to get detailed information about the sequence in testid:
=> SELECT * FROM sequences WHERE identity_table_name='testid';
-[ RECORD 1 ]-------+-------------------sequence_schema
| public
sequence_name
| testid_c1_seq
owner_name
| dbadmin
identity_table_name | testid
session_cache_count | 1000
allow_cycle
| f
output_ordered
| f
increment_by
| 1
minimum
| 1
maximum
| 9223372036854775807
current_value
| 0
SQLReference Manual
HP Vertica System Tables
sequence_schema_id
sequence_id
owner_id
identity_table_id
|
|
|
|
45035996273704976
45035996274150770
45035996273704962
45035996274150768
Use the vsql command \ds to return a list of sequences. The following results show the two
sequences created in the preceding examples. If more sequences existed, the table would list
them.
The CurrentValue of the new sequence is one less than the start number you specified in the
CREATE SEQUENCE and IDENTITY commands, because you have not yet used NEXTVAL to
instantiate the sequences to assign their cache or supply their first start values.
=> \ds
List of Sequences
-[ RECORD 1 ]+-------------------Schema
| public
Sequence
| my_seq
CurrentValue | 149
IncrementBy | 1
Minimum
| 1
Maximum
| 5000
AllowCycle
| f
Comment
|
-[ RECORD 2 ]+-------------------Schema
| public
Sequence
| testid_c1_seq
CurrentValue | 0
IncrementBy | 1
Minimum
| 1
Maximum
| 9223372036854775807
AllowCycle
| f
Comment
|
See Also
l
CREATE SEQUENCE
STORAGE_LOCATIONS
Provides information about storage locations, their IDs labels, and status.
Column
Name
Data Type
Description
LOCATION_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
NODE_NAME
VARCHAR
LOCATION_PATH
VARCHAR
LOCATION_USAGE
VARCHAR
IS_RETIRED
BOOLEAN
Whether the storage location has been retired. This column has a
value of t (true) if the location is retired, or f (false) if it is
not.
LOCATION_LABEL
VARCHAR
RANK
INTEGER
THROUGHPUT
INTEGER
LATENCY
INTEGER
SQLReference Manual
HP Vertica System Tables
Permissions
Must be a superuser.
Example
Query the STORAGE_LOCATIONS table on a one-node cluster database:
onenode=> SELECT * FROM storage_locations;
-[ RECORD 1 ]--+---------------------------------------------location_id
| 45035996273704982
node_name
| v_onenode_node0001
location_path | /home/dbadmin/onenode/v_onenode_node0001_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 0
throughput
| 0
latency
| 0
The next example uses the VMart example database (see Introducing the VMart Example
Database).
VMart=> \x
VMart=> select * from storage_locations;
-[ RECORD 1 ]--+---------------------------------------------location_id
| 45035996273704982
node_name
| v_onenode_node0001
location_path | /home/dbadmin/onenode/v_onenode_node0001_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 1
throughput
| 24
latency
| 38
-[ RECORD 2 ]--+---------------------------------------------location_id
| 45035996273356845
node_name
| v_onenode_node0001
location_path | /home/dbadmin/onenode/v_onenode_node0001_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 2
throughput
| 45
latency
| 42
-[ RECORD 3 ]--+---------------------------------------------location_id
| 45035996273713695
node_name
| v_onenode_node0001
location_path | /home/dbadmin/onenode/v_onenode_node0001_data
location_usage | DATA,TEMP
is_retired
| f
SQLReference Manual
HP Vertica System Tables
location_label |
rank
| 0
throughput
| 26
latency
| 24
-[ RECORD 4 ]--+---------------------------------------------location_id
| 45035996273734821
node_name
| v_onenode_node0002
location_path | /home/dbadmin/onenode/v_onenode_node0002_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 1
throughput
| 33
latency
| 31
-[ RECORD 5 ]--+---------------------------------------------location_id
| 45035996273757686
node_name
| v_onenode_node0002
location_path | /home/dbadmin/onenode/v_onenode_node0002_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 0
throughput
| 25
latency
| 23
-[ RECORD 6 ]--+---------------------------------------------location_id
| 45035996273767432
node_name
| v_onenode_node0002
location_path | /home/dbadmin/onenode/v_onenode_node0002_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 0
throughput
| 44
latency
| 35
-[ RECORD 7 ]--+---------------------------------------------location_id
| 45035996273789765
node_name
| v_onenode_node0002
location_path | /home/dbadmin/onenode/v_onenode_node0002_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 0
throughput
| 43
latency
| 36
-[ RECORD 8 ]--+---------------------------------------------location_id
| 45035996273777654
node_name
| v_onenode_node0003
location_path | /home/dbadmin/onenode/v_onenode_node0003_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 0
throughput
| 25
latency
| 34
-[ RECORD 9 ]--+---------------------------------------------location_id
| 45035996273799043
node_name
| v_onenode_node0003
location_path | /home/dbadmin/onenode/v_onenode_node0003_data
SQLReference Manual
HP Vertica System Tables
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 0
throughput
| 41
latency
| 43
-[ RECORD 10]--+---------------------------------------------location_id
| 45035996273799477
node_name
| v_onenode_node0003
location_path | /home/dbadmin/onenode/v_onenode_node0003_data
location_usage | DATA,TEMP
is_retired
| f
location_label |
rank
| 0
throughput
| 22
latency
| 21
(10 rows)
See Also
l
DISK_STORAGE
MEASURE_LOCATION_PERFORMANCE
SET_LOCATION_PERFORMANCE
STORAGE_POLICIES
STORAGE_USAGE
SYSTEM_COLUMNS
Provides table column information for SYSTEM_TABLES.
Column Name
Data Type
Description
TABLE_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
IS_SYSTEM_TABLE
BOOLEAN
COLUMN_ID
VARCHAR
COLUMN_NAME
VARCHAR
DATA_TYPE
VARCHAR
DATA_TYPE_ID
INTEGER
DATA_TYPE_LENGTH
INTEGER
CHARACTER_MAXIMUM_LENGTH
INTEGER
NUMERIC_PRECISION
INTEGER
NUMERIC_SCALE
INTEGER
DATETIME_PRECISION
INTEGER
INTERVAL_PRECISION
INTEGER
ORDINAL_POSITION
INTEGER
IS_NULLABLE
BOOLEAN
COLUMN_DEFAULT
VARCHAR
Example
=> SELECT table_schema, table_name, column_name, column_id, data_type
FROM system_columns
WHERE table_name = 'projection_columns' ORDER BY 1,2;
SQLReference Manual
HP Vertica System Tables
table_schema |
table_name
|
column_name
| column_id
|
data_
type
--------------+--------------------+------------------------------+-------------+-------------v_catalog
| projection_columns | statistics_updated_timestamp | 10038-17
|
timestamptz
v_catalog
| projection_columns | statistics_type
| 10038-16
| varchar
(8192)
v_catalog
| projection_columns | table_column_name
| 10038-15
| varchar
(128)
v_catalog
| projection_columns | table_column_id
| 10038-14
| varchar
(41)
v_catalog
| projection_columns | table_name
| 10038-13
| varchar
(128)
v_catalog
| projection_columns | table_id
| 10038-12
| int
v_catalog
| projection_columns | table_schema
| 10038-11
| varchar
(128)
v_catalog
| projection_columns | group_id
| 10038-10
| int
v_catalog
| projection_columns | access_rank
| 10038-9
| int
v_catalog
| projection_columns | encoding_type
| 10038-8
| varchar
(18)
v_catalog
| projection_columns | data_type
| 10038-7
| varchar
(128)
v_catalog
| projection_columns | column_id
| 10038-6
| int
v_catalog
| projection_columns | sort_position
| 10038-5
| int
v_catalog
| projection_columns | column_position
| 10038-4
| int
v_catalog
| projection_columns | projection_column_name
| 10038-3
| varchar
(128)
v_catalog
| projection_columns | projection_name
| 10038-2
| varchar
(128)
v_catalog
| projection_columns | projection_id
| 10038-1
| int
(17 rows)
SYSTEM_TABLES
Returns a list of all system table names.
Column Name
Data Type
Description
TABLE_SCHEMA_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
TABLE_DESCRIPTION
VARCHAR
SQLReference Manual
HP Vertica System Tables
Example
Select all the system tables and order them by schema:
=> SELECT * FROM system_tables ORDER BY 1, 2;
TABLE_CONSTRAINTS
Provides information about table constraints.
Column Name
Data Type
Description
CONSTRAINT_ID
VARCHAR
CONSTRAINT_NAME
VARCHAR
CONSTRAINT_SCHEMA_ID
INTEGER
CONSTRAINT_KEY_COUNT
INTEGER
FOREIGN_KEY_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
FOREIGN_TABLE_ID
INTEGER
CONSTRAINT_TYPE
INTEGER
Example
The following command returns constraint column names and types against the VMart schema.
vmartdb=> SELECT constraint_name, constraint_type FROM table_constraints
ORDER BY constraint_type;
constraint_name
| constraint_type
---------------------------+----------------fk_online_sales_promotion | f
fk_online_sales_warehouse | f
fk_online_sales_shipping | f
fk_online_sales_op
| f
fk_online_sales_cc
| f
fk_online_sales_customer | f
fk_online_sales_product
| f
fk_online_sales_shipdate | f
fk_online_sales_saledate | f
fk_store_orders_employee | f
fk_store_orders_vendor
| f
fk_store_orders_store
| f
fk_store_orders_product
| f
fk_store_sales_employee
| f
fk_store_sales_customer
| f
fk_store_sales_promotion | f
fk_store_sales_store
| f
fk_store_sales_product
| f
fk_store_sales_date
| f
fk_inventory_warehouse
| f
fk_inventory_product
| f
fk_inventory_date
| f
| p
| p
| p
| p
| p
| p
| p
| p
SQLReference Manual
HP Vertica System Tables
(33 rows)
| p
| p
| p
See Also
l
ANALYZE_CONSTRAINTS
TABLES
Provides information about all tables in the database.
Column Name
Data Type
Description
TABLE_SCHEMA_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
OWNER_ID
INTEGER
OWNER_NAME
VARCHAR
IS_TEMP_TABLE
BOOLEAN
IS_SYSTEM_TABLE
BOOLEAN
IS_FLEXTABLE
BOOLEAN
HAS_AGGREGATE_PROJECTION
BOOLEAN
SYSTEM_TABLE_CREATOR
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PARTITION_EXPRESSION
VARCHAR
CREATE_TIME
TABLE_DEFINITION
VARCHAR
Tips
The TABLE_SCHEMA and TABLE_NAME columns are case sensitive when you run queries that contain
the equality (=) predicate. Use the ILIKE predicate instead:
=> SELECT table_schema, table_name
FROM v_catalog.tables
WHERE table_schema ILIKE 'schema1';
Examples
This example shows how to find information for a specific table:
=> select * from tables where table_name='clicks';
-[ RECORD 1 ]------------+-----------------------------table_schema_id
| 45035996273704976
table_schema
| public
table_id
| 45035996274100286
table_name
| clicks
owner_id
| 45035996273704962
owner_name
| dbadmin
is_temp_table
| f
is_system_table
| f
is_flextable
| f
has_aggregate_projection | t
system_table_creator
|
partition_expression
|
create_time
| 2014-05-29 17:59:14.210069-04
table_definition
|
To return the timestamp that indicates when the tables were created, use the following table:
vmartdb=> SELECT table_schema, table_name, create_time FROM tables;
table_schema |
table_name
|
create_time
--------------+-----------------------+------------------------------public
| customer_dimension
| 2011-08-15 11:18:25.784203-04
public
| product_dimension
| 2011-08-15 11:18:25.815653-04
public
| promotion_dimension
| 2011-08-15 11:18:25.850592-04
SQLReference Manual
HP Vertica System Tables
public
public
public
public
public
public
store
store
store
online_sales
online_sales
online_sales
(15 rows)
|
|
|
|
|
|
|
|
|
|
|
|
date_dimension
vendor_dimension
employee_dimension
shipping_dimension
warehouse_dimension
inventory_fact
store_dimension
store_sales_fact
store_orders_fact
online_page_dimension
call_center_dimension
online_sales_fact
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
2011-08-15
11:18:25.892347-04
11:18:25.942805-04
11:18:25.966985-04
11:18:25.999394-04
11:18:26.461297-04
11:18:26.513525-04
11:18:26.657409-04
11:18:26.737535-04
11:18:26.825801-04
11:18:27.007329-04
11:18:27.476844-04
11:18:27.49749-04
To return information about whether certain tables are temporary and flex tables:
=> SELECT distinct table_name, table_schema, is_temp_table, is_flextable FROM v_
catalog.tables
WHERE table_name ILIKE 't%';
table_name | table_schema | is_temp_table | is_flextable
--------------+--------------+---------------+----------------t2_temp
| public
| t
| t
tt_keys
| public
| f
| f
t2_temp_keys | public
| f
| f
t3
| public
| t
| f
t1
| public
| f
| f
t9_keys
| public
| f
| f
t2_keys
| public
| f
| t
t6
| public
| t
| f
t5
| public
| f
| f
t2
| public
| f
| t
t8
| public
| f
| f
t7
| public
| t
| f
tt
| public
| t
| t
t2_keys_keys | public
| f
| f
t9
| public
| t
| t
(15 rows)
TYPES
Provides information about supported data types.
Note: This table was updated with new columns in Release 5.1.
Column
Name
Data Type
Description
TYPE_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
ODBC_TYPE
INTEGER
ODBC_
SUBTYPE
INTEGER
MIN_SCALE
INTEGER
MAX_SCALE
INTEGER
COLUMN_
SIZE
INTEGER
INTERVAL_
MASK
INTEGER
For data types that are intervals, the bitmask to determine the range
of the interval from the HP Vertica TYPE_ID. Details are available in
the HP Vertica SDK.
TYPE_NAME
VARCHAR
CREATION_ VARCHAR
PARAMETERS
The data type name associated with a particular data type ID.
A list of keywords, separated by commas, corresponding to each
parameter that the application may specify in parentheses when
using the name that is returned in the TYPE_NAME field. The
keywords in the list can be any of the following: length, precision, or
scale. They appear in the order that the syntax requires them to be
used.
Example
dbadmin=> \x
Expanded display is on.
dbadmin=> SELECT * FROM types LIMIT 3;
-[ RECORD 1 ]-------+-------------------------type_id
| 5
odbc_type
| -7
odbc_subtype
| 0
min_scale
| 0
max_scale
| 0
column_size
| 1
SQLReference Manual
HP Vertica System Tables
interval_mask
| 0
type_name
| Boolean
creation_parameters |
-[ RECORD 2 ]-------+-------------------------type_id
| 6
odbc_type
| -5
odbc_subtype
| 0
min_scale
| 0
max_scale
| 0
column_size
| 20
interval_mask
| 0
type_name
| Integer
creation_parameters |
-[ RECORD 3 ]-------+-------------------------type_id
| 7
odbc_type
| 8
odbc_subtype
| 0
min_scale
| 0
max_scale
| 0
column_size
| 15
interval_mask
| 0
type_name
| Float
creation_parameters | precision
USER_AUDITS
Lists the results of database and object size audits generated by users calling the AUDIT function.
See Monitoring Database Size for License Compliance in the Administrator's Guide for more
information.
Column Name
Data Type
Description
SIZE_BYTES
INTEGER
USER_ID
INTEGER
USER_NAME
VARCHAR
OBJECT_ID
INTEGER
OBJECT_TYPE
VARCHAR
OBJECT_SCHEMA
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
OBJECT_NAME
VARCHAR
AUDIT_START_TIMESTAMP
AUDIT_END_TIMESTAMP
CONFIDENCE_LEVEL_PERCENT
FLOAT
ERROR_TOLERANCE_PERCENT
FLOAT
USED_SAMPLING
BOOLEAN
CONFIDENCE_INTERVAL_LOWER_BOUND_BYTES
INTEGER
CONFIDENCE_INTERVAL_UPPER_BOUND_BYTES
INTEGER
SAMPLE_COUNT
INTEGER
CELL_COUNT
INTEGER
USER_CLIENT_AUTH
The USER_CLIENT_AUTHsystem table provides information about the client authentication
methods that you have associated with your database users. You associate an authentication
method with a user using GRANT(Authentication).
Column Name
Data Type
Description
USER_OID
INTEGER
USER_NAME
VARCHAR
AUTH_OID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
AUTH_NAME
VARCHAR
GRANTED_TO
BOOLEAN
Examples
This example shows the statement you use to retrieve information about each client authentication
that you have created:
=> SELECT * FROM USER_CLIENT_AUTH;
user_oid
| user_name |
auth_oid
| auth_name | granted_to
-------------------+-----------+-------------------+-----------+-----------45035996273704962 | dbadmin
| 45035996273741450 | v_md5
| dbadmin
45035996273741290 | jsmith
| 45035996273741304 | v_ident
| jsmith
45035996273741294 | bbrown
| 45035996273741304 | v_ident
| bbrown
45035996273741298 | jqadams
| 45035996273741304 | v_ident
| jqadams
(4 rows)
USER_FUNCTIONS
Returns metadata about user-defined SQL functions (which store commonly used SQL
expressions as a function in the HP Vertica catalog) and User Defined functions (UDx).
Column Name
Data Type
Description
SCHEMA_NAME
VARCHAR
FUNCTION_NAME
VARCHAR
PROCEDURE_TYPE
VARCHAR
FUNCTION_RETURN_TYPE
VARCHAR
FUNCTION_ARGUMENT_TYPE
VARCHAR
FUNCTION_DEFINITION
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
VOLATILITY
VARCHAR
IS_STRICT
BOOLEAN
IS_FENCED
BOOLEAN
COMMENT
VARCHAR
Notes
l
The volatility and strictness of a SQL function are automatically inferred from the function
definition in order that HP Vertica determine the correctness of usage, such as where an
immutable function is expected but a volatile function is provided.
Example
Create a SQL function called myzeroifnull in the public schema:
=> CREATE FUNCTION myzeroifnull(x INT) RETURN INT
AS BEGIN
RETURN (CASE WHEN (x IS NOT NULL) THEN x ELSE 0 END);
END;
Now query the USER_FUNCTIONS table. The query returns just the myzeroifnull macro because it
is the only one created in this schema:
=> SELECT * FROM user_functions;
-[ RECORD 1 ]----------+--------------------------------------------------schema_name
| public
function_name
| myzeroifnull
procedure_type
| User Defined Function
function_return_type
| Integer
function_argument_type | x Integer
function_definition
| RETURN CASE WHEN (x IS NOT NULL) THEN x ELSE 0 END
volatility
| immutable
is_strict
| f
is_fenced
| f
SQLReference Manual
HP Vertica System Tables
comment
See Also
l
ALTER FUNCTION
DROP FUNCTION
USER_PROCEDURES
Provides information about external procedures that have been defined for HP Vertica. User see
only the procedures they can execute.
Column Name
Data Type
Description
PROCEDURE_NAME
VARCHAR
PROCEDURE_ARGUMENTS
VARCHAR
SCHEMA_NAME
VARCHAR
Example
=> SELECT * FROM user_procedures;
procedure_name | procedure_arguments | schema_name
----------------+---------------------+------------helloplanet
| arg1 Varchar
| public
(1 row)
USER_TRANSFORMS
Lists the currently-defined User Defined Transform Functions (UDTFs).
Column Name
Data Type
Description
SCHEMA_NAME
VARCHAR
(128)
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
FUNCTION_
VARCHAR
NAME
(128)
FUNCTION_
VARCHAR
RETURN_TYPE
(128)
FUNCTION_
VARCHAR
ARGUMENT_
(8192)
The data types of the columns that make up the input row.
TYPE
FUNCTION_
VARCHAR
DEFINITION
(128)
IS_FENCED
BOOLEAN
Permissions
No explicit permissions are required; however, users see only UDTFs contained in schemas to
which they have read access.
See Also
l
Developing a User Defined Transform Function in C++ and Developing a User Defined
Transform Function in Java in the Extending HPVertica Guide.
USERS
Provides information about all users in the database.
Column Name
Data Type
Description
USER_ID
INTEGER
USER_NAME
VARCHAR
IS_SUPER_USER
BOOLEAN
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PROFILE_NAME
VARCHAR
IS_LOCKED
BOOLEAN
LOCK_TIME
RESOURCE_POOL
VARCHAR
MEMORY_CAP_KB
VARCHAR
TEMP_SPACE_CAP_KB
VARCHAR
RUN_TIME_CAP
VARCHAR
ALL_ROLES
VARCHAR
DEFAULT_ROLES
VARCHAR
SEARCH_PATH
VARCHAR
Sets the default schema search path for the user. See Setting
Schema Search Paths in the Administrator's Guide.
Notes
To see if a role has been assigned to a user, call the HAS_ROLE() function.
Example
=> \x
Expanded display is on.
=> SELECT * FROM users;
SQLReference Manual
HP Vertica System Tables
-[ RECORD 1 ]-----+--------------------------user_id
| 45035996273704962
user_name
| dbadmin
is_super_user
| t
profile_name
| default
is_locked
| f
lock_time
|
resource_pool
| general
memory_cap_kb
| unlimited
temp_space_cap_kb | unlimited
run_time_cap
| unlimited
all_roles
| dbadmin*, pseudosuperuser*
default_roles
| dbadmin*, pseudosuperuser*
search_path
| "$user", public, v_catalog, v_monitor, v_internal
-[ RECORD 2 ]-----+--------------------------user_id
| 45035996273713664
user_name
| Alice
is_super_user
| f
profile_name
| default
is_locked
| f
lock_time
|
resource_pool
| general
memory_cap_kb
| unlimited
temp_space_cap_kb | unlimited
run_time_cap
| unlimited
all_roles
| logadmin
default_roles
|
search_path
| "$user", public, v_catalog, v_monitor, v_internal
-[ RECORD 3 ]-----+--------------------------user_id
| 45035996273714428
user_name
| Bob
is_super_user
| f
profile_name
| default
is_locked
| f
lock_time
|
resource_pool
| general
memory_cap_kb
| unlimited
temp_space_cap_kb | unlimited
run_time_cap
| unlimited
all_roles
| logadmin, commentor*
default_roles
|
search_path
| "$user", public, v_catalog, v_monitor, v_internal
See Also
l
GRANTS
HAS_ROLE
ROLES
SQLReference Manual
HP Vertica System Tables
VIEW_COLUMNS
Provides view attribute information.
Column Name
Data Type
Description
TABLE_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_NAME
VARCHAR
COLUMN_ID
VARCHAR
COLUMN_NAME
VARCHAR
DATA_TYPE
VARCHAR
DATA_TYPE_ID
INTEGER
DATA_TYPE_LENGTH
INTEGER
CHARACTER_MAXIMUM_LENGTH
INTEGER
NUMERIC_PRECISION
INTEGER
NUMERIC_SCALE
INTEGER
DATETIME_PRECISION
INTEGER
INTERVAL_PRECISION
INTEGER
ORDINAL_POSITION
INTEGER
SQLReference Manual
HP Vertica System Tables
Notes
A warning like the following means only that view <t> had its associated table dropped. The view is
not returned by the SELECT * FROM view_columns
Example
NULL fields in the results indicate that those columns were not defined. For example, given the
following table, the result for the datetime_precision column is NULL because no precision was
declared:
=> CREATE TABLE c (c TIMESTAMP);
CREATE TABLE
=> SELECT table_name, column_id, column_name, datetime_precision
FROM columns WHERE table_name = 'c';
table_name |
column_id
| column_name | datetime_precision
------------+---------------------+-------------+-------------------c
| 45035996273720664-1 | c
|
(1 row)
In the next statement, the datetime_precision column returns 4 because the precision was
declared as 4 in the CREATE TABLE statement:
=> DROP TABLE c;
=> CREATE TABLE c (c TIMESTAMP(4));
CREATE TABLE
=> SELECT table_name, column_id, column_name, datetime_precision
FROM columns WHERE table_name = 'c';
table_name |
column_id
| column_name | datetime_precision
------------+---------------------+-------------+-------------------c
| 45035996273720700-1 | c
|
4
(1 row)
See Also
l
VIEWS
VIEWS
Provides information about all views within the system. See Implementing Views for more
information.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
TABLE_SCHEMA_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
OWNER_ID
INTEGER
OWNER_NAME
VARCHAR
VIEW_DEFINITION
VARCHAR
IS_SYSTEM_VIEW
BOOLEAN
SYSTEM_VIEW_CREATOR
VARCHAR
CREATE_TIME
Example
Query the VIEWS table:
=>\pset expanded
Expanded display is on.
=> SELECT * FROM VIEWS;
-[ RECORD 1 ]-------+-----------------------------table_schema_id
| 45035996273704976
table_schema
| public
table_id
| 45035996273951536
table_name
| testview
owner_id
| 45035996273704962
owner_name
| dbadmin
view_definition
| SELECT bar.x FROM public.bar
is_system_view
| f
system_view_creator |
create_time
| 2013-01-14 12:02:03.244809-05
SQLReference Manual
HP Vertica System Tables
See Also
l
VIEW_COLUMNS
SQLReference Manual
HP Vertica System Tables
V_MONITOR Schema
The system tables in this section reside in the v_monitor schema. These tables provide
information about the health of the HP Vertica database.
ACTIVE_EVENTS
Returns all active events in the cluster. See Monitoring Events.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
EVENT_CODE
INTEGER
EVENT_ID
INTEGER
EVENT_SEVERITY
VARCHAR
EVENT_POSTED_TIMESTAMP
0Emergency
1Alert
2Critical
3Error
4Warning
5Notice
6Informational
7Debug
TIMESTAMP The year, month, day, and time the event was
reported. The time is posted in military time.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
EVENT_EXPIRATION
VARCHAR
EVENT_CODE_DESCRIPTION
VARCHAR
EVENT_PROBLEM_DESCRIPTION
VARCHAR
REPORTING_NODE
VARCHAR
EVENT_SENT_TO_CHANNELS
VARCHAR
EVENT_POSTED_COUNT
INTEGER
Example
Query the ACTIVE_EVENTS table:
=>\pset expanded
Expanded display is on.
=> SELECT * FROM active_events;
-[ RECORD 1 ]-------------+----------------------------------------node_name
| site01
event_code
| 6
event_id
| 6
event_severity
| Informational
is_event_posted
| 2009-08-11 09:38:39.008458
event_expiration
| 2077-08-29 11:52:46.008458
event_code_description
| Node State Change
event_problem_description | Changing node site01 startup state to UP
reporting_node
| site01
event_sent_to_channels
| Vertica Log
event_posted_count
| 1
-[ RECORD 2 ]-------------+----------------------------------------node_name
| site02
event_code
| 6
event_id
| 6
event_severity
| Informational
SQLReference Manual
HP Vertica System Tables
is_event_posted
| 2009-08-11 09:38:39.018172
event_expiration
| 2077-08-29 11:52:46.018172
event_code_description
| Node State Change
event_problem_description | Changing node site02 startup state to UP
reporting_node
| site02
event_sent_to_channels
| Vertica Log
event_posted_count
| 1
-[ RECORD 3 ]-------------+----------------------------------------current_timestamp
| 2009-08-11 14:38:48.859987
node_name
| site03
event_code
| 6
event_id
| 6
event_severity
| Informational
is_event_posted
| 2009-08-11 09:38:39.027258
event_expiration
| 2077-08-29 11:52:46.027258
event_code_description
| Node State Change
event_problem_description | Changing node site03 startup state to UP
reporting_node
| site03
event_sent_to_channels
| Vertica Log
event_posted_count
| 1
-[ RECORD 4 ]-------------+----------------------------------------node_name
| site04
event_code
| 6
event_id
| 6
event_severity
| Informational
is_event_posted
| 2009-08-11 09:38:39.008288
event_expiration
| 2077-08-29 11:52:46.008288
event_code_description
| Node State Change
event_problem_description | Changing node site04 startup state to UP
reporting_node
| site04
event_sent_to_channels
| Vertica Log
event_posted_count
| 1
...
COLUMN_STORAGE
Returns the amount of disk storage used by each column of each projection on each node.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
COLUMN_ID
INTEGER
COLUMN_NAME
VARCHAR
ROW_COUNT
INTEGER
USED_BYTES
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ENCODINGS
VARCHAR
COMPRESSION
VARCHAR
WOS_ROW_COUNT
INTEGER
ROS_ROW_COUNT
INTEGER
ROS_USED_BYTES
INTEGER
ROS_COUNT
INTEGER
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
PROJECTION_SCHEMA
VARCHAR
ANCHOR_TABLE_ID
INTEGER
ANCHOR_TABLE_NAME
VARCHAR
ANCHOR_TABLE_SCHEMA
VARCHAR
ANCHOR_TABLE_COLUMN_ID
VARCHAR
ANCHOR_TABLE_COLUMN_NAME
VARCHAR
Notes
l
WOS data is stored by row, so per-column byte counts are not available.
The ENCODINGS and COMPRESSION columns let you compare how different encoding types
affect column storage, when optimizing for compression.
Example
Query the COLUMN_STORAGE table:
=> \pset expanded
SQLReference Manual
HP Vertica System Tables
SQLReference Manual
HP Vertica System Tables
anchor_table_name
| trades
anchor_table_schema
| public
anchor_table_column_id
| 45035996273718836-3
anchor_table_column_name | ask
-[ RECORD 4 ]------------+-------------------node_name
| v_onenode_node0001
column_id
| 45035996273718848
column_name
| epoch
row_count
| 1
used_bytes
| 48
encodings
| Int_Delta
compressions
| none
wos_row_count
| 0
ros_row_count
| 1
ros_used_bytes
| 48
ros_count
| 1
projection_id
| 45035996273718838
projection_name
| trades_p
projection_schema
| public
anchor_table_id
| 45035996273718836
anchor_table_name
| trades
anchor_table_schema
| public
anchor_table_column_id
| 45035996273718836-4
anchor_table_column_name |
SQLReference Manual
HP Vertica System Tables
CONFIGURATION_CHANGES
Records the change history of system configuration parameters (V_
MONITOR.CONFIGURATION_PARAMETERS). This information is useful for identifying:
l
Description
EVENT_TIMESTAMP
NODE_NAME
VARCHAR
USER_ID
INTEGER
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
PARAMETER
VARCHAR
VALUE
VARCHAR
Permissions
Must be a superuser.
Example
=> SELECT * FROM configuration_changes;
event_timestamp
| node_name |
user_id
| user_name |
session_
id
|
parameter
| value
-------------------------------+-----------+-------------------+-----------+-------------
SQLReference Manual
HP Vertica System Tables
------+--------------------------------+------2011-09-16 14:40:31.575335-04 | e1
| 45035996273704962
9010:0xb2e | UseOnlyResilientRedistribution | 0
2011-09-16 14:40:31.576015-04 | initiator | 45035996273704962
9010:0xb2e | UseOnlyResilientRedistribution | 0
2011-09-16 14:40:31.576106-04 | e0
| 45035996273704962
9010:0xb2e | UseOnlyResilientRedistribution | 0
2011-09-16 14:40:33.103278-04 | e0
| 45035996273704962
9010:0xb2e | UseOnlyResilientRedistribution | 1
2011-09-16 14:40:33.10332-04 | e1
| 45035996273704962
9010:0xb2e | UseOnlyResilientRedistribution | 1
2011-09-16 14:40:33.104521-04 | initiator | 45035996273704962
9010:0xb2e | UseOnlyResilientRedistribution | 1
2011-09-16 14:51:59.884112-04 | e0
| 45035996273704962
9010:0x109d | UseOnlyResilientRedistribution | 0
2011-09-16 14:51:59.884519-04 | e1
| 45035996273704962
9010:0x109d | UseOnlyResilientRedistribution | 0
2011-09-16 14:51:59.884695-04 | initiator | 45035996273704962
9010:0x109d | UseOnlyResilientRedistribution | 0
2011-09-16 14:52:00.580423-04 | initiator | 45035996273704962
9010:0x109d | UseOnlyResilientRedistribution | 1
2011-09-16 14:52:00.580673-04 | e0
| 45035996273704962
9010:0x109d | UseOnlyResilientRedistribution | 1
2011-09-16 14:52:00.581464-04 | e1
| 45035996273704962
9010:0x109d | UseOnlyResilientRedistribution | 1
(12 rows)
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
| smith
| smthl-
See Also
l
CONFIGURATION_PARAMETERS
CONFIGURATION_PARAMETERS
Provides information about configuration parameters currently in use by the system that are
configurable at the database, node, or session level.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PARAMETER_NAME
VARCHAR
CURRENT_VALUE
VARCHAR
RESTART_VALUE
VARCHAR
DATABASE_VALUE
VARCHAR
DEFAULT_VALUE
VARCHAR
CURRENT_LEVEL
VARCHAR
RESTART_LEVEL
VARCHAR
IS_MISMATCH
BOOLEAN
GROUPS
VARCHAR
ALLOWED_LEVELS
VARCHAR
CHANGE_UNDER_SUPPORT_GUIDANCE
BOOLEAN
CHANGE_REQUIRES_RESTART
BOOLEAN
DESCRIPTION
VARCHAR
SQLReference Manual
HP Vertica System Tables
Example
The following example shows how to retrieve all information for configuration parameters in HP
Vertica :
=> SELECT * FROM CONFIGURATION_PARAMETERS;
The following example shows a case where the parameter requires a restart for the new setting to
take effect:
=> SELECT * FROM CONFIGURATION_PARAMETERS WHERE parameter_name = 'EnableSSL';
-[ RECORD 1 ]-----------------+-------------------------node_name
| ALL
parameter_name
| EnableSSL
current_value
| 0
restart_value
| 1
database_value
| 0
default_value
| 0
current_level
| DEFAULT
restart_level
| NODE
is_mismatch
| t
groups
|
allowed_levels
| NODE, DATABASE
change_under_support_guidance | f
change_requires_restart
| t
description
| Enable SSL for the server
See Also
l
Configuration Parameters
CPU_USAGE
Records CPU usage history on the system.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
START_TIME
END_TIME
AVERAGE_CPU_USAGE_PERCENT
FLOAT
Average CPU usage in percent of total CPU time (0100) during history interval
Permissions
Must be a superuser
Example
=> SELECT * FROM cpu_usage;
node_name |
start_time
|
end_time
| cpu_usage_
percent
-----------+-------------------------------+-------------------------------+-----------------initiator | 2011-09-16 15:23:38.000703-04 | 2011-09-16 15:24:00.005645-04 |
34.49
initiator | 2011-09-16 15:24:00.005645-04 | 2011-09-16 15:25:00.002346-04 |
12.37
e0
| 2011-09-16 15:23:37.002957-04 | 2011-09-16 15:24:00.003022-04 |
35.35
e0
| 2011-09-16 15:24:00.003022-04 | 2011-09-16 15:25:00.004471-04 |
12.38
e1
| 2011-09-16 15:23:37.000871-04 | 2011-09-16 15:24:00.002474-04 |
35.37
e1
| 2011-09-16 15:24:00.002474-04 | 2011-09-16 15:25:00.002049-04 |
12.38
(6 rows)
CRITICAL_HOSTS
Lists the critical hosts whose failure would cause the database to become unsafe and force a
shutdown.
Column Name Data Type
Description
HOST_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> SELECT * FROM critical_hosts;
host_name
-----------Host1
Host3
(2 rows)
CRITICAL_NODES
Lists the critical nodes whose failure would cause the database to become unsafe and force a
shutdown.
Column
Name
Data Type
Description
NODE_ID
INTEGER
NODE_NAME
VARCHAR
Example
=> SELECT * FROM v_monitor.critical_nodes;
node_id
|
node_name
-------------------+-------------------45035996273704980 | v_onenode_node0001
(1 row)
CURRENT_SESSION
Returns information about the current active session. You can use this table to find out the current
session's sessionID and get the duration of the previously-run query.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
CLIENT_HOSTNAME
VARCHAR
CLIENT_PID
INTEGER
LOGIN_TIMESTAMP
SESSION_ID
VARCHAR
CLIENT_LABEL
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
TRANSACTION_START
TRANSACTION_ID
VARCHAR
TRANSACTION_DESCRIPTION
VARCHAR
STATEMENT_START
STATEMENT_ID
VARCHAR
LAST_STATEMENT_DURATION_US
INTEGER
CURRENT_STATEMENT
VARCHAR
LAST_STATEMENT
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
EXECUTION_ENGINE_PROFILING_CONFIGURATION
VARCHAR
QUERY_PROFILING_CONFIGURATION
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SESSION_PROFILING_CONFIGURATION
VARCHAR
CLIENT_TYPE
VARCHAR
ADO.NET Driver
ODBC Driver
JDBC Driver
vsql
CLIENT_VERSION
VARCHAR
CLIENT_OS
VARCHAR
Notes
l
The default for profiling is ON ('1') for all sessions. Each session can turn profiling ON or OFF.
Profiling parameters (such as GlobalEEProfiling in the examples below) are set in the HP
Vertica configuration file (vertica.conf). To turn profiling off, set the parameter to '0'. To turn
profiling on, set the parameter to '1'.
Examples
Query the CURRENT_SESSION table:
SQLReference Manual
HP Vertica System Tables
The sequence of commands in this example shows the use of disabling and enabling profiling for
local and global sessions.
This command disables EE profiling for query execution runs:
=> SELECT disable_profiling('EE');
disable_profiling
----------------------EE Profiling Disabled
(1 row)
The following command sets the GlobalEEProfiling configuration parameter to 0, which turns off
profiling:
=> ALTER DATABASE mydb SET GlobalEEProfiling = 0;
The following command tells you whether profiling is set to 'Local' or 'Global' or none:
SQLReference Manual
HP Vertica System Tables
Note: The result set is empty because profiling was turned off in the preceding example.
This command now enables EE profiling for query execution runs:
=> SELECT enable_profiling('EE');
enable_profiling
---------------------EE Profiling Enabled
(1 row)
Now when you run a select on the CURRENT_SESSION table, you can see profiling is ON for the
local session:
=> SELECT execution_engine_profiling_configuration FROM CURRENT_SESSION;
ee_profiling_config
--------------------Local
(1 row)
Now turn profiling on for all sessions by setting the GlobalEEProfiling configuration parameter to 1:
=> ALTER DATABASE mydb SET GlobalEEProfiling = 1;
Now when you run a select on the CURRENT_SESSION table, you can see profiling is ON for the
local sessions, as well as for all sessions:
=> SELECT execution_engine_profiling_configuration FROM CURRENT_SESSION;
ee_profiling_config
--------------------Local, Global
(1 row)
See Also
l
CLOSE_SESSION
CLOSE_ALL_SESSIONS
EXECUTION_ENGINE_PROFILES
SQLReference Manual
HP Vertica System Tables
QUERY_PROFILES
SESSION_PROFILES
SESSIONS
DATA_COLLECTOR
Shows the Data Collector components, their current retention policies, and statistics about how
much data is retained and how much has been discarded for various reasons. The DATA_
COLLECTOR system table also calculates approximate collection rate, to aid in sizing
calculations.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
COMPONENT
VARCHAR
TABLE_NAME
VARCHAR
DESCRIPTION
VARCHAR
IN_DB_LOG
BOOLEAN
IN_VERTICA_LOG
BOOLEAN
MEMORY_BUFFER_SIZE_KB
INTEGER
DISK_SIZE_KB
INTEGER
INTERVAL_SET
BOOLEAN
INTERVAL_TIME
INTERVAL
RECORD_TOO_BIG_ERRORS
INTEGER
LOST_BUFFERS
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
LOST_RECORDS
INTEGER
RETIRED_FILES
INTEGER
RETIRED_RECORDS
INTEGER
CURRENT_MEMORY_RECORDS
INTEGER
CURRENT_DISK_RECORDS
INTEGER
CURRENT_MEMORY_BYTES
INTEGER
CURRENT_DISK_BYTES
INTEGER
FIRST_TIME
LAST_TIME
KB_PER_DAY
INTEGER
Notes
l
Data Collector is on by default. To turn it off, see Enabling and Disabling Data Collector.
You can configure monitoring information retention policies. See Data Collector Functions and
Configuring Data Retention Policies.
Examples
The following examples show how to query all columns in the DATA_COLLECTOR system table:
=> \x
=> SELECT * FROM data_collector;
-[ RECORD 1 ]----------+-------------------------------------------node_name
| v_vmart_node0001
component
| AllocationPoolStatistics
table_name
| dc_allocation_pool_statistics
description
| Information about global memory pools, which generally
cannot be recovered without restart
access_restricted
| t
in_db_log
| f
in_vertica_log
| f
memory_buffer_size_kb | 64
disk_size_kb
| 256
interval_set
| f
interval_time
| 0
record_too_big_errors | 0
SQLReference Manual
HP Vertica System Tables
lost_buffers
lost_records
retired_files
retired_records
current_memory_records
current_disk_records
current_memory_bytes
current_disk_bytes
first_time
last_time
kb_per_day
|
|
|
|
|
|
|
|
|
|
|
0
0
103
46659
0
1483
0
214291
2014-11-24 11:15:32.001945-05
2014-11-24 11:27:53.00188-05
24372.9440538663
The following example shows how to return all component names and their descriptions. This is a
useful query if you want to change the retention policy for a particular component and don't
remember its name:
=> SELECT DISTINCT component, description FROM data_collector ORDER BY 1 ASC;
component
|
description
----------------------------------+-----------------------------------------------------------------AllocationPoolStatistics
| Information about global memory pools ...
AllocationPoolStatisticsByDay
| Information about global memory pools, ...
(historical, by day)
AllocationPoolStatisticsByHour
| Information about global memory pools, ...
(historical, by hour)
AllocationPoolStatisticsByMinute | Information about global memory pools, ...
(historical, by minute)
AllocationPoolStatisticsBySecond | Information about global memory pools, ...
(historical, by second)
AnalyzeStatistics
| History of statistics collection
Backups
| Monitoring successful backups
CatalogInfo
| Catalog statistics and history
CatalogInfoByDay
| Catalog statistics and history (historical, by day)
CatalogInfoByHour
| Catalog statistics and history (historical, by hour)
CatalogInfoByMinute
| Catalog statistics and history (historical, by
minute)
CatalogInfoBySecond
| Catalog statistics and history (historical, by
second)
ClientServerMessages
| Client-Server Messages (Front End to Back End
Protocol) sent
ConfigurationChanges
| Changes to configuration parameters (vertica.conf)
CpuAggregate
| Aggregate CPU information
CpuAggregateByDay
| Aggregate CPU information (historical, by day)
CpuAggregateByHour
| Aggregate CPU information (historical, by hour)
CpuAggregateByMinute
| Aggregate CPU information (historical, by minute)
CpuAggregateBySecond
| Aggregate CPU information (historical, by second)
CpuInfo
| CPU information
CpuInfoByDay
| CPU information (historical, by day)
CpuInfoByHour
| CPU information (historical, by hour)
CpuInfoByMinute
| CPU information (historical, by minute)
CpuInfoBySecond
| CPU information (historical, by second)
DeploymentsCompleted
| History of designs deployed
DesignsCompleted
| History of designs executed
SQLReference Manual
HP Vertica System Tables
DiskResourceRejections
Errors
ExecutionEngineEvents
execution
ExecutionEngineProfiles
.
.
.
(93 rows)
Related Topics
l
Retaining Monitoring Information and How HP Vertica Calculates Database Size in the
Administrator's Guide
SET_DATA_COLLECTOR_TIME_POLICY
GET_DATA_COLLECTOR_POLICY
DATABASE_BACKUPS
Lists historical information for each backup that successfully completed after running the vbr.py
utility. This information is useful for determining whether to create a new backup before you
advance the AHM. Because this system table displays historical information, its contents do not
always reflect the current state of a backup repository. For example, if you delete a backup from a
repository, the DATABASE_BACKUPS system table continues to display information about it.
To monitor snapshot information while vbr.py is running, query the DATABASE_SNAPSHOTS
system table. To list existing backups, run vbr.py as described in Viewing Backups in the
Administrator's Guide.
Column Name
Data Type
Description
BACKUP_TIMESTAMP
NODE_NAME
VARCHAR
SNAPSHOT_NAME
VARCHAR
BACKUP_EPOCH
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_COUNT
INTEGER
OBJECTS
VARCHAR
Permissions
Must be a superuser.
Example
VMart=> select * from v_monitor.database_backups;
-[ RECORD 1 ]----+-----------------------------backup_timestamp | 2013-05-10 14:41:12.673381-04
node_name
| v_vmart_node0003
snapshot_name
| schemabak
backup_epoch
| 174
node_count
| 3
objects
| public, store, online_sales
-[ RECORD 2 ]----+-----------------------------backup_timestamp | 2013-05-13 11:17:30.913176-04
node_name
| v_vmart_node0003
snapshot_name
| kantibak
backup_epoch
| 175
node_count
| 3
objects
|
.
.
.
-[ RECORD 15 ]---+-----------------------------backup_timestamp | 2013-05-16 07:20:18.585076-04
node_name
| v_vmart_node0003
snapshot_name
| table2bak
backup_epoch
| 180
node_count
| 3
objects
| test2
-[ RECORD 16 ]---+-----------------------------backup_timestamp | 2013-05-28 14:06:03.027673-04
node_name
| v_vmart_node0003
snapshot_name
| kantibak
backup_epoch
| 182
node_count
| 3
objects
|
SQLReference Manual
HP Vertica System Tables
See Also
l
DATABASE_SNAPSHOTS
DATABASE_CONNECTIONS
Lists the connections that have been established to other databases for importing and exporting
data. See Moving Data Between HP Vertica Databases in the Administrator's Guide.
Column Name Data Type
Description
DATABASE
VARCHAR
USERNAME
VARCHAR
HOST
VARCHAR
PORT
VARCHAR
ISVALID
BOOLEAN
Example
=> CONNECT TO VERTICA vmart USER dbadmin PASSWORD '' ON '10.10.20.150',5433;
CONNECT
=> SELECT * FROM DATABASE_CONNECTIONS;
database | username |
host
| port | isvalid
----------+----------+--------------+------+--------vmart
| dbadmin | 10.10.20.150 | 5433 | t
(1 row)
DATABASE_SNAPSHOTS
Displays information about database snapshots. A snapshot is a special temporary image of the
database, which vbr.py uses internally as part of creating a full or object-level backup. When
vbr.py completes a backup, it deletes the associated snapshot and its entry in the database_
snapshots system table.
To see historical data about successfully created backups, query the DATABASE_BACKUPS
system table. To see existing backups, run vbr.py as described in Viewing Backups in the
Administrator's Guide.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SNAPSHOT_NAME
VARCHAR
IS_DURABLE_SNAPSHOT
BOOLEAN
TOTAL_SIZE_BYTES
INTEGER
The total size (in bytes) of the data being backed up.
This value differs from the data storage size (STORAGE_
COST_BYTES), described next.
STORAGE_COST_BYTES
INTEGER
ACQUISITION_TIMESTAMP
Example
To monitor snapshot information during vbr.py execution:
vmartdb=> SELECT * FROM database_snapshots;
node_name | snapshot_name | is_durable_snapshot | total_size_bytes | storage_cost_bytes
| acquisition_timestamp
--------------------+---------------+---------------------+------------------+-------------------+-----------------------node0001 | mysnapshot
| t
|
116108615 |
5054638
| 2010-10-07 12:39:22-04
node0002 | mysnapshot
| t
|
116385001 |
5066175
| 2010-10-07 12:39:35-04
node0003 | mysnapshot
| t
|
116379703 |
505469
| 2010-10-07 12:38:00-04
node0004 | mysnapshot
| t
|
116354638 |
5043155
| 2010-10-07 12:36:10-04
(4 rows)
SQLReference Manual
HP Vertica System Tables
See Also
l
DATABASE_BACKUPS
DELETE_VECTORS
Holds information on deleted rows to speed up the delete process.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SCHEMA_NAME
VARCHAR
The name of the schema where the deleted rows are located.
PROJECTION_NAME
VARCHAR
The name of the projection where the deleted rows are located.
STORAGE_TYPE
VARCHAR
DV_OID
INTEGER
STORAGE_OID
INTEGER
DELETED_ROW_COUNT
INTEGER
USED_BYTES
INTEGER
START_EPOCH
INTEGER
END_EPOCH
INTEGER
DEPLOY_STATUS
Records the history of the Database Designer designs that have been deployed and their
deployment steps.
Column Name
Data Type
Description
EVENT_TIME
USER_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
DEPLOY_NAME
VARCHAR
DEPLOY_STEP
VARCHAR
DEPLOY_STEP_STATUS
VARCHAR
DEPLOY_STEP_COMPLETE_PERCENT
FLOAT
DEPLOY_COMPLETE_PERCENT
FLOAT
ERROR_MESSAGE
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
The following example shows the content of the DEPLOY_STATUS for a Database Designer
deployment executed by the DBADMIN user:
=> select * from v_monitor.deploy_status;
event_time | user_name | deploy_name | deploy_step | deploy_step_status | deploy_
step_complete_percent | deploy_complete_percent | error_message
---------------------+-----------+-------------+-------------------------------------+-------------------+------------------------------+-------------------------+-------------2012-02-14 10:33:14 | dbadmin | design1 | create_deployment | success | | | N/A
2012-02-14 10:33:14 | dbadmin | design1 | populate_deployment | started | | | N/A
2012-02-14 10:33:21 | dbadmin | design1 | populate_deployment | success | | | N/A
2012-02-14 10:33:21 | dbadmin | design1 | deployment_script | started | | | N/A
2012-02-14 10:33:23 | dbadmin | design1 | run_deployment | success | | | N/A
2012-02-14 10:33:23 | dbadmin | design1 | deployment_script | success | | | N/A
2012-02-14 10:33:24 | dbadmin | design1 | execute_deployment | started | | | N/A
2012-02-14 10:33:26 | dbadmin | design1 | add: Dim_DBD_3_rep_ctx_design1 | complete |
100 | 0 | N/A
2012-02-14 10:33:27 | dbadmin | design1 | drop: Dim_b0 | complete | 100 | 0 | N/A
2012-02-14 10:33:27 | dbadmin | design1 | drop: Dim_b1 | complete | 100 | 0 | N/A
2012-02-14 10:33:43 | dbadmin | design1 | add: Fact1_DBD_11_seg_ctx_design1 | complete |
100 | 11.11 | N/A
2012-02-14 10:33:43 | dbadmin | design1 | add: Fact1_DBD_12_seg_1_ctx_design1 | complete
| 100 | 22.22 | N/A
2012-02-14 10:33:43 | dbadmin | design1 | add: Fact1_DBD_1_seg_ctx_design1 | complete |
SQLReference Manual
HP Vertica System Tables
dbadmin
dbadmin
dbadmin
dbadmin
dbadmin
|
|
|
|
|
design1
design1
design1
design1
design1
|
|
|
|
|
DEPLOYMENT_PROJECTION_STATEMENTS
Contains information about the CREATE PROJECTION statements used to deploy your design.
Each row contains information about a different CREATE PROJECTION statement. Running
DESIGNER_RUN_POPULATE_DESIGN_AND_DEPLOY populates this table.
Column Name
Column
Type
Description
DEPLOYMENT_ID
INTEGER
DESIGN_NAME
VARCHAR
DEPLOYMENT_
PROJECTION_ID
INTEGER
STATEMENT_ID
INTEGER
Designer.
Unique ID assigned to the statement type that creates
the projection.
STATEMENT
VARCHAR
SQLReference Manual
HP Vertica System Tables
=> \x
Expanded display is on.
=> SELECT * FROM DEPLOYMENT_PROJECTIONS_STATEMENTS;
-[ RECORD 1 ]------------+-----------------------deployment_id
| 45035996273708449
design_name
| VMART_DESIGN
deployment_projection_id | 1
statement_id
| 1
statement
| CREATE PROJECTION public.customer_dimension_DBD_1_rep_VMART_
DESIGN /*+createtype(D)*/
customer_key ENCODING DELTAVAL,
customer_type ENCODING AUTO,
customer_name ENCODING AUTO,
customer_gender ENCODING AUTO,
title ENCODING AUTO,
household_id ENCODING DELTAVAL,
customer_address ENCODING AUTO,
customer_city ENCODING AUTO,
customer_state ENCODING AUTO,
customer_region ENCODING AUTO,
marital_status ENCODING AUTO,
customer_age ENCODING DELTAVAL,
number_of_children ENCODING BLOCKDICT_COMP,
annual_income ENCODING DELTARANGE_COMP,
occupation ENCODING AUTO,
largest_bill_amount ENCODING DELTAVAL,
store_membership_card ENCODING BLOCKDICT_COMP,
customer_since ENCODING AUTO,
deal_stage ENCODING AUTO,
deal_size ENCODING DELTARANGE_COMP,
last_deal_update ENCODING DELTARANGE_COMP
AS
SELECT customer_key,
customer_type,
customer_name,
customer_gender,
title,
household_id,
customer_address,
customer_city,
customer_state,
customer_region,
marital_status,
customer_age,
number_of_children,
annual_income,
occupation,
largest_bill_amount,
store_membership_card,
customer_since,
deal_stage,
deal_size,
last_deal_update
FROM public.customer_dimension
ORDER BY customer_gender,
annual_income
UNSEGMENTED ALL NODES;
-[ RECORD 2 ]------------+------------------------
SQLReference Manual
HP Vertica System Tables
...
DEPLOYMENT_PROJECTIONS
Contains information about projections created and dropped during the design. Each row contains
information about a different projection. Database Designer populates this table after the design has
been deployed.
Column Name
Column
Type
Description
deployment_id
INTEGER
deployment_projection_id
INTEGER
design_name
VARCHAR
deployment_projection_name
VARCHAR
anchor_table_schema
VARCHAR
anchor_table_name
VARCHAR
deployment_operation
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Column
Type
Description
DEPLOYMENT_PROJECTION_TYPE
VARCHAR
DEPLOY_WEIGHT
INTEGER
DBD
CATALOG
DBD_REENCODED
CATALOG_REENCODED
ESTIMATED_SIZE_ON_DISK
INTEGER
Example
Query the DEPLOYMENT_PROJECTIONS table after deploying a design for the VMart database:
=> \x
Expanded display is on.
=> SELECT * FROM DEPLOYMENT_PROJECTIONS;
-[ RECORD 1 ]--------------+--------------------------------------------deployment_id
| 45035996273708449
deployment_projection_id
| 1
design_name
| VMART_DESIGN
deployment_projection_name | customer_dimension_DBD_1_rep_VMART_DESIGN
anchor_table_schema
| public
anchor_table_name
| customer_dimension
deployment_operation
| add
deployment_projection_type | DBD
deploy_weight
| 1050000
estimated_size_on_disk
| 2165897
-[ RECORD 2 ]--------------+--------------------------------------------deployment_id
| 45035996273708449
deployment_projection_id
| 2
SQLReference Manual
HP Vertica System Tables
design_name
| VMART_DESIGN
deployment_projection_name | product_dimension_DBD_2_rep_VMART_DESIGN
anchor_table_schema
| public
anchor_table_name
| product_dimension
deployment_operation
| add
deployment_projection_type | DBD
deploy_weight
| 1260000
estimated_size_on_disk
| 2327964
-[ RECORD 3 ]--------------+--------------------------------------------deployment_id
| 45035996273708449
deployment_projection_id
| 3
design_name
| VMART_DESIGN
deployment_projection_name | product_dimension_DBD_3_rep_vmart_design
anchor_table_schema
| public
anchor_table_name
| product_dimension
deployment_operation
| add
deployment_projection_type | DBD
deploy_weight
| 300000
estimated_size_on_disk
| 1116277
...
-[ RECORD 13 ]-------------+--------------------------------------------deployment_id
| 4503599628449
deployment_projection_id
| 13
design_name
| VMART_DESIGN
deployment_projection_name | store_orders_fact_DBD_13_seg_VMART_DESIGN_b0
anchor_table_schema
| store
anchor_table_name
| store_orders_fact
deployment_operation
| add
deployment_projection_type | DBD_REENCODED
deploy_weight
| 5700000
estimated_size_on_disk
| 9240800
-[ RECORD 14 ]-------------+----------------------------------------------deployment_id
| 4503599628449
deployment_projection_id
| 13
design_name
| N/A
deployment_projection_name | customer_dimension_super
anchor_table_schema
| public
anchor_table_name
| customer_dimension
deployment_operation
| drop
deployment_projection_type | EXISTING
deploy_weight
| 0
estimated_size_on_disk
| 2165897
...
DESIGN_QUERIES
Contains info about design queries for a given design. The following functions populate this table:
l
DESIGNER_ADD_DESIGN_QUERIES
DESIGNER_ADD_DESIGN_QUERIES_FROM_RESULTS
DESIGNER_ADD_DESIGN_QUERY
SQLReference Manual
HP Vertica System Tables
Column Name
Column Type
Description
design_id
INTEGER
design_name
VARCHAR
design_query_
id
INTEGER
design_query_
id_index
INTEGER
design query.
Database Designer chunks the query text if it exceeds
the maximum attribute size before storing it in this
table. Database Designer stored all chunks stored
under the same value of DESIGN_QUERY_ID.
DESIGN_QUERY_ID_INDEX keeps track of the
order of the chunks, starting with 0 and ending in n, the
index of the final chunk.
query_text
VARCHAR
weight
FLOAT
design_query_
search_path
VARCHAR
design_query_
signature
INTEGER
Example
Add queries to VMART_DESIGN and query the DESIGN_QUERIES table:
=> SELECT DESIGNER_ADD_DESIGN_QUERIES('VMART_DESIGN', '/tmp/examples/vmart_
SQLReference Manual
HP Vertica System Tables
queries.sql','true');
DESIGNER_ADD_DESIGN_QUERIES
----------------------------Number of accepted queries
=9
Number of queries referencing non-design tables =0
Number of unsupported queries
=0
Number of illegal queries
=0
=> \x
Expanded display is on.
=> SELECT * FROM V_MONITOR.DESIGN.QUERIES
-[ RECORD 1 ]------------+------------------design_id
| 45035996273705090
design_name
| vmart_design
design_query_id
| 1
design_query_id_index
| 0
query_text
| SELECT fat_content
FROM (
SELECT DISTINCT fat_content
FROM product_dimension
WHERE department_description
IN ('Dairy') ) AS food
ORDER BY fat_content
LIMIT 5;
weight
| 1
design_query_search_path | v_dbd_vmart_design_vmart_design_ltt, "$user", public, v_
catalog, v_monitor, v_internal
design_query_signature
| 45035996273724651
-[ RECORD 2]-------------+------------------design_query_id
| 2
design_query_id_index
| 0
query_text
| SELECT order_number, date_ordered
FROM store.store_orders_fact orders
WHERE orders.store_key IN (
SELECT store_key
FROM store.store_dimension
WHERE store_state = 'MA')
AND orders.vendor_key NOT IN (
SELECT vendor_key
FROM public.vendor_dimension
WHERE vendor_state = 'MA')
AND date_ordered < '2003-03-01';
weight
| 1
design_query_search_path | v_dbd_vmart_design_vmart_design_ltt, "$user", public, v_
catalog, v_monitor, v_internal
design_query_signature
| 45035996273724508
-[ RECORD 3]-------------+------------------...
DESIGN_STATUS
Records the progress of a running Database Designer design or history of the last Database
Designer design executed by the current user.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
event_time
user_name
VARCHAR
design_name
VARCHAR
design_phase
VARCHAR
phase_step
VARCHAR
phase_step_complete_percent
FLOAT
phase_complete_percent
FLOAT
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
The following example shows the content of the DESIGN_STATUS table of a complete Database
Designer run:
=> SELECT event_time, design_name,
design_phase, phase_complete_percent
FROM v_monitor.design_status;
event_time
| design_name | design_phase
| phase_
complete_percent
---------------------+-------------+------------------------------------------------+----------------------2012-02-14 10:31:20 | design1
| Design started
|
2012-02-14 10:31:21 | design1
| Design in progress: Analyze statistics phase
|
2012-02-14 10:31:21 | design1
| Analyzing data statistics
|
33.33
2012-02-14 10:31:22 | design1
| Analyzing data statistics
|
66.67
2012-02-14 10:31:24 | design1
| Analyzing data statistics
| 100
2012-02-14 10:31:25 | design1
| Design in progress: Query optimization phase
|
2012-02-14 10:31:25 | design1
| Optimizing query performance
| 37.5
2012-02-14 10:31:31 | design1
| Optimizing query performance
| 62.5
2012-02-14 10:31:36 | design1
| Optimizing query performance
| 75
2012-02-14 10:31:39 | design1
| Optimizing query performance
| 87.5
2012-02-14 10:31:41 | design1
| Optimizing query performance
| 87.5
SQLReference Manual
HP Vertica System Tables
2012-02-14
2012-02-14
2012-02-14
16.67
2012-02-14
29.17
2012-02-14
31.25
2012-02-14
33.33
2012-02-14
35.42
2012-02-14
2012-02-14
2012-02-14
2012-02-14
2012-02-14
2012-02-14
(24 rows)
10:31:42 | design1
10:31:44 | design1
10:31:44 | design1
10:32:04 | design1
10:32:04 | design1
10:32:05 | design1
10:32:05 | design1
10:32:05
10:32:05
10:32:39
10:32:39
10:32:41
10:33:12
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
design1
design1
design1
design1
design1
design1
37.5
62.5
87.5
87.5
100
DESIGN_TABLES
Contains information about all the design tables for all the designs for which you are the owner.
Each row contains information about a different design table. Running DESIGNER_CREATE_
DESIGN creates this table in the V_MONITOR schema.
Column Name
Column
Type
Description
design_name
VARCHAR
design_table_
id
INTEGER
table_schema
VARCHAR
table_id
INTEGER
table_name
VARCHAR
table.
Example
Add all the tables from the VMart database to the design VMART_DESIGN. This operation
populates the DESIGN_TABLES table:
=> SELECT DESIGNER_ADD_DESIGN_TABLES('VMART_DESIGN','online_sales.*');
DESIGNER_ADD_DESIGN_TABLES
----------------------------
SQLReference Manual
HP Vertica System Tables
3
(1 row)
=> SELECT DESIGNER_ADD_DESIGN_TABLES('VMART_DESIGN','public.*');
DESIGNER_ADD_DESIGN_TABLES
---------------------------9
(1 row)
=> SELECT DESIGNER_ADD_DESIGN_TABLES('VMART_DESIGN','store.*');
DESIGNER_ADD_DESIGN_TABLES
---------------------------3
(1 row)
=> SELECT * FROM DESIGN_TABLES;
design_name | design_table_id | table_schema |
table_id
|
table_name
-------------+-----------------+--------------+-------------------+---------------------VMART_DESIGN |
1 | online_sales | 45035996373718754 | online_page_dimension
VMART_DESIGN |
2 | online_sales | 45035996373718758 | call_center_dimension
VMART_DESIGN |
3 | online_sales | 45035996373718762 | online_sales_fact
VMART_DESIGN |
4 | public
| 45035996373718766 | customer_dimension
VMART_DESIGN |
5 | public
| 45035996373718770 | product_dimension
VMART_DESIGN |
6 | public
| 45035996373718774 | promotion_dimension
VMART_DESIGN |
7 | public
| 45035996373718778 | date_dimension
VMART_DESIGN |
8 | public
| 45035996373718782 | vendor_dimension
VMART_DESIGN |
9 | public
| 45035996373718786 | employee_dimension
VMART_DESIGN |
10 | public
| 45035996373718822 | shipping_dimension
VMART_DESIGN |
11 | public
| 45035996373718826 | warehouse_dimension
VMART_DESIGN |
12 | public
| 45035996373718830 | inventory_face
VMART_DESIGN |
13 | store
| 45035996373718794 | store_dimension
VMART_DESIGN |
14 | store
| 45035996373718798 | store_sales_fact
VMART_DESIGN |
15 | store
| 45035996373718812 | store_orders_fact
(15 rows)
DESIGNS
Contains information about a Database Designer design. After you create a design and specify
certain parameters for Database Designer, DESIGNER_CREATE_DESIGN creates this table in
the V_MONITOR schema.
Column Name
Column
Type
Description
design_id
INTEGER
design_name
VARCHAR
ksafety_level
INTEGER
K-safety level for the design. Database Designer assigns a Ksafety value of 0 for clusters with 1 or 2 nodes, and assigns a
value of 1 for clusters with 3 or more nodes.
SQLReference Manual
HP Vertica System Tables
Column Name
optimization_
objective
design_type
propose_
super_first
Column
Type
Description
VARCHAR
VARCHAR
BOOLEAN
'QUERY'
'LOAD'
'BALANCED' (Default)
'COMPREHENSIVE'(default)
'INCREMENTAL'
design_
available
BOOLEAN
collected_
statistics
BOOLEAN
populate_
design_
tables_from_
queries
BOOLEAN
encoding_
design
BOOLEAN
deployment_
parallelism
INTEGER
propose_
unsegmented_
projections
BOOLEAN
't' if the design is an encoding optimization design on preexisting projections, otherwise, 'f' (the default).
Number of tables to be deployed in parallel when the design is
complete. Default: 0
SQLReference Manual
HP Vertica System Tables
Column Name
analyze_
correlations_
mode
Column
Type
Description
INTEGER
Example
View the record in the DESIGNS table that HP Vertica adds when you create a comprehensive
design for the VMart database that you name VMART_DESIGN:
=> \x
Expanded display is on.
=> SELECT * FROM DESIGNS;
-[ RECORD 1 ]-----------------------+-----------------design_id
| 45035996273705112
design_name
| VMART_DESIGN
ksafety_level
| 0
optimization_objective
| BALANCED
design_type
| COMPREHENSIVE
propose_super_first
| f
design_available
| f
collected_statistics
| f
populate_design_tables_from_queries | f
encoding_design
| f
deployment_parallelism
| 0
propose_unsegmented_projections
| t
analyze_correlations_mode
| 0
-[ RECORD 2 ]-----------------------+-----------------...
SQLReference Manual
HP Vertica System Tables
DISK_RESOURCE_REJECTIONS
Returns requests for resources that are rejected due to disk space shortages.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
RESOURCE_TYPE
VARCHAR
REJECTED_REASON
VARCHAR
REJECTED_COUNT
INTEGER
FIRST_REJECTED_TIMESTAMP
LAST_REJECTED_TIMESTAMP
LAST_REJECTED_VALUE
INTEGER
Notes
Output is aggregated by both RESOURCE_TYPE and REJECTED_REASON to provide more
comprehensive information.
Example
=>\pset expanded
Expanded display on.
=> SELECT * FROM disk_resource_rejections;
-[ RECORD 1 ]------------+--------------------------node_name
| e0
resource_type
| Table Data
rejected_reason
| Insufficient disk space
rejected_count
| 2
first_rejected_timestamp | 2009-10-16 15:55:16.336246
last_rejected_timestamp | 2009-10-16 15:55:16.336391
last_rejected_value
| 1048576
-[ RECORD 2 ]------------+---------------------------
SQLReference Manual
HP Vertica System Tables
node_name
resource_type
rejected_reason
rejected_count
first_rejected_timestamp
last_rejected_timestamp
last_rejected_value
|
|
|
|
|
|
|
e1
Table Data
Insufficient disk space
2
2009-10-16 15:55:16.37908
2009-10-16 15:55:16.379207
1048576
See Also
l
RESOURCE_REJECTIONS
CLEAR_RESOURCE_REJECTIONS
DISK_STORAGE
Returns the amount of disk storage used by the database on each node. Each node can have one or
more storage locations, and the locations can be on different disks with separate properties, such
as free space, used space, and block size. The information in this system table is useful in
determining where data files reside.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
STORAGE_PATH
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
STORAGE_USAGE
VARCHAR
USER: The storage location can be used by nondbadmin users, who are granted access to the
storage location
RANK
INTEGER
THROUGHPUT
INTEGER
LATENCY
INTEGER
STORAGE_STATUS
VARCHAR
DISK_BLOCK_SIZE_BYTES
INTEGER
DISK_SPACE_USED_BLOCKS
INTEGER
DISK_SPACE_USED_MB
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
DISK_SPACE_FREE_BLOCKS
INTEGER
DISK_SPACE_FREE_MB
INTEGER
DISK_SPACE_FREE_PERCENT
VARCHAR
Notes
l
All returned values for this system table are in the context of the file system of the host operating
system, and are not specific to HP Vertica-specific space.
The storage usage annotation called CATALOG indicates the location is used to store the
catalog. Each CATALOG location is specified only when creating a new database. You can
neither add a CATALOG location annotation using CREATE LOCATION, nor remove an
existing CATALOG annotation.
Example
Query the DISK_STORAGE table:
=>\pset expanded
Expanded display is on.
=> SELECT * FROM DISK_STORAGE;
-[ RECORD 1 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:48:35.932541
node_name
| site01
storage_path
| /mydb/node01_catalog/Catalog
storage_usage
| CATALOG
SQLReference Manual
HP Vertica System Tables
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 34708721
disk_space_used_mb
| 135581
disk_space_free_blocks | 178816678
disk_space_free_mb
| 698502
disk_space_free_percent | 83%
-[ RECORD 2 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:48:53.884255
node_name
| site01
storage_path
| /mydb/node01_data
storage_usage
| DATA,TEMP
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 34708721
disk_space_used_mb
| 135581
disk_space_free_blocks | 178816678
disk_space_free_mb
| 698502
disk_space_free_percent | 83%
-[ RECORD 3 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:49:08.299012
node_name
| site02
storage_path
| /mydb/node02_catalog/Catalog
storage_usage
| CATALOG
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 19968349
disk_space_used_mb
| 78001
disk_space_free_blocks | 193557050
disk_space_free_mb
| 756082
disk_space_free_percent | 90%
-[ RECORD 4 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:49:22.696772
node_name
| site02
storage_path
| /mydb/node02_data
storage_usage
| DATA,TEMP
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 19968349
disk_space_used_mb
| 78001
disk_space_free_blocks | 193557050
disk_space_free_mb
| 756082
disk_space_free_percent | 90%
-[ RECORD 5 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:50:03.960157
node_name
| site03
SQLReference Manual
HP Vertica System Tables
storage_path
| /mydb/node03_catalog/Catalog
storage_usage
| CATALOG
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 19902595
disk_space_used_mb
| 77744
disk_space_free_blocks | 193622804
disk_space_free_mb
| 756339
disk_space_free_percent | 90%
-[ RECORD 6 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:50:27.415735
node_name
| site03
storage_path
| /mydb/node03_data
storage_usage
| DATA,TEMP
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 19902595
disk_space_used_mb
| 77744
disk_space_free_blocks | 193622804
disk_space_free_mb
| 756339
disk_space_free_percent | 90%
-[ RECORD 7 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:50:39.398879
node_name
| site04
storage_path
| /mydb/node04_catalog/Catalog
storage_usage
| CATALOG
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 19972309
disk_space_used_mb
| 78017
disk_space_free_blocks | 193553090
disk_space_free_mb
| 756066
disk_space_free_percent | 90%
-[ RECORD 8 ]-----------+----------------------------current_timestamp
| 2009-08-11 14:50:57.879302
node_name
| site04
storage_path
| /mydb/node04_data
storage_usage
| DATA,TEMP
rank
| 0
throughput
| 0
latency
| 0
storage_status
| Active
disk_block_size_bytes
| 4096
disk_space_used_blocks | 19972309
disk_space_used_mb
| 78017
disk_space_free_blocks | 193553090
disk_space_free_mb
| 756066
disk_space_free_percent | 90%
SQLReference Manual
HP Vertica System Tables
ERROR_MESSAGES
Lists system error messages and warnings HP Vertica encounters while processing queries.
Column Name Data Type
Description
EVENT_TIMESTAMP
NODE_NAME
VARCHAR
USER_ID
INTEGER
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
REQUEST_ID
INTEGER
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Description
ERROR_LEVEL
VARCHAR
LOG
INFO
NOTICE
WARNING
ERROR
ROLLBACK
INTERNAL
FATAL
PANIC
ERROR_CODE
INTEGER
MESSAGE
VARCHAR
DETAIL
VARCHAR
HINT
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Notes
Some errors occur when no transaction is in progress, so the transaction identifier or statement
identifier columns could return NULL.
SQLReference Manual
HP Vertica System Tables
Example
=> SELECT event_timestamp, statement_id, error_level, message FROM error_messages;
event_timestamp
| statement_id | error_level |
message
-------------------------------+--------------+-------------+----------------------------------------------2012-03-30 17:52:12.326927-04 |
-1 | FATAL
| Client canceled session
raster-s1-10295:0x225b
2012-03-30 17:42:12.249989-04 |
20 | ERROR
| Syntax error at or near
"name"
2012-03-30 17:42:07.018451-04 |
-1 | FATAL
| Client canceled session
raster-s1-10295:0x225b
2012-03-30 17:40:22.665446-04 |
17 | ERROR
| Execution canceled by
operator
2012-03-30 16:32:38.784384-04 |
11 | ERROR
| Relation "systm_tables"
does not exist
2012-03-30 16:26:51.072655-04 |
98 | ERROR
| Relation "rebalance_
projections" does not exist
2012-03-30 14:31:09.953241-04 |
-1 | FATAL
| Client canceled session
raster-s1-10295:0x70
2012-03-30 14:26:06.655026-04 |
42 | ERROR
| Syntax error at or near
"constraint"
2012-03-30 11:48:22.30045-04 |
31 | ERROR
| Column "UDX" does not exist
2012-03-30 11:21:14.659128-04 |
20 | ERROR
| Invalid attnum 1 for
rangetable entry t
...
EVENT_CONFIGURATIONS
Monitors the configuration of events.
Column Name
Data Type
Description
EVENT_ID
VARCHAR
EVENT_DELIVERY_CHANNELS
VARCHAR
Example
=> SELECT * FROM event_configurations;
event_id
| event_delivery_channels
-------------------------------------------+------------------------Low Disk Space
| Vertica Log, SNMP Trap
Read Only File System
| Vertica Log, SNMP Trap
Loss Of K Safety
| Vertica Log, SNMP Trap
Current Fault Tolerance at Critical Level | Vertica Log, SNMP Trap
Too Many ROS Containers
| Vertica Log, SNMP Trap
WOS Over Flow
| Vertica Log, SNMP Trap
Node State Change
| Vertica Log, SNMP Trap
Recovery Failure
| Vertica Log, SNMP Trap
SQLReference Manual
HP Vertica System Tables
Recovery Error
Recovery Lock Error
Recovery Projection Retrieval Error
Refresh Error
Refresh Lock Error
Tuple Mover Error
Timer Service Task Error
Stale Checkpoint
(16 rows)
|
|
|
|
|
|
|
|
Vertica
Vertica
Vertica
Vertica
Vertica
Vertica
Vertica
Vertica
Log
Log
Log
Log
Log
Log
Log
Log, SNMP Trap
EXECUTION_ENGINE_PROFILES
Provides profiling information about query execution runs. The hierarchy of IDs, from highest level
to actual execution is:
l
PATH_ID
BASEPLAN_ID
LOCALPLAN_ID
OPERATOR_ID
Counters (output from the COUNTER_NAME column) are collected for each actual Execution Engine
(EE) operator instance.
The following columns form a unique key for rows in the Data Collector table DC_EXECUTION_
ENGINE_EVENTS:
l
TRANSACTION_ID
STATEMENT_ID
NODE_NAME
OPERATOR_ID
COUNTER_NAME
COUNTER_TAG
For additional details about profiling and debugging, see Profiling Database Performance in the
Administrator's Guide.
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
NODE_NAME
VARCHAR
USER_ID
INTEGER
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
OPERATOR_NAME
VARCHAR
OPERATOR_ID
INTEGER
BASEPLAN_ID
INTEGER
PATH_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
LOCALPLAN_ID
INTEGER
ACTIVITY_ID
INTEGER
RESOURCE_ID
INTEGER
COUNTER_NAME
VARCHAR
COUNTER_TAG
VARCHAR
String that uniquely identifies the counter for operators that might
need to distinguish between different instances. For example,
COUNTER_TAG is used to identify to which of the node bytes are
being sent to or received from for the NetworkSend operator.
COUNTER_VALUE
INTEGER
IS_EXECUTING
BOOLEAN
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
COUNTER_NAME Values
The value of COUNTER_NAME can be any of the following:
COUNTER_NAME
Description
buffers spilled
[NetworkSend] Buffers
spilled to disk by
NetworkSend.
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
bytes received
[NetworkRecv] The
number of bytes
received over the
network for query
execution.
[DataSource] The
number of bytes read
from HP Vertica cache
when an EE
DataSource operator is
reading from ROS
containers.
[DataSource] The
number of bytes read
from disk when an EE
DataSource operator is
reading from ROS
containers.
bytes sent
[NetworkSend] Size of
data after encoding and
compression sent over
the network (actual
network bytes).
bytes spilled
[NetworkSend] Bytes
spilled to disk by
NetworkSend.
bytes total
Only relevant to
SendFiles operator
(that is, recover-bycontainer plan) total
number of bytes to
send / receive.
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
Number of merge
phases already
completed by an LSort
or DataTarget
operator. Compare to
the total merge
phases. Variants on
this value include join
inner completed
merge phases.
Total amount of
temporary data the
operator has written to
files. Compare to
cumulative size of
temp files (bytes)
to understand impact
of encoding and
compression in an
externalizing operator.
Variants on this value
include join inner
cumulative size of
raw temp files
(bytes).
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
For externalizing
operators only, the
total number of
encoded and
compressed temp data
the operator has
written to files. A sort
operator might go
through multiple merge
phases, where at each
pass sorted chunks of
data are merged into
fewer chunks. This
counter remembers the
cumulative size of all
temp files past and
present. Variants on
this value include join
inner cumulative
size of temp files
(bytes).
For externalizing
operators only, the
current size of the
encoded and
compressed temp data
that the operator has
written to files.
Variants on this value
include join inner
current size of
temp files (bytes).
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
[Analyze Statistics]
Time spent estimating
the number of distinct
values from the sample
after data has been
read off disk and into
the statistical sample.
[NetworkRecv] Size of
received data after
decompressed (but still
encoded) received over
the network.
[NetworkSend] Size of
data sent over the
network after
encoding.
end time
Time (timestamp)
when HP Vertica
stopped processing the
operation
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
exception data.
Relevant only to
SendFiles/RecvFiles
operators (that is,
recover-by-container
plan) number of files
sent / received.
files total
Relevant only to
SendFiles/RecvFiles
operators (that is,
recover-by-container
plan) total number of
files to send / receive.
[Analyze Statistics]
Time spent estimating
the number of distinct
values from the sample
after data has been
read off disk and into
the statistical sample.
Time in microseconds
that an operator
spends waiting for
upstream operators.
input rows
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
[Analyze Statistics]
Maximum number of
rows that will be stored
in the statistical
sample.
[NetworkSend,
NetworkRecv] Time in
microseconds spent
waiting on the network.
Time in microseconds
that an operator
spends waiting for the
output buffer to be
consumed by a
downstream operator.
[NetworkSend] Time in
microseconds spent by
NetworkSend when
stalled waiting for
network buffers to
clear.
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
[NetworkSend] Time in
microseconds spent by
the input operator
making rows to send.
read (bytes)
Time in microseconds
that a Recv operator
spends reading data
from its socket.
cumulative size
of raw temp data
(bytes)
cumulative size
of temp files
(bytes)
current size of
temp files
(bytes)
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
Number of physical
tuples produced by an
operator.
Complements the rows
produced counter,
which shows the
number of logical rows
produced by an
operator. For example,
if a value occurs 1000
rows consecutively
and is RLE encoded, it
counts as 1000 rows
produced not only 1
rle rows produced.
[DataTarget] Number
of ROS blocks
created, due to
boundary alignment
with RLE prefix
columns, when an EE
DataTarget operator is
writing to ROS
containers.
[DataTarget] Number
of ros blocks created
when an EE
DataTarget operator is
writing to ROS
containers.
[DataTarget] Number
of bytes written to disk
when an EE
DataTarget operator is
writing to ROS
containers.
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
rows in sample
[Analyze Statistics]
Actual number of rows
that will be stored in
the statistical sample.
[DataTarget] Number
of rows sorted when an
EE DataTarget
operator is writing to
ROS containers.
rows processed
[DataSource] Number
of rows processed
when an EE
DataSource operator is
writing to ROS
containers
rows produced
[DataSource] Number
of rows it skips direct
scanning with help of
valindex when an EE
DataSource operator is
writing to ROS
containers. This
counter's value is not
greater than "rows
processed" counter.
rows received
[NetworkRecv]
Number of received
sent over the network.
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
rows rejected
rows sent
[NetworkSend]
Number of rows sent
over the network.
Time in microseconds
that a Send operator
spends writing data to
its socket.
start time
Time (timestamp)
when HP Vertica
started to process the
operation.
Number of merge
phases an LSort or
DataTarget operator
must complete to finish
sorting its data. NULL
until the operator can
compute this value (all
data must first be
ingested by the
operator). Variants on
this value include join
inner total merge
phases.
StorageUnion wait
time in microseconds.
SQLReference Manual
HP Vertica System Tables
COUNTER_NAME
Description
Number of bytes
acquired from the
WOS by a DataTarget
operator.
Note: This is usually
more but can be less
than WOS bytes
written if an earlier
statement in the
transaction acquired
some WOS memory.
Number of bytes
written to the WOS by
a DataTarget
operator.
written rows
[DataTarget] Number
of rows written when
an EE DataTarget
operator writes to ROS
containers
Examples
The next two examples show the contents of the EXECUTION_ENGINE_PROFILES table:
=> SELECT operator_name, operator_id, counter_name, counter_value
FROM EXECUTION_ENGINE_PROFILES WHERE operator_name = 'Scan'
ORDER BY counter_value DESC;
operator_name | operator_id |
counter_name
| counter_value
---------------+-------------+--------------------------+----------------Scan
|
12 | end time
| 397916465478595
Scan
|
9 | end time
| 397916465478510
Scan
|
12 | start time
| 397916465462098
Scan
|
9 | start time
| 397916465447998
Scan
|
14 | bytes read from disk
|
28044535
Scan
|
14 | bytes read from disk
|
28030212
Scan
|
12 | rows processed
|
5000000
Scan
|
12 | estimated rows produced |
4999999
Scan
|
18 | rows produced
|
1074828
Scan
|
18 | rle rows produced
|
1074828
SQLReference Manual
HP Vertica System Tables
Scan
Scan
Scan
Scan
Scan
Scan
Scan
Scan
Scan
Scan
Scan
Scan
Scan
Scan
(24 rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3
7
7
7
12
7
3
12
14
3
14
12
18
18
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1074568
799526
799526
682592
673806
545717
537400
505315
495176
452403
420189
404184
398751
339321
The notable thing about the following query is the path_id column, which links the path that the
query optimizer takes (via the EXPLAIN command's textual output) with join error messages.
=> SELECT operator_name, path_id, counter_name,
counter_value FROM execution_engine_profiles;
operator_name | path_id |
counter_name
| counter_value
---------------+---------+---------------------------+--------------Join
|
1 | estimated rows produced
|
10000
Join
|
1 | file handles
|
0
Join
|
1 | memory allocated (bytes) |
2405824
Join
|
1 | memory reserved (bytes)
|
1769472
Join
|
1 | rle rows produced
|
3
Join
|
1 | rows produced
|
3
Join
|
1 | clock time (us)
|
24105
Join
|
1 | execution time (us)
|
235
HOST_RESOURCES
Provides a snapshot of the node. This is useful for regularly polling the node with automated tools or
scripts.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
HOST_NAME
VARCHAR
OPEN_FILES_LIMIT
INTEGER
THREADS_LIMIT
INTEGER
CORE_FILE_LIMIT_MAX_SIZE_BYTES
INTEGER
PROCESSOR_COUNT
INTEGER
PROCESSOR_CORE_COUNT
INTEGER
PROCESSOR_DESCRIPTION
VARCHAR
OPENED_FILE_COUNT
INTEGER
OPENED_SOCKET_COUNT
INTEGER
OPENED_NONFILE_NONSOCKET_COUNT
INTEGER
TOTAL_MEMORY_BYTES
INTEGER
TOTAL_MEMORY_FREE_BYTES
INTEGER
TOTAL_BUFFER_MEMORY_BYTES
INTEGER
TOTAL_MEMORY_CACHE_BYTES
INTEGER
TOTAL_SWAP_MEMORY_BYTES
INTEGER
TOTAL_SWAP_MEMORY_FREE_BYTES
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
DISK_SPACE_FREE_MB
INTEGER
DISK_SPACE_USED_MB
INTEGER
DISK_SPACE_TOTAL_MB
INTEGER
Examples
Query the HOST_RESOURCES table:
=>\pset expanded
Expanded display is on.
=> SELECT * FROM HOST_RESOURCES;
-[ RECORD 1 ]------------------+-------------------------------------host_name
| myhost-s1
open_files_limit
| 65536
threads_limit
| 15914
core_file_limit_max_size_bytes | 1649680384
processor_count
| 2
processor_core_count
| 8
processor_description
| Intel(R) Xeon(R) CPU E5504 @ 2.00GHz
opened_file_count
| 5
opened_socket_count
| 4
opened_nonfile_nonsocket_count | 3
total_memory_bytes
| 16687161344
total_memory_free_bytes
| 4492627968
total_buffer_memory_bytes
| 1613922304
total_memory_cache_bytes
| 9349111808
total_swap_memory_bytes
| 36502126592
total_swap_memory_free_bytes
| 36411580416
disk_space_free_mb
| 121972
disk_space_used_mb
| 329235
disk_space_total_mb
| 451207
-[ RECORD 2 ]------------------+-------------------------------------host_name
| myhost-s2
open_files_limit
| 65536
threads_limit
| 15914
core_file_limit_max_size_bytes | 3772891136
processor_count
| 2
processor_core_count
| 4
processor_description
| Intel(R) Xeon(R) CPU E5504 @ 2.00GHz
opened_file_count
| 5
opened_socket_count
| 3
opened_nonfile_nonsocket_count | 3
total_memory_bytes
| 16687161344
total_memory_free_bytes
| 9525706752
SQLReference Manual
HP Vertica System Tables
total_buffer_memory_bytes
| 2840420352
total_memory_cache_bytes
| 3060588544
total_swap_memory_bytes
| 34330370048
total_swap_memory_free_bytes
| 34184642560
disk_space_free_mb
| 822190
disk_space_used_mb
| 84255
disk_space_total_mb
| 906445
-[ RECORD 3 ]------------------+-------------------------------------host_name
| myhost-s3
open_files_limit
| 65536
threads_limit
| 15914
core_file_limit_max_size_bytes | 3758211072
processor_count
| 2
processor_core_count
| 4
processor_description
| Intel(R) Xeon(R) CPU E5504 @ 2.00GHz
opened_file_count
| 5
opened_socket_count
| 3
opened_nonfile_nonsocket_count | 3
total_memory_bytes
| 16687161344
total_memory_free_bytes
| 9718706176
total_buffer_memory_bytes
| 2928369664
total_memory_cache_bytes
| 2757115904
total_swap_memory_bytes
| 34315689984
total_swap_memory_free_bytes
| 34205523968
disk_space_free_mb
| 820789
disk_space_used_mb
| 85640
disk_space_total_mb
| 906429
-[ RECORD 4 ]------------------+-------------------------------------host_name
| myhost-s4
open_files_limit
| 65536
threads_limit
| 15914
core_file_limit_max_size_bytes | 3799433216
processor_count
| 2
processor_core_count
| 8
processor_description
| Intel(R) Xeon(R) CPU E5504 @ 2.00GHz
opened_file_count
| 5
opened_socket_count
| 3
opened_nonfile_nonsocket_count | 3
total_memory_bytes
| 16687161344
total_memory_free_bytes
| 8772620288
total_buffer_memory_bytes
| 3792273408
total_memory_cache_bytes
| 2831040512
total_swap_memory_bytes
| 34356912128
total_swap_memory_free_bytes
| 34282590208
disk_space_free_mb
| 818896
disk_space_used_mb
| 55291
disk_space_total_mb
| 874187
IO_USAGE
Provides disk I/O bandwidth usage history for the system.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
START_TIME
END_TIME
READ_KBYTES_PER_SEC
FLOAT
WRITTEN_KBYTES_PER_SEC
FLOAT
Permissions
Must be a superuser.
Example
=> SELECT * FROM io_usage;
node_name |
start_time
|
end_time
| read_kbytes_
per_sec | written_kbytes_per_sec
-----------+------------------------------+-------------------------------+--------------------+-----------------------initiator | 2011-09-16 15:23:38.003714-04 | 2011-09-16 15:24:00.015769-04 |
11.63 |
620.03
e0
| 2011-09-16 15:23:37.005431-04 | 2011-09-16 15:24:00.011519-04 |
11.13 |
593.24
initiator | 2011-09-16 15:24:00.015728-04 | 2011-09-16 15:25:00.015439-04 |
18.67 |
473.87
e1
| 2011-09-16 15:24:00.014491-04 | 2011-09-16 15:25:00.010432-04 |
18.67 |
473.9
e1
| 2011-09-16 15:23:37.006595-04 | 2011-09-16 15:24:00.014533-04 |
11.13 |
593.18
e0
| 2011-09-16 15:24:00.011478-04 | 2011-09-16 15:25:00.017536-04 |
18.66 |
473.82
(6 rows)
LOAD_STREAMS
Monitors active and historical load metrics for load streams on each node. This is useful for
obtaining statistics about how many records got loaded and rejected from the previous load. HP
Vertica maintains system table metrics until they reach a designated size quota (in kilobytes). The
quota is set through internal processes and cannot be set or viewed directly.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SESSION_ID
VARCHAR
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
STREAM_NAME
VARCHAR
SCHEMA_NAME
VARCHAR
TABLE_ID
INTEGER
TABLE_NAME
VARCHAR
LOAD_START
VARCHAR
LOAD_DURATION_MS
NUMERIC
(54,0)
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
IS_EXECUTING
BOOLEAN
ACCEPTED_ROW_COUNT
INTEGER
REJECTED_ROW_COUNT
INTEGER
READ_BYTES
INTEGER
INPUT_FILE_SIZE_BYTES
INTEGER
PARSE_COMPLETE_PERCENT
INTEGER
Percent of rows from the input file that have been loaded.
UNSORTED_ROW_COUNT
INTEGER
SORTED_ROW_COUNT
INTEGER
SORT_COMPLETE_PERCENT
INTEGER
Percent of rows from the input file that have been sorted.
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
LOCK_USAGE
Provides aggregate information about lock requests, releases, and attempts, such as wait
time/count and hold time/count. HP Vertica records:
l
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
NODE_NAME
VARCHAR
SESSION_ID
VARCHAR
Identifier for this session. This identifier is unique within the cluster
at any point in time but can be reused when the session closes.
OBJECT_NAME
VARCHAR
MODE
VARCHAR
T Tuple Mover lock used by the Tuple Mover and also used
for COPY into pre-join projections.
AVG_HOLD_TIME
INTERVAL
NONE
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
MAX_HOLD_TIME
INTERVAL
HOLD_COUNT
INTEGER
AVG_WAIT_TIME
INTERVAL
MAX_WAIT_TIME
INTERVAL
WAIT_COUNT
INTEGER
Total number of times lock was unavailable at the time it was first
requested.
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> SELECT * FROM lock_usage;
-[ RECORD 1 ]-+---------------------------------node_name
| v_myvdb_node0004
session_id
| raster-f1.verticaco-13199:0x100
object_name
| Global Catalog
mode
| S
avg_hold_time | 00:00:00.032718
max_hold_time | 00:00:00.251213
hold_count
| 34
avg_wait_time | 00:00:00.000048
max_wait_time | 00:00:00.000119
wait_count
| 0
-[ RECORD 2 ]-+---------------------------------node_name
| v_myvdb_node0004
session_id
| raster-f1.verticaco-13199:0x102
object_name
| Global Catalog
mode
| S
avg_hold_time | 00:00:00.038148
max_hold_time | 00:00:00.185088
hold_count
| 34
avg_wait_time | 00:00:00.000049
max_wait_time | 00:00:00.000124
wait_count
| 0
-[ RECORD 3 ]-+---------------------------------node_name
| v_myvdb_node0004
SQLReference Manual
HP Vertica System Tables
session_id
| raster-f1.verticaco-13199:0x119
object_name
| Table:public.dwdate
mode
| T
avg_hold_time | 00:00:04.269108
max_hold_time | 00:00:04.269108
hold_count
| 1
avg_wait_time | 00:00:00.000019
max_wait_time | 00:00:00.000019
wait_count
| 0
-[ RECORD 4 ]-+---------------------------------node_name
| v_myvdb_node0004
session_id
| raster-f1.verticaco-13199:0x11d
object_name
| Global Catalog
mode
| X
avg_hold_time | 00:00:00.027261
max_hold_time | 00:00:00.027261
hold_count
| 1
avg_wait_time | 00:00:00.000038
max_wait_time | 00:00:00.000038
wait_count
| 0
...
See Also
l
DUMP_LOCKTABLE
LOCKS
PROJECTION_REFRESHES
SELECT
SESSION_PROFILES
SQLReference Manual
HP Vertica System Tables
LOCKS
Monitors lock grants and requests for all nodes.
See also LOCK_USAGE for aggregate information about lock requests, releases, and attempts,
such as wait time/count and hold time/count.
Column Name
Data Type
Description
NODE_NAMES
VARCHAR
OBJECT_NAME
VARCHAR
OBJECT_ID
INTEGER
TRANSACTION_ID
VARCHAR
TRANSACTION_DESCRIPTION
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
LOCK_MODE
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
LOCK_SCOPE
VARCHAR
STATEMENT_LOCALPLAN
STATEMENT_COMPILE
STATEMENT_EXECUTE
TRANSACTION_POSTCOMMIT
TRANSACTION
GRANT_TIMESTAMP
Notes
l
Lock acquisition and wait times are collected and exposed via the START_TIMESTAMP
column.
Locks acquired on tables that were subsequently dropped by another transaction can result in
the message, Unknown or deleted object, appearing in the output's OBJECT column.
If a SELECT..FROM LOCKS query times out after five minutes, it is possible the cluster has failed.
Run the Diagnostics Utility.
SQLReference Manual
HP Vertica System Tables
SI
Yes
No
No
No
Yes
Yes
No
No
Yes No
No
Yes
Yes
No
SI
No
No
No
No
Yes
Yes
No
No
No
No
No
No
Yes
No
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
No
No
No
No
SI X
SI SI X
SI I
SI
SI SI SI X
SI SI O
SI X
SI X
SI X
SQLReference Manual
HP Vertica System Tables
O O
Example
This example shows an INSERT lock in use:
=>\pset expanded
Expanded display is on.
=> SELECT * FROM LOCKS;
-[ RECORD 1 ]-----------+--------------------------------------------------------node_names
| node01,node02,node03,node04
object_name
| Table:fact
object_id
| 45035996273772278
transaction_description | Txn: a000000000112b 'COPY fact FROM '/data_dg/fact.dat'
DELIMITER '|' NULL '\\N';'
lock_mode
| I
lock_scope
| TRANSACTION
request_timestamp
| 2011-04-17 14:01:07.662325-04
grant_timestamp
| 2011-04-17 14:01:07.662325-04
See Also
l
DUMP_LOCKTABLE
LOCK_USAGE
PROJECTION_REFRESHES
SELECT
SESSION_PROFILES
TRANSACTIONS
LOGIN_FAILURES
This system table lists failures for each failed login attempt. This information helps you determine if
a user is having difficulty getting into the database or identify a possible intrusion attempt.
Column Name
Data Type
LOGIN_TIMESTAMP
DATABASE_NAME
VARCHAR
Description
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
CLIENT_HOSTNAME
VARCHAR
CLIENT_PID
INTEGER
CLIENT_VERSION
VARCHAR
Unused.
AUTHENTICATION_METHOD
VARCHAR
Trust
Reject
GSS
LDAP
Ident
Hash
TLS
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CLIENT_AUTHENTICATION_NAME
VARCHAR
REASON
VARCHAR
INVALID USER
ACCOUNT LOCKED
REJECT
FAILED
INVALID DATABASE
Privileges
Must be a superuser.
Examples
This example shows failed login attempts recorded in the LOGIN_FAILUREStable.
MEMORY_USAGE
Records system resource history for memory usage. This is useful for comparing memory that HP
Vertica uses versus memory in use by the entire system.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
START_TIME
END_TIME
AVERAGE_MEMORY_USAGE_PERCENT
FLOAT
Permissions
Must be a superuser.
Example
=> SELECT * FROM memory_usage;
node_name |
start_time
|
end_time
| average_
memory_usage_percent
-----------+-------------------------------+-------------------------------+---------------------------initiator | 2012-03-25 15:23:38.001952-04 | 2012-03-25 15:24:00.011432-04 |
50.39
initiator | 2012-03-25 15:24:00.011432-04 | 2012-03-25 15:25:00.008539-04 |
51.08
e0
| 2012-03-25 15:23:37.00339-04 | 2012-03-25 15:24:00.006837-04 |
50.3
e0
| 2012-03-25 15:24:00.006837-04 | 2012-03-25 15:25:00.011629-04 |
51.08
e1
| 2012-03-25 15:23:37.001344-04 | 2012-03-25 15:24:00.009634-04 |
50.3
e1
| 2012-03-25 15:24:00.009634-04 | 2012-03-25 15:25:00.005176-04 |
51.08
(6 rows)
MONITORING_EVENTS
Reports significant events that can affect database performance and functionality if you do not
address their root causes.
See Monitoring Events in the Administrator's Guide for details.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
EVENT_CODE
INTEGER
EVENT_ID
INTEGER
EVENT_SEVERITY
VARCHAR
EVENT_POSTED_TIMESTAMP
EVENT_CLEARED_TIMESTAMP
EVENT_EXPIRATION
EVENT_CODE_DESCRIPTION
VARCHAR
EVENT_PROBLEM_DESCRIPTION
VARCHAR
SQLReference Manual
HP Vertica System Tables
Permissions
Must be a superuser.
Notes
For details about where HP Vertica posts events, see Monitoring in the Administrator's Guide
Example
-[ RECORD 1 ]-------------+--------------------------------------------------------------------------------------node_name
| v_myvdb_node0001
event_code
| 0
event_id
| 0
event_severity
| Warning
event_posted_timestamp
| 2012-03-22 11:05:32.002682-04
event_cleared_timestamp
|
event_expiration
| 2012-03-22 17:07:32.002681-04
event_code_description
| Low Disk Space
event_problem_description | Warning: Low disk space detected (80% in use)
-[ RECORD 2 ]-------------+--------------------------------------------------------------------------------------node_name
| v_myvdb_node0001
event_code
| 6
event_id
| 6
event_severity
| Informational
event_posted_timestamp
| 2012-03-22 11:03:49.055705-04
event_cleared_timestamp
|
event_expiration
| 2080-04-09 13:17:56.055704-05
event_code_description
| Node State Change
event_problem_description | Changing node v_myvdb_node0001 startup state to UP
-[ RECORD 3 ]-------------+--------------------------------------------------------------------------------------node_name
| v_myvdb_node0001
event_code
| 6
event_id
| 7
event_severity
| Informational
event_posted_timestamp
| 2012-03-22 11:03:49.03912-04
event_cleared_timestamp
| 2012-03-22 11:03:49.05626-04
event_expiration
| 2080-04-09 13:17:56.039117-05
event_code_description
| Node State Change
event_problem_description | Changing node v_myvdb_node0001 startup state to REA
DY
-[ RECORD 4 ]-------------+--------------------------------------------------------------------------------------node_name
| v_myvdb_node0001
event_code
| 6
event_id
| 8
event_severity
| Informational
event_posted_timestamp
| 2012-03-12 10:26:16.731482-04
event_cleared_timestamp
|
SQLReference Manual
HP Vertica System Tables
event_expiration
| 2080-03-30 12:40:23.731482-05
event_code_description
| Node State Change
event_problem_description | Changing node v_myvdb_node0001 startup state to SHU
TDOWN
...
See Also
l
ACTIVE_EVENTS
NETWORK_INTERFACES
Provides information about network interfaces on all HP Vertica nodes.
Column Name
Data Type
Description
NODE_ID
INTEGER
NODE_NAME
VARCHAR
INTERFACE
VARCHAR
IP_ADDRESS
VARCHAR
SUBNET
VARCHAR
MASK
VARCHAR
BROADCAST_ADDRESS
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> SELECT * FROM network_interfaces;
node_name
| interface |
ip_address
|
subnet
|
mask
|
broadcast_address
------------------+-----------+----------------+--------------+---------------+-----------------v_gry22_node0001 | lo
| 127.0.0.1
| 127.0.0.0
| 255.0.0.X
| 127.0.0.1
v_gry22_node0001 | eth0
| 10.20.XX.XXX
| 10.20.XX.X
| 255.255.255.X |
10.20.XX.XXX
v_gry22_node0001 | eth1
| 192.168.XX.XXX | 192.168.XX.0 | 255.255.255.X |
SQLReference Manual
HP Vertica System Tables
192.168.XX.XXX
v_gry22_node0002
v_gry22_node0002
10.20.XX.XXX
v_gry22_node0002
192.168.XX.XXX
v_gry22_node0003
v_gry22_node0003
10.20.XX.XXX
v_gry22_node0003
192.168.XX.XXX
v_gry22_node0004
v_gry22_node0004
10.20.XX.XXX
v_gry22_node0004
192.168.XX.XXX
(12 rows)
| lo
| eth1
| 127.0.0.1
| 10.20.XX.XXX
| 127.0.0.0
| 10.20.XX.X
| eth2
| lo
| eth1
| 127.0.0.1
| 10.20.XX.XXX
| eth2
| lo
| eth1
| 127.0.0.1
| 10.20.XX.XXX
| eth2
| 127.0.0.0
| 10.20.XX.X
| 127.0.0.0
| 10.20.XX.X
| 255.0.0.0
| 127.0.0.1
| 255.255.255.X |
| 255.0.0.X
| 127.0.0.1
| 255.255.255.X |
| 255.0.0.X
| 127.0.0.1
| 255.255.255.X |
NETWORK_USAGE
Provides network bandwidth usage history on the system. This is useful for determining if HP
Vertica is using a large percentage of its available network bandwidth.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
START_TIME
END_TIME
TX_KBYTES_PER_SEC
FLOAT
RX_KBYTES_PER_SEC
FLOAT
Permissions
Must be a superuser.
Example
=> SELECT node_name, start_time, end_time,
tx_kbytes_per_sec AS tx_kb, rx_kbytes_per_sec AS rx_kb
FROM network_usage;
node_name |
start_time
|
end_time
| AS tx_kb | AS
SQLReference Manual
HP Vertica System Tables
rx_kb
----------+-------------------------------+-------------------------------+----------+--------initiator | 2012-03-25 15:23:38.000834-04 | 2012-03-25 15:24:00.006087-04 |
0.22 |
0.86
e0
| 2012-03-25 15:23:37.003062-04 | 2012-03-25 15:24:00.003448-04 |
0.21 |
0.83
e1
| 2012-03-25 15:24:00.002963-04 | 2012-03-25 15:25:00.002497-04 |
0.81 |
0.45
e1
| 2012-03-25 15:23:37.000989-04 | 2012-03-25 15:24:00.002963-04 |
0.21 |
0.83
e0
| 2012-03-25 15:24:00.003448-04 | 2012-03-25 15:25:00.004897-04 |
0.81 |
0.45
initiator | 2012-03-25 15:24:00.006087-04 | 2012-03-25 15:25:00.007525-04 |
0.81 |
0.45
(6 rows)
NODE_RESOURCES
Provides a snapshot of the node. This is useful for regularly polling the node with automated tools or
scripts.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
HOST_NAME
VARCHAR
PROCESS_SIZE_BYTES
INTEGER
PROCESS_RESIDENT_SET_SIZE_BYTES
INTEGER
PROCESS_SHARED_MEMORY_SIZE_BYTES
INTEGER
PROCESS_TEXT_MEMORY_SIZE_BYTES
INTEGER
PROCESS_DATA_MEMORY_SIZE_BYTES
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PROCESS_LIBRARY_MEMORY_SIZE_BYTES
INTEGER
PROCESS_DIRTY_MEMORY_SIZE_BYTES
INTEGER
Example
Query the NODE_RESOURCES table:
=>\pset expanded
Expanded display is on.
=> SELECT * FROM NODE_RESOURCES;
-[ RECORD 1 ]---------------------+------------------node_name
| v_vmartdb_node01
host_name
| myhost-s1
process_size_bytes
| 2001829888
process_resident_set_size_bytes
| 40964096
process_shared_memory_size_bytes | 16543744
process_text_memory_size_bytes
| 46649344
process_data_memory_size_bytes
| 0
process_library_memory_size_bytes | 1885351936
process_dirty_memory_size_bytes
| 0
-[ RECORD 2 ]---------------------+------------------node_name
| v_vmartdb_node02
host_name
| myhost-s2
process_size_bytes
| 399822848
process_resident_set_size_bytes
| 31453184
process_shared_memory_size_bytes | 10862592
process_text_memory_size_bytes
| 46649344
process_data_memory_size_bytes
| 0
process_library_memory_size_bytes | 299356160
process_dirty_memory_size_bytes
| 0
-[ RECORD 3 ]---------------------+------------------node_name
| v_vmartdb_node03
host_name
| myhost-s3
process_size_bytes
| 399822848
process_resident_set_size_bytes
| 31100928
process_shared_memory_size_bytes | 10735616
process_text_memory_size_bytes
| 46649344
process_data_memory_size_bytes
| 0
process_library_memory_size_bytes | 299356160
process_dirty_memory_size_bytes
| 0
-[ RECORD 4 ]---------------------+------------------node_name
| v_vmartdb_node04
host_name
| myhost-s4
process_size_bytes
| 466923520
process_resident_set_size_bytes
| 31309824
process_shared_memory_size_bytes | 10735616
process_text_memory_size_bytes
| 46649344
process_data_memory_size_bytes
| 0
process_library_memory_size_bytes | 366456832
SQLReference Manual
HP Vertica System Tables
process_dirty_memory_size_bytes
| 0
NODE_STATES
Monitors node recovery state-change history on the system.
Column Name Data Type
Description
EVENT_TIMESTAMP
NODE_ID
INTEGER
NODE_NAME
VARCHAR
NODE_STATE
VARCHAR
UP
READY
UNSAFE
SHUTDOWN
RECOVERING
SQLReference Manual
HP Vertica System Tables
SQLReference Manual
HP Vertica System Tables
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
Query the NODE_STATES table:
=> SELECT * FROM node_states;
event_timestamp
|
node_id
|
node_name
| node_state
-------------------------------+-------------------+--------------------+-------------2012-12-09 06:36:22.10059-05 | 45035996273704980 | v_onenode_node0001 | UP
2012-12-09 06:36:22.10044-05 | 45035996273704980 | v_onenode_node0001 | READY
2012-12-09 06:36:22.081961-05 | 45035996273704980 | v_onenode_node0001 | INITIALIZING
2012-12-09 05:29:13.637828-05 | 45035996273704980 | v_onenode_node0001 | DOWN
2012-12-09 05:29:12.739187-05 | 45035996273704980 | v_onenode_node0001 | SHUTDOWN
2012-12-08 13:50:21.074688-05 | 45035996273704980 | v_onenode_node0001 | UP
2012-12-08 13:50:21.074544-05 | 45035996273704980 | v_onenode_node0001 | READY
2012-12-08 13:50:21.073529-05 | 45035996273704980 | v_onenode_node0001 | INITIALIZING
(8 rows)
OUTPUT_DEPLOYMENT_STATUS
Contains information about the deployment status of all the projections in your design. Each row
contains information about a different projection. Running DESIGNER_RUN_POPULATE_
DESIGN_AND_DEPLOY and deploying the design populates this table.
Column Name
Column
Type
Description
deployment_id
INTEGER
design_name
VARCHAR
deployment_
projection_id
INTEGER
deployment_
projection_
name
VARCHAR
projection.
SQLReference Manual
HP Vertica System Tables
Column Name
deployment_
status
error_message
Column
Type
Description
VARCHAR
VARCHAR
pending
complete
needs_refresh
in_progress
error
Example
Query the OUTPUT_DEPLOYMENT_STATUS table after deploying a design on the VMart
database:
=> \x
Expanded display is on.
=> SELECT * FROM OUTPUT_DEPLOYMENT_STATUS;
-[ RECORD 1 ]--------------+--------------------------------------------deployment_id
| 45035996273708449
design_name
| VMART_DESIGN
deployment_projection_id
| 1
deployment_projection_name | customer_dimension_DBD_1_rep_VMART_DESIGN
deployment_status
| complete
error_message
| N/A
-[ RECORD 2 ]--------------+--------------------------------------------deployment_id
| 45035996273708449
design_name
| VMART_DESIGN
deployment_projection_id
| 2
deployment_projection_name | product_dimension_DBD_2_rep_VMART_DESIGN
deployment_status
| complete
error_message
| N/A
-[ RECORD 3 ]--------------+--------------------------------------------deployment_id
| 45035996273708449
design_name
| VMART_DESIGN
deployment_projection_id
| 3
deployment_projection_name | product_dimension_DBD_3_rep_VMART_DESIGN
deployment_status
| complete
error_message
| N/A
-[ RECORD 4 ]--------------+--------------------------------------------deployment_id
| 45035996273708449
design_name
| VMART_DESIGN
deployment_projection_id
| 4
SQLReference Manual
HP Vertica System Tables
deployment_projection_name | promotion_dimension_DBD_4_rep_VMART_DESIGN
deployment_status
|
error_message
| N/A
...
OUTPUT_EVENT_HISTORY
Contains information about each stage that Database Designer performs to design and optimize
your database design.
Column
Name
Column
Type
TIME_STAMP
DESIGN_ID
INTEGER
DESIGN_NAME
VARCHAR
STAGE_TYPE
VARCHAR
Description
Design in progress
All done
Deployment in progress
ITERATION_
NUMBER
INTEGER
TOTAL_QUERY_
COUNT
INTEGER
REMAINING_
QUERY_COUNT
INTEGER
MAX_STEP_
NUMBER
INTEGER
process.
SQLReference Manual
HP Vertica System Tables
Column
Name
Column
Type
Description
CURRENT_
STEP_NUMBER
INTEGER
SQLReference Manual
HP Vertica System Tables
Column
Name
Column
Type
Description
CURRENT_
STEP_
DESCRIPTION
VARCHAR
design_table_name
projection_name
TABLE_ID
INTEGER
Complete
Running deployment
SQLReference Manual
HP Vertica System Tables
Example
The following example shows the steps that Database Designer performs while optimizing the
VMart example database:
=> SELECT DESIGNER_CREATE_DESIGN('VMART_DESIGN');
=> SELECT DESIGNER_ADD_DESIGN_TABLES('VMART_DESIGN','public.*');
=> SELECT DESIGNER_ADD_DESIGN_QUERIES('VMART_DESIGN','/tmp/examples/vmart_queries.sql',);
...
=> \x
Expanded display is on.
=> SELECT * FROM OUTPUT_EVENT_HISTORY;
-[ RECORD 1 ] -----------+---------------------------time_stamp
| 2013-06-05 11:44:41.588
design_id
| 45035996273705090
design_name
| VMART_DESIGN
stage_type
| Design in progress
iteration_number
|
total_query_count
|
remaining_query_count
|
max_step_number
|
current_step_number
|
current_step_description | Design with deployment started
table id
|
-[ RECORD 2 ] -----------+---------------------------time_stamp
| 2013-06-05 11:44:41.611
design_id
| 45035996273705090
design_name
| VMART_DESIGN
stage_type
| Design in progress
iteration_number
|
total_query_count
|
remaining_query_count
|
max_step_number
|
current_step_number
|
current_step_description | Design in progress: Analyze statistics phase
table id
|
-[ RECORD 3 ] -----------+---------------------------time_stamp
| 2013-06-05 11:44:42.011
design_id
| 45035996273705090
design_name
| VMART_DESIGN
stage_type
| Analyzing statistics
iteration_number
|
total_query_count
|
remaining_query_count
|
max_step_number
| 15
current_step_number
| 1
current_step_description | public.customer_dimension
table id
|
...
-[ RECORD 20 ] ----------+---------------------------time_stamp
| 2013-06-05 11:44:49.324
design_id
| 45035996273705090
design_name
| VMART_DESIGN
stage_type
| Optimizing query performance
iteration_number
| 1
SQLReference Manual
HP Vertica System Tables
total_query_count
| 9
remaining_query_count
| 9
max_step_number
| 7
current_step_number
| 1
current_step_description | Extracting interesting columns
table id
|
...
-[ RECORD 62 ] ----------+---------------------------time_stamp
| 2013-06-05 11:51:23.790
design_id
| 45035996273705090
design_name
| VMART_DESIGN
stage_type
| Deployment in progress
iteration_number
|
total_query_count
|
remaining_query_count
|
max_step_number
|
current_step_number
|
current_step_description | Deployment completed successfully
table id
|
PARTITION_COLUMNS
For each projection of each partitioned table, shows the disk space used by each column on each
node.Thecolumn disk_space_bytes shows how much disk space the partitioned data uses,
including deleted data. So, if you delete rows but do not not purge them, the view's deleted_row_
count column changes to show the number of deleted rows in each column; however, disk_
space_bytes remains the same. After the deleted rows are purged, HP Vertica,reclaims the disk
space:disk_space_bytes changes accordingly, and deleted_row_count is reset to 0.
For grouped partitions, PARTITION_COLUMNS shows the cumulative disk space used for each
column per grouped partition. The column grouped_partition_key, if not null, identifies the
partition in which a given column is grouped.
Column Name
DataType Description
COLUMN_NAME
VARCHAR
COLUMN_ID
INTEGER
TABLE_NAME
VARCHAR
PROJECTION_NAME
VARCHAR
PROJECTION_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
DataType Description
NODE_NAME
VARCHAR
PARTITION_KEY
VARCHAR
GROUPED_PARTITION_KEY
VARCHAR
ROW_COUNT
INTEGER
DELETED_ROW_COUNT
INTEGER
DISK_SPACE_BYTES
INTEGER
Privileges
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
Given the following table definition:
=>
CREATE TABLE messages
(
time_interval timestamp NOT NULL,
thread_id varchar(32) NOT NULL,
unique_id varchar(53) NOT NULL,
msg_id varchar(65),
...
)
PARTITION BY ((messages.time_interval)::date);
SQLReference Manual
HP Vertica System Tables
2010-07-15 | | 178 | 0 | 65
msg_id | 45035996273743190 | messages | messages_super | 45035996273743182 | node03 |
2010-07-03 | | 6782 | 0 | 45107
msg_id | 45035996273743190 | messages | messages_super | 45035996273743182 | node03 |
2010-07-04 | | 866 | 0 | 5883
...
thread_id | 45035996273743186 | messages
2010-07-03 | | 6147 | 0 | 70565
thread_id | 45035996273743186 | messages
2010-07-15 | | 178 | 0 | 2429
thread_id | 45035996273743186 | messages
2010-07-03 | | 6782 | 0 | 77730
thread_id | 45035996273743186 | messages
2010-07-04 | | 866 | 0 | 10317
...
| messages_super | 45035996273743182 |
| messages_super | 45035996273743182 |
| messages_super | 45035996273743182 |
| messages_super | 45035996273743182 |
(11747 rows)
PARTITION_REORGANIZE_ERRORS
Monitors all background partitioning tasks, and if HP Vertica encounters an error, creates an entry
in this table with the appropriate information. Does not log repartitioning tasks that complete
successfully.
Column Name Data Type
Description
SESSION_ID
VARCHAR
cluster at any point in time but can be reused when the session
closes.
SQLReference Manual
HP Vertica System Tables
Description
USER_NAME
Name of the user who received the error at the time HP Vertica
VARCHAR
VARCHAR
TABLE_NAME
VARCHAR
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
MESSAGE
VARCHAR
HINT
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
PARTITION_STATUS
Shows, for each projection of each partitioned table, the fraction of its data that is actually
partitioned according to the current partition expression. When the partitioning of a table is altered,
the value in partition_reorganize_percent for each of its projections drops to zero and goes back up
to 100 when all the data is repartitioned.
Column Name
Data Type
Description
PROJECTION_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_NAME
VARCHAR
TABLE_ID
INTEGER
PROJECTION_SCHEMA
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PROJECTION_NAME
VARCHAR
PARTITION_REORGANIZE_PERCENT
INTEGER
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> SELECT * FROM partition_status;
-[ RECORD 1 ]----------------+----------------------projection_id
| 45035996281788238
table_schema
| public
table_name
| lineorder
table_id
| 45035996281787664
projection_schema
| public
projection_name
| VLINEORDER
partition_reorganize_percent | 100
-[ RECORD 2 ]----------------+----------------------projection_id
| 45035996281788312
table_schema
| public
table_name
| lineorder
table_id
| 45035996281787664
projection_schema
| public
projection_name
| VLINEORDER1
partition_reorganize_percent | 100
-[ RECORD 3 ]----------------+----------------------projection_id
| 45035996281788752
table_schema
| public
table_name
| lineorder
table_id
| 45035996281787664
projection_schema
| public
projection_name
| VLINEORDER2
partition_reorganize_percent | 100
-[ RECORD 4 ]----------------+----------------------projection_id
| 45035996281788822
table_schema
| public
table_name
| lineorder
table_id
| 45035996281787664
projection_schema
| public
projection_name
| VLINEORDER1_BUD
partition_reorganize_percent | 100
...
SQLReference Manual
HP Vertica System Tables
PARTITIONS
Displays partition metadata, one row per partition key, per ROS container.
Column Name
Data Type
Description
PARTITION_KEY
VARCHAR
PROJECTION_ID
INTEGER
TABLE_SCHEMA
VARCHAR
PROJECTION_NAME
VARCHAR
ROS_ID
VARCHAR
ROS_SIZE_BYTES
INTEGER
ROS_ROW_COUNT
INTEGER
NODE_NAME
VARCHAR
DELETED_ROW_COUNT
INTEGER
LOCATION_LABEL
VARCHAR
Notes
l
To find the number of ROS containers having data of a specific partition, aggregate
PARTITIONS over the partition_key column.
To find the number of partitions stored in a ROS container, aggregate PARTITIONS over the
ros_id column.
Example
Given a projection named p1, with three ROS containers, the PARTITIONS table returns three
rows:
SQLReference Manual
HP Vertica System Tables
=> SELECT
PARTITION_KEY,
PROJECTION_NAME,
ROS_ID,
ROS_SIZE_BYTES,
ROS_ROW_COUNT,
NODE_NAME
FROM partitions;
PARTITION_KEY | PROJECTION_NAME |
ROS_ID
| ROS_SIZE_BYTES | ROS_ROW_COUNT |
NODE_NAME
---------------+------------------+-------------------+----------------+---------------+---------------------2008
| trade_p_node0001 | 45035996273740461 |
90 |
1 |
node0001
2007
| trade_p_node0001 | 45035996273740477 |
99 |
2 |
node0001
2006
| trade_p_node0001 | 45035996273740493 |
99 |
2 |
node0001
(3 rows)
PROCESS_SIGNALS
Returns a history of signals that were received and handled by the HP Vertica process.
Column Name
Data Type
Description
SIGNAL_TIMESTAMP
NODE_NAME
VARCHAR
SIGNAL_NUMBER
INTEGER
Signal number.
SIGNAL_CODE
INTEGER
Signal code.
SIGNAL_PID
INTEGER
SIGNAL_UID
INTEGER
SIGNAL_ADDRESS
INTEGER
Permissions
Must be a superuser.
SQLReference Manual
HP Vertica System Tables
Notes
l
For more information about signals, please see the Linux documentation:
http://man7.org/linux/man-pages/man7/signal.7.html
Example
=> SELECT signal_timestamp, node_name, signal_number, signal_pid, signal_uid, signal_
address FROM process_signals;
signal_timestamp
| node_name | signal_number | signal_pid | signal_uid |
signal_address
-------------------------------+-----------+---------------+------------+------------+--------------2012-02-14 13:15:23.608359-04 | initiator |
15 |
31721 |
500 |
2147483679721
(1 row)
PROJECTION_RECOVERIES
Retains history about projection recoveries. Since HP Vertica adds an entry per recovery plan, a
projection/node pair could appear multiple times in the output.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
TRANSACTION_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
STATEMENT_ID
INTEGER
METHOD
VARCHAR
STATUS
VARCHAR
incremental
incremental-replay-delete
split
recovery-by-container
queued
running
finished
ignored
error-retry
error-fatal
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PROGRESS
INTEGER
DETAIL
VARCHAR
END_TIME
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RUNTIME_PRIORITY
VARCHAR
HIGH
MEDIUM
LOW
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Notes
If you are interested in monitoring recovery progress when recovery seems to be taking a while,
note that you cannot query system tables table during cluster recovery; the cluster must be UP to
accept connections.
Example
=> SELECT node_name, recover_epoch, recovery_phase,
current_completed,current_total, is_running
FROM recovery_status;
node_name | recover_epoch | recovery_phase
| current_completed | current_total |
is_running
-----------+---------------+-------------------+-------------------+---------------+----------node01
|
|
| 0
| 0
| f
node02
| 0
| historical pass 1 | 0
| 0
| t
node03
| 1
| current
| 0
| 0
| f
(3 rows)
SQLReference Manual
HP Vertica System Tables
-------------------------+------------------------------node02
| public.t_p1
| incremental
| running | 69
Scan:100% Sort:100% Write:87% | 2011-10-04 14:41:51.354757-04
node02
| public.t_p0
| incremental-replay-delete | running | 71
Delete:0/6563442
| 2011-10-04 14:41:51.353797-04
node02
| public.tt_p0
| recovery-by-container
| running | 76
CopyStorage:27427070/35938922 | 2011-10-04 14:44:50.525465-04
(3 rows)
|
|
|
See Also
l
RECOVERY_STATUS
PROJECTION_REFRESHES
Provides information about refresh operations for projections.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
PROJECTION_SCHEMA
VARCHAR
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
ANCHOR_TABLE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
REFRESH_STATUS
VARCHAR
REFRESH_PHASE
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
REFRESH_METHOD
VARCHAR
REFRESH_FAILURE_COUNT
INTEGER
SESSION_ID
VARCHAR
REFRESH_START
REFRESH_DURATION_SEC
INTERVAL
SECOND (0)
IS_EXECUTING
BOOLEAN
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RUNTIME_PRIORITY
VARCHAR
transaction_id
Int
HIGH
MEDIUM
LOW
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Notes
l
Tables and projections can be dropped while a query runs against them. The query continues to
run, even after the drop occurs. Only when the query finishes does it notice the drop, which
could cause a rollback. The same is true for refresh queries. PROJECTION_REFRESHES,
therefore, could report that a projection failed to be refreshed before the refresh query completes.
In this case, the REFRESH_DURATION_SEC column continues to increase until the refresh
query completes.
SQLReference Manual
HP Vertica System Tables
Example
The following command purges projection refresh history from the PROJECTION_REFRESHES
table:
=> SELECT clear_projection_refreshes();
clear_projection_refreshes
---------------------------CLEAR
(1 row)
Only the rows where the IS_EXECUTING column equals false are cleared.
See Also
l
CLEAR_PROJECTION_REFRESHES
PROJECTION_STORAGE
Monitors the amount of disk storage used by each projection on each node.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
PROJECTION_ID
VARCHAR
PROJECTION_NAME
VARCHAR
PROJECTION_SCHEMA
VARCHAR
PROJECTION_COLUMN_COUNT
INTEGER
ROW_COUNT
INTEGER
USED_BYTES
INTEGER
WOS_ROW_COUNT
INTEGER
WOS_USED_BYTES
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ROS_ROW_COUNT
INTEGER
ROS_USED_BYTES
INTEGER
ROS_COUNT
INTEGER
ANCHOR_TABLE_NAME
VARCHAR
ANCHOR_TABLE_SCHEMA
VARCHAR
ANCHOR_TABLE_ID
INTEGER
Notes
Projections that have no data never have full statistics. Querying this system table lets you see if
your projection contains data.
Example
Query the system table:
=> SELECT * FROM projection_storage;
-[ RECORD 1 ]-----------+------------------node_name
| v_onenode_node0001
projection_id
| 45035996273718838
projection_name
| trades_p
projection_schema
| public
projection_column_count | 4
row_count
| 1
used_bytes
| 147
wos_row_count
| 0
wos_used_bytes
| 0
ros_row_count
| 1
ros_used_bytes
| 147
ros_count
| 1
anchor_table_name
| trades
anchor_table_schema
| public
anchor_table_id
| 45035996273718836
=> SELECT projection_name, row_count, ros_used_bytes, used_bytes
FROM PROJECTION_STORAGE WHERE projection_schema = 'store' ORDER BY used_bytes;
projection_name
| row_count | ros_used_bytes
| used_bytes
------------------------------------------------------------+-----------+---------------+-----------store_dimension_DBD_4_seg_vmartdb_design_vmartdb_design
|
53 |
2791
SQLReference Manual
HP Vertica System Tables
2791
store_dimension_DBD_29_seg_vmartdb_design_vmartdb_design
|
53 |
|
2791
store_dimension_DBD_29_seg_vmartdb_design_vmartdb_design
|
56 |
|
2936
store_dimension_DBD_4_seg_vmartdb_design_vmartdb_design
|
56 |
|
2936
store_dimension_DBD_4_seg_vmartdb_design_vmartdb_design
|
68 |
|
3360
store_dimension_DBD_29_seg_vmartdb_design_vmartdb_design
|
68 |
|
3360
store_dimension_DBD_29_seg_vmartdb_design_vmartdb_design
|
73 |
|
3579
store_dimension_DBD_4_seg_vmartdb_design_vmartdb_design
|
73 |
|
3579
store_orders_fact_DBD_31_seg_vmartdb_design_vmartdb_design |
53974 |
|
1047782
store_orders_fact_DBD_6_seg_vmartdb_design_vmartdb_design |
53974 |
|
1047782
store_orders_fact_DBD_6_seg_vmartdb_design_vmartdb_design |
66246 |
|
1285786
store_orders_fact_DBD_31_seg_vmartdb_design_vmartdb_design |
66246 |
|
1285786
store_orders_fact_DBD_31_seg_vmartdb_design_vmartdb_design |
71909 |
|
1395258
store_orders_fact_DBD_6_seg_vmartdb_design_vmartdb_design |
71909 |
|
1395258
store_orders_fact_DBD_6_seg_vmartdb_design_vmartdb_design |
107871 |
|
2090941
store_orders_fact_DBD_31_seg_vmartdb_design_vmartdb_design |
107871 |
|
2090941
store_sales_fact_DBD_5_seg_vmartdb_design_vmartdb_design
|
1235825 |
|
24285740
store_sales_fact_DBD_30_seg_vmartdb_design_vmartdb_design |
1235825 |
|
24285740
store_sales_fact_DBD_30_seg_vmartdb_design_vmartdb_design |
1245865 |
|
24480819
store_sales_fact_DBD_5_seg_vmartdb_design_vmartdb_design
|
1245865 |
|
24480819
store_sales_fact_DBD_5_seg_vmartdb_design_vmartdb_design
|
1249547 |
|
24551817
store_sales_fact_DBD_30_seg_vmartdb_design_vmartdb_design |
1249547 |
|
24551817
store_sales_fact_DBD_30_seg_vmartdb_design_vmartdb_design |
1268763 |
|
24930549
store_sales_fact_DBD_5_seg_vmartdb_design_vmartdb_design
|
1268763 |
|
24930549
(24 rows)
The following command returns the per-node storage used by a segmented table:
SELECT anchor_table_name, node_name,
SUM(ros_used_bytes)/1024/1024 AS MB,
SUM(ros_row_count) AS Rows
FROM projection_storage GROUP BY 1,2 ORDER BY 1,2;
anchor_table_name
|
node_name
| MB | Rows
-----------------------+--------------------+----+--------call_center_dimension | v_vmartdb_node0001 | 0 |
98
call_center_dimension | v_vmartdb_node0002 | 0 |
101
call_center_dimension | v_vmartdb_node0003 | 0 |
102
2791
2936
2936
3360
3360
3579
3579
1047782
1047782
1285786
1285786
1395258
1395258
2090941
2090941
24285740
24285740
24480819
24480819
24551817
24551817
24930549
24930549
SQLReference Manual
HP Vertica System Tables
call_center_dimension
customer_dimension
customer_dimension
customer_dimension
customer_dimension
date_dimension
date_dimension
date_dimension
date_dimension
employee_dimension
employee_dimension
employee_dimension
employee_dimension
inventory_fact
inventory_fact
inventory_fact
inventory_fact
online_page_dimension
online_page_dimension
online_page_dimension
online_page_dimension
online_sales_fact
online_sales_fact
online_sales_fact
online_sales_fact
product_dimension
product_dimension
product_dimension
product_dimension
promotion_dimension
promotion_dimension
promotion_dimension
promotion_dimension
rostab
rostab
rostab
rostab
shipping_dimension
shipping_dimension
shipping_dimension
shipping_dimension
store_dimension
store_dimension
store_dimension
store_dimension
store_orders_fact
store_orders_fact
store_orders_fact
store_orders_fact
store_sales_fact
store_sales_fact
store_sales_fact
store_sales_fact
vendor_dimension
vendor_dimension
vendor_dimension
vendor_dimension
warehouse_dimension
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
v_vmartdb_node0002
v_vmartdb_node0003
v_vmartdb_node0004
v_vmartdb_node0001
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
59
59
59
59
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
2
2
2
46
47
46
46
0
0
0
0
0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99
24030
1648
25970
48352
910
913
916
913
4998
4999
5002
5001
150414
149736
149586
150264
499
500
501
500
4941898
5024898
5058102
4975102
103185
100428
76815
79572
499
500
501
500
0
0
0
0
49
50
51
50
123
125
127
125
147768
149759
152232
150241
2501318
2512691
2498682
2487309
48
48
52
52
49
SQLReference Manual
HP Vertica System Tables
warehouse_dimension
warehouse_dimension
warehouse_dimension
(64 rows)
| v_vmartdb_node0002 |
| v_vmartdb_node0003 |
| v_vmartdb_node0004 |
0 |
0 |
0 |
50
51
50
See Also
l
PROJECTIONS
ANALYZE_STATISTICS
PROJECTION_USAGE
Records information about projections HP Vertica uses in each processed query.
Column Name
Data Type
Description
QUERY_START_TIMESTAMP
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
REQUEST_ID
INTEGER
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
IO_TYPE
VARCHAR
Input/output.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
ANCHOR_TABLE_ID
INTEGER
ANCHOR_TABLE_SCHEMA
VARCHAR
ANCHOR_TABLE_NAME
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Examples
=> SELECT query_start_timestamp, node_name, user_name, request_id,
io_type, projection_id, projection_name, anchor_table_name
FROM projection_usage;
query_start_timestamp
| node_name | user_name | request_id | io_type |
projection_name | anchor_table_name
-------------------------------+-----------+-----------+------------+----------+----------------+------------------2011-09-16 13:38:47.00034-04
| node01
| kelly
|
16 |
1 | t_super
| t
2011-09-16 13:38:52.920688-04 | node01
| kelly
|
18 |
2 | t_super
| t
2011-09-16 13:38:52.987128-04 | node01
| kelly
|
20 |
1 | t_super
| t
(3 rows)
QUERY_EVENTS
Returns information about query planning, optimization, and execution events.
Column Name
Data Type
Description
EVENT_TIMESTAMP
NODE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
USER_ID
INTEGER
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
REQUEST_ID
INTEGER
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
EVENT_CATEGORY
VARCHAR
EVENT_TYPE
VARCHAR
EXTERNAL_PREDICATE_PUSHDOWN_NOT_
SUPPORTED
EVENT_DESCRIPTION
VARCHAR
NO HISTOGRAM
GROUP_BY_SPILLED
JOIN_SPILLED
PARTITIONS_ELIMINATED
MERGE_CONVERTED_TO_UNION
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
OPERATOR_NAME
VARCHAR
PATH_ID
INTEGER
OBJECT_ID
INTEGER
EVENT_DETAILS
VARCHAR
SUGGESTED_ACTION
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Examples
=> \x
Expanded display is on.
=> SELECT * FROM query_events;
-[ RECORD 1 ]-----+------------------------------------------------------------event_timestamp
| 2012-12-09 23:59:00.174464-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| doca01.verticacorp.-31427:0x82fb
request_id
| 1
transaction_id
| 45035996273711993
statement_id
| 1
event_category
| EXECUTION
event_type
| RLE_OVERRIDDEN
event_description | Compressed execution will not be used on some columns, because the
SQLReference Manual
HP Vertica System Tables
SQLReference Manual
HP Vertica System Tables
suggested_action |
-[ RECORD 5 ]-----+-------------------------------------------------------------event_timestamp
| 2012-12-08 13:54:27.394169-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| doca01.verticacorp.-19852:0x14
request_id
| 10
transaction_id
| 45035996273705005
statement_id
| 1
event_category
| EXECUTION
event_type
| RLE_OVERRIDDEN
event_description | Compressed execution will not be used on some columns, because the
average run counts are not large enough.
operator_name
| Scan
path_id
| 2
object_id
| 45035996273718840
event_details
| Column public.trades_p.stock will not be processed using RLE.
suggested_action |
-[ RECORD 6 ]-----+-------------------------------------------------------------event_timestamp
| 2012-12-08 13:54:27.39424-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| doca01.verticacorp.-19852:0x14
request_id
| 10
transaction_id
| 45035996273705005
statement_id
| 1
event_category
| EXECUTION
event_type
| SMALL_MERGE_REPLACED
event_description | Small StorageMerge replaced with StorageUnion for efficiency
operator_name
| StorageMerge
path_id
| 2
object_id
| 45035996273718838
event_details
| Projection: public.trades_p
suggested_action |
-[ RECORD 7 ]-----+-------------------------------------------------------------event_timestamp
| 2012-12-08 13:54:27.403897-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| doca01.verticacorp.-19852:0x14
request_id
| 10
transaction_id
| 45035996273705005
statement_id
| 2
event_category
| EXECUTION
event_type
| RLE_OVERRIDDEN
event_description | Compressed execution will not be used on some columns, because the
average run counts are not large enough.
operator_name
| Scan
path_id
| 2
object_id
| 45035996273718840
event_details
| Column public.trades_p.stock will not be processed using RLE.
suggested_action |
-[ RECORD 8 ]-----+-------------------------------------------------------------event_timestamp
| 2012-12-08 13:54:27.415003-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
SQLReference Manual
HP Vertica System Tables
user_name
| dbadmin
session_id
| doca01.verticacorp.-19852:0x14
request_id
| 10
transaction_id
| 45035996273705005
statement_id
| 3
event_category
| EXECUTION
event_type
| RLE_OVERRIDDEN
event_description | Compressed execution will not be used on some columns, because the
average run counts are not large enough.
operator_name
| Scan
path_id
| 2
object_id
| 45035996273718840
event_details
| Column public.trades_p.stock will not be processed using RLE.
suggested_action |
-[ RECORD 9 ]-----+-------------------------------------------------------------event_timestamp
| 2012-12-08 13:53:23.425399-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| doca01.verticacorp.-19852:0x14
request_id
| 8
transaction_id
| 45035996273704996
statement_id
| 1
event_category
| EXECUTION
event_type
| RLE_OVERRIDDEN
event_description | Compressed execution will not be used on some columns, because the
average run counts are not large enough.
operator_name
| Scan
path_id
| 2
object_id
| 45035996273718840
event_details
| Column public.trades_p.stock will not be processed using RLE.
suggested_action |
-[ RECORD 10 ]----+-------------------------------------------------------------event_timestamp
| 2012-12-08 13:52:04.122981-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| doca01.verticacorp.-19852:0x14
request_id
| 6
transaction_id
| 45035996273704983
statement_id
| 1
event_category
| EXECUTION
event_type
| RLE_OVERRIDDEN
event_description | Compressed execution will not be used on some columns, because the
average run counts are not large enough.
operator_name
| Scan
path_id
| 2
object_id
| 45035996273718840
event_details
| Column public.trades_p.stock will not be processed using RLE.
suggested_action |
-[ RECORD 11 ]----+-------------------------------------------------------------event_timestamp
| 2012-12-08 13:52:04.123235-05
node_name
| v_onenode_node0001
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| doca01.verticacorp.-19852:0x14
request_id
| 6
transaction_id
| 45035996273704983
SQLReference Manual
HP Vertica System Tables
statement_id
event_category
event_type
event_description
operator_name
path_id
object_id
event_details
suggested_action
|
|
|
|
|
|
|
|
|
1
EXECUTION
SMALL_MERGE_REPLACED
Small StorageMerge replaced with StorageUnion for efficiency
StorageMerge
2
45035996273718838
Projection: public.trades_p
See Also
l
EXECUTION_ENGINE_PROFILES
QUERY_PLAN_PROFILES
QUERY_METRICS
Monitors the sessions and queries running on each node.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
ACTIVE_USER_SESSION_COUNT
INTEGER
ACTIVE_SYSTEM_SESSION_COUNT
INTEGER
TOTAL_USER_SESSION_COUNT
INTEGER
TOTAL_SYSTEM_SESSION_COUNT
INTEGER
TOTAL_ACTIVE_SESSION_COUNT
INTEGER
TOTAL_SESSION_COUNT
INTEGER
RUNNING_QUERY_COUNT
INTEGER
EXECUTED_QUERY_COUNT
INTEGER
Notes
Totals get reset each time you restart the database.
SQLReference Manual
HP Vertica System Tables
Example
=>\pset expanded
Expanded display is on.
=> SELECT * FROM QUERY_METRICS;
-[ RECORD 1 ]---------------+------------------node_name
| v_vmartdb_node01
active_user_session_count
| 1
active_system_session_count | 2
total_user_session_count
| 2
total_system_session_count | 6248
total_active_session_count | 3
total_session_count
| 6250
running_query_count
| 1
executed_query_count
| 42
-[ RECORD 2 ]---------------+------------------node_name
| v_vmartdb_node02
active_user_session_count
| 1
active_system_session_count | 2
total_user_session_count
| 2
total_system_session_count | 6487
total_active_session_count | 3
total_session_count
| 6489
running_query_count
| 0
executed_query_count
| 0
-[ RECORD 3 ]---------------+------------------node_name
| v_vmartdb_node03
active_user_session_count
| 1
active_system_session_count | 2
total_user_session_count
| 2
total_system_session_count | 6489
total_active_session_count | 3
total_session_count
| 6491
running_query_count
| 0
executed_query_count
| 0
-[ RECORD 4 ]---------------+------------------node_name
| v_vmartdb_node04
active_user_session_count
| 1
active_system_session_count | 2
total_user_session_count
| 2
total_system_session_count | 6489
total_active_session_count | 3
total_session_count
| 6491
running_query_count
| 0
executed_query_count
| 0
QUERY_PLAN_PROFILES
Provides detailed execution status for queries that are currently running in the system. Output from
the table shows the real-time flow of data and the time and resources consumed for each path in
each query plan.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
PATH_ID
INTEGER
PATH_LINE_INDEX
INTEGER
PATH_IS_EXECUTING
BOOLEAN
Status of a path in the query plan. True (t) if the path has
started running, otherwise false.
PATH_IS_COMPLETE
BOOLEAN
Status of a path in the query plan. True (t) if the path has
finished running, otherwise false.
IS_EXECUTING
BOOLEAN
RUNNING_TIME
INTERVAL
MEMORY_ALLOCATED_BYTES
INTEGER
READ_FROM_DISK_BYTES
INTEGER
The number of bytes the path read from disk (or the disk
cache).
RECEIVED_BYTES
INTEGER
SENT_BYTES
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PATH_LINE
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Best Practices
Table results can be very wide. For best results when you query the QUERY_PLAN_PROFILES
table, sort on these columns:
l
TRANSACTION_ID
STATEMENT_ID
PATH_ID
PATH_LINE_INDEX
For example:
=> SELECT ... FROM query_plan_profiles
WHERE ...
ORDER BY transaction_id, statement_id, path_id, path_line_index;
Example
For examples and additional information, see Profiling query plan profiles in the Administrator's
Guide
See Also
l
EXECUTION_ENGINE_PROFILES
EXPLAIN
PROFILE
QUERY_EVENTS
SQLReference Manual
HP Vertica System Tables
QUERY_PROFILES
Provides information about queries that have already executed.
Column Name
Data Type
Description
SESSION_ID
VARCHAR
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
IDENTIFIER
VARCHAR
NODE_NAME
VARCHAR
QUERY
VARCHAR
QUERY_SEARCH_PATH
VARCHAR
SCHEMA_NAME
VARCHAR
TABLE_NAME
VARCHAR
PROJECTIONS_USED
VARCHAR
QUERY_DURATION_US
NUMERIC
(18,0)
QUERY_START_EPOCH
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
QUERY_START
VARCHAR
QUERY_TYPE
VARCHAR
ERROR_CODE
INTEGER
USER_NAME
VARCHAR
PROCESSED_ROW_COUNT
INTEGER
RESERVED_EXTRA_MEMORY
INTEGER
IS_EXECUTING
BOOLEAN
Notes
l
Example
Query the QUERY_PROFILES table:
SQLReference Manual
HP Vertica System Tables
=>\pset expanded
Expanded display is on.
=> SELECT * FROM QUERY_PROFILES;-[ RECORD 1 ]-------+-----------------------------------------------------...
-[ RECORD 18 ]------+------------------------------------------------------node_name
| v_vmartdb_node0001
session_id
| raster-s1-17956:0x1d
transaction_id
| 45035996273728061
statement_id
| 6
identifier
|
query
| SELECT * FROM event_configurations;
query_search_path
| "$user", public, v_catalog, v_monitor, v_internal
schema_name
|
table_name
|
projections_used
| v_monitor.event_configurations_p
query_duration_us
| 9647
query_start_epoch
| 429
query_start
| 2010-10-07 12:46:24.370044-04
query_type
| SELECT
error_code
| 0
user_name
| release
processed_row_count
| 16
reserved_extra_memory | 0
is_executing
| f
-[ RECORD ...]------+------------------------------------------------------...
See Also
l
QUERY_REQUESTS
RESOURCE_ACQUISITIONS
QUERY_REQUESTS
Returns information about user-issued query requests.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SESSION_ID
VARCHAR
REQUEST_ID
INTEGER
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
REQUEST_TYPE
VARCHAR
QUERY
DDL
LOAD
UTILITY
TRANSACTION
PREPARE
EXECUTE
SET
SHOW
REQUEST
VARCHAR
Query statement.
REQUEST_LABEL
VARCHAR
SEARCH_PATH
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
MEMORY_ACQUIRED_MB
FLOAT
SUCCESS
BOOLEAN
ERROR_COUNT
INTEGER
START_TIMESTAMP
END_TIMESTAMP
REQUEST_DURATION_MS
INTEGER
IS_EXECUTING
BOOLEAN
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Examples
=> \x
Expanded display is on.
=> select * from query_requests;
-[ RECORD 1 ]-------+---------------------------------------------------node_name
| v_vmart_node0001
user_name
| dbadmin
session_id
| localhost.localdoma-10713:0xd8fd
request_id
| 15
transaction_id
| 45035996273733877
statement_id
| 13
request_type
| QUERY
request
| select * from query_requests;
request_label
|
search_path
| "$user", public, v_catalog, v_monitor, v_internal
memory_acquired_mb | 100
success
|
error_count
|
start_timestamp
| 2013-12-05 15:40:17.270719-08
end_timestamp
|
request_duration_ms |
is_executing
| t
-[ RECORD 2 ]-------+--------------------------------------------node_name
| v_vmart_node0001
user_name
| dbadmin
session_id
| localhost.localdoma-10713:0xd8fd
SQLReference Manual
HP Vertica System Tables
request_id
| 14
transaction_id
| 45035996273733877
statement_id
| 12
request_type
| QUERY
request
| select * from query_events;
request_label
|
search_path
| "$user", public, v_catalog, v_monitor, v_internal
memory_acquired_mb | 100
success
| t
error_count
|
start_timestamp
| 2013-12-05 15:39:04.938447-08
end_timestamp
| 2013-12-05 15:39:05.455356-08
request_duration_ms | 517
is_executing
| f
-[ RECORD 3 ]-------+---------------------------------------------------node_name
| v_vmart_node0001
user_name
| dbadmin
session_id
| localhost.localdoma-10713:0xd8fd
request_id
| 13
transaction_id
| 45035996273733877
statement_id
| 11
request_type
| QUERY
request
| SELECT node_name, start_time, end_time, tx_kbytes_per_sec AS tx_
kbytes, rx_kbytes_per_sec as rx_kbytes FROM network_usage;
request_label
|
search_path
| "$user", public, v_catalog, v_monitor, v_internal
memory_acquired_mb | 100
success
| t
error_count
|
start_timestamp
| 2013-12-05 12:46:54.652349-08
end_timestamp
| 2013-12-05 12:47:09.386931-08
request_duration_ms | 14734
is_executing
| f
-[ RECORD 4 ]-------+--------------------------------------------node_name
| v_vmart_node0001
user_name
| dbadmin
session_id
| localhost.localdoma-10713:0xd8fd
request_id
| 12
transaction_id
| 45035996273733877
statement_id
| 10
request_type
| QUERY
request
| select * from storage_locations ;
request_label
|
search_path
| "$user", public, v_catalog, v_monitor, v_internal
memory_acquired_mb | 100
success
| t
error_count
|
start_timestamp
| 2013-12-05 10:02:13.425322-08
end_timestamp
| 2013-12-05 10:02:13.49068-08
request_duration_ms | 65
is_executing
| f
...
SQLReference Manual
HP Vertica System Tables
See Also
l
QUERY_PROFILES
REBALANCE_PROJECTION_STATUS
Maintain history on rebalance progress for relevant projections.
Column Name
Data Type
Description
PROJECTION_ID
INTEGER
PROJECTION_SCHEMA
VARCHAR
PROJECTION_NAME
VARCHAR
ANCHOR_TABLE_ID
INTEGER
ANCHOR_TABLE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
REBALANCE_METHOD
VARCHAR
DURATION_SEC
INTERVAL
SEC
SEPARATED_PERCENT
TRANSFERRED_PERCENT
SEPARATED_BYTES
NUMERIC
(5,2)
projection.
NUMERIC
(5,2)
projection.
INTEGER
TO_SEPARATE_BYTES
INTEGER
TRANSFERRED_BYTES
INTEGER
TO_TRANSFER_BYTES
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
IS_LATEST
BOOLEAN
ELASTIC_CLUSTER_VERSION
INTEGER
Permissions
Must be a superuser.
See Also
l
ELASTIC_CLUSTER
REBALANCE_TABLE_STATUS
REBALANCE_TABLE_STATUS
Maintain history on rebalance progress for relevant tables.
Column Name
Data Type
Description
TABLE_ID
INTEGER
TABLE_SCHEMA
VARCHAR
TABLE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
REBALANCE_METHOD
VARCHAR
DURATION_SEC
REFRESH
REPLICATE
ELASTIC_CLUSTER
INTERVAL
SEC
SEPARATED_PERCENT
NUMERIC
(5,2)
TRANSFERRED_PERCENT
NUMERIC
(5,2)
SEPARATED_BYTES
INTEGER
TO_SEPARATE_BYTES
INTEGER
TRANSFERRED_BYTES
INTEGER
TO_TRANSFER_BYTES
INTEGER
IS_LATEST
BOOLEAN
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ELASTIC_CLUSTER_VERSION
INTEGER
Permissions
Must be superuser.
See Also
l
ELASTIC_CLUSTER
REBALANCE_PROJECTION_STATUS
RECOVERY_STATUS
Provides the status of recovery operations, returning one row for each node.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
RECOVER_EPOCH
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RECOVERY_PHASE
VARCHAR
SPLITS_COMPLETED
INTEGER
NULL
current
SPLITS_TOTAL
INTEGER
HISTORICAL_COMPLETED
INTEGER
HISTORICAL_TOTAL
INTEGER
CURRENT_COMPLETED
INTEGER
CURRENT_TOTAL
INTEGER
IS_RUNNING
BOOLEAN
SQLReference Manual
HP Vertica System Tables
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Note
If you are interested in monitoring recovery progress when recovery seems to be taking a while,
note that you cannot query system tables table during cluster recovery; the cluster must be UP to
accept connections.
Example
=> SELECT node_name, recover_epoch, recovery_phase, current_completed, current_total, is_
running
FROM recovery_status;
node_name | recover_epoch | recovery_phase
| current_completed | current_total | is_
running
-----------+---------------+-------------------+-------------------+---------------+----------node01
|
|
| 0
| 0
| f
node02
| 0
| historical pass 1 | 0
| 0
| t
node03
| 1
| current
| 0
| 0
| f
See Also
l
PROJECTION_RECOVERIES
RESOURCE_ACQUISITIONS
Retains information about resources (memory, open file handles, threads) acquired by each running
request for each resource pool in the system.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
TRANSACTION_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
STATEMENT_ID
INTEGER
REQUEST_TYPE
VARCHAR
Reserverelated to queries
POOL_ID
INTEGER
POOL_NAME
VARCHAR
THREAD_COUNT
INTEGER
OPEN_FILE_HANDLE_COUNT
INTEGER
MEMORY_INUSE_KB
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
QUEUE_ENTRY_TIMESTAMP
ACQUISITION_TIMESTAMP
RELEASE_TIMESTAMP
DURATION_MS
INTEGER
IS_EXECUTING
BOOLEAN
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Notes
l
When monitoring resource pools and resource usage by queries, the queue wait time is the
difference between ACQUISITION_TIMESTAMP and QUEUE_ENTRY_TIMESTAMP. For example, to
determine how long a query waits in the queue before it is admitted to run, you can get the
difference between the ACQUISITION_TIMESTAMP and the QUEUE_ENTRY_TIMESTAMP using a
query like the following:
=> SELECT pool_name, queue_entry_timestamp, acquisition_timestamp,
(acquisition_timestamp-queue_entry_timestamp) AS 'queue wait'
SQLReference Manual
HP Vertica System Tables
For the WOSDATA built-in pool, the queue_entry_timestamp column shows the time when data
was first loaded into the WOS. The acquisition_timestamp reflects the last time the amount of
data in the WOS changed. There is always a delay between when the data in WOS shrinks in
size and when the resource system tables reflect the new size.
Examples
This examples shows how to display all fields from the RESOURCE_ACQUISITIONS system table.
vmartdb=> \x
Expanded display is on.
=> SELECT * FROM resource_acquisitions;
-[ RECORD 1 ]----------+-----------------------------node_name
| v_onenode_node0001
transaction_id
| 45035996273708628
statement_id
| 1
request_type
| Reserve
pool_id
| 45035996273718740
pool_name
| sysquery
thread_count
| 4
open_file_handle_count | 2
memory_inuse_kb
| 16384
queue_entry_timestamp | 2012-12-09 07:56:41.297533-05
acquisition_timestamp | 2012-12-09 07:56:41.297536-05
release_timestamp
| 2012-12-09 07:56:41.303201-05
duration_ms
| 6
is_executing
| f
-[ RECORD 2 ]----------+-----------------------------...
See Also
l
QUERY_PROFILES
RESOURCE_POOL_STATUS
RESOURCE_POOLS
RESOURCE_QUEUES
RESOURCE_REJECTIONS
RESOURCE_POOL_MOVE
Displays the cascade event information on each node.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
MOVE_TIMESTAMP
TIMESTAMPZ
SESSION_ID
VARCHAR
USER_ID
INTEGER
USER_NAME
VARCHAR
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
SOURCE_POOL_NAME
VARCHAR
TARGET_POOL_NAME
VARCHAR
CAP_EXCEEDED
VARCHAR
SOURCE_CAP
INTEGER
session RUNTIMECAP
user RUNTIMECAP
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
TARGET_CAP
INTEGER
SUCCESS
BOOLEAN
session RUNTIMECAP
user RUNTIMECAP
REASON
VARCHAR
Usage Considerations
Sometimes, the target pool does not have sufficient resources available to execute the query at the
time requested. In such cases, the query may re-queue, re-plan, and abort on that pool.
Examples
This example shows how to display all fields from the RESOURCE_POOL_MOVE system table.
=> SELECT * FROM resource_pool_move;
-[ RECORD 1 ]----------+-----------------------------node_name
| node01
move_timestamp
| 2014-07-24 14:07:36.914879-04
session_id
| doca01.verticacorp.-31427:0x82fb
user_id
| 45035996273704962
user_name
| dbadmin
transaction_id
| 45035996273718740
statement_id
| 1
source_pool_name
| rp1
target_pool_name
| rp2
cap_exceeded
| RUNTIMECAP
source_cap
| 1000000
target_cap
| 120000000
success
| t
reason
| Move Resources Success
-[ RECORD 2 ]----------+-----------------------------...
SQLReference Manual
HP Vertica System Tables
See Also
l
QUERY_PROFILES
RESOURCE_POOL_STATUS
RESOURCE_POOLS
RESOURCE_QUEUES
RESOURCE_REJECTIONS
RESOURCE_POOL_STATUS
Provides configuration settings of the various resource pools in the system, including internal pools.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
POOL_OID
INTEGER
A unique numeric ID
that identifies the pool
and is assigned by
the HP Vertica
catalog.
POOL_NAME
VARCHAR
IS_INTERNAL
BOOLEAN
Denotes whether a
pool is one of the
Built-In Pools.
MEMORY_SIZE_KB
INTEGER
Value of MEMORYSIZE
setting of the pool in
kilobytes.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
MEMORY_SIZE_ACTUAL_KB
INTEGER
Current amount of
memory, in kilobytes,
allocated to the pool
by the resource
manager. The actual
size can be less than
specified in the DDL,
if both the following
conditions exist:
l
The request to
shuffle memory is
pending.
See ALTER
RESOURCE POOL.
MEMORY_INUSE_KB
INTEGER
Amount of memory, in
kilobytes, acquired by
requests running
against this pool.
GENERAL_MEMORY_BORROWED_KB
INTEGER
Amount of memory, in
kilobytes, borrowed
from the GENERAL pool
by requests running
against this pool. The
sum of MEMORY_
INUSE_KB and
GENERAL_MEMORY_
BORROWED_KB should
be less than MAX_
MEMORY_SIZE_KB.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
QUEUEING_THRESHOLD_KB
INTEGER
Calculated as MAX_
MEMORY_SIZE_KB *
95%. When the
amount of memory
used by all requests
against this queue
exceeds the
QUEUEING_
THRESHOLD_KB (but is
less than MAX_
MEMORY_SIZE_KB),
new requests against
the pool are queued
until memory
becomes available.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
MAX_MEMORY_SIZE_KB
INTEGER
Value, in kilobytes, of
the MAXMEMORYSIZE
parameter specified
when defining the
pool. After this
threshold is reached,
new requests against
this pool are rejected
or queued until
memory becomes
available.
MAX_MEMORY_SIZE_KB
may not reflect the
set MAXMEMORYSIZE
parameter value if the
specified value
cannot be reached.
Example:
If MAXMEMORYSIZE =
10G, but less than 2G
is available, MAX_
MEMORY_SIZE_KB will
not reflect the original
value in KB, but will
instead reflect 2G in
KB, since that is the
highest value that can
be reached.
Ordinarily, the ALTER
RESOURCE POOL and
CREATE RESOURCE
POOL statements
provide error
messages to prevent
setting the
MAXMEMORYSIZE to a
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
value greater than
available, but making
system changes or
other configuration
changes can cause
this scenario.
RUNNING_QUERY_COUNT
INTEGER
Number of queries
actually running using
this pool.
PLANNED_CONCURRENCY
INTEGER
Value of
PLANNEDCONCURRENCY
parameter specified
when defining the
pool.
MAX_CONCURRENCY
INTEGER
Value of
MAXCONCURRENCY
parameter specified
when defining the
pool.
IS_STANDALONE
BOOLEAN
If the pool is
configured to have
MEMORYSIZE equal to
MAXMEMORYSIZE, the
pool is considered
standalone because it
does not borrow any
memory from the
General pool.
QUEUE_TIMEOUT_IN_SECONDS
INTEGER
Value of
QUEUETIMEOUT
parameter that was
specified when
defining the pool.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
EXECUTION_PARALLELISM
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PRIORITY
INTEGER
Value of PRIORITY
parameter specified
when defining the
pool.
When set to HOLD, HP
Vertica sets a pool's
priority to -999 so the
query remains queued
until QUEUETIMEOUT is
reached.
RUNTIME_PRIORITY
VARCHAR
Value of RUNTIME_
PRIORITY specified
when defining the
pool.
RUNTIME_PRIORITY_THRESHOLD
INTEGER
Value of RUNTIME_
PRIORITY_THRESHOLD
specified when
defining the pool.
SINGLE_INITIATOR
BOOL
Value of
SINGLEINITIATOR
parameter specified
when defining the
pool.
QUERY_BUDGET_KB
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CPU_AFFINITY_SET
VARCHAR
A percentage of
CPUs on the
system
A zero-based list
of CPUs (a fourCPU system c of
CPUs 0, 1, 2, and
3).
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CPU_AFFINITY_MASK
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CPU_AFFINITY_MODE
VARCHAR
EXCLUSIVE
Queries from this
pool can only run
on CPUs specified
in CPU_
AFFINITY_SET,
which are reserved
exclusively for this
pool.
SHARED
Queries from this
pool can only run
on the CPUs
specified in CPU_
AFFINITY_SET.
However, other
pools can use the
same CPUs in the
set.
Examples
The following example shows how to view the configuration settings of various resource pools.
=> SELECT * FROM resource_pool_status LIMIT 2;
-[ RECORD 1 ]--------------+-----------------node_name
| v_db_node0001
pool_oid
| 45035996273718660
SQLReference Manual
HP Vertica System Tables
pool_name
| general
is_internal
| t
memory_size_kb
| 1265331
memory_size_actual_kb
| 1265331
memory_inuse_kb
| 0
general_memory_borrowed_kb | 0
queueing_threshold_kb
| 1202064
max_memory_size_kb
| 1265331
running_query_count
| 0
planned_concurrency
| 4
max_concurrency
|
is_standalone
| t
queue_timeout_in_seconds
| 300
execution_parallelism
| AUTO
priority
| 0
runtime_priority
| MEDIUM
runtime_priority_threshold | 2
single_initiator
| false
query_budget_kb
| 300516
cpu_affinity_set
|
cpu_affinity_mask
| c
cpu_affinity_mode
| ANY
-[ RECORD 2 ]--------------+-----------------node_name
| v_db_node0001
pool_oid
| 45035996273732654
pool_name
| mypool
is_internal
| f
memory_size_kb
| 0
memory_size_actual_kb
| 0
memory_inuse_kb
| 0
general_memory_borrowed_kb | 0
queueing_threshold_kb
| 1202064
max_memory_size_kb
| 1265331
running_query_count
| 0
planned_concurrency
| 4
max_concurrency
|
is_standalone
| f
queue_timeout_in_seconds
| 300
execution_parallelism
| AUTO
priority
| 0
runtime_priority
| MEDIUM
runtime_priority_threshold | 2
single_initiator
| false
query_budget_kb
| 300516
cpu_affinity_set
| 0-1
cpu_affinity_mask
| 3
cpu_affinity_mode
| EXCLUSIVE
See Also
l
RESOURCE_ACQUISITIONS
SQLReference Manual
HP Vertica System Tables
RESOURCE_POOLS
RESOURCE_QUEUES
RESOURCE_REJECTIONS
Managing Workloads
RESOURCE_QUEUES
Provides information about requests pending for various resource pools.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
POOL_NAME
VARCHAR
MEMORY_REQUESTED_KB
INTEGER
PRIORITY
INTEGER
POSITION_IN_QUEUE
INTEGER
QUEUE_ENTRY_TIMESTAMP
SQLReference Manual
HP Vertica System Tables
See Also
l
RESOURCE_ACQUISITIONS
RESOURCE_POOLS
RESOURCE_REJECTIONS
RESOURCE_REJECTION_DETAILS
Records an entry for each resource request that HP Vertica denies. This is useful for determining if
there are resource space issues, as well as which users/pools encounter problems.
Column Name
Data Type
Description
REJECTED_TIMESTAMP
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
REQUEST_ID
INTEGER
TRANSACTION_ID
INTEGER
STATEMENT_ID
INTEGER
POOL_ID
INTEGER
POOL_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
REASON
VARCHAR
RESOURCE_TYPE
VARCHAR
INTEGER
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
See Also
l
RESOURCE_REJECTIONS
SQLReference Manual
HP Vertica System Tables
RESOURCE_REJECTIONS
Monitors requests for resources that are rejected by the Resource Manager.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
POOL_ID
INTEGER
POOL_NAME
VARCHAR
REASON
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RESOURCE_TYPE
VARCHAR
INTEGER
FIRST_REJECTED_TIMESTAMP
LAST_REJECTED_TIMESTAMP
LAST_REJECTED_VALUE
INTEGER
SQLReference Manual
HP Vertica System Tables
Notes
Information is valid only as long as the node is up and the counters reset to 0 upon node restart.
Example
=> SELECT node_name, pool_name, reason, resource_type,
rejection_count AS count,
last_rejected_value AS value
FROM resource_rejections;
node_name | pool_name |
reason
|
resource_type
|
count |
value
-----------+-------------+---------------------------------------+-------------------+-------------------------initiator | alsohassome | Request exceeded high limit
| Memory(KB)
| 1
|
102400
initiator | ceo
| Timedout waiting for resource request | Memory(KB)
| 1
|
102400
initiator | empty
| Request exceeded high limit
| Queries
| 1
|
1
initiator | general
| Request exceeded high limit
| Address space(KB) | 2
| 45035996273704970
initiator | general
| Request exceeded high limit
| Memory(KB)
| 24
|
8395584
initiator | sa
| Request exceeded high limit
| Memory(KB)
| 3
|
102400
initiator | sa
| Timedout waiting for resource request | Memory(KB)
| 1
|
10
initiator | small
| Request exceeded high limit
| Memory(KB)
| 26
|
102400
initiator | small
| Timedout waiting for resource request | Memory(KB)
| 2
|
122880
initiator | sysdata
| Request exceeded high limit
| Memory(KB)
| 5
|
102400
(10 rows)
The following command returns the type of resources currently running on the node:
=> SELECT resource_type FROM resource_rejections;
resource_type
--------------UPDATE_QUERY
UPDATE_QUERY
UPDATE_QUERY
(3 rows)
SQLReference Manual
HP Vertica System Tables
See Also
l
CLEAR_RESOURCE_REJECTIONS
DISK_RESOURCE_REJECTIONS
RESOURCE_USAGE
Monitors system resource management on each node.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
REQUEST_COUNT
INTEGER
LOCAL_REQUEST_COUNT
INTEGER
REQUEST_QUEUE_DEPTH
INTEGER
ACTIVE_THREAD_COUNT
INTEGER
OPEN_FILE_HANDLE_COUNT
INTEGER
MEMORY_REQUESTED_KB
INTEGER
ADDRESS_SPACE_REQUESTED_KB
INTEGER
WOS_USED_BYTES
INTEGER
WOS_ROW_COUNT
INTEGER
ROS_USED_BYTES
INTEGER
ROS_ROW_COUNT
INTEGER
TOTAL_USED_BYTES
INTEGER
TOTAL_ROW_COUNT
INTEGER
RESOURCE_REQUEST_REJECT_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RESOURCE_REQUEST_TIMEOUT_COUNT
INTEGER
RESOURCE_REQUEST_CANCEL_COUNT
INTEGER
DISK_SPACE_REQUEST_REJECT_COUNT
INTEGER
FAILED_VOLUME_REJECT_COUNT
INTEGER
TOKENS_USED
INTEGER
TOKENS_AVAILABLE
INTEGER
Example
=>\pset expanded
Expanded display is on.
=> SELECT * FROM RESOURCE_USAGE;
-[ RECORD 1 ]-------------------+--------------------------node_name
| node01
request_count
| 1
local_request_count
| 1
request_queue_depth
| 0
active_thread_count
| 4
open_file_handle_count
| 2
memory_requested_kb
| 4352
address_space_requested_kb
| 106752
wos_used_bytes
| 0
wos_row_count
| 0
ros_used_bytes
| 10390319
ros_row_count
| 324699
total_used_bytes
| 10390319
total_row_count
| 324699
resource_request_reject_count
| 0
resource_request_timeout_count | 0
resource_request_cancel_count
| 0
disk_space_request_reject_count | 0
failed_volume_reject_count
| 0
tokens_used
| 1
tokens_available
| 7999999
-[ RECORD 2 ]-------------------+--------------------------node_name
| node02
request_count
| 0
local_request_count
| 0
request_queue_depth
| 0
active_thread_count
| 0
open_file_handle_count
| 0
memory_requested_kb
| 0
address_space_requested_kb
| 0
wos_used_bytes
| 0
wos_row_count
| 0
ros_used_bytes
| 10359489
SQLReference Manual
HP Vertica System Tables
ros_row_count
| 324182
total_used_bytes
| 10359489
total_row_count
| 324182
resource_request_reject_count
| 0
resource_request_timeout_count | 0
resource_request_cancel_count
| 0
disk_space_request_reject_count | 0
failed_volume_reject_count
| 0
tokens_used
| 0
tokens_available
| 8000000
-[ RECORD 3 ]-------------------+--------------------------node_name
| node03
request_count
| 0
local_request_count
| 0
request_queue_depth
| 0
active_thread_count
| 0
open_file_handle_count
| 0
memory_requested_kb
| 0
address_space_requested_kb
| 0
wos_used_bytes
| 0
wos_row_count
| 0
ros_used_bytes
| 10355231
ros_row_count
| 324353
total_used_bytes
| 10355231
total_row_count
| 324353
resource_request_reject_count
| 0
resource_request_timeout_count | 0
resource_request_cancel_count
| 0
disk_space_request_reject_count | 0
failed_volume_reject_count
| 0
tokens_used
| 0
tokens_available
| 8000000
-[ RECORD 4 ]-------------------+--------------------------node_name
| node04
request_count
| 0
local_request_count
| 0
request_queue_depth
| 0
active_thread_count
| 0
open_file_handle_count
| 0
memory_requested_kb
| 0
address_space_requested_kb
| 0
wos_used_bytes
| 0
wos_row_count
| 0
ros_used_bytes
| 10385744
ros_row_count
| 324870
total_used_bytes
| 10385744
total_row_count
| 324870
resource_request_reject_count
| 0
resource_request_timeout_count | 0
resource_request_cancel_count
| 0
disk_space_request_reject_count | 0
failed_volume_reject_count
| 0
tokens_used
| 0
tokens_available
| 8000000
SQLReference Manual
HP Vertica System Tables
SESSION_PARAMETERS
Provides information about current parameters that are configurable at the session level. To view
parameters configurable at all levels, see the CONFIGURATION_PARAMETERS system table.
Column Name
Data Type
Description
SOURCE_NAME
VARCHAR
PARAMETER_NAME
VARCHAR
CURRENT_VALUE
VARCHAR
DEFAULT_VALUE
VARCHAR
LEVEL
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
GROUPS
VARCHAR
CHANGE_UNDER_SUPPORT_GUIDANCE
BOOLEAN
DESCRIPTION
VARCHAR
Example
The following example shows how to retrieve all information for parameters configurable at the
session level:
=> SELECT * FROM SESSION_PARAMETERS;
-[ RECORD 1 ]-----------------+-------------------------------------------------------source_name
|
parameter_name
| ForceUDxFencedMode
current_value
| 0
default_value
| 0
level
| DEFAULT
groups
| EEVOptions
change_under_support_guidance | f
description
| Force all UDx's to run in fenced mode
.
.
.
See Also
l
Configuration Parameters
CONFIGURATION_PARAMETERS
SESSION_PROFILES
Provides basic session parameters and lock time out data. To obtain information about sessions,
see Profiling Database Performance.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
CLIENT_HOSTNAME
VARCHAR
LOGIN_TIMESTAMP
TIMESTAMP The date and time the user logged into the
database or when the internal session was
created. This field is useful for identifying
sessions that have been left open for a
period of time and could be idle.
LOGOUT_TIMESTAMP
TIMESTAMP The date and time the user logged out of the
database or when the internal session was
closed.
SESSION_ID
VARCHAR
EXECUTED_STATEMENT_SUCCESS_COUNT
INTEGER
EXECUTED_STATEMENT_FAILURE_COUNT
INTEGER
LOCK_GRANT_COUNT
INTEGER
DEADLOCK_COUNT
INTEGER
LOCK_TIMEOUT_COUNT
INTEGER
LOCK_CANCELLATION_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
LOCK_REJECTION_COUNT
INTEGER
LOCK_ERROR_COUNT
INTEGER
CLIENT_TYPE
VARCHAR
ADO.NET Driver
ODBC Driver
JDBC Driver
vsql
CLIENT_VERSION
VARCHAR
CLIENT_OS
VARCHAR
Example
Query the SESSION_PROFILES Table:
=>\pset expanded
Expanded display on.
=> SELECT * FROM SESSION_PROFILES;
-[ RECORD 1 ]-------------------+--------------------------------node_name
| node04
user_name
| dbadmin
client_hostname
| 192.168.1.1:46816
login_timestamp
| 2009-09-28 11:40:34.01518
logout_timestamp
| 2009-09-28 11:41:01.811484
session_id
| myhost.verticacorp-20790:0x32f
executed_statement_success_count | 51
executed_statement_failure_count | 1
lock_grant_count
| 579
deadlock_count
| 0
lock_timeout_count
| 0
lock_cancellation_count
| 0
lock_rejection_count
| 0
lock_error_count
| 0
client_type
| vsql
client_version
| 07.00.0000
client_os
| Linux 2.6.18-308.el5 x86_64
SQLReference Manual
HP Vertica System Tables
See Also
l
LOCKS
SESSIONS
This system table monitors external sessions. Use this table to:
l
Identify users who are holding locks because of an idle but uncommitted transaction.
Determine the details of the database security used for a particular session, either Secure
Socket Layer (SSL) or client authentication.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
CLIENT_HOSTNAME
VARCHAR
CLIENT_PID
INTEGER
LOGIN_TIMESTAMP
TIMESTAMP The date and time the user logged into the
database or when the internal session was
created. This field can help you identify sessions
that have been left open for a period of time and
could be idle.
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SESSION_ID
VARCHAR
CLIENT_LABEL
VARCHAR
TRANSACTION_START
DATE
TRANSACTION_ID
INTEGER
TRANSACTION_DESCRIPTION
VARCHAR
STATEMENT_START
INTEGER
LAST_STATEMENT_DURATION_US
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RUNTIME_PRIORITY
VARCHAR
HIGH
MEDIUM
LOW
VARCHAR
LAST_STATEMENT
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SSL_STATE
VARCHAR
VARCHAR
Unknown
Trust
Reject
Hash
Ident
LDAP
GSS
TLS
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CLIENT_TYPE
VARCHAR
ADO.NET Driver
ODBC Driver
JDBC Driver
vsql
CLIENT_VERSION
VARCHAR
Client version.
CLIENT_OS
VARCHAR
CLIENT_AUTHENTICATION_NAME
VARCHAR
CLIENT_AUTHENTICATION
INTEGER
JVM_MEMORY_KB
INTEGER
Privileges
A superuser has unrestricted access to all session information. Users can view information only
about their own, current sessions.
l
During session initialization and termination, you might see sessions running only on nodes
other than the node on which you ran the virtual table query. This is a temporary situation that
corrects itself as soon as session initialization and termination completes.
Examples
This example shows all the external session information for a specific record.
This example shows all the external session information for a specific record.
=>\pset expanded
Expanded display is on.
=> SELECT * FROM SESSIONS;
-[ RECORD 1 ]--------------+---------------------------------------
SQLReference Manual
HP Vertica System Tables
node_name
user_name
client_hostname
client_pid
login_timestamp
session_id
client_label
transaction_start
transaction_id
transaction_description
statement_start
statement_id
last_statement_duration_us
runtime_priority
current_statement
last_statement
ssl_state
authentication_method
client_type
client_version
client_os
client_authentication_name
client_authentication
jvm_memory_kb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v_mcdb_node0001
dbadmin
00.00.000.00:xxxxx
12345
2013-05-09 07:18:11.161721-04
myhost.verticacorp.-7695:0x4f337
MC
2013-05-09 07:18:16.051058-04
49539595901174387
user dbadmin (select * from sessions;)
2013-05-09 07:18:19.54812-04
2
16508
select * from sessions;
select * from sessions;
None
Password
JDBC Driver
07.01.0100
Linux 2.6.32-358.el6.x86_64 amd64
v_md5
45035996273741450
0
See Also
l
CLOSE_SESSION
CLOSE_ALL_SESSIONS
STORAGE_CONTAINERS
Monitors information about WOS and ROS storage containers in the database.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SCHEMA_NAME
VARCHAR
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
STORAGE_TYPE
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
STORAGE_OID
INTEGER
TOTAL_ROW_COUNT
VARCHAR
DELETED_ROW_COUNT
INTEGER
USED_BYTES
INTEGER
START_EPOCH
INTEGER
END_EPOCH
INTEGER
GROUPING
VARCHAR
SEGMENT_LOWER_BOUND
INTEGER
SEGMENT_UPPER_BOUND
INTEGER
IS_SORTED
BOOLEAN
LOCATION_LABEL
VARCHAR
The location label (if any) for the storage container is stored.
(128)
DELETE_VECTOR_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
The following command returns all the nodes on which a segmented projection has data on the
TickStore database:
TickStore=> SELECT node_name, projection_name,
total_row_count
FROM storage_containers
ORDER BY projection_name;
node_name
|
projection_name
| total_row_count
-----------------+--------------------------+----------------v_tick_node0001 | Quotes_Fact_tmp_node0001 |
512
v_tick_node0001 | Quotes_Fact_tmp_node0001 |
480176
v_tick_node0002 | Quotes_Fact_tmp_node0002 |
512
v_tick_node0002 | Quotes_Fact_tmp_node0002 |
480176
v_tick_node0003 | Quotes_Fact_tmp_node0003 |
480176
v_tick_node0003 | Quotes_Fact_tmp_node0003 |
512
v_tick_node0004 | Quotes_Fact_tmp_node0004 |
480176
v_tick_node0004 | Quotes_Fact_tmp_node0004 |
512
v_tick_node0001 | Trades_Fact_tmp_node0001 |
512
v_tick_node0001 | Trades_Fact_tmp_node0001 |
500334
v_tick_node0002 | Trades_Fact_tmp_node0002 |
500334
v_tick_node0002 | Trades_Fact_tmp_node0002 |
512
v_tick_node0003 | Trades_Fact_tmp_node0003 |
500334
v_tick_node0003 | Trades_Fact_tmp_node0003 |
512
v_tick_node0004 | Trades_Fact_tmp_node0004 |
500334
v_tick_node0004 | Trades_Fact_tmp_node0004 |
512
(16 rows)
The following command returns information on inventory_fact projections on all nodes on the Vmart
schema:
=> SELECT * FROM storage_containers WHERE projection_name LIKE 'inventory_fact_p%';
-[ RECORD 1 ]-----+-------------------------node_name
| node01
schema_name
| public
projection_name
| inventory_fact_p_node0001
storage_type
| WOS
storage_oid
| 45035996273720173
total_row_count
| 3000
deleted_row_count | 100
used_bytes
| 196608
start_epoch
| 1
end_epoch
| 2
grouping
| ALL
-[ RECORD 2 ]-----+--------------------------
SQLReference Manual
HP Vertica System Tables
node_name
| node01
schema_name
| public
projection_name
| inventory_fact_p_node0001
storage_type
| ROS
storage_oid
| 45035996273722211
total_row_count
| 500
deleted_row_count | 25
used_bytes
| 5838
start_epoch
| 1
end_epoch
| 1
grouping
| ALL
-[ RECORD 3 ]-----+-------------------------node_name
| node01
schema_name
| public
projection_name
| inventory_fact_p_node0001
storage_type
| ROS
storage_oid
| 45035996273722283
total_row_count
| 500
deleted_row_count | 25
used_bytes
| 5794
start_epoch
| 1
end_epoch
| 1
grouping
| ALL
-[ RECORD 4 ]-----+-------------------------node_name
| node01
schema_name
| public
projection_name
| inventory_fact_p_node0001
storage_type
| ROS
storage_oid
| 45035996273723379
total_row_count
| 500
deleted_row_count | 25
used_bytes
| 5838
start_epoch
| 1
end_epoch
| 1
grouping
| ALL
-[ RECORD 5 ]-----+-------------------------node_name
| node01
schema_name
| public
projection_name
| inventory_fact_p_node0001
storage_type
| ROS
storage_oid
| 45035996273723451
total_row_count
| 500
deleted_row_count | 25
used_bytes
| 5794
start_epoch
| 1
end_epoch
| 1
grouping
| ALL
-[ RECORD 6 ]-----+-------------------------node_name
| node01
schema_name
| public
projection_name
| inventory_fact_p_node0001
storage_type
| ROS
storage_oid
| 45035996273724547
total_row_count
| 500
deleted_row_count | 0
used_bytes
| 5838
start_epoch
| 2
end_epoch
| 2
SQLReference Manual
HP Vertica System Tables
grouping
| ALL
-[ RECORD 7 ]-----+-------------------------node_name
| node01
schema_name
| public
projection_name
| inventory_fact_p_node0001
storage_type
| ROS
storage_oid
| 45035996273724619
total_row_count
| 500
deleted_row_count | 0
used_bytes
| 5794
start_epoch
| 2
end_epoch
| 2
grouping
| ALL
-[ RECORD 8 ]-----+-------------------------...
STORAGE_POLICIES
Monitors the current storage policies in effect for one or more database objects.
Column
Name
Data Type
Description
SCHEMA_NAME
VARCHAR
OBJECT_NAME
VARCHAR
POLICY_DETAILS
VARCHAR
LOCATION_LABEL
VARCHAR
(128)
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
The following query returns the current storage polices:
VMART=> select * from v_monitor.storage_policies;
schema_name | object_name | policy_details | location_label
-------------+-------------+----------------+---------------public
| states
| Table
| LEVEL3
public
| newstates
| Table
| LEVEL3
SQLReference Manual
HP Vertica System Tables
(2 rows)
See Also
l
PARTITIONS
STORAGE_CONTAINERS
STORAGE_USAGE
STORAGE_TIERS
Provides information about all storage locations with the same label across all cluster nodes. This
table lists data totals for all same-name labeled locations.
The system table shows what labeled locations exist on the cluster, as well as other cluster-wide
data about the locations.
Column Name
Data Type
Description
LOCATION_LABEL
VARCHAR
NODE_COUNT
INTEGER
LOCATION_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ROS_CONTAINER_COUNT
INTEGER
TOTAL_OCCUPIED_SIZE
INTEGER
Permissions
Must be a superuser.
Example
VMart=> select * from v_monitor.storage_tiers;
location_label | node_count | location_count | ros_container_count | total_occupied_size
----------------+------------+----------------+---------------------+-------------------|
1 |
2 |
17 |
297039391
SSD
|
1 |
1 |
9 |
1506
Schema
|
1 |
1 |
0 |
0
(3 rows)
See Also
l
DISK_STORAGE
STORAGE_POLICIES
STORAGE_USAGE
STORAGE_USAGE
Provides information about file system storage usage. This is useful for determining disk space
usage trends.
Column
Name
Data Type
POLL_TIMESTAMP
Description
SQLReference Manual
HP Vertica System Tables
Column
Name
Data Type
Description
NODE_NAME
VARCHAR
PATH
VARCHAR
DEVICE
VARCHAR
FILESYSTEM
VARCHAR
USED_BYTES
INTEGER
FREE_BYTES
INTEGER
USAGE_PERCENT
FLOAT
Permissions
Must be a superuser.
Example
=> \x
Expanded display is on.
=> select * from storage_usage;
-[ RECORD 1 ]--+-----------------------------poll_timestamp | 2013-12-05 15:55:43.011662-08
node_name
| v_vmart_node0001
path
|
device
|
filesystem
| vertica
used_bytes
| 10964557824
free_bytes
| 45094535168
usage_percent | 19.56
-[ RECORD 2 ]--+-----------------------------poll_timestamp | 2013-12-05 15:55:43.011659-08
node_name
| v_vmart_node0001
path
| /boot
device
| /dev/sda1
filesystem
| ext3
used_bytes
| 32920576
free_bytes
| 269733888
usage_percent | 10.88
-[ RECORD 3 ]--+-----------------------------poll_timestamp | 2013-12-05 15:55:43.011651-08
node_name
| v_vmart_node0001
path
| /
device
| /dev/root
SQLReference Manual
HP Vertica System Tables
filesystem
used_bytes
free_bytes
usage_percent
(3 rows)
|
|
|
|
ext3
10964557824
45094535168
19.56
See Also
l
DISK_STORAGE
STORAGE_CONTAINERS
STORAGE_POLICIES
STORAGE_TIERS
STRATA
Contains internal details of how the Tuple Mover combines ROS containers in each projection,
broken down by stratum and classifies the ROS containers by size and partition. The related
STRATA_STRUCTURES table provides a summary of the strata values.
The STRATA table contains detailed information on
For a brief overview of how the Tuple Mover combines ROS containers, see Tuple Mover in the
Administrator's Guide.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SCHEMA_NAME
VARCHAR
PROJECTION_ID
INTEGER
PROJECTION_NAME
VARCHAR
PARTITION_KEY
VARCHAR
STRATA_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
MERGING_STRATA_COUNT
INTEGER
STRATUM_CAPACITY
INTEGER
STRATUM_HEIGHT
FLOAT
STRATUM_NO
INTEGER
STRATUM_LOWER_SIZE
VARCHAR
STRATUM_UPPER_SIZE
VARCHAR
ROS_CONTAINER_COUNT
INTEGER
Example
onenode=> SELECT * FROM strata;
-[ RECORD 1 ]--------+------------------node_name
| v_onenode_node0001
schema_name
| public
projection_id
| 45035996273718838
projection_name
| trades_p
partition_key
|
strata_count
| 11
merging_strata_count | 4
stratum_capacity
| 32
stratum_height
| 28.8
stratum_no
| 0
stratum_lower_size
| 0B
stratum_upper_size
| 4MB
ROS_container_count | 1
vmartdb=> \pset expanded
Expanded display is on.
vmartdb=> SELECT node_name, schema_name, projection_name, strata_count,
stratum_capacity, stratum_height, stratum_no, stratum_lower_size,
stratum_upper_size, ros_container_count
FROM strata WHERE node_name ILIKE 'node01' AND stratum_upper_size < '15MB';
-[ RECORD 1 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| online_sales
projection_name
| call_center_dimension_DBD_32_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 19
stratum_height
| 8.97589786696783
stratum_no
| 0
SQLReference Manual
HP Vertica System Tables
stratum_lower_size | 0B
stratum_upper_size | 13MB
ROS_container_count | 1
-[ RECORD 2 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| online_sales
projection_name
| call_center_dimension_DBD_8_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 19
stratum_height
| 8.97589786696783
stratum_no
| 0
stratum_lower_size | 0B
stratum_upper_size | 13MB
ROS_container_count | 1
-[ RECORD 3 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| online_sales
projection_name
| online_sales_fact_DBD_33_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 13
stratum_height
| 8.16338338718601
stratum_no
| 1
stratum_lower_size | 19MB
stratum_upper_size | 155.104MB
ROS_container_count | 1
-[ RECORD 4 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| online_sales
projection_name
| online_sales_fact_DBD_9_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 13
stratum_height
| 8.16338338718601
stratum_no
| 1
stratum_lower_size | 19MB
stratum_upper_size | 155.104MB
ROS_container_count | 1
-[ RECORD 5 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| public
projection_name
| promotion_dimension_DBD_16_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 19
stratum_height
| 8.97589786696783
stratum_no
| 0
stratum_lower_size | 0B
stratum_upper_size | 13MB
ROS_container_count | 1
-[ RECORD 6 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| public
projection_name
| promotion_dimension_DBD_17_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 19
stratum_height
| 8.97589786696783
stratum_no
| 0
stratum_lower_size | 0B
stratum_upper_size | 13MB
ROS_container_count | 1
SQLReference Manual
HP Vertica System Tables
-[ RECORD 7 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| store
projection_name
| store_sales_fact_DBD_29_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 16
stratum_height
| 8.52187248329035
stratum_no
| 1
stratum_lower_size | 16MB
stratum_upper_size | 136.35MB
ROS_container_count | 1
-[ RECORD 8 ]-------+----------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| store
projection_name
| store_sales_fact_DBD_5_seg_vmart_design_vmart_design
strata_count
| 5
stratum_capacity
| 16
stratum_height
| 8.52187248329035
stratum_no
| 1
stratum_lower_size | 16MB
stratum_upper_size | 136.35MB
ROS_container_count | 1
STRATA_STRUCTURES
This table provides an overview of Tuple Mover internal details. It summarizes how the ROS
containers are classified by size. A more detailed view can be found in the STRATA virtual table.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SCHEMA_NAME
VARCHAR
PROJECTION_NAME
VARCHAR
PROJECTION_ID
INTEGER
PARTITION_KEY
VARCHAR
STRATA_COUNT
INTEGER
MERGING_STRATA_COUNT
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
STRATUM_CAPACITY
INTEGER
STRATUM_HEIGHT
FLOAT
ACTIVE_STRATA_COUNT
INTEGER
Example
onenode=> SELECT * FROM strata_structures;
-[ RECORD 1 ]--------+------------------node_name
| v_onenode_node0001
schema_name
| public
projection_name
| trades_p
projection_id
| 45035996273718838
partition_key
|
strata_count
| 11
merging_strata_count | 4
stratum_capacity
| 32
stratum_height
| 28.8
active_strata_count | 1
vmartdb=> \pset expanded
Expanded display is on.
vmartdb=> SELECT node_name, schema_name, projection_name, strata_count,
stratum_capacity, stratum_height, stratum_no, stratum_lower_size,
stratum_upper_size, ros_container_count
WHERE stratum_capacity > 60;
-[ RECORD 1 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| public
projection_name
| shipping_dimension_DBD_22_seg_vmart_design_vmart_design
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
-[ RECORD 2 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node01
schema_name
| public
projection_name
| shipping_dimension_DBD_23_seg_vmart_design_vmart_design
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
-[ RECORD 3 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node02
schema_name
| public
projection_name
| shipping_dimension_DBD_22_seg_vmart_design_vmart_design
SQLReference Manual
HP Vertica System Tables
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
-[ RECORD 4 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node02
schema_name
| public
projection_name
| shipping_dimension_DBD_23_seg_vmart_design_vmart_design
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
-[ RECORD 5 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node03
schema_name
| public
projection_name
| shipping_dimension_DBD_22_seg_vmart_design_vmart_design
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
-[ RECORD 6 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node03
schema_name
| public
projection_name
| shipping_dimension_DBD_23_seg_vmart_design_vmart_design
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
-[ RECORD 7 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node04
schema_name
| public
projection_name
| shipping_dimension_DBD_22_seg_vmart_design_vmart_design
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
-[ RECORD 8 ]-------+-------------------------------------------------------node_name
| v_vmartdb_node04
schema_name
| public
projection_name
| shipping_dimension_DBD_23_seg_vmart_design_vmart_design
partition_key
|
strata_count
| 4
stratum_capacity
| 62
stratum_height
| 25.6511590887058
active_strata_count | 1
See Also
l
STRATA
SQLReference Manual
HP Vertica System Tables
SYSTEM
Monitors the overall state of the database.
Column Name
Data
Type
Description
CURRENT_EPOCH
INTEGER
AHM_EPOCH
INTEGER
LAST_GOOD_EPOCH
INTEGER
REFRESH_EPOCH
INTEGER
DESIGNED_FAULT_TOLERANCE
INTEGER
NODE_COUNT
INTEGER
NODE_DOWN_COUNT
INTEGER
CURRENT_FAULT_TOLERANCE
INTEGER
CATALOG_REVISION_NUMBER
INTEGER
WOS_USED_BYTES
INTEGER
WOS_ROW_COUNT
INTEGER
ROS_USED_BYTES
INTEGER
ROS_ROW_COUNT
INTEGER
TOTAL_USED_BYTES
INTEGER
TOTAL_ROW_COUNT
INTEGER
Example
Query the SYSTEM table:
SQLReference Manual
HP Vertica System Tables
=>\pset expanded
Expanded display is on.
=> SELECT * FROM SYSTEM;
-[ RECORD 1 ]------------+---------current_epoch
| 429
ahm_epoch
| 428
last_good_epoch
| 428
refresh_epoch
| -1
designed_fault_tolerance | 1
node_count
| 4
node_down_count
| 0
current_fault_tolerance | 1
catalog_revision_number | 1590
wos_used_bytes
| 0
wos_row_count
| 0
ros_used_bytes
| 443131537
ros_row_count
| 21809072
total_used_bytes
| 443131537
total_row_count
| 21809072
SYSTEM_RESOURCE_USAGE
Provides history about system resources, such as memory, CPU, network, disk, I/O.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
END_TIME
AVERAGE_MEMORY_USAGE_PERCENT
FLOAT
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
AVERAGE_CPU_USAGE_PERCENT
FLOAT
NET_RX_KBYTES_PER_SECOND
FLOAT
NET_TX_KBYTES_PER_SECOND
FLOAT
IO_READ_KBYTES_PER_SECOND
FLOAT
IO_WRITTEN_KBYTES_PER_SECOND
FLOAT
Permissions
Must be a superuser.
Example
=> SELECT * FROM system_resource_usage WHERE node_name = 'v_myvdb_node04';
-[ RECORD 1 ]----------------+-------------------node_name
| v_myvdb_node04
end_time
| 2012-03-30 17:43:00
average_memory_usage_percent | 3.6
average_cpu_usage_percent
| 9.1
net_rx_kbytes_per_second
| 12.75
net_tx_kbytes_per_second
| 5.77
io_read_kbytes_per_second
| 0
io_written_kbytes_per_second | 643.92
-[ RECORD 2 ]----------------+-------------------node_name
| v_myvdb_node04
end_time
| 2012-03-30 17:38:00
average_memory_usage_percent | 3.59
average_cpu_usage_percent
| 10.4
net_rx_kbytes_per_second
| 5.78
net_tx_kbytes_per_second
| 0.88
io_read_kbytes_per_second
| 0
io_written_kbytes_per_second | 650.28
-[ RECORD 3 ]----------------+-------------------node_name
| v_myvdb_node04
end_time
| 2012-03-30 17:37:00
average_memory_usage_percent | 3.59
average_cpu_usage_percent
| 8.47
SQLReference Manual
HP Vertica System Tables
net_rx_kbytes_per_second
| 5.41
net_tx_kbytes_per_second
| 0.77
io_read_kbytes_per_second
| 0
io_written_kbytes_per_second | 621.39
-[ RECORD 4 ]----------------+-------------------node_name
| v_myvdb_node04
end_time
| 2012-03-30 17:31:00
average_memory_usage_percent | 3.59
average_cpu_usage_percent
| 12.35
net_rx_kbytes_per_second
| 5.71
net_tx_kbytes_per_second
| 0.87
io_read_kbytes_per_second
| 0
io_written_kbytes_per_second | 647.06
-[ RECORD 5 ]----------------+-------------------node_name
| v_myvdb_node04
end_time
| 2012-03-30 17:29:00
average_memory_usage_percent | 3.59
average_cpu_usage_percent
| 8.52
net_rx_kbytes_per_second
| 5.56
net_tx_kbytes_per_second
| 0.81
io_read_kbytes_per_second
| 0
io_written_kbytes_per_second | 631.21
...
SYSTEM_SERVICES
Provides information about background system services that the Workload Analyzer monitors.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SERVICE_TYPE
SERVICE_GROUP
VARCHAR
VARCHAR
SYSTEM
TUPLE MOVER
SERVICE_NAME
VARCHAR
SERVICE_INTERVAL_SEC
INTEGER
IS_ENABLED
BOOLEAN
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
LAST_RUN_START
LAST_RUN_END
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> SELECT * FROM system_services;
-[ RECORD 1 ]--------+-----------------------------node_name
| v_myvdb_node0004
service_type
| System
service_group
|
service_name
| Ageout Session Profiling Data
service_interval_sec | 86400
is_enabled
| t
last_run_start
| 2012-04-03 11:36:54.001782-04
last_run_end
| 2012-04-03 11:36:54.001793-04
-[ RECORD 2 ]--------+-----------------------------node_name
| v_myvdb_node0004
service_type
| System
service_group
|
service_name
| AgeOutEvents
service_interval_sec | 3
is_enabled
| t
last_run_start
| 2012-04-03 14:41:24.001538-04
last_run_end
| 2012-04-03 14:41:24.001544-04
-[ RECORD 3 ]--------+-----------------------------node_name
| v_myvdb_node0004
service_type
| System
service_group
|
service_name
| CatalogCheckpointer
service_interval_sec | 86400
is_enabled
| t
last_run_start
| 2012-04-03 11:36:54.001788-04
last_run_end
| 2012-04-03 11:36:54.002721-04
-[ RECORD 4 ]--------+-----------------------------node_name
| v_myvdb_node0004
service_type
| System
service_group
|
service_name
| Cluster Inviter
service_interval_sec | 2
is_enabled
| t
last_run_start
| 2012-04-03 14:41:25.002031-04
last_run_end
| 2012-04-03 14:41:25.002671-04
-[ RECORD 5 ]--------+-----------------------------...
=> SELECT service_type, last_run_start, last_run_end FROM system_services;
SQLReference Manual
HP Vertica System Tables
service_type |
last_run_start
|
last_run_end
--------------+-------------------------------+------------------------------System
|
|
System
| 2012-03-01 08:10:05.010077-05 | 2012-03-01 08:10:05.010081-05
System
|
|
System
| 2012-03-01 08:10:06.003775-05 | 2012-03-01 08:10:06.00499-05
System
| 2012-03-01 07:27:05.004958-05 | 2012-03-01 07:27:05.005376-05
System
| 2012-03-01 06:32:45.001812-05 | 2012-03-01 06:32:45.002249-05
System
|
|
System
| 2012-03-01 08:10:05.006397-05 | 2012-03-01 08:10:05.006399-05
System
| 2012-03-01 06:29:05.000905-05 | 2012-03-01 06:29:05.001517-05
System
| 2012-03-01 08:10:05.006213-05 | 2012-03-01 08:10:05.006215-05
System
| 2012-03-01 08:10:05.006379-05 | 2012-03-01 08:10:05.007055-05
System
| 2012-03-01 08:10:05.009981-05 | 2012-03-01 08:10:05.009983-05
System
| 2012-03-01 08:10:05.00988-05 | 2012-03-01 08:10:05.009882-05
Tuple Mover | 2012-03-01 08:10:05.006673-05 | 2012-03-01 08:10:05.006675-05
Tuple Mover | 2012-03-01 08:07:05.006837-05 | 2012-03-01 08:07:05.009541-05
Tuple Mover | 2012-03-01 08:09:05.001376-05 | 2012-03-01 08:09:05.001378-05
Tuple Mover | 2012-03-01 07:17:05.000908-05 | 2012-03-01 07:17:05.015156-05
Tuple Mover | 2012-03-01 08:07:05.00679-05 | 2012-03-01 08:07:05.007486-05
Tuple Mover | 2012-03-01 08:07:05.006673-05 | 2012-03-01 08:07:05.010128-05
Tuple Mover | 2012-03-01 08:07:05.002946-05 | 2012-03-01 08:07:05.010192-05
Tuple Mover | 2012-03-01 08:07:05.002946-05 | 2012-03-01 08:07:05.010192-05
Tuple Mover | 2012-03-01 08:07:05.002962-05 | 2012-03-01 08:07:05.007198-05
SYSTEM_SESSIONS
Provides information about system internal session history by system task.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
USER_NAME
VARCHAR
SESSION_ID
INTEGER
TRANSACTION_ID
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
STATEMENT_ID
VARCHAR
SESSION_TYPE
VARCHAR
INTERNAL
CLIENT
DBD
MERGEOUT
MOVEOUT
REBALANCE_CLUSTER
RECOVERY
REFRESH
TIMER_SERVICE
CONNECTION
SUBSESSION
REPARTITION_TABLE
LICENSE_AUDIT
STARTUP
SHUTDOWN
VSPREAD
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
RUNTIME_PRIORITY
VARCHAR
HIGH
MEDIUM
LOW
VARCHAR
SESSION_START_TIMESTAMP
SESSION_END_TIMESTAMP
IS_ACTIVE
BOOLEAN
SESSION_DURATION_MS
INTEGER
CLIENT_TYPE
VARCHAR
CLIENT_VERSION
VARCHAR
CLIENT_OS
VARCHAR
Permissions
Must be a superuser..
SQLReference Manual
HP Vertica System Tables
Example
=> \x
Expanded display is on.
=> SELECT * FROM system_sessions;
-[ RECORD 1 ]-----------+------------------------------------------------------node_name
| v_vmart_node0002
user_name
| dbadmin
session_id
| xxxx02.verticacorp.-23295:0x2b7
transaction_id
| 49539595901220372
statement_id
|
session_type
| MERGEOUT
runtime_priority
|
description
| Txn: b0000000023614 'Mergeout: Tuple Mover'
session_start_timestamp | 2012-12-10 06:41:03.025615-05
session_end_timestamp
| 2012-12-10 06:41:03.030063-05
is_active
| f
session_duration_ms
| 1
client_type
|
client_version
|
client_os
|
-[ RECORD 2 ]-----------+------------------------------------------------------node_name
| v_vmart_node0003
user_name
| dbadmin
session_id
| xxxx03.verticacorp.-22620:0x2bd
transaction_id
| 54043195528590868
statement_id
|
session_type
| MOVEOUT
runtime_priority
|
description
| Txn: c0000000023614 'Moveout: Tuple Mover'
session_start_timestamp | 2012-12-10 06:41:03.007496-05
session_end_timestamp
| 2012-12-10 06:41:03.00844-05
is_active
| f
session_duration_ms
| 1
client_type
|
client_version
|
client_os
|
-[ RECORD 3 ]-----------+------------------------------------------------------node_name
| v_vmart_node0001
user_name
| dbadmin
session_id
| xxxx01.verticacorp.-30972:0x1f3
transaction_id
| 45035996273960317
statement_id
|
session_type
| REBALANCE_CLUSTER
runtime_priority
|
description
| Txn: a000000003e57d 'rebalance_cluster(background)'
session_start_timestamp | 2012-12-10 06:37:26.015479-05
session_end_timestamp
| 2012-12-10 06:37:26.033779-05
is_active
| f
session_duration_ms
| 13
client_type
|
client_version
|
client_os
|
-[ RECORD 4 ]-----------+------------------------------------------------------...
SQLReference Manual
HP Vertica System Tables
See Also
l
CURRENT_SESSION
SESSION_PROFILES
SESSIONS
USER_SESSIONS
TRANSACTIONS
Records the details of each transaction.
Column Name
Data Type
Description
START_TIMESTAMP
END_TIMESTAMP
NODE_NAME
VARCHAR
USER_ID
INTEGER
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
TRANSACTION_ID
INTEGER
DESCRIPTION
VARCHAR
START_EPOCH
INTEGER
END_EPOCH
INTEGER
NUMBER_OF_STATEMENTS
INTEGER
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
ISOLATION
VARCHAR
IS_READ_ONLY
BOOLEAN
IS_COMMITTED
BOOLEAN
IS_LOCAL
BOOLEAN
IS_INITIATOR
BOOLEAN
IS_DDL
BOOLEAN
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> SELECT * FROM transactions LIMIT 4;
-[ RECORD 1 ]--------+----------------------------------------------------start_timestamp
| 2012-03-30 17:25:16.025136-04
end_timestamp
| 2012-03-30 17:25:16.029179-04
node_name
| v_myvdb_node0004
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| raster-s1-10295:0x389d
transaction_id
| 58546795155820007
description
| Txn: d0000000000de7 'RemoteNodeLocalState_RowCounts'
start_epoch
| 4
end_epoch
| 4
number_of_statements | 1
isolation
| SERIALIZABLE
is_read_only
| f
is_committed
| f
is_local
| t
is_initiator
| t
is_ddl
| f
-[ RECORD 2 ]--------+----------------------------------------------------start_timestamp
| 2012-03-30 17:25:14.001833-04
end_timestamp
| 2012-03-30 17:25:14.001915-04
node_name
| v_myvdb_node0004
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| raster-s4-22870:0x3b4b
SQLReference Manual
HP Vertica System Tables
transaction_id
| 58546795155820006
description
| Txn: d0000000000de6 'Check LGE'
start_epoch
| 4
end_epoch
| 4
number_of_statements | 1
isolation
| SERIALIZABLE
is_read_only
| f
is_committed
| f
is_local
| t
is_initiator
| t
is_ddl
| f
-[ RECORD 3 ]--------+----------------------------------------------------start_timestamp
| 2012-03-30 17:22:16.0105-04
end_timestamp
| 2012-03-30 17:22:16.014883-04
node_name
| v_myvdb_node0004
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| raster-s1-10295:0x3839
transaction_id
| 58546795155819998
description
| Txn: d0000000000dde 'RemoteNodeLocalState_RowCounts'
start_epoch
| 4
end_epoch
| 4
number_of_statements | 1
isolation
| SERIALIZABLE
is_read_only
| f
is_committed
| f
is_local
| t
is_initiator
| t
is_ddl
| f
-[ RECORD 4 ]--------+----------------------------------------------------start_timestamp
| 2012-03-30 17:22:10.0063-04
end_timestamp
| 2012-03-30 17:22:10.006571-04
node_name
| v_myvdb_node0004
user_id
| 45035996273704962
user_name
| dbadmin
session_id
| raster-s1-10295:0x3835
transaction_id
| 58546795155819997
description
| Txn: d0000000000ddd 'ProjUtil::getLocalNodeLGE'
start_epoch
| 4
end_epoch
| 4
number_of_statements | 1
isolation
| SERIALIZABLE
is_read_only
| f
is_committed
| f
is_local
| t
is_initiator
| t
is_ddl
| f
See Also
l
Transactions
SQLReference Manual
HP Vertica System Tables
TUNING_RECOMMENDATIONS
Returns the tuning recommendation results from the last ANALYZE_WORKLOAD() call. This
information is useful for letting you build filters on the Workload Analyzer result set.
Column
Data type
Description
observation_
count
INTEGER
Integer for the total number of events observed for this tuning
recommendation. For example, if you see a return value of 1,
WLA is making its first tuning recommendation for the event
in 'scope'.
first_
observation_time
TIMESTAM
PTZ
last_
observation_time
TIMESTAM
PTZ
tuning_parameter
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column
Data type
Description
tuning_
description
VARCHAR
tuning_command
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column
Data type
Description
tuning_cost
VARCHAR
Permissions
Must be a superuser.
Examples
For examples, see ANALYZE_WORKLOAD().
See Also
l
Analyzing Workloads
TUPLE_MOVER_OPERATIONS
Monitors the status of the Tuple Mover (TM) on each node.
Column Name
Data Type
OPERATION_START_TIMESTAMP
NODE_NAME
VARCHAR
Description
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
OPERATION_NAME
VARCHAR
OPERATION_STATUS
VARCHAR
TABLE_SCHEMA
VARCHAR
TABLE_NAME
VARCHAR
PROJECTION_NAME
VARCHAR
PROJECTION_ID
INTEGER
COLUMN_ID
INTEGER
EARLIEST_CONTAINER_START_EPOCH
INTEGER
LATEST_CONTAINER_END_EPOCH
INTEGER
ROS_COUNT
INTEGER
TOTAL_ROS_USED_BYTES
INTEGER
PLAN_TYPE
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SESSION_ID
VARCHAR
IS_EXECUTING
BOOLEAN
RUNTIME_PRIORITY
VARCHAR
HIGH
MEDIUM
LOW
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Notes
Manual mergeouts are invoked using one of the following APIs:
l
DO_TM_TASK
PURGE
Example
=> SELECT node_name, operation_status, projection_name, plan_type
FROM TUPLE_MOVER_OPERATIONS;
node_name | operation_status | projection_name | plan_type
-----------+------------------+------------------+----------node0001 | Running
| p1_b2
| Mergeout
node0002 | Running
| p1
| Mergeout
node0001 | Running
| p1_b2
| Replay Delete
node0001 | Running
| p1_b2
| Mergeout
node0002 | Running
| p1_b2
| Mergeout
node0001 | Running
| p1_b2
| Replay Delete
SQLReference Manual
HP Vertica System Tables
node0002
node0003
node0001
node0002
|
|
|
|
Running
Running
Running
Running
|
|
|
|
p1
p1_b2
p1
p1_b1
|
|
|
|
Mergeout
Replay Delete
Mergeout
Mergeout
See Also
l
DO_TM_TASK
PURGE
UDX_FENCED_PROCESSES
Provides information about processes HP Vertica uses to run user-defined extensions in fenced
mode.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
PROCESS_TYPE
VARCHAR
Indicates what kind of side process this row is for and can be
one of the following values:
l
SESSION_ID
VARCHAR
LANGUAGE
VARCHAR
MAX_MEMORY_JAVA_KB
INT
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
PID
INTEGER
PORT
VARCHAR
For HP Vertica internal use. The TCP port that the side
process is listening on.
STATUS
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
Example
=> select * from udx_fenced_processes;
node_name
|
process_type
| session_id | language | max_memory_java_kb |
pid | port | status
--------------------+------------------+------------+----------+--------------------+------+-------+-------v_pulsedb_node0002 | UDxZygoteProcess |
|
|
139999290851360 |
10846 | 36539 | UP
(1 row)
USER_LIBRARIES
Lists the user libraries that are currently loaded. These libraries contain User Defined Extensions
(UDxs)that provide additional analytic functions.
Column Name
Data Type
Description
SCHEMA_NAME
VARCHAR
(8192)
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
LIB_NAME
VARCHAR
(8192)
LIB_OID
INTEGER
AUTHOR
VARCHAR
(8192)
OWNER_ID
INTEGER
LIB_FILE_NAME
VARCHAR
(8192)
MD5_SUM
SDK_VERSION
VARCHAR
The MD5 checksum of the library file, used to verify that the
(8192)
VARCHAR
(8192)
REVISION
LIB_BUILD_TAG
LIB_VERSION
VARCHAR
(8192)
library.
VARCHAR
(8192)
VARCHAR
(8192)
LIB_SDK_VERSION
VARCHAR
The version of the HP Vertica SDK intended for use with the
(8192)
SOURCE_URL
VARCHAR
(8192)
DESCRIPTION
VARCHAR
(8192)
LICENSES_REQUIRED
VARCHAR
(8192)
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
SIGNATURE
VARCHAR
(8192)
DEPENDENCIES
VARCHAR
(8192)
USER_LIBRARY_MANIFEST
Lists the user-defined fnctions contained in all of the loaded user libraries.
Column
Name
Data Type
Description
SCHEMA_NAME
VARCHAR
LIB_NAME
VARCHAR
LIB_OID
INTEGER
OBJ_NAME
VARCHAR
OBJ_TYPE
VARCHAR
ARG_TYPES
VARCHAR
RETURN_TYPE
VARCHAR
USER_SESSIONS
Returns user session history on the system.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
USER_NAME
VARCHAR
SESSION_ID
VARCHAR
TRANSACTION_ID
VARCHAR
STATEMENT_ID
VARCHAR
RUNTIME_PRIORITY
VARCHAR
HIGH
MEDIUM
LOW
SESSION_END_TIMESTAMP
IS_ACTIVE
BOOLEAN
CLIENT_HOSTNAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
CLIENT_PID
INTEGER
CLIENT_LABEL
VARCHAR
SSL_STATE
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
AUTHENTICATION_METHOD
VARCHAR
Unknown
Trust
Reject
Kerberos
Password
MD5
LDAP
Kerberos-GSS
Ident
VARCHAR
ADO.NET Driver
ODBC Driver
JDBC Driver
vsql
CLIENT_VERSION
VARCHAR
CLIENT_OS
VARCHAR
Permissions
No explicit permissions are required; however, users see only the records that correspond to tables
they have permissions to view.
SQLReference Manual
HP Vertica System Tables
Example
=> SELECT * FROM USER_SESSIONS;
...
-[ RECORD 2 ]-----------+---------------------------------node_name
| v_vmart_node0001
user_name
| dbadmin
session_id
| 000000.verticacorp.-30972:0x15
transaction_id
|
statement_id
|
runtime_priority
|
session_start_timestamp | 2012-12-10 06:22:39.539826-05
session_end_timestamp
| 2012-12-10 06:22:39.844873-05
is_active
| f
client_hostname
| 10.20.100.62:41307
client_pid
| 31517
client_label
|
ssl_state
| None
authentication_method
| Password
client_type
| vsql
client_version
| 07.00.0000
client_os
| Linux 2.6.18-308.el5 x86_64
See Also
l
CURRENT_SESSION
SESSION_PROFILES
SESSIONS
SYSTEM_SESSIONS
WOS_CONTAINER_STORAGE
Monitors information about WOS storage, which is divided into regions. Each region allocates
blocks of a specific size to store rows.
Column Name
Data Type
Description
NODE_NAME
VARCHAR
SQLReference Manual
HP Vertica System Tables
Column Name
Data Type
Description
WOS_TYPE
VARCHAR
WOS_ALLOCATION_REGION
VARCHAR
REGION_VIRTUAL_SIZE_KB
INTEGER
REGION_ALLOCATED_SIZE_KB
INTEGER
REGION_IN_USE_SIZE_KB
INTEGER
REGION_SMALL_RELEASE_COUNT
INTEGER
REGION_BIG_RELEASE_COUNT
INTEGER
EXTRA_RESERVED_BYTES
INTEGER
EXTRA_USED_BYTES
INTEGER
Notes
l
The WOS allocator can use large amounts of virtual memory without assigning physical
memory.
To see the difference between virtual size and allocated size, look at the REGION_IN_USE_SIZE
column to see if the WOS is full. The summary line tells you the amount of memory used by the
WOS, which is typically capped at one quarter of physical memory per node.
Examples
=>\pset expanded
SQLReference Manual
HP Vertica System Tables
SQLReference Manual
HP Vertica System Tables
wos_type
| system
wos_allocation_region
| 16 KB Region
region_virtual_size_kb
| 1024
region_allocated_size_kb
| 960
region_in_use_size_kb
| 0
region_small_release_count | 38
region_big_release_count
| 2
-[ RECORD 8 ]--------------+--------------------------node_name
| host02
wos_type
| system
wos_allocation_region
| 64 KB Region
region_virtual_size_kb
| 1024
region_allocated_size_kb
| 64
region_in_use_size_kb
| 0
region_small_release_count | 10
region_big_release_count
| 0
-[ RECORD 9 ]--------------+--------------------------...
SQLReference Manual
Appendix: Compatibility with Other RDBMS
SQLReference Manual
Appendix: Compatibility with Other RDBMS
Oracle
NUMBER
(no explicit
precision)
HP
Vertica
Notes
INT,
In Oracle, the NUMBER data type with no explicit precision stores
NUMERIC or each number N as an integer M, together with a scale S. The scale
FLOAT
can range from -84 to 127, while the precision of M is limited to 38
digits. So N = M * 10^S.
When precision is specified, precision/scale applies to all entries in
the column. If omitted, the scale defaults to 0.
For the common case where Oracles NUMBER with no explicit
precision data type is used to store only integer values, INT is the best
suited and the fastest HP Vertica data type. However, INT (the same
as BIGINT) is limited to a little less than 19 digits, with a scale of 0; if
the Oracle column contains integer values outside of the range [9223372036854775807, +9223372036854775807], use the HP
Vertica data type NUMERIC(p,0) where p is the maximum number of
digits required to represent the values of N.
Even though no explicit scale is specified for an Oracle NUMBER
column, Oracle allows non-integer values, each with its own scale. If
the data stored in the column is approximate, HP Vertica recommends
using the HP Vertica data type FLOAT, which is standard IEEE
floating point, like ORACLE BINARY_DOUBLE. If the data is exact
with fractional places, for example dollar amounts, HP Vertica
recommends NUMERIC(p,s) where p is the precision (total number of
digits) and s is the maximum scale (number of decimal places).
HP Vertica conforms to standard SQL, which requires that p >= s and
s >= 0. HP Vertica's NUMERIC data type is most effective for p=18,
and increasingly expensive for p=37, 58, 67, etc., where p <= 1024.
HP Vertica recommends against using the data type NUMERIC(38,s)
as a default "failsafe" mapping to guarantee no loss of precision.
NUMERIC(18,s) is better, and INT or FLOAT are better yet, if one of
these data types will do the job.
NUMBER
(P,0),
P <= 18
INT
SQLReference Manual
Appendix: Compatibility with Other RDBMS
Oracle
HP
Vertica
NUMBER
(P,0),
NUMERIC
(p,0)
P > 18
Notes
An Oracle column precision greater than 18 is often more than an
application really needs.
If all values in the Oracle column are within the INT range
[-9223372036854775807,+9223372036854775807], use INT for best
performance. Otherwise, use the HP Vertica data type NUMERIC(p,
0), where p = P.
NUMBER
(P,S)
NUMERIC
(p,s)
all cases
or FLOAT
When P >= S and S >= 0, use p = P and s = S, unless the data allows
reducing P or using FLOAT as discussed above.
If S > P, use p = S, s = S. If S < 0, use p = P S, s = 0.
other than
previous 3
rows
NUMERIC
(P,S)
See notes
DECIMAL
(P,S)
See notes
-->
type.
BINARY_
FLOAT
FLOAT
BINARY_
DOUBLE
FLOAT
RAW
-->
CHAR(n)
CHAR(n)
SQLReference Manual
Appendix: Compatibility with Other RDBMS
Oracle
HP
Vertica
NCHAR(n)
Notes
VARCHAR
(n)
NVARCHAR2 VARCHAR
(n)
(n*3)
DATE
TIMESTAMP Oracles DATE is different from the SQL standard DATE data type
or
implemented by HP Vertica. Oracles DATE includes the time (no
possibly
DATE
INTERVAL
YEAR
TO MONTH
TO MONTH
INTERVAL
DAY
INTERVAL
DAY
TO SECOND TO SECOND
SQLReference Manual
Appendix: Compatibility with Other RDBMS
Oracle
CLOB,
BLOB
HP
Vertica
Notes
LONG
You can store a CLOB (character large object) or BLOB (binary large
VARCHAR, object) value in a table or in an external location. The maximum size of
LONG
a CLOB or BLOB is 128 TB.
VARBINARY
You can store HP Vertica LONG data types only in LONG VARCHAR
and LONG VARBINARY columns. The maximum size of the LONG
data types is 32,000,000 bytes.
LONG,
LONG RAW
LONG
Oracle recommends using CLOB and BLOB data types instead of
VARCHAR, LONG and LONG RAW data types.
LONG
VARBINARY In Oracle, a table can contain only one LONG column, The maximum
size of a LONG or LONG RAW data type is 2 GB.
SQLReference Manual
Appendix: Compatibility with Other RDBMS