Skip to content

22030 — duplicate_json_object_key_value

Source-backed reference for PostgreSQL SQLSTATE 22030.

22030

At a glance

A JSON object construction encountered a duplicate key. The fixed unique-key JSON builder and aggregate paths report duplicate JSON object key value: %s; JSONB finalization has a related variant.

Field Value
SQLSTATE 22030
Condition duplicate_json_object_key_value
Status active
Known present by 12.0
Locked snapshots 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3
Macros ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE
Aliases

Messages

The unique-key paths use these primary texts:

Path Primary
JSON builder or aggregate with unique keys duplicate JSON object key value: %s
JSONB object finalization or unique-key validation duplicate JSON object key value

Meaning

22030 is raised when a JSON object operation has explicitly enabled key uniqueness and sees the same key twice in one object. The JSON builders and object aggregates carry a unique_keys flag; their unique variants record keys and raise at insertion or object finalization. Ordinary json/jsonb input uses the flag as false, and ordinary builders or aggregates do not turn every duplicate in input text into 22030. Strict or absent-on-null variants omit NULL-valued fields from output, but the unique variants retain the key long enough to check it, so a duplicate key can still fail even when its value would be skipped. A NULL key itself is a separate argument error.

Diagnosis

Identify the constructor or aggregate and whether its documented form enforces unique keys. The %s primary names the duplicate key for the JSON builder/aggregate path; the JSONB finalization and validation path uses the shorter primary. Distinguish a duplicate-key policy from invalid JSON syntax, a NULL object key, or ordinary json/jsonb parsing that permits duplicate input under its normal semantics.

Response

Apply the owner’s duplicate-key policy: de-duplicate or aggregate upstream values when uniqueness is required, or use a documented non-unique operation only when retaining the operation’s duplicate-key semantics is intentional. Do not solve a NULL key or malformed JSON error by changing the uniqueness flag. If an ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected action.

Versions

The locked catalogue records this condition from 12.0; the fixed JSON and JSONB source paths here are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

22032, 22023

Sources

JSON unique-key builders and aggregates are src/backend/utils/adt/json.c#L1002-1127 and #L1224-1295; JSON uniqueness validation is #L1810-1853. JSONB ordinary input leaves uniqueness disabled in src/backend/utils/adt/jsonb.c#L74-102, while unique builders and finalization are #L1125-1163 and src/backend/utils/adt/jsonb_util.c#L1952-2005. The structured evidence record retains the unique-key and NULL-skipping boundaries; no natural runtime was run.