Note The ID index is created automatically during table creation. All other table indexes must be created after the table is created.
Request examples
Create an index on the name field in the test1 table
{
"api": "db",
"requestId": "1",
"action": "createIndex",
"params": {
"tableName": "test1",
"indexName": "name",
"fields": [
{
"name": "name"
}
],
"waitToBeLoaded": true
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Create an index on the ranking field in the athlete table
{
"api": "db",
"apiVersion": "1.0",
"requestId": "2",
"action": "createIndex",
"params": {
"tableName": "athlete",
"indexName": "ranking",
"fields": [
{
"name": "ranking"
}
],
"waitToBeLoaded": true
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Create index on earnings field in athlete table
{
"api": "db",
"apiVersion": "1.0",
"requestId": "3",
"action": "createIndex",
"params": {
"tableName": "athlete",
"indexName": "earnings",
"fields": [
{
"name": "earnings"
}
],
"waitToBeLoaded": true
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Create a filtered index on the name field in the athlete table
This index sorts records by name in descending order and includes only records when the athlete lived past the year 2000. It also uses index compression and collects statistics and is stored in the file admin_athlete_name_livedpast2000.idx.
{
"api": "db",
"apiVersion": "1.0",
"requestId": "4",
"action": "createIndex",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "athlete",
"indexName": "name_livedpast2000",
"isPrimaryIndex": true
"fields": [
{
"name": "name",
"caseInsensitive": true,
"sortDescending": true,
"reverseCompare": true
}
],
"conditionalExpression": "livedpast2000 == 1",
"unique": false,
"immutableKeys": false,
"waitToBeLoaded": true,
"filename": "admin_athlete_name_livedpast2000",
"collectStats": true,
"compression": "auto"
},
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string"
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
Successful index creation on the name field in the test1 table
{
"result": {
"data": {
"collectStats": true,
"compression": "off",
"conditionalExpression": null,
"databaseName": "ctreeSQL",
"deferIndexing": false,
"fields": [
{
"caseInsensitive": false,
"name": "name",
"reverseCompare": false,
"sortDescending": false
}
],
"filename": "admin_test1.idx",
"immutableKeys": false,
"indexName": "name",
"indexNumber": 1,
"ownerName": "admin",
"tableName": "test1",
"unique": false
}
},
"requestId": "1",
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Athlete ranking
{
"result": {
"data": {
"collectStats": true,
"compression": "off",
"conditionalExpression": null,
"databaseName": "ctreeSQL",
"deferIndexing": false,
"fields": [
{
"caseInsensitive": false,
"name": "ranking",
"reverseCompare": false,
"sortDescending": false
}
],
"filename": "admin_athlete.idx",
"immutableKeys": false,
"indexName": "ranking",
"indexNumber": 1,
"ownerName": "admin",
"tableName": "athlete",
"unique": false
}
},
"requestId": "2",
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Athlete earnings
{
"result": {
"data": {
"collectStats": true,
"compression": "off",
"conditionalExpression": null,
"databaseName": "ctreeSQL",
"deferIndexing": false,
"fields": [
{
"caseInsensitive": false,
"name": "earnings",
"reverseCompare": false,
"sortDescending": false
}
],
"filename": "admin_athlete.idx",
"immutableKeys": false,
"indexName": "earnings",
"indexNumber": 2,
"ownerName": "admin",
"tableName": "athlete",
"unique": false
}
},
"requestId": "3",
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Filtered maximal
{
"result": {
"primaryIndexName": “name”,
"data": {
"collectStats": true,
"compression": "on",
"conditionalExpression": "livedpast2000 == 1",
"databaseName": "ctreeSQL",
"deferIndexing": false,
"fields": [
{
"caseInsensitive": true,
"name": "name",
"reverseCompare": true,
"sortDescending": true
}
],
"filename": ".\\ctreeSQL.dbs\\admin_athlete_name_livedpast2000.idx",
"immutableKeys": false,
"indexName": "name_livedpast2000",
"indexNumber": 3,
"ownerName": "admin",
"tableName": "athlete",
"unique": false
}
},
"requestId": "4",
"debugInfo": {
"request": {
"api": "db",
"action": "createIndex",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "athlete",
"indexName": "name_livedpast2000",
"fields": [
{
"name": "name",
"caseInsensitive": true,
"sortDescending": true,
"reverseCompare": true
}
],
"conditionalExpression": "livedpast2000 == 1",
"unique": false,
"immutableKeys": false,
"waitToBeLoaded": true,
"filename": "admin_athlete_name_livedpast2000",
"collectStats": true,
"compression": "auto"
},
"apiVersion": "1.0",
"requestId": "4",
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string"
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
},
"serverSuppliedValues": {
"databaseName": "ctreeSQL",
"ownerName": "admin"
},
"errorData": {
"errorData": null
},
"warnings": []
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Failed index creation because the index already exists
Each index must have a unique name. Attempting to create an index with a previously used name will fail.
{
"requestId": "1",
"errorCode": 4093,
"errorMessage": "Can't add new index to table",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Troubleshooting errors
You cannot modify a table while it is in use. When a table has no activity for a default of 2 seconds, it will be closed so you can modify it.
- When a table is in use, the following actions return an error, such as -8 or 4012:
- "alterTable"
- "rebuildTables"
- "deleteTables"
- "createIndex"
- "deleteIndexes"
- "rebuildIndexes"
- "runSqlStatements"
- A table is in use when any account is performing one or more of the following actions with the table:
- "insertRecords"
- "updateRecords"
- "deleteRecords"
- "truncateRecords"
- "getRecords..."
- Has open cursors on the table.
- Has open transactions on the table (such "createTransaction").
- Modify the SQL_IDLE_WAKE startup configuration setting to change the number of seconds the server waits before closing a table. A larger number keeps the table open longer for better performance. A smaller number allows you to modify the table sooner.
- Modify the SQL_IDLE_WAKE startup configuration setting to change the number of tables the server keeps open after they are no longer being actively used. A larger number caches more tables and improves performance. A smaller number allows you to modify tables sooner.
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
databaseName |
The You specify this property when you want to use a different database instead of the default. This property is useful because objects, such as tables and code packages, can have the same name in multiple databases. This feature allows you to create multiple environments in the same server and reuse the same JSON actions in each environment. For example, you can create It is an error to set If no default database is specified during |
Defaults to the session's "defaultDatabaseName" property |
string | 1 to 64 bytes |
ownerName |
The You specify this property when you want to use a different account instead of the default. Your session's account must have the appropriate privileges to access the code package. This property is useful because objects, such as tables and code packages, can have the same name in the same database as long as different accounts own each object. This feature allows you to create duplicate objects for different users on the same server and reuse the same JSON actions on those objects. For example, an administrator can copy objects from a production environment to her account so she can troubleshoot an issue using the same JSON actions, JavaScript, and SQL code. It is an error to set If no default owner is specified during |
Optional with default of the session's "defaultOwnerName" property |
string | 1 to 64 bytes |
tableName |
The See table name in System specifications for the table naming requirements and limitations.
"params": {
"tableName": "ctreeTable"
} |
Required - No default value | string | 1 to 64 bytes |
indexName |
The "params": {
"indexName": "index1"
} |
Required - No default value |
string | 1 to 64 bytes |
isPrimaryIndex |
The
|
Optional with default of false
|
Boolean |
|
fields |
The
"fields":
[
{
"name": "name",
"caseInsensitive": true,
"sortDescending": true,
"reverseCompare": false
}
] |
Required - No default value |
array of objects |
|
|
fields .name |
The The The
|
Required - No default value | string | 1 to 64 bytes |
|
fields .caseInsensitive |
The When "fields": [
{
"caseInsensitive": true
}
] |
Optional with default of false
|
Boolean |
|
|
fields .sortDescending |
The "fields": [
{
"sortDescending": true
}
] |
Optional with default of false
|
Boolean |
|
|
fields .reverseCompare |
The When "fields": [
{
"reverseCompare": true
}
] |
Optional with default of false
|
Boolean |
|
conditionalExpression |
The
"params": {
"conditionalExpression": "livedpast2000 == 1"
} |
Optional with default of ""
|
string | 0 to 65,535 bytes |
unique |
The "params": {
"unique": true
} |
Optional with default of false
|
Boolean |
|
immutableKeys |
The
"params": {
"immutableKeys": true
} |
Optional with default of false
|
Boolean |
|
waitToBeLoaded |
The
"params": {
"waitToBeLoaded": true
} |
Optional with default of true
|
Boolean |
|
filename |
The
"params": {
"filename": "admin_athlete_name_livedpast2000"
} |
Optional with default of ""
|
string | 0 to 2048 bytes |
collectStats |
The "params": {
"collectStats": true
} |
Optional with default of true
|
Boolean |
|
compression |
The Possible values
"params": {
"compression": "off"
} |
Optional with default of "auto"
|
string |
|
Response properties ("result")
| Property | Description | Type | Limits (inclusive) |
|---|---|---|---|
primaryIndexName |
The “primaryIndexName” property returns the name of the primary key index. If there is none, it returns “”.
|
string | 0 to 256 bytes |
data |
The |
array of objects | The action determines its contents. |
|
data .collectStats |
The “collectStats” property identifies whether usage statistics are being collected and stored. |
boolean |
|
|
data .compression |
The “compression” property identifies whether the index is compressed. |
string |
|
|
data .conditionalExpression |
The “conditionalExpression” property identifies an optional conditional expression that filters which records are included in the index. It is null when there is no conditional expression. |
string |
null or a string containing a conditional expression. |
|
data .databaseName |
The
|
string | 1 to 64 bytes |
|
data .deferIndexing |
“deferindexing” identifies whether deferred indexing is enabled. A deferred index builds and updates asynchronously. This speeds up inserts, updates, and deletes, with a slight delay due to the changes being included in the index. |
boolean |
|
|
data .fields |
The
"fields": [
{
"autoValue": "none",
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"defaultValue": null,
"nullable": false, |
array |
updateRecords and deleteRecords only:
|
|
data .fields .caseInsensitive |
The When "fields": [
{
"caseInsensitive": true
}
] |
Boolean |
|
|
data .fields .name |
The The The
|
string | 1 to 64 bytes |
|
data .fields .reverseCompare |
The When "fields": [
{
"reverseCompare": true
}
] |
Boolean |
|
|
data .fields .sortDescending |
The "fields": [
{
"sortDescending": true
}
] |
Optional with default of false
|
Boolean |
|
data .filename |
The
|
string | 0 to 2048 bytes |
|
data .immutableKeys |
"immutableKeys" indicates whether a key's value can be changed. |
boolean |
|
|
data .indexName |
The "params": {
"indexName": "index1"
} |
Required - No default value |
string |
|
data .ownerName |
The "ownerName" property identifies the user who owns an object (see Object owner). |
string | 0 to 64 bytes |
|
data .tableName |
The See table name in System specifications for the table naming requirements and limitations. |
string | 1 to 64 bytes |
|
data .unique |
The "unique" property causes the "createIndex" action to create a unique index, which requires the columns in the index to have a unique value for each record in the table, when set to true. |
Boolean |
|