Link to the series home page: https://www.couchbase.com/blog/couchbase-oracle-developers-part-2-architecture/
As part of data remodeling, while moving from the relational model to the JSON model, you’ll have to consider the data type mapping. In Oracle, you’ll have to create and declare the types of each column explicitly before you load the data or write queries. In Couchbase, you simply conform to JSON syntax and the data type interpretation is automatic and implicit. Here’s the overview of mappings, conversion, and arithmetic on these data types.
| Feature | Oracle | Couchbase |
|---|---|---|
| Model | Relational, Object-relational | JSON model with N1QL (SQL for JSON) |
| Data Types |
Oracle Data Types Reference |
Couchbase Data Types Reference |
| String Data Types | CHAR, VARCHAR, VARCHAR2, NCHAR, NVARCHAR, LONGVARCHAR | String (Unicode), up to 20 MB |
| Date & Time Data Types | DATE, TIME, TIMESTAMP (with timezone), INTERVAL |
ISO-8601 strings with N1QL date functions Detailed article |
| Boolean | BOOLEAN | true / false |
| Numerical | NUMBER, DECIMAL, BIGINT, SMALLINT, INTEGER, FLOAT, REAL, DOUBLE |
Integer, fractional, exponential values Numeric ranges |
| Binary Data Types | BINARY, VARBINARY, LONGVARBINARY | Binary document or Base64 encoded values |
| Large Object Data Types | BLOB, RAW, LONG_RAW, CLOB | Each document up to 20 MB |
| Objects |
User-defined object types Oracle Object Types |
Native JSON objects with unlimited nesting |
| Arrays |
VARRAY with predefined type VARRAY documentation |
First-class JSON arrays of mixed types “A”: [1, “X”, [3, 4]] “B”: [{“x”:1}, {“x”:2}] |
Additional Notes
Date and Datetime types.
Oracle and other RDBMS have extensive data types for handling time-related data and manipulating them. JSON does not have a date or datetime type. We’ve chosen the ISO 8601 . The idea is to store the date & time related data in a string form, conforming to ISO 8601 and then manipulating it in a consistent way.
Primary key to Document key conversion.
Couchbase document key is always less than 255 bytes and is usually a string. RDBMS can have a single column or multiple columns (composite) primary key for a table. One common way convert is to simply have a separator between the individual parts after converting each part to a string. The document key should be unique to a bucket and hence it’s typically prefixed with the table (collection) type. See the blog with examples of how to do this correctly.