KDB knowledge

SHOW TABLES, COLUMNS, CREATE TABLE

List the tables of a database, the columns of a table, its partitions, and the full CREATE TABLE statement - also with QuestDB's tables() and table_columns().

These statements show what is in a database: which tables there are, which columns a table has, and how a table was made. They only read; they never change anything.

StatementShows
SHOW TABLESevery table, its kind, partitions, columns and rows
SHOW COLUMNS FROM tthe columns of one table
SHOW CREATE TABLE tthe CREATE TABLE statement of one table
SHOW PARTITIONS FROM tthe partitions of one table: rows, time range, size
tables(), table_columns('t'), wal_tables()the same facts with QuestDB's column names (below)

Other SHOW statements: SHOW DATABASES (databases), SHOW VIEWS (views), SHOW INDEXES (indexes), SHOW FUNCTIONS (saved functions), SHOW PROCEDURES (procedures), SHOW TRIGGERS (triggers), SHOW USERS (users and roles).

Example: What is in the sample database (sample data: sample)

SHOW TABLES;
SHOW COLUMNS FROM trade_log;

Result:

SHOW TABLES

name (STRING)kind (STRING)partition (STRING)columns (INT)rows (LONG)
brokersrelationalNONE25
live_datatimeseriesDAY1212
ochl_daytimeseriesYEAR757
ochl_minutestimeseriesMONTH7956
securitiesrelationalNONE35
trade_logtimeseriesDAY832

(6 rows)

SHOW COLUMNS FROM trade_log

name (STRING)type (STRING)primary_key (BOOL)not_null (BOOL)computed (BOOL)references (STRING)
dateTIMESTAMPfalsefalsefalseNULL
transaction_idLONGfalsefalsefalseNULL
symbolSYMBOLfalsefalsefalseNULL
buyerINTfalsefalsefalsebrokers(id)
sellerINTfalsefalsefalsebrokers(id)
quantityLONGfalsefalsefalseNULL
rateDOUBLEfalsefalsefalseNULL
amountDOUBLEfalsefalsetrueNULL

(8 rows)

SHOW TABLES

Syntax:

SHOW TABLES

Lists the tables of the current database, sorted by name. Views are not in this list (use SHOW VIEWS).

ColumnTypeMeaning
nameSTRINGtable name, spelled as in CREATE TABLE
kindSTRINGrelational or timeseries
partitionSTRINGDAY, MONTH, YEAR, or NONE (always NONE for relational tables)
columnsLONGnumber of columns, computed columns included
rowsLONGnumber of rows now

Example: An app database with users, accounts and a ledger

Setup:

CREATE TABLE users (id LONG PRIMARY KEY AUTO, email STRING NOT NULL UNIQUE);
CREATE TABLE accounts (id INT PRIMARY KEY AUTO, user_id LONG NOT NULL REFERENCES users(id), balance DECIMAL(2) NOT NULL DEFAULT 0);
CREATE TABLE ledger (time TIMESTAMP, account INT, amount DECIMAL(2)) TIMESERIES(time) PARTITION BY MONTH;
INSERT INTO users (email) VALUES ('ram@example.com'), ('sita@example.com');
INSERT INTO accounts (user_id, balance) VALUES (1, 1000.00);
SHOW TABLES;

Result:

name (STRING)kind (STRING)partition (STRING)columns (INT)rows (LONG)
accountsrelationalNONE31
ledgertimeseriesMONTH30
usersrelationalNONE22

(3 rows)

Command line: The same list from the shell (sample data: sample)

kdb shell market
> .tables

Output:

KDB 0.2.0-dev shell on market
End statements with ';'. Type .help for commands, .exit to quit.
kdb> name         | kind       | partition | columns | rows
-------------+------------+-----------+---------+-----
brokers      | relational | NONE      |       2 |    5
live_data    | timeseries | DAY       |      12 |   12
ochl_day     | timeseries | YEAR      |       7 |   57
ochl_minutes | timeseries | MONTH     |       7 |  956
securities   | relational | NONE      |       3 |    5
trade_log    | timeseries | DAY       |       8 |   32
(6 rows, 0.0 ms)
kdb>

SHOW COLUMNS FROM

Syntax:

SHOW COLUMNS FROM table

Lists the columns of one table, in table order.

ColumnTypeMeaning
nameSTRINGcolumn name
typeSTRINGcolumn type, like LONG, DECIMAL(2), TIMESTAMP
primary_keyBOOLtrue for the PRIMARY KEY column
not_nullBOOLtrue when the column has NOT NULL
computedBOOLtrue for a computed column (AS (...))
referencesSTRINGtable(column) when the column has REFERENCES, else NULL

Example: The trade_log table: references and a computed column (sample data: sample)

SHOW COLUMNS FROM trade_log;

Result:

name (STRING)type (STRING)primary_key (BOOL)not_null (BOOL)computed (BOOL)references (STRING)
dateTIMESTAMPfalsefalsefalseNULL
transaction_idLONGfalsefalsefalseNULL
symbolSYMBOLfalsefalsefalseNULL
buyerINTfalsefalsefalsebrokers(id)
sellerINTfalsefalsefalsebrokers(id)
quantityLONGfalsefalsefalseNULL
rateDOUBLEfalsefalsefalseNULL
amountDOUBLEfalsefalsetrueNULL

(8 rows)

Example: Forum posts that point to their parent post

Setup:

CREATE TABLE posts (id LONG PRIMARY KEY AUTO, parent_id LONG REFERENCES posts(id), author STRING NOT NULL, body STRING NOT NULL, words LONG AS (length(body)));
SHOW COLUMNS FROM posts;

Result:

name (STRING)type (STRING)primary_key (BOOL)not_null (BOOL)computed (BOOL)references (STRING)
idLONGtruefalsefalseNULL
parent_idLONGfalsefalsefalseposts(id)
authorSTRINGfalsetruefalseNULL
bodySTRINGfalsetruefalseNULL
wordsLONGfalsefalsetrueNULL

(5 rows)

Example: A table that does not exist (shows an error)

SHOW COLUMNS FROM userz;

Result:

Error: table 'userz' does not exist

Example: FROM is needed (shows an error)

Setup:

CREATE TABLE users (id LONG PRIMARY KEY);
SHOW COLUMNS users;

Result:

Error: line 1, column 14: expected FROM after SHOW COLUMNS but found 'users'

SHOW CREATE TABLE

Syntax:

SHOW CREATE TABLE table

Gives the full CREATE TABLE statement of a table, with every rule KDB keeps: types, keys, defaults, ROUND, computed columns, REFERENCES, CHECK rules with their names, and the table options with their default values filled in (like PARTITION BY DAY and SORT BY (symbol, time)).

ColumnTypeMeaning
create_sqlSTRINGthe statement; newer KDB versions add one more row for each index: CREATE INDEX ...

Example: The daily candles table of the sample data (sample data: sample)

SHOW CREATE TABLE ochl_day;

Result:

create_sql (STRING)
CREATE TABLE ochl_day ( time TIMESTAMP ROUND 1d, symbol SYMBOL, open DOUBLE, high DOUBLE, low DOUBLE, close DOUBLE, volume DOUBLE ) TIMESERIES(time) PARTITION BY YEAR SORT BY (symbol,...

(1 row)

Example: Defaults filled in: PARTITION BY and SORT BY

Setup:

CREATE TABLE live_data (timestamp TIMESTAMP, symbol SYMBOL, ltp DOUBLE) TIMESERIES(timestamp);
SHOW CREATE TABLE live_data;

Result:

create_sql (STRING)
CREATE TABLE live_data ( timestamp TIMESTAMP, symbol SYMBOL, ltp DOUBLE ) TIMESERIES(timestamp) PARTITION BY DAY SORT BY (symbol, timestamp)

(1 row)

Example: An accounts table with a CHECK rule and an index

Setup:

CREATE TABLE accounts (
  id INT PRIMARY KEY AUTO,
  email STRING NOT NULL UNIQUE,
  balance DECIMAL(2) NOT NULL DEFAULT 0 CHECK (balance >= 0)
);
CREATE INDEX accounts_balance ON accounts (balance);
SHOW CREATE TABLE accounts;

Result:

create_sql (STRING)
CREATE TABLE accounts ( id INT PRIMARY KEY AUTO, email STRING NOT NULL UNIQUE, balance DECIMAL(2) NOT NULL DEFAULT 0, CONSTRAINT accounts_balance_check CHECK (balance >= 0) )
CREATE INDEX accounts_balance ON accounts (balance)

(2 rows)

Command line: See the whole text in CSV format (sample data: sample)

kdb sql market "SHOW CREATE TABLE trade_log" --format csv

Output:

create_sql
"CREATE TABLE trade_log (
  date TIMESTAMP ROUND 1d,
  transaction_id LONG,
  symbol SYMBOL,
  buyer INT REFERENCES brokers(id),
  seller INT REFERENCES brokers(id),
  quantity LONG,
  rate DOUBLE,
  amount DOUBLE AS (quantity * rate)
) TIMESERIES(date) PARTITION BY DAY SORT BY (symbol, date) DEDUP KEY (date, transaction_id)"

SHOW PARTITIONS FROM

Syntax:

SHOW PARTITIONS FROM table
SELECT * FROM table_partitions('table')

Lists the partitions of one table, oldest first, with QuestDB's columns. Both forms give the same rows.

ColumnTypeMeaning
indexINT0 for the first partition, then 1, 2, ...
partitionBySTRINGDAY, MONTH, YEAR or NONE
nameSTRING2026-09-24, 2026-09, 2026; default for a table without time partitions
minTimestamp, maxTimestampTIMESTAMPthe first and last time in it; NULL for a table without a time column
numRowsLONGrows now
diskSizeLONGbytes: its file, plus its new rows still in the log
diskSizeHumanSTRINGthe same, like 12.4 KiB
readOnly, active, attached, detached, attachableBOOLactive is true for the newest partition; KDB has no read-only or detached partitions

Example: Trades split by day

Setup:

CREATE TABLE trades (time TIMESTAMP, symbol SYMBOL, price DOUBLE) TIMESERIES(time) PARTITION BY DAY;
INSERT INTO trades VALUES ('2026-09-24T05:00:00Z', 'CITY', 10), ('2026-09-24T05:03:00Z', 'CITY', 11), ('2026-09-25T05:00:00Z', 'VOLT', 50);
SHOW PARTITIONS FROM trades;

Result:

index (INT)partitionBy (STRING)name (STRING)minTimestamp (TIMESTAMP)maxTimestamp (TIMESTAMP)numRows (LONG)diskSize (LONG)diskSizeHuman (STRING)readOnly (BOOL)active (BOOL)attached (BOOL)detached (BOOL)attachable (BOOL)
0DAY2026-09-242026-09-24T05:00:00.000Z2026-09-24T05:03:00.000Z2548548 Bfalsefalsetruefalsefalse
1DAY2026-09-252026-09-25T05:00:00.000Z2026-09-25T05:00:00.000Z1520520 Bfalsetruetruefalsefalse

(2 rows)

QuestDB's meta functions

Apps written for QuestDB read the schema with functions in FROM. KDB has them with QuestDB 9.4.3's column names and types, so that code runs unchanged.

FunctionOne row perColumns
tables()tableid, table_name, designatedTimestamp, partitionBy, maxUncommittedRows, o3MaxLag, walEnabled, directoryName, dedup, ttlValue, ttlUnit, matView
table_columns('t')column of tcolumn, type, indexed, indexBlockCapacity, symbolCached, symbolCapacity, designated, upsertKey
wal_tables()tablename, suspended, writerTxn, bufferedTxnSize, sequencerTxn, errorTag, errorMessage, memoryPressure
table_partitions('t')partition of tas SHOW PARTITIONS
information_schema.tables()table or viewthe same as information_schema.tables

Example: What a rebuild reads first: time column, partitions, dedup keys

Setup:

CREATE TABLE ticks (time TIMESTAMP, symbol SYMBOL, price DOUBLE) TIMESERIES(time) PARTITION BY DAY DEDUP KEY (symbol, time);
SELECT table_name, designatedTimestamp, partitionBy, dedup FROM tables() WHERE table_name = 'ticks';
SELECT "column", type, indexed, designated, upsertKey FROM table_columns('ticks');
SELECT name, suspended, writerTxn = sequencerTxn AS caught_up FROM wal_tables() WHERE name = 'ticks';

Result:

SELECT table_name, designatedTimestamp, partitionBy, dedup FROM tables() WHERE table_name = 'ticks'

table_name (STRING)designatedTimestamp (STRING)partitionBy (STRING)dedup (BOOL)
tickstimeDAYtrue

(1 row)

SELECT column, type, indexed, designated, upsertKey FROM table_columns('ticks')

column (STRING)type (STRING)indexed (BOOL)designated (BOOL)upsertKey (BOOL)
timeTIMESTAMPfalsetruetrue
symbolSYMBOLfalsefalsetrue
priceDOUBLEfalsefalsefalse

(3 rows)

SELECT name, suspended, writerTxn = sequencerTxn AS caught_up FROM wal_tables() WHERE name = 'ticks'

name (STRING)suspended (BOOL)caught_up (BOOL)
ticksfalsetrue

(1 row)

Example: A table that does not exist (shows an error)

SELECT * FROM table_columns('tickz');

Result:

Error: table 'tickz' does not exist