The ongoing debate between SQL and NoSQL is as old as relational database systems. Since Edgar F. Codd introduced the relational database concept in 1970, there has been an ongoing deep tension between structure and flexibility in database systems. SQL databases claim superiority through decades of proven reliability, strong ACID guarantees, and powerful query capabilities ideal for complex, relational data models. In contrast, NoSQL databases argue that rigid schemas can't keep pace with modern development, offering schema flexibility, simple application development, or better performance for high-velocity or unstructured data.
Each camp claims dominance—SQL for consistency and integrity, NoSQL for speed and agility—yet the real-world trend is convergence, as both camps increasingly work on borrowing features from the other.
All these multi-model databases have introduced a binary format for storing JSON data natively and optimized. This includes Oracle's OSON format, which has shown advantages over BSON in research for performance and efficiency of incremental updates.
For developers seeking a document-first experience, vendors offer APIs that expose native JSON stores, such as MySQL's xDev API, PostgreSQL-based FerretDB, or Oracle's Database API for MongoDB. These APIs provide the simplicity of NoSQL development on top of relational infrastructure. Developers enjoy the simplicity and agility of schema-flexible development without needing a special-purpose document store database.
However, unlike SQL, document store APIs are not standardized and remain vendor specific. Efforts to define a common standard are underway but are still in the early stages.
Here’s an example that queries a JSON collection of movies, extracts attributes, aggregates gross revenue by year and calculates each year’s revenue share:
WITH revenue AS (
SELECT
m.data.year
, round(sum(JSON_VALUE(data,'$.gross' RETURNING NUMBER NULL ON ERROR NULL ON EMPTY ))/1000000) as millions
FROM movies m
WHERE m.data.gross IS NOT NULL
GROUP BY m.data.year
)
SELECT year
, millions
, ROUND((RATIO_TO_REPORT(millions) OVER ())*100,2) pct_revenue
FROM revenue r
WHERE year > 2000
ORDER BY year DESC;
This example uses both the ANSI SQL/JSON operator JSON_VALUE and Oracle's simplified dot notation, a straightforward SQL-style way to extract JSON scalar values from a JSON document (m.data.year).
Developers extract and “relationalize” attributes stored in JSON documents, join this information with relational tables, and use nested subqueries or other constructs — the same way they use any available SQL operator or function for relational objects.
CREATE OR REPLACE JSON COLLECTION VIEW emp_collection AS
SELECT
JSON{'_id' : empno,
'employeeName' : ename,
'jobRole' : job}
FROM emp;
Using this collection view through a document store API would return data similar to
json> db.emp_collection.findOne()
{ _id: 7369, employeName: 'SMITH', jobRole: 'CLERK' }
This bidirectional flexibility blurs the boundaries between SQL and NoSQL and decouples how data is processed from how it is stored.
In short, duality views store the JSON documents internally in a highly efficient normalized format, using relational and JSON constructs. At the same time, developers interact with JSON documents.
Duality Views - stored as rows, exposed as documents
Whether the application uses REST or document-centric APIs, developers benefit from the simplicity of retrieving and working with all the data needed for a single application-tier object: the JSON document. Creating a JSON duality view is pretty straightforward. Like a JSON collection view, developers define the Object Document Model for the business object as metadata in the database.
Here’s a simple example that defines a duality view to model a conference schedule using GraphQL. The schedule object is comprised of:
The schedule object comprises of:
create or replace JSON Duality view ScheduleV
AS
attendee
{ _id : aid name : aname
schedule : schedule @insert @update @delete
{ scheduleId : schedule_id
sessions @unnest
{ sessionId : sid
name : name
location : room
speaker @unnest
{ speakerId : sid
speaker : name
}
}
}
} ;
JSON Relational Duality, therefore, provides the storage, consistency, and efficiency benefits of the relational model while applications retrieve and manipulate deeply nested JSON structures.
Oracle’s JSON Relational Duality views go beyond coexistence by fusing the strengths of relational and document models into a unified architecture. As multimodel systems continue to evolve, this approach sets a compelling precedent — and others are likely to follow.
This blog post was originally published at https://thenewstack.io/to-sql-or-not-to-sql-that-is-not-the-question/
Hermann is a Senior Director of Product Management in the Oracle Database organization. He and his team focus on Oracle's core functionality, such as Oracle Partitioning, the Oracle Optimizer, and analytical SQL. His team also looks after semi-structured data processing, such as the relational SQL/JSON capabilities, Oracle Text, and more recently Autonomous JSON Database and the Oracle Database API for Mongo DB.
Hermann has held several positions at Oracle in Sales Consulting and Consulting, dealing with the database for quite some time
Previous Post
Next Post