Using JSONB Containment (@>) Operator in PostgreSQL
📖 Scenario: You are managing a PostgreSQL database for a small online bookstore. Each book's details are stored in a table with a JSONB column that holds various attributes like genre, author, and publication year.
🎯 Goal: Learn how to use the JSONB containment operator @> to find books that contain specific JSON attributes.
📋 What You'll Learn
Create a table called
books with an id column and a details column of type JSONB.Insert sample book data with JSONB details including
genre, author, and year.Write a query using the
@> operator to find books with a specific genre.Write a query using the
@> operator to find books by a specific author.💡 Why This Matters
🌍 Real World
Many modern applications store flexible data in JSONB columns in PostgreSQL. Using the @> operator helps quickly find records matching specific JSON criteria.
💼 Career
Understanding JSONB queries is valuable for backend developers, data engineers, and database administrators working with PostgreSQL and semi-structured data.
Progress0 / 4 steps