To SQL or Not To SQL: That Is Not the Question
The convergence of SQL and NoSQL combines the simplicity of JSON document development and the power of relational databases within a single database.
May 7th, 2025 11:00am by
Featured image by rangizzz on Shutterstock.
Oracle sponsored this post.
SQL and NoSQL: Converging Into Multimodel Databases
Multimodel databases like MySQL, PostgreSQL and Oracle are at the forefront of integrating non-relational capabilities into traditionally relational systems. Recent innovations include vector processing, document store features and support for collections of JSON documents. These new capabilities allow developers to:- Work with JSON documents using familiar document APIs
- Query and process both structured and semistructured data using SQL
- Combine relational normalization with document-centric development
Multimodel Databases Support Native Document Store APIs
All these multimodel 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 X DevAPI, 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.Querying JSON With SQL
With native JSON support, developers can treat document collections as first-class citizens in the database. Using ANSI SQL/JSON (introduced in SQL:2016), you can extract values, unnest arrays, filter documents and apply SQL functions to JSON content. This bridges relational and semistructured data through a unified language, opening the door to benefit from the power of SQL for analytics and reporting. 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;
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.
Exposing Relational Data as JSON Documents
Conversely, relational data can be exposed as JSON documents using JSON collection views, making it accessible to document-centric applications. The following example creates a JSON collection view on top of Oracle’s EMP table, probably one of the first relational tables ever created for demonstration purposes:
CREATE OR REPLACE JSON COLLECTION VIEW emp_collection AS
SELECT
JSON{'_id' : empno,
'employeName' : ename,
'jobRole' : job}
FROM emp;
jason> db.emp_collection.findOne()
{ _id: 7369, employeName: 'SMITH', jobRole: 'CLERK' }
Beyond Dual Access: JSON-Relational Duality
While native binary JSON storage, document APIs and SQL/JSON functionality represent strong progress, JSON-relational duality takes things a step further. This new capability offers the best of both relational and JSON documents without the trade-offs of either model. 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
- The attendee information
- The schedule for an individual attendee
- The schedule representation for one or more sessions that an attendee is planning to attend
- The detailed information about a session, including the speaker information
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
}
}
}
} ;
The Best of Both Worlds
The convergence of SQL and NoSQL enables developers to benefit from the simplicity of JSON document development and the power of relational databases with a single database. Multimodel databases eliminate the need to choose one paradigm over another, taking over the single-purpose NoSQL database systems market. Developers don’t have to face the choice between SQL and NoSQL systems and lock themselves into one programming paradigm. They enjoy the flexibility and freedom to pick the best approach for individual applications without sacrificing functionality. 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. Begin innovating today with JSON-relational duality, either locally with Oracle Database 23ai Free or in the cloud on OCI with Oracle Autonomous Database.
YOUTUBE.COM/THENEWSTACK
Tech moves fast, don't miss an episode. Subscribe to our YouTube
channel to stream all our podcasts, interviews, demos, and more.