ASQL docs / SQL

Data types

ASQL accepts the MySQL and MariaDB type names. Each column is stored as one of four kinds, compressed by column: integer, double, decimal, or text (dates and binary data are text with a type attached).

TypeStored asNotes
TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINTintegerUNSIGNED and ZEROFILL accepted; values checked against the type's range
BOOL, BOOLEANintegershown as tinyint(1)
BIT(n)integer
DECIMAL(p,s), NUMERIC, DEC, FIXEDexact decimaldefault (10,0); precision up to 65, scale up to 30
FLOAT, DOUBLE, DOUBLE PRECISION, REALdouble(M,D) sets display decimals only
SERIALintegerBIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE, as in MySQL
CHAR(n), VARCHAR(n), CHARACTER VARYING(n), NCHAR, NVARCHARtextlength counted in characters; CHAR drops trailing spaces
TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXTtext
BINARY(n), VARBINARY(n), TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOBtext, binaryBINARY(n) is padded with zero bytes
DATEtext, dateYYYY-MM-DD
DATETIME[(fsp)], TIMESTAMP[(fsp)]text, date and time
TIME[(fsp)]text, time
YEARtext
ENUM('a', ...), SET('a', ...)textmembers checked in strict mode
JSONtexta CHECK (JSON_VALID(col)) is added for you
GEOMETRY, LINESTRING, POLYGON, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTIONtextWKT; see the geometry functions

PostgreSQL-style enum types also work:

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE people (name TEXT, current mood);
DROP TYPE mood;

Values that do not fit

What happens depends on strict mode, which is off by default (see Support and differences).

ValueStrict mode offStrict mode on
Text longer than VARCHAR(n) or CHAR(n)cut to n characterserror "Data too long"
Integer out of the type's rangeclamped to the rangeerror "Out of range value"
Decimal past its precisionclampederror
Invalid datezero dateerror "Incorrect date value"
Value not in an ENUM or SETstored as givenerror "Data truncated"

Turn strict mode on for the server with AIOS_SQL_STRICT=1, or per session with SET sql_mode = 'STRICT_TRANS_TABLES'.

Storage

Integers and decimals are stored as scaled integers with the smallest width that fits the column's values. Text is dictionary-coded. Dates are stored as day or second counts. A column's encoding is chosen per column and per segment; it does not change how values behave.