Identifiers
Identifiers are the names you give to database objects: tables, vertex and edge tables, columns, indexes, constraints, views, serials, triggers, stored procedures and users.
Rules for plain identifiers
Section titled “Rules for plain identifiers”A name written without quotes must follow these rules:
- It starts with a letter, an underscore (
_) or a number sign (#). It cannot start with a digit. - The other characters can be letters, digits,
_and#. - Letters can be any Unicode letters, not only
A–Z:preț_produsis a valid name. - It cannot contain spaces or operator characters (
+ - * / % || ! < > = | ^ & ~). - It cannot be a reserved word.
identifier ::= first_character [ other_character ... ]first_character ::= letter | _ | #other_character ::= letter | digit | _ | #Valid names:
order_itemsssn#_staging#tmp_orderspreț_produsInvalid names, unless quoted:
2fer -- starts with a digitlow cost -- contains a spaceprice+tax -- contains an operator characterorder -- reserved wordUsing a reserved word as a plain name is a syntax error:
SELECT order FROM orders;ERROR: Syntax error: unexpected 'order'Case-insensitivity
Section titled “Case-insensitivity”Identifiers are not case-sensitive: Mixed_Case, mixed_case and MIXED_CASE are the same table. CoraDB stores and displays names in lowercase. This also applies to quoted names.
Quoted identifiers
Section titled “Quoted identifiers”Enclose a name in double quotes ("), square brackets ([ ]) or backticks (`) to use a name that the rules above would not allow, such as a reserved word, a name with spaces or a name starting with another symbol. The three forms are interchangeable:
CREATE TABLE "low cost" ("select" INT, [position] INT, `order` INT, "@lowcost" INT);INSERT INTO "low cost" VALUES (1, 2, 3, 4);
SELECT "select", [position], `order`, "@lowcost" FROM [low cost];| select | position | order | @lowcost |
|---|---|---|---|
| 1 | 2 | 3 | 4 |
A reserved word used as a column name does not need quotes when it is qualified with the table name or alias:
SELECT t.select, t.position FROM "low cost" t;You also need quotes for names that contain a hyphen, such as the database name in the result column of SHOW TABLES on the e-commerce database: [Tables_in_e-commerce].
Quoting identifiers that do not need it is harmless, but quoted names are harder to read and type. Prefer plain names in snake_case that avoid reserved words.
Maximum length
Section titled “Maximum length”The maximum length of a name is counted in bytes, not characters. In UTF-8, letters outside the ASCII range take 2 to 4 bytes, so a name made of such letters can hold fewer characters.
| Object | Maximum length |
|---|---|
| Database | 17 bytes |
| Table, vertex table, edge table, view | 254 bytes |
| Column | 254 bytes |
| Index, constraint | 254 bytes |
| Serial | 254 bytes |
| Trigger | 254 bytes |
| Java stored procedure | 254 bytes |
The names CoraDB generates for constraints, such as pk_<table>_<column> for a primary key or fk_<table>_<column> for a foreign key, are subject to the same limit. With long table and column names, give such constraints an explicit, shorter name.