Skip to main content
Version: 2.x

SQL Language

This document introduces the foundational elements of SQL as used in Apache Cloudberry. Understanding these elements is essential when defining queries, as they form the building blocks of query statements.

SQL lexicon

SQL is a standard language for accessing databases. The language consists of elements that enable data storage, retrieval, analysis, viewing, manipulation, and so on. You use SQL commands to construct queries and commands that the Apache Cloudberry engine understands. SQL queries consist of a sequence of commands. Commands consist of a sequence of valid tokens in correct syntax order, terminated by a semicolon (;).

Apache Cloudberry uses PostgreSQL's structure and syntax, with some exceptions. For more information about SQL rules and concepts in PostgreSQL, see "SQL Syntax" in the PostgreSQL documentation.

SQL value expressions

SQL value expressions consist of one or more values, symbols, operators, SQL functions, and data. The expressions compare data or perform calculations and return a value as the result. Calculations include logical, arithmetic, and set operations.

The following are value expressions:

  • An aggregate expression
  • An array constructor
  • A column reference
  • A constant or literal value
  • A correlated subquery
  • A field selection expression
  • A function call
  • A new column value in an INSERTor UPDATE
  • An operator invocation column reference
  • A positional parameter reference, in the body of a function definition or prepared statement
  • A row constructor
  • A scalar subquery
  • A search condition in a WHERE clause
  • A target list of a SELECT command
  • A type cast
  • A value expression in parentheses, useful to group sub-expressions and override precedence
  • A window expression

SQL constructs such as functions and operators are expressions but do not follow any general syntax rules. For more information about these constructs, see Using Functions and Operators.