KDBS SQL: Syntax That Differs from Other DBs
KDBS states that it is "not a dialect compatibility layer". If a statement with the same meaning had two spellings, it would have two statement shapes (fingerprints), so KDBS fixes one spelling and rejects the rest. When it rejects, it reports the byte offset of the offending token in the statement. The examples in this lesson run only in the KDBS sandbox. Examples in other SQL lessons are not ported to KDBS syntax, so they have no run button on KDBS.
Use AS for aliases
KDBS · Alias without AS
SELECT o.ord_id, o.amt
FROM orders o
WHERE o.cust_id = 101
It is rejected with unexpected token 'o' after end of statement. Accepting bare aliases (FROM orders o) would let a typo in a keyword be read as an alias. Use AS for table aliases.
KDBS · Alias with AS
SELECT o.ord_id, o.ord_dt, o.amt
FROM orders AS o
WHERE o.cust_id = 101
ORDER BY o.ord_dt DESC
LIMIT 5
Write literals in the column's type
KDBS has no implicit conversion. A literal must be written in the spelling of the column it is compared with; otherwise, it is rejected at compile time, before any row is read.
| Column type | Literal to use | Rejected examples |
|---|---|---|
| Integer | 20 | '20', 20.0 |
varchar, char | '5' | 5 |
timestamp | '2025-09-01 00:00:00' | '2025-09-01', DATE '2025-09-01' |
date | '2025-09-01' | |
decimal | '12.34' or an integer | |
bool | 0, 1 |
KDBS · Number against a string column
SELECT * FROM orders WHERE ord_no = 2025083101946001
KDBS · Date only against a timestamp
SELECT COUNT(*) FROM orders WHERE ord_dt >= '2025-09-26'
KDBS · timestamp literal
SELECT COUNT(*) FROM orders WHERE ord_dt >= '2025-09-26 00:00:00'
Comparing two columns also works only within the same family: integers with integers (compared by value even if width and sign differ), decimal with decimal of the same width and scale, char with varchar, date with date, and timestamp with timestamp. Comparing date with timestamp is rejected (it would compare a day count with microseconds).
A single quote cannot appear inside a string
KDBS string literals have no escape. Another DB's 'it''s' is two adjacent literals in KDBS and is rejected.
KDBS · Doubled single quote
SELECT COUNT(*) FROM customers WHERE cust_nm = 'it''s'
Comments: -- only
The KDBS lexer reads only -- line comments. The sandbox replaces /* … */ block comments with whitespace before sending, so examples with block comments still run. Sent directly from the admin tool (ckdbs_cli.py), they are rejected with expected identifier, got '/'.
KDBS · Comments
-- KDBS reads line comments itself
SELECT cust_id, cust_nm /* the sandbox removes block comments */
FROM customers
WHERE cust_id = 42
Value expressions and functions
Expressions in the select list, CASE, COALESCE, CAST, and || are computed by the query layer (Step chain and query layer). Expressions have no implicit conversion, so amt + 1 works but cust_nm + 1 is rejected.
KDBS · Expressions and CASE
SELECT ord_id,
amt * 2,
status || '-' || ord_no AS tag,
CASE WHEN amt >= 400000 THEN 'big' ELSE 'small' END AS size,
CAST(ord_dt AS date) AS ord_day
FROM orders
WHERE ord_id BETWEEN 1 AND 5
|| does not convert types either. Concatenating an integer column with a string is rejected.
KDBS · Concatenating an integer and a string
SELECT cust_id || '-' || status FROM orders WHERE ord_id = 1
string literal cannot be used as int64 … there is no implicit conversion. To concatenate, convert with CAST(cust_id AS varchar).
Columns are NOT NULL by default
In KDBS CREATE TABLE, only columns declared NULL allow NULL. This is the opposite of standard SQL. Every column in the sandbox is NOT NULL, so IS NULL always returns 0 rows. The three-valued logic of NULL comparisons is the same as the standard (= NULL selects no rows).
KDBS · IS NULL and = NULL
SELECT COUNT(*) FROM customers WHERE cust_id BETWEEN 1 AND 100 AND grade IS NULL
-- Admin statement (cannot be run in the sandbox)
CREATE TABLE contacts (
id int64, -- first column: tuple key
name varchar(40), -- NOT NULL (default)
email varchar(64) NULL -- allowing NULL must be declared
);
INSERT INTO contacts (name, email) VALUES ('kim', NULL); -- the engine assigns id
Summary
| On other DBs | On KDBS |
|---|---|
FROM orders o | FROM orders AS o |
WHERE ord_no = 123 (implicit conversion) | WHERE ord_no = '123' |
DATE '2025-09-01' | '2025-09-01 00:00:00' (timestamp column) |
'it''s' | Not allowed |
/* … */ | -- (the sandbox removes block comments before sending) |
| Columns allow NULL by default | NOT NULL by default |