Link to the series home page:

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.


ModelRelational, Object-relationalJSON model with N1QL (SQL for JSON)
Data Types
String Data typesCHAR, VARCHAR, VARCHAR2, NCHAR, NVARCHAR, LOONGVARCHARString, up to 20MB in length. All of the string data in JSON is Unicode.
Date and Time Data TypesDATE, TIME, TIMESTAMP, all these with TIMEZONE, INTERVALDate, Time, Timestamp, all these with timezones should be represented in ISO 8601 format and saved as strings. N1QL has extensive functions for formatting, extraction, conversion, and arithmetic.

This article covers conversion and arithmetic on them in detail.


true and false are automatically interpreted as a boolean value.









Numeric data: can be integer, fraction or an exponent.  Here are the ranges:
Binary Data TypesBINARY



You can store the whole document as binary or encode the binary as base64 values.
Large Object Data Types
BLOB, RAW, LONG_RAWEach document can be up to 20 MB.  Binary data can be encoded via BASE64
CLOBEach document can be up to 20 MB. 
ABSTRACT Types, NESTED TABLESBuiltin support for objects, arrays, arrays of objects, objects of arrays. No support for user defined opaque data types.
XMLAnyone still use XML in databases? 😉 
ANY TYPEANY TYPE was invented to make the Oracle routines flexiblle — in terms of types they handle as parameters and return types. 

In JSON model, 

ObjectsCREATE the object types and the columns associated with it explicity: CREATE TYPE person_typ AS OBJECT


OBJECTs are built into JSON model with any number of nested levels with any data type, objects or arrays.
ArraysVARRAY can create an array of a specific type and then use that type as the type for a column. 


Array is a first class citizen in the JSON data model and can be used for any value. Each array can be of scalars of any type: scalars, objects, arrays, etc.

“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.


Posted by Keshav Murthy

Keshav Murthy is a Vice President at Couchbase R&D. Previously, he was at MapR, IBM, Informix, Sybase, with more than 20 years of experience in database design & development. He lead the SQL and NoSQL R&D team at IBM Informix. He has received two President's Club awards at Couchbase, two Outstanding Technical Achievement Awards at IBM. Keshav has a bachelor's degree in Computer Science and Engineering from the University of Mysore, India, holds ten US patents and two US patents pending.

Leave a reply