The "insertRecords" action inserts one or more records into a table.
Request examples
Insert into test1 table using objects
{
"requestId": "1",
"api": "db",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "test1",
"dataFormat": "objects",
"fixedLengthCharFormat": "sql",
"sourceData": [
{
"name": "test name 1"
},
{
"name": "test name 2"
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Insert into test1 table using an array of arrays
{
"requestId": "2",
"api": "db",
"action": "insertRecords",
"params": {
"tableName": "test1",
"dataFormat": "arrays",
"fixedLengthCharFormat": "sql",
"fieldNames": [
"name"
],
"sourceData": [
[
"test name 3"
],
[
"test name 4"
]
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Insert into athlete table
{
"api": "db",
"apiVersion": "1.0",
"requestId": "3",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"tableName": "athlete",
"dataFormat": "objects",
"fixedLengthCharFormat": "sql",
"sourceData": [
{
"name": "Michael Jordan",
"ranking": 1,
"birthDate": "19630217",
"playerNumber": 23,
"livedPast2000": true,
"earnings": 1700000000,
"favoriteSaying": "There is no 'i' in team but there is in win."
},
{
"name": "Babe Ruth",
"ranking": 2,
"birthDate": "18950206",
"playerNumber": 3,
"livedPast2000": false,
"earnings": 800000,
"favoriteSaying": "Every strike brings me closer to the next home run."
},
{
"name": "Muhammad Ali",
"ranking": 3,
"birthDate": "19420117",
"playerNumber": 1,
"livedPast2000": true,
"earnings": 60000000,
"favoriteSaying": "Float like a butterfly, sting like a bee."
},
{
"name": "Pele",
"ranking": 4,
"birthDate": "19401023",
"playerNumber": 10,
"livedPast2000": true,
"earnings": 115000000,
"favoriteSaying": "Everything is practice."
},
{
"name": "Wayne Gretzky",
"ranking": 5,
"birthDate": "19610126",
"playerNumber": 99,
"livedPast2000": true,
"earnings": 1720000,
"favoriteSaying": "You miss 100 percent of the shots you never take."
},
{
"name": "Michael Schumacher",
"ranking": 6,
"birthDate": "19690103",
"playerNumber": 1,
"livedPast2000": true,
"earnings": 990000000,
"favoriteSaying": "Once something is a passion, the motivation is there."
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Insert into all_types table
{
"requestId": "4",
"api": "db",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "all_types",
"dataFormat": "objects",
"binaryFormat": "hex",
"fixedLengthCharFormat": "sql",
"sourceData": [
{
"nested_json_object_or_array": {
"hello": "world"
},
"boolean_byte": true,
"signed_int8": -128,
"signed_int16": -32768,
"signed_int32": -2147483648,
"signed_int64": -9223372036854776000,
"ieee_base2float32": -0.000001,
"ieee_base2float64": "-9223372036800000000.0",
"signed32digits_base10_left32right0": "-12345678901234567890123456789012",
"signed32digits_base10_left0right32": "-0.12345678901234567890123456789012",
"signed32digits_base10_left20right12": "-12345678901234567890.123456789012",
"signed32digits_base10_left30right2": "-123456789012345678901234567890.12",
"signed32digits_base10_left28right4": "-1234567890123456789012345678.9012",
"date_yyyymmdd": "2023-04-18",
"time_hhmmssfff": "15:43:59.013",
"datetime_yyyymmddthhmmssfff": "2023-04-18T15:43:59.013",
"fixed_string_10bytes": "_ 3456 _",
"variable_string_up_to_max65500bytes": "Variable-length string up to 65,500 bytes.",
"variable_string_up_to_2GB": "Variable-length string up to 2GB in length.",
"fixed_binary_10bytes": "FF00FF",
"variable_binary_up_to_max65500bytes": "FF00FF",
"variable_binary_up_to_2GB": "FF00FF"
}
]
},
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string",
"variantFormat": "variantObject"
},
"apiVersion": "1.0",
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
Insert into test1 table because of an incorrect field name failure
{
"result": {
"dataFormat": "objects",
"binaryFormat": "hexadecimal",
"fields": [
{
"name": "id",
"type": "bigint",
"length": null,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": false,
"primaryKey": 1
},
{
"name": "changeId",
"type": "bigint",
"length": null,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": true,
"primaryKey": 0
},
{
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": true,
"primaryKey": 0
}
],
"data": []
},
"requestId": "1",
"errorCode": 4014,
"errorMessage": "field 'BOGUS' does not belong to the table",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Successfully inserted into test1 table
{
"result": {
"dataFormat": "objects",
"binaryFormat": "hex",
"fields": [
{
"name": "id",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 1,
"autoValue": "incrementOnInsert"
},
{
"name": "changeId",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "changeId"
},
{
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
}
],
"data": [
{
"changeId": 1289789,
"id": 1,
"name": "test name 1"
},
{
"changeId": 1289789,
"id": 2,
"name": "test name 2"
}
],
"primaryKeyFields": [
"id"
],
"changeIdField": "changeId"
},
"requestId": "1",
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Insert into all_types table
{
"result": {
"dataFormat": "objects",
"binaryFormat": "hex",
"fields": [
{
"name": "id",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 1,
"autoValue": "incrementOnInsert"
},
{
"name": "changeId",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "changeId"
},
{
"name": "nested_json_object_or_array",
"type": "json",
"length": 65500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "boolean_byte",
"type": "bit",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int8",
"type": "tinyint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int16",
"type": "smallint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int32",
"type": "integer",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int64",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "ieee_base2float32",
"type": "real",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "ieee_base2float64",
"type": "float",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left32right0",
"type": "number",
"length": 32,
"scale": 0,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left0right32",
"type": "number",
"length": 32,
"scale": 32,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left20right12",
"type": "number",
"length": 32,
"scale": 12,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left30right2",
"type": "money",
"length": 32,
"scale": 2,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left28right4",
"type": "money",
"length": 32,
"scale": 4,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "date_yyyymmdd",
"type": "date",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "time_hhmmssfff",
"type": "time",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "datetime_yyyymmddthhmmssfff",
"type": "timestamp",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "fixed_string_10bytes",
"type": "char",
"length": 10,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_string_up_to_max65500bytes",
"type": "varchar",
"length": 65500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_string_up_to_2GB",
"type": "lvarchar",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "fixed_binary_10bytes",
"type": "binary",
"length": 10,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_binary_up_to_max65500bytes",
"type": "varbinary",
"length": 65500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_binary_up_to_2GB",
"type": "lvarbinary",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
}
],
"data": [
{
"boolean_byte": true,
"changeId": "1293834",
"date_yyyymmdd": "2023-04-18",
"datetime_yyyymmddthhmmssfff": "2023-04-18T15:43:59.013",
"fixed_binary_10bytes": "FF00FF00000000000000",
"fixed_string_10bytes": "_ 3456 _",
"id": "1",
"ieee_base2float32": "-1e-06",
"ieee_base2float64": "-9.22337e+18",
"nested_json_object_or_array": {
"hello": "world"
},
"signed32digits_base10_left0right32": "-0.12345678901234567890123456789012",
"signed32digits_base10_left20right12": "-12345678901234567890.123456789012",
"signed32digits_base10_left28right4": "-1234567890123456789012345678.9012",
"signed32digits_base10_left30right2": "-123456789012345678901234567890.12",
"signed32digits_base10_left32right0": "-12345678901234567890123456789012",
"signed_int16": "-32768",
"signed_int32": "-2147483648",
"signed_int64": "-9223372036854775808",
"signed_int8": "-128",
"time_hhmmssfff": "15:43:59.013",
"variable_binary_up_to_2GB": "FF00FF",
"variable_binary_up_to_max65500bytes": "FF00FF",
"variable_string_up_to_2GB": "Variable-length string up to 2GB in length.",
"variable_string_up_to_max65500bytes": "Variable-length string up to 65,500 bytes."
}
],
"primaryKeyFields": [
"id"
],
"changeIdField": "changeId"
},
"requestId": "4",
"debugInfo": {
"request": {
"api": "db",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "all_types",
"dataFormat": "objects",
"binaryFormat": "hex",
"variantFormat": "variantObject",
"sourceData": [
{
"nested_json_object_or_array": {
"hello": "world"
},
"boolean_byte": true,
"signed_int8": -128,
"signed_int16": -32768,
"signed_int32": -2147483648,
"signed_int64": -9223372036854776000,
"ieee_base2float32": -0.000001,
"ieee_base2float64": "-9223372036800000000.0",
"signed32digits_base10_left32right0": "-12345678901234567890123456789012",
"signed32digits_base10_left0right32": "-0.12345678901234567890123456789012",
"signed32digits_base10_left20right12": "-12345678901234567890.123456789012",
"signed32digits_base10_left30right2": "-123456789012345678901234567890.12",
"signed32digits_base10_left28right4": "-1234567890123456789012345678.9012",
"date_yyyymmdd": "2023-04-18",
"time_hhmmssfff": "15:43:59.013",
"datetime_yyyymmddthhmmssfff": "2023-04-18T15:43:59.013",
"fixed_string_10bytes": "_ 3456 _",
"variable_string_up_to_max65500bytes": "Variable-length string up to 65,500 bytes.",
"variable_string_up_to_2GB": "Variable-length string up to 2GB in length.",
"fixed_binary_10bytes": "FF00FF",
"variable_binary_up_to_max65500bytes": "FF00FF",
"variable_binary_up_to_2GB": "FF00FF"
}
]
},
"apiVersion": "1.0",
"requestId": "4",
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string",
"variantFormat": "variantObject"
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
},
"serverSuppliedValues": {
"databaseName": "ctreeSQL",
"ownerName": "admin"
},
"errorData": {
"errorData": null
},
"warnings": []
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Properties
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
binaryFormat |
The "binaryFormat" property designates the format of binary values embedded in JSON strings. For more details, see "binaryFormat". |
Optional with default of "hex"
|
string | One of the following: "base64", "hex", or "byteArray". |
databaseName |
The You specify this property when you want to use a different database 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 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 |
dataFormat |
The There are three different (but similar) versions of the "dataFormat" property:
Two of those versions occur in a request, and another occurs in a response. They all indicate how data is formatted.
|
Optional with default of "arrays"
|
string |
|
fieldNames |
The
|
Optional with default of When |
array | 1 to 64 bytes |
fixedLengthCharFormat |
The
For more details, see |
Optional with default "sql"
|
string |
|
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 |
sourceData |
The "sourceData" property contains source data for an insert or update operation |
Optional with default of []
|
array | An array of arrays or an array of objects |
tableName |
The See table name in System limits for the table naming requirements and limitations.
"params": {
"tableName": "ctreeTable"
} |
Required - No default value | string | 1 to 64 bytes |
Response properties ("result")
| Property | Description | Type | Limits (inclusive) |
|---|---|---|---|
binaryFormat |
The "binaryFormat" property designates the format of binary values embedded in JSON strings. See binaryFormat for more details. |
string | One of the following: "base64", "hex", or "byteArray". |
changeIdField |
This property's value designates the name of the field used for change-tracking functionality if you are not using the
However, if you use the name |
string | 1 to 64 bytes |
data |
The |
array of objects | The action determines its contents. |
|
data .changeId |
The "changeId" property specifies a unique, server-generated id. When this property is present, the database compares the value of "changeId" to the current transaction number stored in the "changeId" field of the record. This ensures an update does not modify a record that has subsequently been modified by another operation. |
integer | No limit |
|
data .id |
The |
integer |
|
|
data .name |
The The The
|
string | 1 to 64 bytes |
dataFormat |
The
|
string |
|
fields |
The
"fields": [
{
"autoValue": "none",
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"defaultValue": null,
"nullable": false
}
] |
array |
updateRecords and deleteRecords only:
|
|
fields .autoValue |
The "autoValue" property indicates when and how the server automatically sets the field value. See autoValue for more details. |
string |
Some actions only:
|
|
fields .defaultValue |
The "defaultValue" property specifies the field's default value. |
string | 0 to 65,500 bytes |
|
fields .length |
The "length" property identifies the length of the field. |
integer |
1 to 65500 |
|
fields .name |
The The The |
string | 1 to 64 bytes |
|
fields .nullable |
The "nullable" property identifies whether a field can contain a NULL value. |
Boolean |
|
|
fields .primaryKey |
The |
integer |
0 to 32
|
|
fields .scale |
The The value of A scale of The You may optionally use the |
integer |
0 to 32
|
|
fields .type |
The "type" property specifies the field's data type. See Data types for the limits, valid values, and whether "length" and "scale" are required. |
string |
|
primaryKeyFields |
The "primaryKeyFields" property specifies the fields to use for the table’s primary key. For more details, see "primaryKeyFields". |
array of strings | ["field1", …,"fieldN"] |