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
Option | Description | Possible Values | Mandatory |
---|---|---|---|
IF NOT EXISTS | If specified, the view will only be created if it does not already exist. | N/A | Optional |
view_name | The name of the view to be created. | String | Yes |
query | The SQL query that will be executed when the view is called. | Valid SQL query | Yes |
COMMENT | A brief description of what the view does. | String | Optional |
Parameter Types
Parameter Type | Description | Possible Values | Sample Value |
---|---|---|---|
String | A string parameter. | String | 'example' |
Int | An integer parameter. | Integer | 42 |
Float | A floating-point parameter. | Float | 3.14 |
Boolean | A boolean parameter. | true , false | true |
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
id | name | query | parameters | schema | description |
---|---|---|---|---|---|
739c4f80-9e6c-48d0-9b3e-246ecc3ec54a | semantics_tool | SELECT content FROM pretty_print((SELECT * FROM semantics(1))) | [] | {"content":"String"} | NULL |
4151b09e-995b-40e2-9cb2-3ca2b370751f | models_count | SELECT COUNT(*) FROM langdb.models | [] | {"COUNT()":"UInt64"} | Count of models in the database |