惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
L
LangChain Blog
美团技术团队
N
Netflix TechBlog - Medium
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
博客园 - 司徒正美
爱范儿
爱范儿
D
DataBreaches.Net
月光博客
月光博客
U
Unit 42
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
MongoDB | Blog
MongoDB | Blog
腾讯CDC

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
PostgreSQL 22034 Error: Causes and Solutions Complete Guide
umzzil nng · 2026-06-17 · via DEV Community

umzzil nng

PostgreSQL Error 22034: more than one sql json item

PostgreSQL error code 22034 (more than one sql json item) occurs when a SQL/JSON function such as JSON_VALUE() or JSON_QUERY() encounters a JSON path expression that returns more than one item, while the function context expects exactly one. This error became more prevalent with the introduction of SQL-standard JSON functions in PostgreSQL 15 and later.


Top 3 Causes

1. Wildcard path in JSON_VALUE() returning multiple results

JSON_VALUE() strictly requires a single scalar return value. Using a wildcard like $[*] across an array will match multiple elements and immediately trigger error 22034.

-- Triggers 22034
SELECT JSON_VALUE('{"fruits": ["apple", "banana", "cherry"]}', '$.fruits[*]');

-- Fix: specify an explicit index
SELECT JSON_VALUE('{"fruits": ["apple", "banana", "cherry"]}', '$.fruits[0]');
-- Result: "apple"

-- Fix: suppress the error gracefully
SELECT JSON_VALUE(
    '{"fruits": ["apple", "banana", "cherry"]}',
    '$.fruits[*]'
    NULL ON ERROR
);
-- Result: NULL

2. JSON_QUERY() without WITH ARRAY WRAPPER on multi-value paths

JSON_QUERY() also fails when a path resolves to multiple independent values and no wrapper option is provided to consolidate them into a single JSON array.

-- Triggers 22034
SELECT JSON_QUERY('{"scores": [95, 87, 76]}', '$.scores[*]');

-- Fix: wrap results into a JSON array
SELECT JSON_QUERY(
    '{"scores": [95, 87, 76]}',
    '$.scores[*]'
    WITH ARRAY WRAPPER
);
-- Result: [95, 87, 76]

3. Navigating nested array structures with simple path expressions

Deeply nested JSON arrays compound the cardinality problem at every path step. Using JSON_VALUE() or JSON_QUERY() on paths that traverse multiple array levels without index constraints will almost always produce multiple results.

-- Sample nested data
WITH doc AS (
    SELECT '{"orders": [{"id":1}, {"id":2}, {"id":3}]}'::jsonb AS data
)

-- Triggers 22034 (multiple ids returned)
-- SELECT JSON_VALUE(data::json, '$.orders[*].id') FROM doc;

-- Fix: use jsonb_path_query() to return a set of rows
SELECT jsonb_path_query(data, '$.orders[*].id')
FROM doc;

-- Fix: use jsonb_array_elements() for row-by-row processing
SELECT elem->>'id' AS order_id
FROM doc, jsonb_array_elements(data->'orders') AS elem;


Quick Fix Solutions

Scenario Recommended Fix
Need only the first value Use $.array[0] explicit index
Need all values as JSON array JSON_QUERY(... WITH ARRAY WRAPPER)
Need all values as rows jsonb_path_query() or jsonb_array_elements()
Want to avoid query failure Add NULL ON ERROR clause
Complex nested structures Use JSON_TABLE() (PostgreSQL 17+)
-- JSON_TABLE() for structured unnesting (PostgreSQL 17+)
SELECT *
FROM JSON_TABLE(
    '{"orders": [{"id":1,"amt":100},{"id":2,"amt":250}]}'::json,
    '$.orders[*]'
    COLUMNS (
        order_id  INT  PATH '$.id',
        amount    INT  PATH '$.amt'
    )
) AS jt;


Prevention Tips

Always verify path cardinality before using scalar JSON functions.
Before deploying queries with JSON path expressions into production, use jsonb_path_query_array() to check how many items a path returns. If the count exceeds one, switch to a set-returning function or add WITH ARRAY WRAPPER.

-- Pre-flight cardinality check
SELECT jsonb_array_length(
    jsonb_path_query_array(your_column, '$.some.path[*]')
)
FROM your_table
LIMIT 10;

Always declare explicit error and empty behavior clauses.
Never rely on default behavior for SQL/JSON functions. Explicitly specifying NULL ON ERROR and NULL ON EMPTY prevents a single malformed or unexpectedly multi-valued JSON document from failing an entire query batch — especially critical when handling externally sourced JSON data.

SELECT JSON_VALUE(
    payload::json,
    '$.event.type'
    NULL ON EMPTY
    NULL ON ERROR
)
FROM event_log;


Related Errors

  • 22033invalid sql json subscript: bad array index in path expression
  • 22032invalid json text: malformed JSON, often encountered before 22034
  • 22035no sql json item: the opposite of 22034; path matches nothing
  • 2203Asql json scalar required: path returns an object/array where a scalar is expected

📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.