Data Modeling

Couchbase for Oracle Developers – Part 4 : Data types

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.

 

Share this article
Get Couchbase blog updates in your inbox
This field is required.

Author

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, and has received twenty four US patents.

Leave a comment

Ready to get Started with Couchbase Capella?

Start building

Check out our developer portal to explore NoSQL, browse resources, and get started with tutorials.

Use Capella free

Get hands-on with Couchbase in just a few clicks. Capella DBaaS is the easiest and fastest way to get started.

Get in touch

Want to learn more about Couchbase offerings? Let us help.