Skip to main content

CREATE VIEW

The CREATE VIEW statement is used to define a new view for executing a specific query with optional parameters.

Syntax

CREATE VIEW [IF NOT EXISTS] view_name() 
AS query
[COMMENT 'view_description'];

Options

OptionDescriptionPossible ValuesMandatory
IF NOT EXISTSIf specified, the view will only be created if it does not already exist.N/AOptional
view_nameThe name of the view to be created.StringYes
queryThe SQL query that will be executed when the view is called.Valid SQL queryYes
COMMENTA brief description of what the view does.StringOptional

Parameter Types

Parameter TypeDescriptionPossible ValuesSample Value
StringA string parameter.String'example'
IntAn integer parameter.Integer42
FloatA floating-point parameter.Float3.14
BooleanA boolean parameter.true, falsetrue

Example

Here is an example of a CREATE VIEW statement:

CREATE VIEW IF NOT EXISTS models_count()
AS SELECT COUNT(*) FROM langdb.models
COMMENT 'Count of models in the database';

SELECT * FROM langdb.views
idnamequeryparametersschemadescription
739c4f80-9e6c-48d0-9b3e-246ecc3ec54asemantics_toolSELECT content FROM pretty_print((SELECT * FROM semantics(1)))[]{"content":"String"}NULL
4151b09e-995b-40e2-9cb2-3ca2b370751fmodels_countSELECT COUNT(*) FROM langdb.models[]{"COUNT()":"UInt64"}Count of models in the database