0% found this document useful (0 votes)
4 views

SQream SQL Reference Guide Ver 1-9-2

The SQream SQL Reference Guide for version 1.9.2 provides comprehensive information on SQL commands, including data definition, manipulation languages, and queries. It details the syntax and usage of various commands such as CREATE, DROP, and ALTER for databases, users, schemas, tables, and views. Additionally, it covers data types and value expressions, making it a valuable resource for users of the SQream database system.

Uploaded by

Ismail Cansiz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SQream SQL Reference Guide Ver 1-9-2

The SQream SQL Reference Guide for version 1.9.2 provides comprehensive information on SQL commands, including data definition, manipulation languages, and queries. It details the syntax and usage of various commands such as CREATE, DROP, and ALTER for databases, users, schemas, tables, and views. Additionally, it covers data types and value expressions, making it a valuable resource for users of the SQream database system.

Uploaded by

Ismail Cansiz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

SQream SQL Reference Guide

SQream Version 1.9.2


Table of Contents
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1. SQL Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1. Data Definition Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1. Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
DROP DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2. Users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
CREATE USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DROP USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
ALTER USER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.3. Schemas. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CREATE SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
DROP SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.4. Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
ALTER TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Rename table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Rename column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Drop column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
DROP TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.1.5. Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
CREATE VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
DROP VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.1.6. DROP_PARTITION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2. Data Manipulation Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.1. INSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.2. COPY FROM (bulk import) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2.3. COPY TO (bulk export) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2.4. TRUNCATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3. Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.1. SELECT lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.2. FROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.3. WHERE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.3.4. GROUP BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.5. HAVING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.6. ORDER BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.7. VALUES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.8. Set operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.9. Query hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.4. Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.4.1. Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.4.2. Numeric types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.3. Date/time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.4. Text types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.5. Value expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.5.1. String literal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5.2. Number literal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.5.3. Typed literal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.5.4. Binary operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.5.5. Unary operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.5.6. Postfix unary operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.5.7. Special operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.5.8. EXTRACT operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.5.9. CASE expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.5.10. Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.5.11. Aggregate function app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.5.12. Window function app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.5.13. Operator precedences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.5.14. Type conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Casts in value expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Assignment resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Expression set type resolution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
1.5.15. Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Logical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
AND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Binary comparison operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
BETWEEN, NOT BETWEEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
IS NULL, IS NOT NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
IN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Mathematical functions and operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
SQRT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
ABS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
ROUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
ASIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
ATAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
ATN2 – Arctangent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
COS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
COT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
CEILING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
LOG10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
LOG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
LOG (base-y) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
FLOOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
SIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
SQUARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
TAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
PI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
POWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
TO_HEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
String functions and operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
LOWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
UPPER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LIKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
RLIKE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
SUBSTRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
REGEXP_COUNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
REGEXP_INSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
REGEXP_SUBSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
ISPREFIXOF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Concatenation (||) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
CHARINDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
PATINDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
LTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
REVERSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
RTRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Pattern matching syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Regular Expression Pattern Matching Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Date/time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Geospatial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
POINT_IN_POLYGON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
LINE_CROSSES_POLYGON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.5.16. Aggregate functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.5.17. Window functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.6. Saved queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.6.1. save_query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.6.2. execute_saved_query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.6.3. drop_saved_query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.6.4. show_saved_query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.6.5. list_saved_queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.7. SQream Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.7.1. Quering SQream Catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Overview
SQream SQL is based on a subset of ANSI SQL, with a little inspiration from well known SQL DBMSs.

1. SQL Reference
This is the reference guide for the SQL statements supported by SQream. For a conceptual overview
and recommendations on best practices regarding SQream internal behaviour, please refer to SQream
User Administrator Guide.

Note: All keywords in are case insensitive.

1.1. Data Definition Language


1.1.1. Databases

CREATE DATABASE

CREATE DATABASE will create a new database in the current database storage set. To use the new
database you can use the utility function 'use_database' or disconnect and reconnect to the new
database.

create_database_statement ::=

CREATE DATABASE database_name ;

database_name ::= identifier

A database storage set is the set of files on disk which represent a set of databases

 managed by a single running server. This is called a 'cluster' in PostgreSQL, and a


'catalog cluster' in the SQL standard.

Examples

create database my_database;

DROP DATABASE

DROP DATABASE will delete a database and all its files. Any connections open to this database will
subsequently fail.

1
drop_database_statement ::=

DROP DATABASE database_name ;

Examples

drop database my_database;

1.1.2. Users

CREATE USER

CREATE USER adds a new user to the current database.

create_user_statement ::=

CREATE USER user_name WITH PASSWORD = string_literal ;

user_name ::= identifier

create user new_user_name WITH PASSWORD='wanted_passport';

DROP USER

DROP USER deletes a user from the current database.

drop_user_statement ::=

DROP USER user_name ;

ALTER USER

ALTER USER can be used to change an existing user’s password.

alter_user_statement ::=

ALTER USER user_name WITH PASSWORD = string_literal ;

2
1.1.3. Schemas

CREATE SCHEMA

CREATE SCHEMA will create a new schema in the current database.

create_schema_statement ::=

CREATE SCHEMA schema_name ;

schema_name ::= identifier

New tables should be explicitly associated to an existing schema, or implicitly


 associated to 'PUBLIC' default schema.

Examples

create schema my_schema;

DROP SCHEMA will delete an empty schema from the database.

DROP SCHEMA

drop_schema_statement ::=

DROP SCHEMA schema_name ;

 'PUBLIC' schema can not be dropped.

Examples

drop schema my_schema;

1.1.4. Tables

CREATE TABLE

CREATE TABLE creates a new table in the current database under a specific schema.

New tables should be explicitly associated to an existing schema, or implicitly


 associated to 'public' default schema.

3
create_table_statement ::=

CREATE TABLE [schema_name].table_name (


{ column_name type_name [ column_constraint ]
[ default ] }
[, ... ]
)
[ partitioning ]
;

schema_name ::= identifier

table_name ::= identifier

column_name ::= identifier

identifier is defined below in the identifier definition section.

type_name is defined below in the type name definition section.

column_constraint ::=

{ NOT NULL | NULL }

default ::=

DEFAULT default_value

| IDENTITY [ ( start_with [ , increment_by ] ) ]

The default_value can be NULL or a literal.

The common sequence generator options can be comma or whitespace separated.

Identity columns are only supported for columns of type TINYINT, SMALLINT, INT and BIGINT.

compression_type ::=

CHECK ( 'CS "*_compression_name_*"' )

When compression is needed, SQream recommends using the default compression type with: check
('CS "default"')

4
partitioning ::=

PARTITION BY RANGE ( column_name )


( every integer timeframe )

timeframe ::=

YEAR[S] | MONTH[S] | DAY[S] | HOUR[S] | MINUTE[S] | SECOND[S] | MILLLISECOND[S]

Partitioning only supports columns with DATETIME datatype.

5
Examples

create table t (
a int identity (1,1) check ('CS "default"'),
b int
);

create table my_schema.t (


a int null,
b int not null
);

create table u (
a int default 0,
b int,
c date
);

create table u (
k int not null identity,
v varchar(10)
);

create table u (
k bigint not null identity(1,1),
v varchar(10)
);

create table t(x int not null,


y int default 0 not null)

create table calls (


calldate datetime not null,
number varchar(12) not null
)
partition by range (calldate) (every month);

ALTER TABLE

ALTER TABLE is used to alter the structure of an existing table.

Rename table

This form of alter table allows you to rename a table.

6
alter_table_statement_rename_table ::=

ALTER TABLE [schema_name].table_name RENAME TO new_table_name ;

Examples

alter table my_table rename to your_table;

Rename column

This form of alter table allows you to rename a column in an existing table.

alter_table_statement_rename_column ::=

ALTER TABLE [schema_name].table_name


RENAME COLUMN column_name TO new_column_name ;

Examples

alter table my_table rename col1 to col2;

Drop column

This form of alter table allows you to drop a column from an existing table.

alter_table_statement_rename_table ::=

ALTER TABLE [schema_name].table_name drop column column_name ;

Examples

alter table my_table drop column not_deeded_column;

DROP TABLE

DROP TABLE will delete a table and all its data.

Dropping a table without explicit schema_name, will drop the table under PUBLIC
 schema.

7
drop_table ::=

DROP TABLE [schema_name].table_name ;

Examples

drop table my_schema.my_table;

1.1.5. Views

CREATE VIEW

CREATE VIEW creates a new view in the current database.

create_view_statement ::=

CREATE VIEW [schema_name].view_name [ ( column_name [, ... ] ) ]


AS query ;

view_name ::= identifier

Examples

create view [*_schema_name_*].my_view as select * from my_schema.t where x > 5;

DROP VIEW

DROP VIEW will delete a view from the current database.

drop_view_statement ::=

DROP VIEW [schema_name].view_name ;

Examples

drop view my_schema.my_view;

1.1.6. DROP_PARTITION

DROP_PARTITION is used to delete all the rows in that partition. To see the list of existing partitions,
use the command: select list_partitions('table_name')

8
CREATE PARTITION is being done automatically by SQream while inserting data
 into a partitioned table.

drop_partition_statement ::=

SELECT drop_partition( '[schema_name].table_name' , partition_id ) ;

Examples

select drop_partition('my_table', 4);

1.2. Data Manipulation Language


This section covers updates to the data in tables. Queries are in their own section which follows this
one.

1.2.1. INSERT

INSERT is used to add rows to a table.

insert_statement ::=

INSERT INTO [schema_name].table_name


[ ( column_name [, ... ] ) ]
query ;

Examples

INSERT INTO my_schema.dst1 SELECT a,b,c from src;

INSERT INTO dst2(d1, d3) SELECT d1,d3 from src;

INSERT INTO t(cint,cint_2) VALUES(1,3);

INSERT INTO t VALUES(1,3);

When the insert statement does not include all the columns in the table, columns

 which aren’t explicitly mentioned with get their default values (string/number,
NULL or identity)

9
1.2.2. COPY FROM (bulk import)

COPY FROM is used to quickly insert CSV data into a table. It is the recommended way to insert data in
production.

copy_from_statement ::=

COPY [schema_name].table_name [ ( column_name [, ... ] ) ]


FROM 'filename'
[ WITH DELIMITER 'delimiter' ]
[PARSERS 'dt=fixed_datetime']
[ ERROR_LOG 'error_log_filename' ]
[ ERROR_VERBOSITY { 0 | 1 } ]
;

The filename read from must be a path available to the sqreamd process on the server machine.

The delimiter default is ',' and it must be a single character. You cannot set the record delimiter, it is
always '\n'.

PARSERS 'dt=fixed_datetime' will stop the parser from doing 'date' validations. Use this option only if
you certain the date/datetime columns on your CSV are in the above formats:

datetime - YYYY-MM-DD HH24:MI:SS (for example: 2015-01-01 09:05:00)

date - YYYY-MM-DD (for example: 2015-01-01)

Adding the syntax PARSERS 'dt=fixed_datetime' without caution, can damage your
 data.

Error verbosity:

0 - only the bad line is printed

1 - both bad line and error message are printed

Examples

COPY table_name from 'filename.csv'


with delimiter ','
error_log 'error.log'
error_verbosity 0;

1.2.3. COPY TO (bulk export)

COPY TO is used to save query results to disk in CSV format.

10
copy_to_statement ::=

COPY ( query ) TO 'file_name'


WITH FORMAT CSV DELIMITER 'delimiter' ;

The target path must be accessible by the sqreamd process.

1.2.4. TRUNCATE TABLE

The TRUNCATE TABLE command deletes all the rows from a table.

truncate_statement ::=

TRUNCATE TABLE [schema_name].table_name [ RESTART IDENTITY | CONTINUE IDENTITY ] ;

Using RESTART IDENTITY will reset the identity columns to their starting values. CONTINUE
IDENTITY is the default.

Examples

truncate table my_schema.t;

1.3. Queries
Queries are used to retrieve data from the current database.

11
query_term ::=

SELECT
[ TOP num_rows ]
[ DISTINCT ]
select_list
[ FROM table_ref [, ... ]
[ WHERE value_expr ]
[ GROUP BY value_expr [, ... ]
[ HAVING value_expr ]
]
]
|
VALUES ( value_expr [, ... ] ) [, ... ]

select_list ::=

value_expr [ AS column_alias ] [, ... ]

column_alias ::= identifier

table_ref ::=

table_name [ AS alias [ ( column_alias [, ... ] ) ] ]


| ( query ) [ AS alias [ ( column_alias [, ... ] ) ] ]
| table_ref [ NATURAL ] join_type table_ref
[ ON value_expr | USING ( join_column [, ... ] ) ]

alias ::= identifier

join_type ::=

[ INNER ] [ join_hint ] JOIN


| LEFT [ OUTER ] [ join_hint ] JOIN
| RIGHT [ OUTER ] [ join_hint ] JOIN
| CROSS [ join_hint ] JOIN

join_hint ::=

MERGE | LOOP

order ::=

value_expr [ ASC | DESC ] [, ...] [NULLS FIRST | LAST ]

12
1.3.1. SELECT lists

TOP is used to retrieve only the first rows from a query.

TOP will be the last operation on the query execution. This means that SQream will
 limit the results to the end-user after executing the entire statement.

DISTINCT removes duplicate rows.

Value expressions in select lists support aggregate and window functions as well as normal value
expressions (see below).

Examples

select * from t;

select 1 + a from t;

select a as b from t;

select a+b, c+d from t;

select top 10 col from tbl;

select col from tbl limit 10;

select distinct a,b from t;

1.3.2. FROM

FROM is used to specify which tables to read in a query. You can also put complete subqueries in the
from clause.

13
Examples

select * from t;

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;

SELECT *
FROM table1,table2
WHERE table1.column_name=table2.column_name;

Join hints can be used to override the query compiler and choose a particular join algorithm. The
available algorithms are LOOP (corresponding to non-indexed nested loop join algorithm), and
MERGE (corresponding to sort merge join algorithm).

SELECT *
FROM table1
INNER MERGE JOIN table2
ON table1.column_name=table2.column_name;

SELECT *
FROM table1
INNER LOOP JOIN table2
ON table1.column_name=table2.column_name;

1.3.3. WHERE

WHERE is used to filter out rows.

14
Examples

SELECT Column1
FROM table1
WHERE column2 <= 1;

1.3.4. GROUP BY

GROUP BY is used to partition a table so that aggregates can be applied separately to each partition.

Examples

select a,sum(b) from t group by a;

1.3.5. HAVING

HAVING is used to filter out rows after GROUP BY processing.

Examples

select a,sum(b) from t group by a having sum(b) > 5;

1.3.6. ORDER BY

ORDER BY is used to order the results.

Examples

select * from t order by a asc, b desc;

1.3.7. VALUES

VALUES is a way to create a 'literal table value'.

values (1,'a'), (2,'b');

1.3.8. Set operators

UNION is used to concatenate two queries together. The only UNION supported is UNION ALL, which
doesn’t remove duplicate rows.

15
Examples

select * from t
union all
select * from u;

1.3.9. Query hints

The global query hints can be used to select algorithms for reduce which implements GROUP BY
aggregates.

Examples

select count(distinct x), count(x+y)


from t group by y option(partition group);

select count(distinct x), count(x+y)


from t from t group by y option(partition group, columnar cpu group);

1.4. Data types


SQream data types to be used in CREATE TABLE and ALTER TABLE, and in value_expr.

type_name ::=

BOOL

| INT

| BIGINT

| FLOAT/DOUBLE

| REAL

| DATE

| DATETIME

| VARCHAR ( digits )

1.4.1. Boolean

Table 1. Boolean data type

16
Type Description Uncompressed size

BOOL boolean type 1 byte

Boolean literals can be written TRUE, FALSE.

Examples

create table boo (col1 bool)


insert into boo values (true)

1.4.2. Numeric types

Table 2. Numeric types

Type Description Uncompressed Minimum Maximum


size

INT signed integer 4 bytes -2,147,483,648 2,147,483,647

BIGINT signed integer 8 bytes -9,223,372,036,854, 9,223,372,036,854,7


775,808 75,807

REAL floating point 4 bytes -3.40e+38 3.40e+38


number

FLOAT floating point 8 bytes -1.79e+308 1.79e+308


number

1.4.3. Date/time

Table 3. Date/time data types

Type Description Uncompressed size Example

DATETIME Date and time, 8 bytes '2015-12-31 08:08:00.000'


January 1, 1 CE to
December 31, 9999 CE,
1 millisecond precision

DATE Date only, January 1, 1 4 bytes '2015-12-31'


CE to December 31, 9999
CE

Timezones are not supported.

1.4.4. Text types

Table 4. Text data type

17
Type Description Uncompressed size

VARCHAR( n ) character string n bytes

VARCHAR datatype is intended to ASCII character set. The maximum size of a VARCHAR is 2048.
Varchars are padded with spaces. SQream ignores the trailing whitespaces in functions, and compress
them in storage level.

The only supported character set/encoding for VARCHAR datatype is ASCII, and the
 only collation is ASCII byte order/ byte equality.

1.5. Value expressions


Value expressions are used in select lists, ON conditions, WHERE conditions, GROUP BY expressions,
HAVING conditions and ORDER BY expressions.

18
value_expr ::=

string_literal

| number_literal

| NULL | TRUE | FALSE

| typed_literal

| value_expr binary_operator value_expr

| unary_operator value_expr

| value_expr postfix_unary_operator

| special_operator

| extract_operator

| case_expression

| conditional_expression

| ( value_expr )

| identifier

| star

| function_app

| aggregate_function_app

| window_function_app

| cast_operator

1.5.1. String literal

string_literal is delimited by single quotes ('), and can contain any printable character other than
single quote. To include a single quote in a string use two quotes together.

19
Examples

'string literal'

'string literal ''with something'' quoted'

-- this produces the string "string literal 'with something' quoted"

1.5.2. Number literal

number_literal ::=

digits

| digits . [ digits ] [ e [+-] digits ]

| [ digits ] . digits [ e [+-] digits ]

| digits e [+-] digits

Examples

1234

1234.56

12.

.34

123.56e-45

1.5.3. Typed literal

typed_literal ::=

type_name string_literal

type_name is defined above in the type name definition section.

1.5.4. Binary operator

20
<strong><em>binary_operator</em></strong> ::=

. | + | ^ | * | / | % | + | - | >= | <= | != | <> | ||

| LIKE | NOT LIKE | RLIKE | NOT RLIKE | < | > | = | OR | AND

1.5.5. Unary operator

unary_operator ::=

+ | - | NOT

1.5.6. Postfix unary operator

postfix_unary_operator ::=

IS NULL | IS NOT NULL

1.5.7. Special operator

special_operator ::=

value_expr IN ( value_expr [, ... ] )

| value_expr NOT IN ( value_expr [, ... ] )

| value_expr BETWEEN value_expr AND value_expr

| value_expr NOT BETWEEN value_expr AND value_expr

Note: to use AND in the middle value_expr in a BETWEEN operator, use parentheses like this:

expr BETWEEN ( min_expr_with_and ) AND max_expr

1.5.8. EXTRACT operator

The extract operator can be used to extract parts of dates/times from date or datetime values.

21
extract_operator ::=

EXTRACT ( extract_field FROM value_expr )

extract_field ::=

YEAR

| MONTH

| DAY

| HOUR

| MINUTE

| SECOND

| MILLISECOND

| DOW

| DOY

| QUARTER

1.5.9. CASE expression

22
case_expression ::=

searched_case | simple_case

searched_case ::=

CASE WHEN value_expr THEN value_expr


[WHEN ...]
[ELSE value_expr]
END

simple_case ::=

CASE value_expr
WHEN value_expr THEN value_expr
[WHEN ...]
[ELSE value_expr]
END

searched_case works as follows:

• each WHEN value_expr is checked in order, the value of the CASE expression is the value of the
THEN value_expr then for the first WHEN branch which evaluates to true;

• if no WHEN branches evaluate to true, then the value is the value of the ELSE expression, or if
there is no ELSE, then the value is NULL.

The simple_case style is shorthand:

CASE v0
WHEN v1 THEN r1
WHEN v2 THEN r2
...
ELSE e
END

->

CASE
WHEN v0 = v1 THEN r1
WHEN v0 = v2 THEN r2
...
ELSE e
END

23
1.5.10. Identifier

identifier is

• unquoted identifier: any letter, underscore or digit, and the first character must be a letter or
underscore;

• quoted identifier: delimited by double quotes, any printable character other than double quotes. To
include a double quotes, use two double quotes next to each other.

1.5.11. Aggregate function app

aggregate_function_app ::=

agg_name ( [ value_expr [, ... ] ] )

| agg_name ( [ DISTINCT ] [ value_expr [, ... ] ] )

agg_name ::= identifier

1.5.12. Window function app

window_function_app ::=

window_fn_name ( [ value_expr [, ... ] ] )


OVER ( [ value_expr [, ... ] ]
[ PARTITION BY value_expr [, ... ] ]
[ ORDER BY value_expr [ ASC | DESC] [, ... ] ] )

window_fn_name ::= identifier

1.5.13. Operator precedences

This table lists the operators in decreasing order of precedence. We recommend using parentheses
rather than relying on precedences in anything other than trivial expressions.

Table 5. Operator precedences

Operator Associativity

. left

+ - (unary)

^ left

*/% left

24
Operator Associativity

+ - (binary) left

|| right

BETWEEN, IN, LIKE, RLIKE

< > = <= >= <> !=

IS NULL, IS NOT NULL

NOT

AND left

OR left

The NOT variations: NOT BETWEEN, NOT IN, NOT LIKE, NOT RLIKE have the same precedence as
their non-NOT variations.

1.5.14. Type conversion

Casts in value expressions

Here is the cast operator which explicit converts between types.

cast_operator ::=

CAST ( value_expr AS typename )

There is also a system of implicit casting, where the system will insert a cast automatically.

Table 6. Available casts

From type To Type Context

int int n/a

bigint implicit

real implicit

float implicit

bool explicit

datetime none

date none

varchar explicit

25
From type To Type Context

bigint int explicit

bigint n/a

real implicit

float implicit

bool explicit

datetime none

date none

varchar explicit

real int explicit

bigint explicit

real n/a

float implicit

bool none

datetime none

date none

varchar explicit

float int explicit

bigint explicit

real explicit

float n/a

bool none

datetime none

date none

varchar explicit

26
From type To Type Context

bool int explicit

bigint explicit

real explicit

float explicit

bool n/a

datetime none

date none

varchar explicit

date* int none

bigint none

real none

float none

bool none

datetime implicit

date n/a

varchar explicit

datetime* int none

bigint none

real none

float none

bool none

datetime n/a

date implicit

varchar explicit

27
From type To Type Context

varchar** int explicit

bigint explicit

real explicit

float explicit

bool explicit

datetime explicit

date explicit

varchar explicit

* there are conversion functions to convert part of a date or datetime to integer, or to convert the
whole date/datetime to unix timestamps but these are not considered casts or available using the
cast syntax

** string literals without an explicit type are considered unknown type (and not varchar) and will
implicitly cast to any type.

Assignment resolution

This is a different kind of implicit cast which applies when you are inserting one type of expression
into a column with a different type. The casting rules are essentially the same as the implicit casting in
value expressions for the equals operator.

Expression set type resolution

The last system of implicit casts is used to resolve the type of a collection of expressions with different
types which should resolve to a single compatible type.

This is used in:

• case then expressions

• in list values

• join keys

• union columns

It is based on the implicit casting rules for the equals operator.

1.5.15. Operators

28
Logical

Table 7. Logical operators

Name Type Description

and (bool, bool) returns bool logical and

or (bool, bool) returns bool logical or

not (bool) returns bool logical not

AND

and (bool, bool) returns bool

Logical and.

Examples

TRUE AND FALSE

OR

or (bool, bool) returns bool

Logical or.

Examples

a OR b

NOT

not (bool) returns bool

Logical not.

Examples

NOT TRUE

29
Comparison

Table 8. Comparison operators

Name Type Description

< > <= >= == != (any, any) returns bool regular binary comparison
operations

between (exp any, min any, max any) is exp between min and max
returns bool inclusive

not between (exp any, min any, max any) inverse of between
returns bool

is null (any) returns bool argument is null

is not null (any) returns bool argument isn’t null

in (any [, … ] ) returns bool list membership

any is any type.

Binary comparison operators

<em>binary_comparison_operator</em> (<strong><em>any</em></strong>,
<strong><em>any</em></strong> ) <strong>returns</strong> <strong>bool</strong>

<em>binary_comparison_operator</em> is one of < > <= >= == !=

Regular binary comparison operators. The two input types should be the same, but the system will
insert valid implicit casts in many cases (see the cast section).

BETWEEN, NOT BETWEEN

exp between min and max is shorthand for exp >= min and exp <= max.

exp not between min and max is shorthand for not (exp between min and max).

between (exp any, min any, max any) returns bool

Examples

a between b and c

IS NULL, IS NOT NULL

IS NULL checks if the argument is null.

30
IS NOT NULL checks if the argument isn’t null.

Testing for null using exp = NULL will not work to check if a value is null, and testing

 for not null using exp <> NULL will not work to check if a value is not null. You have
to use the IS NULL and IS NOT NULL operators.

Examples

(1 + null) is null

(a * b) is not null

IN

IN tests for membership in a list.

Note: IN subqueries are not supported.

Examples

a in (1,3,5,7,11)

Mathematical functions and operators

SQRT

SQRT - Square root of the argument to the function

SELECT SQRT (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

ABS

ABS - |x|- Absolute (positive) value of the argument

SELECT ABS (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting) Returns Float/Double

ROUND

ROUND - Rounds the number to the nearest precision

31
SELECT ROUND (cfloat,2) FROM table

Parameters Float/Double (All other numbers available via implicit casting) Int32T Precision (number
of places after the decimal point)

Returns Float/Double

ASIN

ASIN sin-1 (x) – Arcsine (angle in radians whose sine is the argument of the function)

SELECT ASIN (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting) Returns Float/Double

ATAN

ATAN tg-1 (x)- Arctangent (angle in radians whose tangent is the argument of the function)

SELECT atan(cfloat) FROM t

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

ATN2 – Arctangent

ATN2 (angle in radians between positive X-axis and the ray from the origin where x and y are the first
and second arguments)

SELECT ATN2 (cfloat,cfloat2) FROM table

Parameters Float/Double (All other numbers available via implicit casting) Float/Double (All other
numbers available via implicit casting)

Returns Float/Double

COS

COS - cos x- - trigonometric cosine of the angle in radians

SELECT COS (cfloat) FROM table

32
Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

COT

COT - cot x - Cotangent - trigonometric cotangent of the angle in radians

SELECT COT (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

CEILING

CEILING - returns the smallest integer to the argument

SELECT CEILING (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

LOG10

LOG10 - log10 x- base 10 logarithm of the argument

SELECT LOG10 (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

LOG

LOG - ln x - Natural base logarithm (ln or loge) of the argument

SELECT LOG (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

33
LOG (base-y)

LOG base=y - Base-y logarithm of the x parameter, where x,y are the arguments

SELECT LOG (cfloat,cint) FROM table


SELECT LOG (cfloat,8) FROM table

Parameters Float/DoubleArgument (all other numbers available via implicit casting) Integer Base

Returns Float/Double

FLOOR

FLOOR - Floor returns the smallest integer to the argument

SELECT FLOOR (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

SIN

SIN - trigonometric sine of the angle in radians

SELECT SIN (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

SQUARE

SQUARE - x2 - the square of the argument

SELECT SQUARE (cfloat) FROM table

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

TAN

TAN - Tangent of the argument

34
SELECT tan(cfloat) FROM t

Parameters Float/Double (All other numbers available via implicit casting)

Returns Float/Double

PI

PI - mathematical constant

SELECT PI () FROM table

Parameters none

Returns Double value of Pi to 10 digits after the decimal point

POWER

POWER - perform a power of one value over the other (x raised to the power of y)

SELECT POWER (cfloat,cfloat2) FROM table

Parameters Float/Double (All other numbers available via implicit casting) Float/Double (All other
numbers available via implicit casting)

Returns Float/Double

TO_HEX

TO_HEX - Converts an integer to its base-16 string representation

SELECT TO_HEX (x) FROM table

Parameters Int/Long parameter

Returns VarChar - Base-16 string representation

String functions and operators

LOWER

LOWER - Converts a string to lowercase

35
SELECT LOWER (varchar_column) FROM table

UPPER

UPPER - Converts a string to uppercase

SELECT UPPER (varchar_column) FROM table

LEN

LEN - Returns the length of a varchar.

SELECT LEN (varchar_column) FROM table

Remarks Trailing whitespace on the right are ignored: LEN on ‘abc’ and ‘abc ‘ will both return 3.

LIKE

*LIKE / NOT LIKE * - Checks if a string matches a LIKE pattern

SELECT * FROM table WHERE varchar_column LIKE '%string%'


SELECT * FROM table WHERE varchar_column NOT LIKE '%string%'

Remarks Currently SQream only support literal pattern.

RLIKE

RLIKE - Checks if a string matches a regex pattern

SELECT * FROM table WHERE varchar_column RLIKE '[0-9]+$'

Parameters VarChar

Returns Boolean

SUBSTRING

SUBSTRING - Returns a specific substring of a string

SELECT SUBSTRING (varchar_column,start,length) FROM table

Parameters start - the starting point of the substring, while the value 1 represent the first character.

36
length - the length of the substring

Remarks If start ⇐1, then the substring begins from the first character but the length is reduced.
substring(1,2,’abc’) == ‘ab’ substring(0,2,’abc’) == substring(1,1,’abc’) == ‘a’

REGEXP_COUNT

REGEXP_COUNT - Counts regex matches in string. For example, the pattern ‘[1-9]’ appears once in ‘01’
and twice in ‘12’.

SELECT REGEXP_COUNT (varchar_column,’[0-9]’,2) FROM table

Parameters varchar_column - the string column to match VarChar - the regex (literal only) Int - starting
location (Optional. When unset, default is 1)

Returns Int

REGEXP_INSTR

REGEXP_INSTR - Matches regex and returns the position in a string

SELECT REGEXP_INSTR (varchar_column,’[0-9]’) FROM table


SELECT REGEXP_INSTR (varchar_column,’[0-9]’,2) FROM table
SELECT REGEXP_INSTR (varchar_column,’[0-9]’,2,2) FROM table
SELECT REGEXP_INSTR (varchar_column,’[0-9]’,2,2,1) FROM table

Parameters varchar_column - the string column to match VarChar - the regex (literal only) Int - starting
location (Optional. When unset, default is 1) Int - which occurence of the pattern (Optional. When
unset, default is 1) Int - 0 to return the match’s start position, 1 for its end (Optional. When unset,
default is 0)

Returns Int -the location of each

REGEXP_SUBSTR

REGEXP_SUBSTR - matches regex and returns it.

SELECT REGEXP_SUBSTR (varchar_column,’[0-9]’) FROM table


SELECT REGEXP_SUBSTR (varchar_column,’[0-9]’,2) FROM table
SELECT REGEXP_SUBSTR (varchar_column,’[0-9]’,2,2) FROM table

Parameters varchar_column - the string column to match VarChar - the regex (literal only) Int - starting
location (Optional. When unset, default is 1) Int - which occurence of the pattern (Optional. When
unset, default is 1)

37
Returns VarChar vector (string column of the matches)

ISPREFIXOF

ISPREFIXOF - Checks if one string is a prefix of the other.

SELECT ISPREFIXOF (x,y) FROM table

Remarks Internal function. “isprefix(x,y)” is equivalent to “y LIKE x + ‘%’ “, but more efficient

Concatenation (||)

|| - String concatenation - concatenates two string values

SELECT fname || '_' || lname FROM customers

CHARINDEX

CHARINDEX - Returns the position of a subexpression in an expression

SELECT CHARINDEX (y,x,1) FROM table

Parameters VarChar -the subexpression. Either a scalar or a column VarChar -the expression Int
(optional) -starts the search from this index

Returns Int - the position of the subexpression in the expression or 0 if it wasn’t found

PATINDEX

PATINDEX - Returns the position of a pattern in an expression

SELECT PATINDEX (‘%[0-9]%’,x) FROM table

Parameters VarChar (literal) -the subexpression VarChar - the expression

Returns Int -the position of the first match of the pattern in the expression or 0 if there’s no match

LTRIM

LTRIM - Trims trailing whitespace from the left side of the string

SELECT LTRIM (x) FROM table

38
Parameters VarChar

Returns VarChar

REVERSE

REVERSE - Reverses a string

SELECT REVERSE (x) FROM table

Parameters VarChar

Returns VarChar

RTRIM

RTRIM - Trims trailing whitespace from the right side of the string

SELECT RTRIM (x) FROM table

Parameters VarChar

Returns VarChar

Pattern matching syntax

Table 9. Pattern matching syntax

Syntax Description

% match zero or more characters

_ match exactly one character

[A-Z] match any character between A and Z inclusive

[^A-Z] match any character not between A and Z

[abcde] match any one of a b c d and e

[^abcde] match any character that isn’t one of a b c d and e

[abcC-F] match a b c or between C and F

Regular Expression Pattern Matching Syntax

Table 10. Regular expression pattern matching syntax

Syntax Description

^ Match the beginning of a string

39
Syntax Description

$ Match the end of a string

. Match any character (including carriage return and newline)

* Match the previous pattern zero or more times

+ Match the previous pattern zero or more times

? Match the previous pattern zero or one times

de|abc Match either 'de' or 'abc'

(abc)* Match zero or more instances of the sequence abc

{2} Match the previous pattern exactly two times

{2,4} Match the previous pattern between two and four times

[a-dX], [^a- Matches any character that is (or is not, if ^ is used) either a, b, c, d or X. A - character
dX] between two other characters forms a range that matches all characters from the first
character to the second. For example, [0-9] matches any decimal digit. To include a
literal ] character, it must immediately follow the opening bracket [. To include a literal
- character, it must be written first or last. Any character that does not have a defined
special meaning inside a [] pair matches only itself.

Date/time

Table 11. Date/time functions

Name Type Description

getdate () returns datetime returns the current time in the


current timezone

trunc (datetime) returns datetime truncates the time to midnight

datepart (datepart, anydate) returns int returns specific part of a date

dateadd (datepart, anydate) returns adds to a date


date

to_unixts (datetime) returns bigint converts to unix timestamp,


seconds since epoch

to_unixtsms (datetime) returns bigint converts to unix timestamp,


milliseconds since epoch

anydate is either DATE or DATETIME

datepart is one of the following keywords:

Table 12. Datepart syntax

40
Datepart Shorthand
aliases

year yyyy, yy

quarter qq, q

month mm, m

dayofyear dy, y

day dd, d

week wk, ww

weekday dw

hour hh

minute n

second ss, s

millisecond ms

Geospatial

Point
Points are represented as longitude and latitude columns. Example:

create table point (


longitude float not null,
latitude float not null
);

Polygon
Polygons are N number of points:

create table polygon (


long1 float not null,
lat1 float not null,

...

long5 float not null,


lat5 float not null,
);

Polyline

41
A polyline is a collection of line segments, and contains up to twenty points. We represent it as twenty
points plus a count column which indicates how many points are actually used in the given row.

create table polyline (


num_of_points int not null,
long1 float not null,
lat1 float not null,

...

long20 float not null,


lat20 float not null
);

Table 13. Geospatial functions

Name Type Description

point_in_polygon (point_long float, point_lat float, point inside polygon


poly_long1 float, poly_lat1 float,

poly_long5 float, poly_lat5 float)


returns bool

line_crosses_polygon (number_of_points_ int, line crosses polygon


polyline_long1 float,
polyline_lat1 float,

polyline_long20 float,
polyline_lat20 float,
poly_long1 float, poly_lat1 float,

poly_long5 float, poly_lat5 float)


returns bool

POINT_IN_POLYGON

Returns true if the point is inside the polygon.

Limitations: the point arguments cannot be literals. The polygon arguments can either be all columns
or all literals.

42
LINE_CROSSES_POLYGON

Returns true if the line crosses the polygon.

Limitations: the polyline arguments cannot be literals. The polygon arguments can either be all
columns or all literals.

1.5.16. Aggregate functions

Table 14. Aggregate functions

Name Type Description

avg (anynumber) returns float average

count (any) returns int count

max (any) returns any maximum

min (any) returns any minimum

sum (anynumber) returns sum


anynumber

stdev (anynumber) returns float standard deviation

string_agg (values varchar, delimiter string concatenation


varchar) returns varchar

any can be any type. anynumber is any numeric type: INT, BIGINT, REAL, FLOAT.

STRING_AGG has limitation of maximum 1024 characters in its result.

1.5.17. Window functions

Table 15. Window functions

Name Type

rank() returns int

row_number() returns int

min() returns int

max() returns int

sum() returns int

Examples

select col_a,col_c, rank() over ( partition by col_c order by col_c) from my_table;
select sum(col_a) over ( partition by col_c order by col_c) from my_table;

43
1.6. Saved queries
Saved queries allow SQream to save the query plan for a query. Saved query will save the compiler
time on each execution, and therefor can help optimize the total query execution time.

Example

Save the query:


select save_query('q1', 'select * from t where xint > ? AND xdatetime < ? AND xvarchar6 =
?')

Execute the query:


select execute_saved_query('q1', 1, '2013-12-02 12:01:22', 'sqream')

The result: SQream will execute the query:

select * from t where xint > 1 AND xdate < '2015-10-03' AND xvarchar6 = 'sqream'

The saved query names must be unique in the database.

1.6.1. save_query

SELECT save_query ( saved_query_name , parameterized_query_string ) ;

saved_query_name ::= string_literal

parameterized_query_string ::= string_literal

1.6.2. execute_saved_query

SELECT execute_saved_query ( saved_query_name [ , argument [ , ... ] ] ) ;

argument ::= string_literal | number_literal

1.6.3. drop_saved_query

SELECT drop_saved_query ( saved_query_name ) ;

1.6.4. show_saved_query

Show the query for the saved query name.

44
SELECT show_saved_query ( saved_query_name ) ;

1.6.5. list_saved_queries

Show all the saved queries in the database.

SELECT list_saved_queries ( ) ;

1.7. SQream Metadata


1.7.1. Quering SQream Catalog

All SQream metadata can be seen via SQream Catalog. To access the catalog, query the internal views
sqream_catalog.<object type>

SELECT * from <strong>sqream_catalog.<object type></strong> ;

Table 16. SQream internal catalog

view_name Description

sqream_catalog.columns See all the columns in the database

sqream_catalog.databases See all the databases in the cluster

sqream_catalog.schemas See all the schemas in the database

sqream_catalog.tables See all the tables in the database

sqream_catalog.views See all the views in the database

Example

to see all the tables:


select * from sqream_catalog.tables;

45

You might also like