Defining an Interface View¶
Interface views are a special type of derived views that consist only of a definition of fields and a reference to another view. You can use them to do a top-down design where you first define the fields of the interface and later, you set the “implementation view” of the interface.
When the Server executes a query that involves the interface, the query is delegated to the implementation view.
Interface views are created with the statement CREATE INTERFACE VIEW
.
CREATE [ OR REPLACE ] INTERFACE VIEW <name:identifier>
( <field> [, <field> ]* )
[ SET IMPLEMENTATION <view identifier>
[ ( <field name:identifier> = <expression:value>
[, <field name:identifier> = <expression:value> ]* )
]
]
[ FOLDER = <literal> ]
[ DESCRIPTION = <literal> ]
[ <tag list> ]
<view identifier> ::= (see Basic elements of VQL statements)
<field> ::= (see Syntax of the statement CREATE TABLE)
<tag list> ::= (see Syntax of the statement CREATE TABLE)
For example,
CREATE INTERFACE VIEW i_order (
id:long,
customer_id:long,
status:text,
order_date:timestamp,
comment:text
)
SET IMPLEMENTATION order
FOLDER = '/Interface views';
This statement creates an interface view with the fields id
,
customer_id
, status
and order_date
and sets order
as the
implementation view (SET IMPLEMENTATION
clause). With this syntax,
the interface view (i_order
) and its implementation
(order
) must have the same number of fields and with the same
name.
To create an interface view whose implementation view does not match the definition of the interface, you have to define an expression for each field of the interface. For example,
CREATE OR REPLACE INTERFACE VIEW i_order (
id:long,
customer_id:long,
status:text,
order_date:timestamp
)
SET IMPLEMENTATION order (
id = id,
customer_id = customer_id,
status = coalesce(status, '<NEW ORDER>'),
order_date = order_date
)
FOLDER = '/Interface views';
In this example, the status
field of the interface is mapped to an
expression instead of just a field.
Also, the view order
has more fields and they are not taken into account
in the definition of the interface.
To modify the definition of an interface view or
change its implementation, use the ALTER INTERFACE VIEW
statement.
ALTER INTERFACE VIEW <name:identifier>
[ ( <field name:identifier> : <field type>
[, <field name:identifier> : <field type> ]* ) ]
[ SET IMPLEMENTATION <view identifier>
[ ( <field name:identifier> = <expression:value>
[, <field name:identifier> = <expression:value> ]* )
]
]
<view identifier> ::= (see Basic elements of VQL statements)
For example,
ALTER INTERFACE VIEW i_order (
id:long
, customer_id:long
, status:text
)
SET IMPLEMENTATION another_view;
This statement removes the field order_date
from the definition of the
interface and changes the implementation view of the interface.
To delete an interface view use the statement DROP INTERFACE VIEW
(see Syntax of the DROP statement).
To modify other properties of an interface view, use the statement ALTER VIEW
as with derived views. Examples:
To rename an interface view:
ALTER VIEW i_order RENAME i_order_full;
To add/change the description of a field of an interface view:
ALTER VIEW i_order (
ALTER COLUMN id ADD (DESCRIPTION = 'A unique id of the order')
ALTER COLUMN STATUS ADD (DESCRIPTION = 'The values of this column are: NEW, ACCEPTED, PACKAGING or SENT'));
To move an interface view to a folder:
ALTER FOLDER '/customer360' MOVE VIEW i_order;