---
title: "Discussion on \"PostgreSQL JSONB in Production: The Good, The Bad, and The Slow Queries\" | Hashnode"
description: "Discussion on \"PostgreSQL JSONB in Production: The Good, The Bad, and The Slow Queries\". How to safely query, aggregate, and index polymorphic JSONB data alongside relational tables without destroying your database latency."
url: "https://hashnode.com/posts/postgresql-jsonb-in-production-the-good-the-bad-and-the-slow-queries/6b0136fa893b4b1e5e55e81e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [PostgreSQL JSONB in Production: The Good, The Bad, and The Slow Queries](https://beyond-prompt-engineering.hashnode.dev/postgresql-jsonb-in-production-the-good-the-bad-and-the-slow-queries?utm_source=hashnode&utm_medium=feed)

How to safely query, aggregate, and index polymorphic JSONB data alongside relational tables without destroying your database latency.

Nov 21 · 7 min read · beyond-prompt-engineering.hashnode.dev  
Read the article

-   [#postgresql](https://hashnode.com/tag/postgresql)
-   [#database](https://hashnode.com/tag/database)
-   [#sql](https://hashnode.com/tag/sql)
-   [#backend](https://hashnode.com/tag/backend)
-   [#performance](https://hashnode.com/tag/performance)
-   [#performance-optimization](https://hashnode.com/tag/performance-optimization)

## Written by

[Aman Lath](https://hashnode.com/@lathaman)

@lathaman · Delhi, India

  
[View profile](https://hashnode.com/@lathaman)

I am an AI Full Stack Developer who bridges the gap between sophisticated machine learning integration.

I am an AI Full Stack Developer who bridges the gap between sophisticated machine learning integration and robust DevOps-driven infrastructure. With a focus on architecting scalable applications within compliance-intensive sectors, I specialize in building intelligent, automated systems from the ground up through a combination of full-stack engineering and streamlined CI/CD pipelines.

## Responses 1

Markdown supported · ⌘↵ to post

[SqlOtter](https://hashnode.com/@sqlotter)

[2d ago](https://hashnode.com/posts/postgresql-jsonb-in-production-the-good-the-bad-and-the-slow-queries/6b0136fa893b4b1e5e55e81e/comment/6b0cf49427886f718af5684c)

One small regression case for the set-based rewrite: put a row with `"severity_level": "  "` in the test data. The original `NULLIF(BTRIM(...), '')` predicate excludes it, but the rewrite normalizes it to an empty string, which satisfies `severity <> 'NORMAL'`. If blanks should be excluded, use `NULLIF(UPPER(BTRIM(payload_json->>'severity_level')), '')` in both UNION ALL branches.

I work on SqlOtter. On a small fixture, I’d pin the original query result and compare it with the rewritten result in the SQL Editor. Keep the entire fixture in the loaded results so the comparison includes the blank-value case.
