↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / Functions

jsonb_insert

Returns jsonb_in with replacement inserted. If the item designated by the path is an array element, replacement will be inserted before that item if insert_after is false (which is the default), or after it if insert_after is true. If the item designated by the path is an object field, replacement will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the jsonb_in is returned unchanged. As with the path oriented operators, negative integers that appear in the path count from the end of JSON arrays. If the last path step is an array index that is out of range, the new value is added at the beginning of the array if the index is negative, or at the end of the array if it is positive.

English manual coverage begins with PostgreSQL 7.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

group
json
group label
JSON 函数和操作符
lang
en
layout
table-new
pages
functions-json.html
prose only
false

Definition PG 18

Returns jsonb_in with replacement inserted. If the item designated by the path is an array element, replacement will be inserted before that item if insert_after is false (which is the default), or after it if insert_after is true. If the item designated by the path is an object field, replacement will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the jsonb_in is returned unchanged. As with the path oriented operators, negative integers that appear in the path count from the end of JSON arrays. If the last path step is an array index that is out of range, the new value is added at the beginning of the array if the index is negative, or at the end of the array if it is positive.

Signatures and overloads

jsonb_insert ( jsonb_in jsonb, path text[], replacement jsonb [, insert_after boolean] ) → jsonb → jsonb
Returns jsonb_in with replacement inserted. If the item designated by the path is an array element, replacement will be inserted before that item if insert_after is false (which is the default), or after it if insert_after is true. If the item designated by the path is an object field, replacement will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the jsonb_in is returned unchanged. As with the path oriented operators, negative integers that appear in the path count from the end of JSON arrays. If the last path step is an array index that is out of range, the new value is added at the beginning of the array if the index is negative, or at the end of the array if it is positive.

Compare versions

Complete source facts

documentation revision

{"inputs":[{"file":"functions-json.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"060b67147827d70ddcf5948833ddfbeada321366476016c8b8b7d68afda8045c","version":"18.7"},{"file":"functions-json.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"31b98fa7f00387abf441728c31918bfe8b368642bceeb8bba88a73c3fbd607de","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:42fa4bad0e77e50cd5edae6baef701974e042519e2849723510b66e4a2a28927

Text language: en · wiki-repair-20261023:42fa4bad0e77e50cd5edae6baef701974e042519e2849723510b66e4a2a28927