Concept Flow - JSONB existence (?) operator
Start with JSONB column
Apply ? operator with key
Check if key exists in JSONB
Return TRUE
Return FALSE
The ? operator checks if a specified key exists in a JSONB column and returns true or false.
SELECT data ? 'name' AS has_name FROM users;
| Row | data (JSONB) | Key Checked | Condition (key exists?) | Result (TRUE/FALSE) |
|---|---|---|---|---|
| 1 | {"name": "Alice", "age": 30} | name | Exists | TRUE |
| 2 | {"age": 25, "city": "NY"} | name | Does not exist | FALSE |
| 3 | {"name": "Bob", "city": "LA"} | name | Exists | TRUE |
| 4 | {"city": "Chicago"} | name | Does not exist | FALSE |
| Variable | Start | Row 1 | Row 2 | Row 3 | Row 4 |
|---|---|---|---|---|---|
| data | N/A | {"name": "Alice", "age": 30} | {"age": 25, "city": "NY"} | {"name": "Bob", "city": "LA"} | {"city": "Chicago"} |
| key | N/A | name | name | name | name |
| result | N/A | TRUE | FALSE | TRUE | FALSE |
JSONB existence (?) operator: - Syntax: jsonb_column ? 'key' - Returns TRUE if 'key' exists at top-level in JSONB - Returns FALSE if 'key' is missing - Only checks top-level keys, not nested - Useful for quick key presence checks in JSONB columns