I´m trying to create a table (collection container) using GridDB Cloud, using a Python script, as shown in GridDB Developers Quick Start Guide, available here. The script runs fine, but with the exception of the primary key column (Order_ID), all other columns have their nullity set to NULL. I´d like to be able to set all columns to NOT NULL. Any ideas?
The Python script that drops and then creates the Orders table is shown below:
#CreateOrderTable.py
import requests
import json
# Set table name
tableName = "Orders"
# URL and authentication
url = "https://cloud5197.griddb.com:443/griddb/v2/gs_clustermfcloud5197/dbs/s4Rqrm4g/containers"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic **************************',
'User-Agent': 'PostmanRuntime/7.29.0'
}
# If table exists, drop it...
payload = json.dumps([
tableName
])
response = requests.request("DELETE", url, headers=headers, data=payload)
print("Drop table result: ", response.status_code)
# Create table Order
payload = json.dumps({
"container_name": tableName,
"container_type": "COLLECTION",
"rowkey": True,
"columns": [
{
"name": "Order_ID",
"type": "INTEGER",
},
{
"name": "Order_Date",
"type": "TIMESTAMP",
},
{
"name": "Client_ID",
"type": "INTEGER",
},
{
"name": "Order_NF",
"type": "STRING"
}
]
})
response = requests.request("POST", url, headers=headers, data=payload)
print("Create table result: ", response.status_code)
It seems that GridDB´s REST API doesn't currently support a key-value pair to set a column´s nullity, such as "nullable": False. A workaround for that is to use the query editor of GridDB´s management website to create the table, using a regular CREATE TABLE SQL statement:
Create table Orders (
Order_ID INTEGER NOT NULL PRIMARY KEY,
Order_Date TIMESTAMP NOT NULL,
Client_ID INTEGER NOT NULL,
Order_NF STRING NOT NULL)