Retrieves a result set from one or more tables.
[ AT EPOCH LATEST ] | [ AT TIME 'timestamp' ]
SELECT * | [ ALL | DISTINCT ] expression [ [ AS ] output_name ] [, ...]
[ FROM clause ]
Specifies one or more source tables from which to retrieve rows.
Syntax
FROM table-reference [ ,
table-reference ] ...
Syntax
Syntax
table-reference join-type table-reference
Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information.
Syntax
column-reference
=
column-reference
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Semantics
column-reference |
refers to a column of one the tables specified in the FROM clause. |
Notes
Semantics
table-reference |
is a table-primary or another joined-table. |
join-type |
is one of the following: INNER JOIN LEFT [ OUTER ] JOIN RIGHT [ OUTER ] JOIN |
join-predicate |
for an INNER JOIN, an equi-join based on a PRIMARY KEY-FOREIGN KEY constraint relationship between the joined tables. for an OUTER JOIN: an equi-join based on a PRIMARY KEY-join key relationship between the joined tables that does not involve a FOREIGN KEY constraint. |
Notes
Note to reviewers: "anchor table" may not be the right term. See note in Outer Joins.
Syntax
{ table-name [ AS ] alias
[ ( column-alias [ , ...] ) ] [ , ...] ]
| ( joined-table ) }
Syntax
table-reference join-type table-reference
Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information.
Syntax
column-reference
=
column-reference
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Semantics
column-reference |
refers to a column of one the tables specified in the FROM clause. |
Notes
Semantics
table-reference |
is a table-primary or another joined-table. |
join-type |
is one of the following: INNER JOIN LEFT [ OUTER ] JOIN RIGHT [ OUTER ] JOIN |
join-predicate |
for an INNER JOIN, an equi-join based on a PRIMARY KEY-FOREIGN KEY constraint relationship between the joined tables. for an OUTER JOIN: an equi-join based on a PRIMARY KEY-join key relationship between the joined tables that does not involve a FOREIGN KEY constraint. |
Notes
Note to reviewers: "anchor table" may not be the right term. See note in Outer Joins.
Semantics
table-name |
specifies a table in the logical schema. Vertica selects a suitable projection to use. |
alias |
specifies a temporary name to be used for references to the table. |
column-alias |
specifies a temporary name to be used for references to the column. |
joined-table |
specifies an outer join. |
Semantics
table-primary |
specifies an optionally qualified table name with optional table aliases, column aliases, and outer joins. |
joined-table |
specifies an outer join. |
Syntax
Syntax
table-reference join-type table-reference
Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information.
Syntax
column-reference
=
column-reference
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Semantics
column-reference |
refers to a column of one the tables specified in the FROM clause. |
Notes
Semantics
table-reference |
is a table-primary or another joined-table. |
join-type |
is one of the following: INNER JOIN LEFT [ OUTER ] JOIN RIGHT [ OUTER ] JOIN |
join-predicate |
for an INNER JOIN, an equi-join based on a PRIMARY KEY-FOREIGN KEY constraint relationship between the joined tables. for an OUTER JOIN: an equi-join based on a PRIMARY KEY-join key relationship between the joined tables that does not involve a FOREIGN KEY constraint. |
Notes
Note to reviewers: "anchor table" may not be the right term. See note in Outer Joins.
Syntax
{ table-name [ AS ] alias
[ ( column-alias [ , ...] ) ] [ , ...] ]
| ( joined-table ) }
Syntax
table-reference join-type table-reference
Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information.
Syntax
column-reference
=
column-reference
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Semantics
column-reference |
refers to a column of one the tables specified in the FROM clause. |
Notes
Semantics
table-reference |
is a table-primary or another joined-table. |
join-type |
is one of the following: INNER JOIN LEFT [ OUTER ] JOIN RIGHT [ OUTER ] JOIN |
join-predicate |
for an INNER JOIN, an equi-join based on a PRIMARY KEY-FOREIGN KEY constraint relationship between the joined tables. for an OUTER JOIN: an equi-join based on a PRIMARY KEY-join key relationship between the joined tables that does not involve a FOREIGN KEY constraint. |
Notes
Note to reviewers: "anchor table" may not be the right term. See note in Outer Joins.
Semantics
table-name |
specifies a table in the logical schema. Vertica selects a suitable projection to use. |
alias |
specifies a temporary name to be used for references to the table. |
column-alias |
specifies a temporary name to be used for references to the column. |
joined-table |
specifies an outer join. |
Semantics
table-primary |
specifies an optionally qualified table name with optional table aliases, column aliases, and outer joins. |
joined-table |
specifies an outer join. |
Semantics
table-reference |
is a Syntax table-reference join-type table-reference Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information. Syntax
Syntax [ tablename. ] columnname Semantics
Notes
Syntax [ tablename. ] columnname Semantics
Notes
Semantics
Notes
Semantics
Notes
Syntax { table-name [ AS ] alias [ ( column-alias [ , ...] ) ] [ , ...] ] | ( Syntax table-reference join-type table-reference Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information. Syntax
Syntax [ tablename. ] columnname Semantics
Notes
Syntax [ tablename. ] columnname Semantics
Notes
Semantics
Notes
Semantics
Notes
Semantics
|
Notes
Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information.
Syntax
column-reference
=
column-reference
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Semantics
column-reference |
refers to a column of one the tables specified in the FROM clause. |
Notes
[ WHERE clause ]
Eliminates rows from the result table that do not satisfy one or more predicates.
Syntax
WHERE boolean-expression
Semantics
boolean-expression |
is an expression that returns true or false. Only rows for which the expression is true become part of the result set. |
The boolean-expression can include Boolean operators and the following elements:
Syntax
[ AND | OR | NOT ]
Semantics
SQL uses a three-valued Boolean logic where the null value represents "unknown."
a |
b |
a AND b |
a OR b |
TRUE |
TRUE |
TRUE |
TRUE |
TRUE |
FALSE |
FALSE |
TRUE |
TRUE |
NULL |
NULL |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
NULL |
FALSE |
NULL |
NULL |
NULL |
NULL |
NULL |
a |
NOT a |
TRUE |
FALSE |
FALSE |
TRUE |
NULL |
NULL |
Notes
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.The special BETWEEN
predicate is available as a convenience.
Syntax
a BETWEEN x AND y
Semantics
a BETWEEN x AND y is equivalent to
a >= x AND a <= y
Similarly,
a NOT BETWEEN x AND y
is equivalent to
a < x OR a > y
The 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
Semantics
A Boolean predicate always return true or false, never a null value, even when the operand is null. A null input is treated as the value UNKNOWN.
Notes
Syntax
[ AND | OR | NOT ]
Semantics
SQL uses a three-valued Boolean logic where the null value represents "unknown."
a |
b |
a AND b |
a OR b |
TRUE |
TRUE |
TRUE |
TRUE |
TRUE |
FALSE |
FALSE |
TRUE |
TRUE |
NULL |
NULL |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
NULL |
FALSE |
NULL |
NULL |
NULL |
NULL |
NULL |
a |
NOT a |
TRUE |
FALSE |
FALSE |
TRUE |
NULL |
NULL |
Notes
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.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.Syntax
column-name comparison-op constant-expression
Semantics
column-name |
is a single column of one the tables specified in the FROM clause. |
||||||||||||
comparison-op |
is one of the 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. Syntax and Semantics
Notes The != operator is converted to <> in the parser stage. It is not possible to implement != and <> operators that do different things.
|
||||||||||||
constant-expression |
is a constant value of the same data type as the column-name |
Notes
Examples
Dimension.column1 = 2
Dimension.column2 = 'Seafood'
Syntax
column-expression [ NOT ] IN (
list-expression )
Semantics
column-expression |
is a single column of one the tables specified in the FROM clause. |
list-expression |
is a comma-separated list of constant values matching the data type of the column-expression |
Examples
x IN (5, 6, 7) |
|
x in (select a from table) |
not allowed |
(x, y) in ((5,6), (7,8)) |
not allowed |
Vertica supports only equi-joins based on a primary key-foreign key relationship between the joined tables. See Adding Primary Key and Foreign Key Constraints in the Database Administrator's Guide for more information.
Syntax
column-reference
=
column-reference
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Syntax
[ tablename. ] columnname
Semantics
tablename |
is one of:
|
columnname |
is the name of a column that must be unique across all the tables being used in a query |
Notes
Semantics
column-reference |
refers to a column of one the tables specified in the FROM clause. |
Notes
The LIKE predicate retrieves rows where the string value of a column matches a specified pattern. The pattern can contain one or more wildcard characters, which match all valid characters. ILIKE is equivalent to LIKE except that the match is case-insensitive (non-standard extension).
Syntax
string { LIKE | ILIKE } pattern [ESCAPE escape-character]
string NOT { LIKE | ILIKE } pattern [ESCAPE escape-character]
Semantics
string |
(CHAR or VARCHAR) is the column value to be compared to the pattern. |
NOT |
returns true if LIKE returns false, and vice versa (equivalent to |
pattern |
specifies a string containing wildcard characters.
|
ESCAPE |
specifies an escape-character. A null escape character ('') disables the escape mechanism. To match the escape character itself, use two consecutive escape characters. |
escape-character |
when preceding an underscore or percent sign character in the pattern, causes that character to be treated as a literal rather than a wildcard. The default escape character is the backslash (/) character. |
Notes
~~ |
LIKE |
~~* |
ILIKE |
!~~ |
NOT LIKE |
!~~* |
NOT ILIKE |
Examples
'abc' LIKE 'abc' true
'abc' LIKE 'a%' true
'abc' LIKE '_b_' true
'abc' LIKE 'c' false
Syntax
column-name IS [ NOT ] NULL
Semantics
column-name |
is a single column of one the tables specified in the FROM clause. |
Examples
a IS NULL |
b IS NOT NULL |
See Also
Notes
WHERE NOT (A=1 AND B=2) OR C=3;
[ GROUP BY clause ]
GROUP BY divides a query result set into groups of rows that match an expression.
Syntax
GROUP BY expression [ ,... ]
Semantics
expression |
is any expression including constants and Syntax [ tablename. ] columnname Semantics
Notes
|
Notes
Examples
SELECT C1, C2
FROM T1
GROUP BY C1, C2;
SELECT C1, AVG(C2)
FROM T1
GROUP BY C1;
SELECT x+y, SUM(z)
FROM foo
GROUP BY x+y;
SELECT x+y, y+z, COUNT(*)
FROM foo
GROUP BY x+y, y+z;
SELECT RTRIM(a) || LTRIM(b), AVG(c), COUNT(c)
FROM foo
GROUP BY RTRIM(a) || LTRIM(b);
Invalid Examples
SELECT C1, C2
FROM T1
GROUP BY C1;
[ HAVING clause ]
Eliminates group rows that do not satisfy a predicate.
Syntax
HAVING predicate [, ...]
Semantics
predicate |
is the same as specified for the WHERE clause. |
Notes
[ ORDER BY clause ]
Sorts a query result set on one or more columns.
Syntax
ORDER BY expression [ ASC | DESC ] [, ...]
Semantics
expression |
can be:
|
Notes
Special characters collate in between and after the groups mentioned. See man ascii
for details.
[ LIMIT clause ]
Specifies the maximum number of result set rows to return.
Syntax
LIMIT { rows | ALL }
Semantics
rows |
specifies the maximum number of rows to return |
ALL |
returns all rows (same as omitting LIMIT) |
Notes
C1 |
C2 |
1 |
2 |
2 |
1 |
1 |
1 |
2 |
2 |
SELECT *
FROM T
ORDER BY C1
LIMIT 3;
The last row of the result set in this example is undefined in any SQL database but may be consistent enough in other databases for poorly-coded application programs or reports to get the same result set every time. In Vertica however, the distributed nature of the database makes the last row unpredictable, which may cause poorly-coded application programs or reports to get different a result set each time.
[ OFFSET clause ]
Omits a specified number of rows from the beginning of the result set.
Syntax
OFFSET rows
Semantics
rows |
specifies the number of result set rows to omit. |
Notes
Semantics
AT EPOCH LATEST
|
queries all data in the database up to but not including the current An epoch represents committed changes to the data stored in a database between two specific points in time. In other words, an epoch contains all COPY, INSERT, UPDATE, and DELETE operations that have been executed and committed since the end of the previous epoch. By default, queries execute under the SERIALIZABLE isolation level, which holds locks and blocks write operations. For optimal query performance, use AT EPOCH LATEST. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AT TIME 'timestamp' |
queries all data in the database up to and including the epoch representing the specified date and time without holding a lock or blocking write operations. This is called an Vertica can execute a query from a snapshot of the database taken at a specific date and time. The syntax is: AT TIME 'timestamp' SELECT... The command queries all data in the database up to and including the An epoch represents committed changes to the data stored in a database between two specific points in time. In other words, an epoch contains all COPY, INSERT, UPDATE, and DELETE operations that have been executed and committed since the end of the previous epoch. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
is equivalent to listing all columns of the tables in the FROM Clause. Vertica recommends that you avoid using SELECT * for performance reasons. An extremely large and wide result set can cause swapping. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expression |
forms the output rows of the SELECT statement. The expression can contain:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
output_name |
specifies a different name for an output column. This name is primarily used to label the column for display. It can also be used to refer to the column's value in ORDER BY and GROUP BY clauses, but not in the WHERE or HAVING clauses. |
Notes
SQL Language References
PostgreSQL 8.0.12 Documentation
In This Section |