SQL
Querying JSON Data Stored in a Column
Learn how to efficiently query and extract specific values from JSON data stored within a database column, common in modern web applications.
SELECT
id,
data->>'name' AS user_name,
data->>'email' AS user_email
FROM
users
WHERE
data->>'status' = 'active';
How it works: This query demonstrates how to access and filter data within a JSONB (or JSON) column in PostgreSQL. The ->> operator extracts a JSON object field as text, allowing it to be used in SELECT and WHERE clauses like any other text column. This is crucial for applications that store semi-structured data directly in the database.