Reference
SQL API

SQL API reference

SQL API supports the following commands as well as functions and operators.

If you'd like to propose a function or an operator to be implemented by the SQL API, check the existing issues on GitHub (opens in a new tab). If there are no relevant issues, please file a new one (opens in a new tab).

SQL commands

SELECT

Synopsis:

SELECT select_expr [, ...]
  FROM from_item
    CROSS JOIN join_item
    ON join_criteria]*
  [ WHERE where_condition ]
  [ GROUP BY grouping_expression ]
  [ HAVING having_expression ]
  [ LIMIT number ] [ OFFSET number ];

SELECT retrieves rows from a cube.

The FROM clause specifies one or more source cube tables for the SELECT. Qualification conditions can be added (via WHERE) to restrict the returned rows to a small subset of the original dataset.

Example:

SELECT COUNT(*), orders.status, users.city
FROM orders
  CROSS JOIN users
WHERE city IN ('San Francisco', 'Los Angeles')
GROUP BY orders.status, users.city
HAVING status = 'shipped'
LIMIT 1 OFFSET 1;

EXPLAIN

Synopsis:

EXPLAIN [ ANALYZE ] statement

The EXPLAIN command displays the query execution plan that the Cube planner will generate for the supplied statement.

The ANALYZE will execute statement and display actual runtime statistics, including the total elapsed time expended within each plan node and the total number of rows it actually returned.

Example:

EXPLAIN WITH cte AS (
  SELECT o.count as count, p.name as product_name, p.description as product_description
  FROM orders o
    CROSS JOIN products p
)
SELECT COUNT(*) FROM cte;
   plan_type   |                                plan
---------------+---------------------------------------------------------------------
 logical_plan  | Projection: #COUNT(UInt8(1))                                       +
               |   Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1))]]                +
               |     CubeScan: request={                                            +
               |   "measures": [                                                    +
               |     "orders.count"                                                 +
               |   ],                                                               +
               |   "dimensions": [                                                  +
               |     "products.name",                                               +
               |     "products.description"                                         +
               |   ],                                                               +
               |   "segments": []                                                   +
               | }
 physical_plan | ProjectionExec: expr=[COUNT(UInt8(1))@0 as COUNT(UInt8(1))]        +
               |   HashAggregateExec: mode=Final, gby=[], aggr=[COUNT(UInt8(1))]    +
               |     HashAggregateExec: mode=Partial, gby=[], aggr=[COUNT(UInt8(1))]+
               |       CubeScanExecutionPlan                                        +
               |
(2 rows)

With ANALYZE:

EXPLAIN ANALYZE WITH cte AS (
  SELECT o.count as count, p.name as product_name, p.description as product_description
  FROM orders o
    CROSS JOIN products p
)
SELECT COUNT(*) FROM cte;
     plan_type     |                                                                                plan
-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Plan with Metrics | ProjectionExec: expr=[COUNT(UInt8(1))@0 as COUNT(UInt8(1))], metrics=[output_rows=1, elapsed_compute=541ns, spill_count=0, spilled_bytes=0, mem_used=0]           +
                   |   HashAggregateExec: mode=Final, gby=[], aggr=[COUNT(UInt8(1))], metrics=[output_rows=1, elapsed_compute=6.583Β΅s, spill_count=0, spilled_bytes=0, mem_used=0]     +
                   |     HashAggregateExec: mode=Partial, gby=[], aggr=[COUNT(UInt8(1))], metrics=[output_rows=1, elapsed_compute=13.958Β΅s, spill_count=0, spilled_bytes=0, mem_used=0]+
                   |       CubeScanExecutionPlan, metrics=[]                                                                                                                           +
                   |
(1 row)

SHOW

Synopsis:

SHOW name
SHOW ALL

Returns the value of a runtime parameter using name, or all runtime parameters if ALL is specified.

Example:

SHOW timezone;
 setting
---------
 GMT
(1 row)
 
SHOW ALL;
            name             |    setting     | description
-----------------------------+----------------+-------------
 max_index_keys              | 32             |
 max_allowed_packet          | 67108864       |
 timezone                    | GMT            |
 client_min_messages         | NOTICE         |
 standard_conforming_strings | on             |
 extra_float_digits          | 1              |
 transaction_isolation       | read committed |
 application_name            | NULL           |
 lc_collate                  | en_US.utf8     |
(9 rows)

SQL functions and operators

SQL API currently implements a subset of functions and operators supported by PostgreSQL (opens in a new tab).

Comparison operators

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
<Returns TRUE if the first value is less than the secondβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
>Returns TRUE if the first value is greater than the secondβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
<=Returns TRUE if the first value is less than or equal to the secondβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
>=Returns TRUE if the first value is greater than or equal to the secondβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
=Returns TRUE if the first value is equal to the secondβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
<> or !=Returns TRUE if the first value is not equal to the secondβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)

Comparison predicates

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
BETWEENReturns TRUE if the first value is between the second and the third❌ Noβœ… Outer
βœ… Inner (selections)
❌ Inner (projections)
IS NULLTest whether value is NULLβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
IS NOT NULLTest whether value is not NULLβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)

Mathematical functions

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
ABSAbsolute valueβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
CEILNearest integer greater than or equal to argumentβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
DEGREESConverts radians to degreesβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
EXPExponential (e raised to the given power)βœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
FLOORNearest integer less than or equal to argumentβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
LNNatural logarithmβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
LOGBase 10 logarithmβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
LOG10Base 10 logarithm (same as LOG)βœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
PIApproximate value of Ο€βœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
POWERa raised to the power of bβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
RADIANSConverts degrees to radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
ROUNDRounds v to s decimal placesβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
SIGNSign of the argument (-1, 0, or +1)βœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
SQRTSquare rootβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
TRUNCTruncates to integer (towards zero)βœ… Yesβœ… Outer
βœ… Inner (selections)
❌ Inner (projections)

Trigonometric functions

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
ACOSInverse cosine, result in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
ASINInverse sine, result in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
ATANInverse tangent, result in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
ATAN2Inverse tangent of y/x, result in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
COSCosine, argument in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
COTCotangent, argument in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
SINSine, argument in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
TANTangent, argument in radiansβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)

String functions and operators

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
||Concatenates two stringsβœ… Yesβœ… Outer
βœ… Inner (selections)
❌ Inner (projections)
BTRIMRemoves the longest string containing only characters in characters from the start and end of stringβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
BIT_LENGTHReturns number of bits in the string (8 times the OCTET_LENGTH)βœ… Yesβœ… Outer
❌ Inner (selections)
❌ Inner (projections)
CHAR_LENGTH or CHARACTER_LENGTHReturns number of characters in the stringβœ… Yesβœ… Outer
❌ Inner (selections)
❌ Inner (projections)
LOWERConverts the string to all lower caseβœ… Yesβœ… Outer
βœ… Inner (selections)
❌ Inner (projections)
LTRIMRemoves the longest string containing only characters in characters from the start of stringβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
OCTET_LENGTHReturns number of bytes in the stringβœ… Yesβœ… Outer
❌ Inner (selections)
❌ Inner (projections)
POSITIONReturns first starting index of the specified substring within string, or zero if it's not presentβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
RTRIMRemoves the longest string containing only characters in characters from the end of stringβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
SUBSTRINGExtracts the substring of stringβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
TRIMRemoves the longest string containing only characters in characters from the start, end, or both ends of stringβœ… Yesβœ… Outer
❌ Inner (selections)
❌ Inner (projections)
UPPERConverts the string to all upper caseβœ… Yesβœ… Outer
❌ Inner (selections)
❌ Inner (projections)

Other string functions

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
ASCIIReturns the numeric code of the first character of the argumentβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
CONCATConcatenates the text representations of all the argumentsβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
LEFTReturns first n characters in the string, or when n is negative, returns all but last ABS(n) charactersβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
REPEATRepeats string the specified number of timesβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
REPLACEReplaces all occurrences in string of substring from with substring toβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
RIGHTReturns last n characters in the string, or when n is negative, returns all but first ABS(n) charactersβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
STARTS_WITHReturns TRUE if string starts with prefixβœ… Yesβœ… Outer
βœ… Inner (selections)
❌ Inner (projections)

Pattern matching

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
LIKEReturns TRUE if the string matches the supplied patternβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
REGEXP_SUBSTRReturns the substring that matches a POSIX regular expression patternβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)

Data type formatting functions

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
TO_CHARConverts a timestamp to string according to the given formatβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)

Date/time functions

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
DATE_ADDAdd an interval to a timestamp with time zoneβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
DATE_TRUNCTruncate a timestamp to specified precisionβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
DATEDIFFFrom Redshift (opens in a new tab). Returns the difference between the date parts of two date or time expressionsβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
EXTRACTRetrieves subfields such as year or hour from date/time valuesβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
LOCALTIMESTAMPReturns the current date and time without time zoneβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
NOWReturns the current date and time with time zoneβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)

Conditional expressions

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

Function, expressionDescriptionPushdownPost-processing
CASEGeneric conditional expressionβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
COALESCEReturns the first of its arguments that is not NULLβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
NULLIFReturns NULL if both arguments are equal, otherwise returns the first argumentβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
GREATESTSelect the largest value from a list of expressionsβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)
LEASTSelect the smallest value from a list of expressionsβœ… Yesβœ… Outer
❌ Inner (selections)
βœ… Inner (projections)

General-purpose aggregate functions

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
AVGComputes the average (arithmetic mean) of all the non-NULL input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
COUNTComputes the number of input rows in which the input value is not NULLβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
COUNT(DISTINCT)Computes the number of input rows containing unique input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
MAXComputes the maximum of the non-NULL input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
MINComputes the minimum of the non-NULL input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
SUMComputes the sum of the non-NULL input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
MEASUREWorks with measures of any typeβœ… Yes❌ Outer
βœ… Inner (selections)
βœ… Inner (projections)

In projections in inner parts of post-processing queries:

  • AVG, COUNT, MAX, MIN, and SUM can only be used with measures of compatible types.
  • If COUNT(*) is specified, Cube will query the first measure of type count of the relevant cube.

Aggregate functions for statistics

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
COVAR_POPComputes the population covarianceβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
COVAR_SAMPComputes the sample covarianceβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
STDDEV_POPComputes the population standard deviation of the input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
STDDEV_SAMPComputes the sample standard deviation of the input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
VAR_POPComputes the population variance of the input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
VAR_SAMPComputes the sample variance of the input valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)

Row and array comparisons

You can learn more in the relevant section (opens in a new tab) of the PostgreSQL documentation.

FunctionDescriptionPushdownPost-processing
INReturns TRUE if a left-side value matches any of right-side valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)
NOT INReturns TRUE if a left-side value matches none of right-side valuesβœ… Yesβœ… Outer
βœ… Inner (selections)
βœ… Inner (projections)