PostgreSQL Compatibility
CockroachDB is compatible with version 3.0 of the PostgreSQL wire protocol (pgwire) and works with the majority of PostgreSQL database tools. This means that existing applications built on PostgreSQL can often be migrated to CockroachDB without changing application code.What’s Supported
CockroachDB supports:- PostgreSQL wire protocol: Connect using any PostgreSQL-compatible driver or tool
- Standard SQL syntax: Most PostgreSQL SQL statements work in CockroachDB
- PostgreSQL data types: All common data types including JSONB, arrays, and UUIDs
- Transactions: Full ACID compliance with serializable isolation by default
- PostgreSQL functions: Most built-in PostgreSQL functions and operators
Key Differences from PostgreSQL
While CockroachDB is highly compatible with PostgreSQL, some differences exist due to its distributed architecture:- Integer Division
- Float Overflow
- Shift Operations
In PostgreSQL, division of integers results in an integer. In CockroachDB, integer division results in a Use the
DECIMAL.// operator for floor division:SQL Shell Help
In thecockroach sql shell, you can get inline help about SQL statements and functions:
Transaction Model
CockroachDB supports bundling multiple SQL statements into a single all-or-nothing transaction. Each transaction guarantees ACID semantics spanning arbitrary tables and rows, even when data is distributed.Key Features
- ACID Compliance: All transactions are atomic, consistent, isolated, and durable
- Serializable Isolation: By default, transactions use
SERIALIZABLEisolation - Read Committed: Optional
READ COMMITTEDisolation level available - Distributed Transactions: Transactions work seamlessly across multiple nodes
Transaction
Statement Categories
CockroachDB organizes SQL statements into several categories:Data Definition (DDL)
Create, modify, and drop database objects:CREATE TABLE,ALTER TABLE,DROP TABLECREATE INDEX,ALTER INDEX,DROP INDEXCREATE DATABASE,ALTER DATABASE,DROP DATABASECREATE VIEW,ALTER VIEW,DROP VIEW
Data Manipulation (DML)
Query and modify data:SELECT- Query data from tablesINSERT- Insert new rowsUPDATE- Modify existing rowsDELETE- Remove rowsUPSERT- Insert or update rows
Data Control (DCL)
Manage access and permissions:GRANT,REVOKE- Manage privilegesCREATE USER,DROP USER- Manage usersCREATE ROLE,DROP ROLE- Manage roles
Transaction Control
Manage transactions:BEGIN- Start a transactionCOMMIT- Commit a transactionROLLBACK- Abort a transactionSAVEPOINT- Create nested transactions