Skip to main content
Create and manage tables using DDL operations.

Create Table

:CREATE TABLE Entity WITH column:TYPE, column:TYPE:CONSTRAINT

Basic Table

:CREATE TABLE User WITH id:AUTO, name:STRING, email:STRING
DatabaseOutput
PostgreSQLCREATE TABLE users (id SERIAL, name VARCHAR, email VARCHAR)
MySQLCREATE TABLE users (id INT AUTO_INCREMENT, name VARCHAR(255), email VARCHAR(255))
MongoDBCreates collection on first insert

Data Types

OmniQL TypePostgreSQLMySQLMongoDB
AUTOSERIALINT AUTO_INCREMENTObjectId
BIGAUTOBIGSERIALBIGINT AUTO_INCREMENTObjectId
INTINTEGERINTInt32
BIGINTBIGINTBIGINTInt64
SMALLINTSMALLINTSMALLINTInt32
STRINGVARCHARVARCHAR(255)String
TEXTTEXTTEXTString
CHARCHARCHARString
BOOLEANBOOLEANBOOLEANBoolean
BOOLBOOLEANBOOLEANBoolean
TIMESTAMPTIMESTAMPTIMESTAMPDate
DATETIMETIMESTAMPDATETIMEDate
DATEDATEDATEDate
TIMETIMETIMEString
JSONJSONJSONObject
JSONBJSONBJSONObject
UUIDUUIDCHAR(36)UUID
DECIMALDECIMALDECIMALDecimal128
NUMERICNUMERICDECIMALDecimal128
FLOATDOUBLE PRECISIONDOUBLEDouble
REALREALFLOATDouble
BINARYBYTEABLOBBinData
BLOBBYTEABLOBBinData

With Size

:CREATE TABLE User WITH id:AUTO, name:STRING(100), description:TEXT

With Constraints

Constraints are added after the type using colons:
:CREATE TABLE User WITH id:AUTO, name:STRING:NOTNULL, email:STRING:UNIQUE
DatabaseOutput
PostgreSQLCREATE TABLE users (id SERIAL, name VARCHAR NOT NULL, email VARCHAR UNIQUE)

Multiple Constraints

:CREATE TABLE User WITH id:AUTO, email:STRING:NOTNULL:UNIQUE

Complete Example

:CREATE TABLE User WITH
  id:AUTO,
  email:STRING:NOTNULL:UNIQUE,
  name:STRING:NOTNULL,
  active:BOOLEAN,
  created_at:TIMESTAMP

Drop Table

:DROP TABLE User
DatabaseOutput
PostgreSQLDROP TABLE users
MySQLDROP TABLE users
MongoDBdb.users.drop()

Alter Table

Add Column

:ALTER TABLE User ADD name:STRING
DatabaseOutput
PostgreSQLALTER TABLE users ADD COLUMN name VARCHAR

Drop Column

:ALTER TABLE User DROP name

Rename Column

:ALTER TABLE User RENAME name:full_name

Modify Column Type

:ALTER TABLE User MODIFY name:TEXT

Rename Table

:RENAME TABLE User TO Customer
DatabaseOutput
PostgreSQLALTER TABLE users RENAME TO customers
MySQLRENAME TABLE users TO customers

MongoDB Collections

For MongoDB, use COLLECTION instead of TABLE:
:CREATE COLLECTION User
:DROP COLLECTION User

Next Steps