select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 22 · DATA EXCEPTION

duplicate_json_object_key_value

SQLSTATE
22030
Condition name
duplicate_json_object_key_value
Class
Data Exception
Source macro
ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>22030</h1>

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.

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.

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.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

22030 is duplicate_json_object_key_value in SQLSTATE Class 22.

Method: Read fixed definition.

src.errcodes.18.6

Fixed JSON and JSONB builders/aggregates enable uniqueness checks only for their unique-key variants; duplicate keys then raise 22030, while ordinary json/jsonb input leaves unique_keys false and does not use this guard. Strict/absent-on-null variants skip NULL-valued entries from output but retain their key long enough to enforce uniqueness when unique_keys is true.

Method: Read the complete unique-key builder, parser-validation, JSONB input, and final uniqueify paths.

Limits: Source confirmation is not a natural runtime observation.

src.path.0 src.json.unique-builder src.json.unique-constructor src.json.unique-validate src.jsonb.unique-builder src.jsonb.input src.jsonb.uniqueify

The locked catalogue records 22030 from 12.0 without proving exact implementation introduction.

Method: Use catalogue boundary.

src.errcodes.18.6

Message templates

ERROR · message.0

Primary

duplicate JSON object key value: %s
ERROR · message.jsonb

Primary

duplicate JSON object key value
ERROR · message.json-validate

Primary

duplicate JSON object key value

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Version history 1
  1. PG 11 → 12added

Definition snapshot: english-manuals:23e505dbdb75e5df832ceee20a2… · English manual source