Skip to content

SQL API

A SQL-like interface for developers who prefer relational-style queries.


OperationJWTAPI Key (read)API Key (write)API Key (admin)
SELECTYesYesYesYes
INSERT/UPDATE/DELETEYesNoYesYes
CREATE/ALTER/DROP TABLEYesNoNoYes

Executes a SQL query (SELECT, INSERT, UPDATE, DELETE).

Request:

{
"sql": "SELECT * FROM users WHERE id = ?",
"parameters": {
"id": "user_123"
},
"limit": 100,
"pageToken": null
}
FieldTypeRequiredDescription
sqlstringYesSQL statement to execute
parametersobjectNoNamed parameters for the query
limitintegerNoMax rows to return
pageTokenstringNoPagination token from previous response

Response (200 OK):

{
"rows": [
{
"id": "user_123",
"name": "John Doe",
"email": "john@example.com"
}
],
"rowCount": 1,
"columns": [
{ "name": "id", "type": "text" },
{ "name": "name", "type": "text" },
{ "name": "email", "type": "text" }
],
"nextPageToken": null,
"executionTimeMs": 15
}

Executes a DDL statement (CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX, DROP INDEX).

Request:

{
"sql": "CREATE TABLE users (id TEXT, name TEXT, email TEXT, PRIMARY KEY (id))"
}

Response (200 OK):

{
"success": true,
"message": "Table 'users' created successfully",
"affectedRows": 0
}

Lists all tables in the database.

Response (200 OK):

{
"tables": [
{
"name": "users",
"rowCount": 1500,
"createdAt": "2024-01-15T10:00:00Z"
},
{
"name": "orders",
"rowCount": 5200,
"createdAt": "2024-01-15T10:05:00Z"
}
]
}

GET /databases/{databaseId}/sql/tables/{tableName}/schema

Section titled “GET /databases/{databaseId}/sql/tables/{tableName}/schema”

Gets the schema of a specific table.

Response (200 OK):

{
"tableName": "users",
"columns": [
{
"name": "id",
"type": "text",
"isPartitionKey": true,
"isClusteringKey": false,
"isNullable": false,
"defaultValue": null
},
{
"name": "name",
"type": "text",
"isPartitionKey": false,
"isClusteringKey": false,
"isNullable": true,
"defaultValue": null
}
],
"primaryKey": {
"partitionKeys": ["id"],
"clusteringKeys": []
},
"indexes": [
{
"name": "users_email_idx",
"columns": ["email"],
"isUnique": false
}
]
}

SQL TypeDescription
VARCHAR, TEXT, STRINGUTF-8 string
INT, INTEGER32-bit signed integer
BIGINT, LONG64-bit signed integer
SMALLINT, SHORT16-bit signed integer
TINYINT, BYTE8-bit signed integer
FLOAT, REAL32-bit IEEE-754 floating point
DOUBLE64-bit IEEE-754 floating point
DECIMAL, NUMERICVariable-precision decimal
BOOLEAN, BOOLTrue/false value
DATEDate without time
TIMETime without date
TIMESTAMP, DATETIMEDate and time
BLOB, BINARYBinary data
UUID, GUIDUUID value
TIMEUUIDTime-based UUID
LIST<T>Ordered collection (e.g., LIST<TEXT>)
SET<T>Unique collection (e.g., SET<INT>)
MAP<K,V>Key-value collection (e.g., MAP<TEXT,INT>)

CREATE TABLE products (
category TEXT,
product_id TEXT,
name TEXT,
price DECIMAL,
in_stock BOOLEAN,
tags SET<TEXT>,
PRIMARY KEY (category, product_id)
)
INSERT INTO products (category, product_id, name, price, in_stock)
VALUES ('electronics', 'prod_001', 'Wireless Mouse', 29.99, true)
SELECT name, price FROM products
WHERE category = 'electronics' AND product_id > 'prod_000'
ORDER BY product_id
LIMIT 10
UPDATE products SET price = 24.99, in_stock = false
WHERE category = 'electronics' AND product_id = 'prod_001'
DELETE FROM products
WHERE category = 'electronics' AND product_id = 'prod_001'
CREATE INDEX products_name_idx ON products (name)

FeatureStatus
JOIN operationsNot Supported
SubqueriesNot Supported
GROUP BYNot Supported
Aggregate functionsCOUNT only
Complex expressions in SELECTNot Supported
WHERE on non-indexed columnsLimited
ORDER BYClustering columns only

CodeDescription
SQL_SYNTAX_ERRORSQL statement has syntax errors
SQL_VALIDATION_ERRORSQL is valid but violates constraints
ACCESS_DENIEDUser lacks permission for this operation
TABLE_NOT_FOUNDReferenced table does not exist
DATABASE_NOT_FOUNDDatabase ID is invalid
SQL_EXECUTION_ERRORError during query execution

Error Response (400 Bad Request):

{
"code": "SQL_SYNTAX_ERROR",
"message": "Unexpected token at position 15",
"details": "Expected FROM keyword"
}

Terminal window
# Create table
curl -X POST "https://api.terrascale.io/databases/my-db/sql/execute" \
-H "Authorization: Bearer ts_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"sql": "CREATE TABLE users (id TEXT, name TEXT, PRIMARY KEY (id))"
}'
# Insert data
curl -X POST "https://api.terrascale.io/databases/my-db/sql/query" \
-H "Authorization: Bearer ts_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"sql": "INSERT INTO users (id, name) VALUES ('\''user_1'\'', '\''John'\'')"
}'
# Query data
curl -X POST "https://api.terrascale.io/databases/my-db/sql/query" \
-H "Authorization: Bearer ts_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"sql": "SELECT * FROM users WHERE id = ?",
"parameters": { "id": "user_1" }
}'

Good for:

  • Interactive data exploration
  • Ad-hoc queries
  • Admin tools
  • Developers with SQL background
  • Prototyping

Consider Custom API for:

  • Production applications
  • Performance-critical code
  • Full feature access
  • Type safety