Skip to main content

CREATE VIRTUAL TABLE

The CREATE VIRTUAL TABLE statement creates a table whose contents are computed on-the-fly by a module rather than stored in the database file. Virtual tables provide a SQL interface over external data sources, custom generators, and table-valued functions.

Syntax

Description

A virtual table delegates row storage and retrieval to a module. The module determines what columns the table has, what data it returns, and how queries against it are optimized. Virtual tables can be queried with SELECT just like regular tables, but they cannot be targets of INSERT, UPDATE, or DELETE unless the module implements write support.

Clauses

Available Modules

csv

The csv module reads data from a CSV file and exposes its contents as a read-only table. Load the csv extension first with load_extension('csv').

generate_series

The generate_series module is a built-in table-valued function that produces a sequence of integer values. It does not require an extension to be loaded. The generate_series module can be used either as a virtual table or as a table-valued function in the FROM clause.

Examples

Read a CSV File

Generate a Sequence of Integers

Generate a Date Series with generate_series

See Also