SELECT

Returns a result set from one or more data sources—tables, views, joined tables, and named subqueries.

Syntax

[ AT epoch ] SELECT [ /*+ LABEL(label‑name)*/ ] [ ALL | DISTINCT ] 
... { * | expression [ [AS] output-name] }[,…]
... [ into-table-clause ]
... [ from-clause ]
... [ where‑clause ]
... [ time‑series‑clause ]
... [ group‑by‑clause[,…] ]
... [ having-clause[,…] ]
... [ match-clause ]
... [ UNION { ALL | DISTINCT } ]
... [ except‑clause ]
... [ intersect‑clause ]
... [ ORDER BY expression { ASC | DESC }[,…] ]
... [ LIMIT { count | ALL } ]
... [ OFFSET start‑row ]
... [ FOR UPDATE [ OF table-name[,…] ] ]

Parameters

SELECT clauses such as INTO and WHERE are discussed in sub-sections of this page.

AT epoch

Returns data from the specified epoch, where epoch is one of the following:

  • EPOCH LATEST: Return data up to but not including the current epoch. The result set includes data from the latest committed DML transaction.
  • EPOCH integer: Return data up to and including the integer-specified epoch.
  • TIME 'timestamp': Return data from the timestamp-specified epoch.

These options are ignored if used to query temporary or external tables.

For details, see Historical Queries.

/*+LABEL(label‑name)*/

Assigns a label to a query so you can identify it for profiling and debugging.

In a UNION statement, only the first SELECT statement can be labeled; Vertica ignores labels in subsequent SELECT statements.

ALL | DISTINCT
  • ALL (default): Retains duplicate rows in result set or group.
  • DISTINCT: Removes duplicate rows from the result set or group.

The ALL or DISTINCT qualifier must immediately follow the SELECT keyword. Only one instance of this keyword can appear in the select list.

*

Lists all columns in the queried tables.

Selecting all columns from the queried tables can produce a very large wide set, which can adversely affect performance.

expression

Forms the output rows of the SELECT statement. The expression can contain:

expression
[[AS] output‑name]

A table column or column expression to select from the queried tables. You can optionally qualify expression
with an output name, which can be used in several ways:

  • Label the column for display.
  • Refer to the column's value in ORDER BY and GROUP BY clauses (it cannot be referenced in WHERE or HAVING clauses).
from-clause

A comma-separated list of data sources to query.

FOR UPDATE

Specifies to obtain an X lock on all tables specified in the query, most often used from READ COMMITTED isolation.

FOR UPDATE requires update/delete permissions on the queried tables and cannot be issued from a read-only transaction.

Privileges

Non-superusers:

  • USAGE on the schema
  • SELECT on the table or view

Example

When multiple clients run transactions as 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;