---
title: "SQL or NoSQL? Why not use both (with PostgreSQL)?"
description: "PostgreSQL's JSONB columns let an app store nested, variable-length data (here, a daily food, water and exercise log) as a single row instead of spreading it across several normalized tables, while keeping SQL available for analysis."
url: "https://swe.quest/articles/sql-or-nosql-why-not-use-both-with-postgresql-98c239e2ff7e761c"
canonical: "https://supabase.com/blog/sql-or-nosql-both-with-postgresql"
source: "Supabase"
published: "2022-11-24"
difficulty: "medium"
kind: "How-to"
reading_minutes: 12
tags: ["postgres","sql","databases"]
---

# SQL or NoSQL? Why not use both (with PostgreSQL)?

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2022-11-24, 12 min read, How-to. Original: [https://supabase.com/blog/sql-or-nosql-both-with-postgresql](https://supabase.com/blog/sql-or-nosql-both-with-postgresql)

## Summary

PostgreSQL's JSONB columns let an app store nested, variable-length data (here, a daily food, water and exercise log) as a single row instead of spreading it across several normalized tables, while keeping SQL available for analysis. A worked example builds a calendar table with JSONB log fields and inserts a whole day in one statement. It then uses jsonb\_array\_elements with the -\> and -\>\> operators to flatten the arrays into rows. Because aggregates cannot wrap set-returning functions, the flattened query goes into a CTE before summing daily calories or filtering for specific items.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- basic SQL queries ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- JSON

## Keywords

PostgreSQL, JSONB, jsonb\_array\_elements, Supabase

## Related posts

- [What's New in PostgreSQL 14?](https://swe.quest/articles/what-s-new-in-postgresql-14-d679a59b3961e203.md): Render · 2021-10-05 · Medium · 4 min read · PostgreSQL, SQL
  PostgreSQL 14 adds jsonb subscripting, which lets queries read, filter and update nested JSONB values with JavaScript-like bracket syntax instead of path operators such as #\>.
- [Understanding the new JSON capabilities in Postgres 16](https://swe.quest/articles/understanding-the-new-json-capabilities-in-postgres-16-72256e4ab11a87d0.md): Neon · 2023-09-18 · Medium · 3 min read · PostgreSQL, SQL
  Postgres 16 expands SQL/JSON syntax with JSON\_ARRAY(), JSON\_ARRAYAGG() and the IS JSON predicate, each shown with runnable examples.
- [pg\_graphql: A GraphQL extension for PostgreSQL](https://swe.quest/articles/pg-graphql-a-graphql-extension-for-postgresql-3a34efbe6d730fc2.md): Supabase · 2021-12-03 · Medium · 4 min read · GraphQL, PostgreSQL, API design
  pg\_graphql is an open-source PostgreSQL extension, written in C and SQL, that reflects a GraphQL schema from existing tables and resolves queries entirely inside the database.
- [What's New in pg\_clickhouse - JSONB Support, SQL value functions, Streaming, and more](https://swe.quest/articles/what-s-new-in-pg-clickhouse-jsonb-support-sql-value-functions-streaming-and-more-ecb202cf6ff32298.md): ClickHouse · 2026-04-24 · Medium · 10 min read · PostgreSQL, Analytics & OLAP, Query engines, Memory management
  pg\_clickhouse, the Postgres foreign data wrapper for querying ClickHouse, now pushes down far more operations to ClickHouse.
- [PostgREST Aggregate Functions](https://swe.quest/articles/postgrest-aggregate-functions-f622df6532444e20.md): Supabase · 2024-02-29 · Medium · 7 min read · PostgreSQL, API design, SQL
  PostgREST v12 adds on-the-fly aggregate functions (avg, count, max, min, sum) to its API.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
