Skip to content

information_schema ​

The information_schema views describe the database's tables, columns, constraints, indexes, views and external data in the SQL-standard (PostgreSQL-like) shape. SQLite has none of them; smaltdb also offers SQLite's sqlite_schema table and the schema pragmas. For a task-oriented overview, see Introspection.

The views are read-only and computed when queried. Names are matched without regard to case (INFORMATION_SCHEMA.TABLES works). Every view lists objects of the main schema only:

  • TEMP tables and TEMP views are not listed.
  • Internal tables (smalt_*) are not listed.
  • table_catalog and table_schema (and the other *_catalog / *_schema columns) are always main.

The examples use these objects:

sql
CREATE TABLE customer(
  id INTEGER PRIMARY KEY,
  email TEXT NOT NULL UNIQUE COLLATE NOCASE,
  tier INTEGER DEFAULT 1 CHECK (tier BETWEEN 1 AND 3)
);
CREATE TABLE orders(
  id INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL,
  total REAL,
  CONSTRAINT orders_customer FOREIGN KEY (customer_id) REFERENCES customer(id) ON DELETE CASCADE
);
CREATE INDEX orders_by_customer ON orders(customer_id, total DESC);
CREATE VIEW big_orders AS SELECT id, total FROM orders WHERE total > 100;
CREATE MATERIALIZED VIEW order_totals AS SELECT customer_id, sum(total) AS spent FROM orders GROUP BY customer_id;
CREATE CONNECTION api WITH (url = 'https://example.com/data/', credentials = 'token');
CREATE EXTERNAL TABLE rates (currency TEXT, rate REAL) WITH (location = 'rates.csv', connection = 'api', header = true);

schemata ​

ColumnMeaning
catalog_namemain
schema_namemain or information_schema
schema_ownerNULL
sql
SELECT * FROM information_schema.schemata
catalog_nameschema_nameschema_owner
mainmainNULL
maininformation_schemaNULL

tables ​

One row per table, view, materialized view and external table.

ColumnMeaning
table_catalog, table_schemamain
table_namename
table_typeBASE TABLE, VIEW, MATERIALIZED VIEW or EXTERNAL
is_insertable_intoYES for base tables, NO otherwise
sql
SELECT table_name, table_type, is_insertable_into FROM information_schema.tables
table_nametable_typeis_insertable_into
customerBASE TABLEYES
ordersBASE TABLEYES
order_totalsMATERIALIZED VIEWNO
big_ordersVIEWNO
ratesEXTERNALNO

columns ​

One row per column of every table, view, materialized view and external table.

ColumnMeaning
table_catalog, table_schema, table_namethe owner
column_namename
ordinal_positionposition, from 1
column_defaultthe default's source text, or NULL
is_nullableNO for NOT NULL and primary key columns, else YES (always YES for views and external tables)
data_typedeclared type as written (upper-cased); ANY when none
collation_nameBINARY, NOCASE or RTRIM for table columns; NULL for views and external tables
is_identityYES for the INTEGER PRIMARY KEY (rowid) column
is_generatedalways NEVER

A view's columns are found by planning its query; a view that cannot be planned (for example, its table was dropped) has no rows here.

sql
SELECT table_name, column_name, ordinal_position AS pos, column_default, is_nullable, data_type, collation_name, is_identity
FROM information_schema.columns WHERE table_name IN ('customer', 'big_orders')
table_namecolumn_nameposcolumn_defaultis_nullabledata_typecollation_nameis_identity
customerid1NULLNOINTEGERBINARYYES
customeremail2NULLNOTEXTNOCASENO
customertier31YESINTEGERBINARYNO
big_ordersid1NULLYESINTEGERNULLNO
big_orderstotal2NULLYESREALNULLNO

views ​

ColumnMeaning
table_catalog, table_schema, table_namethe view
view_definitionthe SELECT text
check_optionNONE
is_updatable, is_insertable_intoNO
sql
SELECT table_name, view_definition FROM information_schema.views
table_nameview_definition
big_ordersSELECT id, total FROM orders WHERE total > 100

materialized_views ​

A smaltdb extension (PostgreSQL has pg_matviews).

ColumnMeaning
table_catalog, table_schema, table_namethe view
view_definitionthe SELECT text
storagerow or columnar
locationfile, or memory for location = 'memory' in a file database
refresh_modeMANUAL, or the automatic policy: EVERY n SECONDS, ON RECONNECT, or both
is_populatedNO after WITH NO DATA until the first refresh
last_refreshtime of the last refresh (ISO 8601, UTC), or NULL
is_freshYES while no table the view reads has changed since the last refresh
last_refresh_errorthe error of the last automatic refresh, or NULL
sql
SELECT table_name, view_definition, storage, location, refresh_mode, is_populated, is_fresh, last_refresh IS NOT NULL AS refreshed
FROM information_schema.materialized_views
table_nameview_definitionstoragelocationrefresh_modeis_populatedis_freshrefreshed
order_totalsSELECT customer_id, sum(total) AS spent FROM orders GROUP BY customer_idrowfileMANUALYESYES1

external_tables ​

A smaltdb extension.

ColumnMeaning
table_catalog, table_schema, table_namethe table
locationthe location option
formatthe format option as given (lower case), or else the format the file extension selects (csv, tsv, json, parquet); NULL when no installed plugin reads that extension
connection_namethe connection, or NULL
optionsthe other options as a JSON object
sql
SELECT * FROM information_schema.external_tables
table_catalogtable_schematable_namelocationformatconnection_nameoptions
mainmainratesrates.csvcsvapi

connections ​

A smaltdb extension. Never shows secrets: credentials is only the name of a provider the application registers.

ColumnMeaning
connection_namename
connection_typehttp, s3 or azure: the type option in lower case, with https shown as http (http when none)
urlthe url option, or NULL
credentialsthe credentials option, or NULL
optionsthe other options as a JSON object
sql
SELECT * FROM information_schema.connections
connection_nameconnection_typeurlcredentialsoptions
apihttphttps://example.com/data/token{}

table_constraints ​

One row per PRIMARY KEY, UNIQUE, FOREIGN KEY and CHECK constraint. Constraints without a CONSTRAINT name get PostgreSQL-style names: <table>_pkey, <table>_<columns>_key, <table>_<columns>_fkey, <table>_check<n>.

ColumnMeaning
constraint_catalog, constraint_schema, constraint_namethe constraint
table_catalog, table_schema, table_nameits table
constraint_typePRIMARY KEY, UNIQUE, FOREIGN KEY or CHECK
is_deferrableYES for a foreign key declared DEFERRABLE (with or without INITIALLY …), else NO
initially_deferredYES for DEFERRABLE INITIALLY DEFERRED, the only form checked at COMMIT; else NO
sql
SELECT constraint_name, table_name, constraint_type, is_deferrable FROM information_schema.table_constraints
constraint_nametable_nameconstraint_typeis_deferrable
customer_pkeycustomerPRIMARY KEYNO
customer_email_keycustomerUNIQUENO
customer_check1customerCHECKNO
orders_pkeyordersPRIMARY KEYNO
orders_customerordersFOREIGN KEYNO

key_column_usage ​

One row per column of each PRIMARY KEY, UNIQUE and FOREIGN KEY constraint.

ColumnMeaning
constraint_catalog, constraint_schema, constraint_namethe constraint
table_catalog, table_schema, table_nameits table
column_namethe column
ordinal_positionposition in the constraint, from 1
position_in_unique_constraintfor foreign keys, the position of the referenced column; NULL otherwise
sql
SELECT constraint_name, table_name, column_name, ordinal_position, position_in_unique_constraint
FROM information_schema.key_column_usage
constraint_nametable_namecolumn_nameordinal_positionposition_in_unique_constraint
customer_pkeycustomerid1NULL
customer_email_keycustomeremail1NULL
orders_pkeyordersid1NULL
orders_customerorderscustomer_id11

referential_constraints ​

One row per foreign key.

ColumnMeaning
constraint_catalog, constraint_schema, constraint_namethe foreign key
unique_constraint_catalog, unique_constraint_schema, unique_constraint_namethe parent's primary key or unique constraint it references (NULL if none matches)
match_optionNONE
update_rule, delete_ruleNO ACTION, RESTRICT, CASCADE, SET NULL or SET DEFAULT
sql
SELECT constraint_name, unique_constraint_name, match_option, update_rule, delete_rule FROM information_schema.referential_constraints
constraint_nameunique_constraint_namematch_optionupdate_ruledelete_rule
orders_customercustomer_pkeyNONENO ACTIONCASCADE

check_constraints ​

ColumnMeaning
constraint_catalog, constraint_schema, constraint_namethe constraint
check_clausethe expression's source text
sql
SELECT constraint_name, check_clause FROM information_schema.check_constraints
constraint_namecheck_clause
customer_check1tier BETWEEN 1 AND 3

statistics ​

Indexes and their columns, one row per indexed column (a non-standard view, as in MySQL). Includes the indexes behind PRIMARY KEY and UNIQUE constraints (but not the rowid).

ColumnMeaning
table_catalog, table_schema, table_namethe table
non_unique0 for a unique index, 1 otherwise
index_namethe index
seq_in_indexposition in the index, from 1
column_namethe column, or NULL for an expression
collationA (ascending) or D (descending)
index_typeBTREE
sql
SELECT table_name, non_unique, index_name, seq_in_index, column_name, collation FROM information_schema.statistics
table_namenon_uniqueindex_nameseq_in_indexcolumn_namecollation
customer0smalt_autoindex_customer_11emailA
orders1orders_by_customer1customer_idA
orders1orders_by_customer2totalD

routines ​

The built-in scalar and aggregate functions. Window-only functions (row_number, lag, …) and table-valued functions (read_csv, …) are not listed.

ColumnMeaning
specific_name, routine_namefunction name
routine_catalog, routine_schemamain
routine_typeFUNCTION or AGGREGATE
is_deterministicNO for functions such as random() and changes(), else YES
routine_bodyEXTERNAL
sql
SELECT routine_name, routine_type, is_deterministic FROM information_schema.routines WHERE routine_name IN ('abs', 'count', 'random')
routine_nameroutine_typeis_deterministic
absFUNCTIONYES
countAGGREGATEYES
randomFUNCTIONNO

The standard parameters view does not exist.

sqlite_schema ​

sqlite_schema (also sqlite_master and smalt_schema) is the catalog table, with SQLite's columns. It cannot be modified directly.

ColumnMeaning
typethe kind of object; see below
nameobject name
tbl_namethe table an index belongs to; for other objects, the name itself
rootpagefirst page of the object's B+tree; 0 for views, external tables and connections
sqlthe CREATE statement as written; NULL for constraint indexes
typeObject
tablea table, including internal smalt_* tables (statistics, materialized view metadata)
indexan index, including smalt_autoindex_* constraint indexes
viewa view
matviewa materialized view (smaltdb)
externalan external table (smaltdb)
connectiona connection (smaltdb)
sql
SELECT type, name, tbl_name, rootpage > 0 AS has_pages, sql IS NOT NULL AS has_sql
FROM sqlite_schema WHERE name NOT LIKE 'smalt\_%' ESCAPE '\' OR type = 'index'
typenametbl_namehas_pageshas_sql
tablecustomercustomer11
indexsmalt_autoindex_customer_1customer10
tableordersorders11
indexorders_by_customerorders11
viewbig_ordersbig_orders01
matvieworder_totalsorder_totals11
connectionapiapi01
externalratesrates01

For an external table created without a column list, sql is a rewritten statement that includes the inferred columns.

TEMP objects are not in sqlite_schema. As in SQLite, temp.sqlite_schema (also temp.sqlite_master, sqlite_temp_schema and sqlite_temp_master) lists them, with the same columns, in creation order: TEMP tables, their indexes and TEMP views. Their rootpage is the page in the in-memory store that holds TEMP objects, and their sql is the statement as written.

MIT License