Skip to content

Latest commit

 

History

History
128 lines (96 loc) · 4.86 KB

SQL-Create-Property.adoc

File metadata and controls

128 lines (96 loc) · 4.86 KB

SQL - CREATE PROPERTY

edit

Creates a new property in the schema. It requires that the type for the property already exist on the database.

Syntax

CREATE PROPERTY
<type>.<property> [IF NOT EXISTS] <data-type> [OF <embd-type>]
[<property-constraint>[,]*]
  • <type> Defines the type for the new property.

  • <property> Defines the logical name for the property.

  • <data-type> Defines the property data type. For supported types, see the table below.

  • <embd-type> Defines the property’s embedded type (only for embedding property types EMBEDDED, LIST, MAP, as well as LINK).

  • <property-constraint> See ALTER PROPERTY <attribute-name> * <attribute-value>

    • mandatory <true|false> If true, the property must be present. Default is false

    • notnull <true|false> If true, the property, if present, cannot be null. Default is false

    • readonly <true|false> If true, the property cannot be changed after the creation of the record. Default is false

    • hidden <true|false> If true, the property is not added to the result set when using * in projections such as in SELECT * FROM; it is included when SELECT FROM is used or if the hidden property is part of the projection list . Default is false

    • min <number|string> Defines the minimum value for this property. For number types it is the minimum number as a value. For strings it represents the minimum number of characters. For dates is the minimum date (uses the database date format). For collections (lists, sets, maps) this attribute determines the minimally required number of elements.

    • max <number|string> Defines the maximum value for this property. For number types it is the maximum number as a value. For strings it represents the maximum number of characters. For dates is the maximum date (uses the database date format). For collections (lists, sets, maps) this attribute determines the maximally allowed number of elements.

    • regexp <string> Defines the mask to validate the input as a Regular Expression

    • default <any> Defines default value if not present. Default is null.

    • IF NOT EXISTS If specified, create the property only if not exists. If a property with the same name already exists in the type, then no error is returned

Note
When you create a property, ArcadeDB checks the data for property and type. In the event that persistent data contains incompatible values for the specified type, the property creation fails. It applies no other constraints on the persistent data.
Note
When constraints are set, such as mandatory, read-only, etc., it’s not possible to use the Gremlin syntax to add vertices and edges without incurring in a Validation exception. The issue is that Gremlin API sets the properties after the creation of the vertex and edge.
Note
Properties of the type LINK may have the value NULL, furthermore accessing a LINK property which is not set results also in a NULL value.

Examples

  • Create the property name of the string type in the type User:

ArcadeDB> CREATE PROPERTY User.name STRING
  • Create a property called tags in the type Profile only allowing list members of type string:

ArcadeDB> CREATE PROPERTY Profile.tags LIST OF STRING
  • Create the property friends, as an embedded map:

ArcadeDB> CREATE PROPERTY Profile.friends MAP
  • Create the property address, as an embedded document:

ArcadeDB> CREATE PROPERTY Profile.address EMBEDDED
  • Create the property createdOn of type date with additional constraints:

ArcadeDB> CREATE PROPERTY Transaction.createdOn DATE (mandatory true, notnull true, readonly true, min "2010-01-01")
  • Create the property secret of type string with hidden constraint:

ArcadeDB> CREATE PROPERTY Employee.secret STRING (hidden true, notnull true)
  • Create the property salary only if it does not exist:

ArcadeDB> CREATE PROPERTY Employee.salary IF NOT EXISTS double
  • Create the property hiredAt with the time of creation being the default value:

ArcadeDB> CREATE PROPERTY Employee.hiredAt DATETIME (readonly, default sysdate('YYYY-MM-DD HH:MM:SS'))

For more information, see:

Supported Types

ArcadeDB supports the following data types for standard properties:

BOOLEAN

BYTE

SHORT

INTEGER

LONG

STRING

LINK

BINARY

DATE

DATETIME

FLOAT

DOUBLE

DECIMAL

It supports the following data types for container properties:

LIST

MAP

EMBEDDED