{"Entry":{"collection":"func","key":"jsonb-insert","name":"jsonb_insert","aliases":[],"metadata":{"changed_in":[],"changes":[{"descriptions_changed":false,"doc_overhaul":false,"from":"9.5","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"added","to":"9.6"},{"descriptions_changed":false,"doc_overhaul":true,"from":"12","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"changed","to":"13"}],"content_hash":"59d8fbd32ab5d9715cebe73f7558b93fd56026f3b52044643cdb3f376e684e7f","first_version":"9.6","group":"json","group_label":"Json Functions And Operators","groups":["json"],"imported_at":"2026-09-14T21:49:48.802978+08:00","last_version":"20","name":"jsonb_insert","name_key":"jsonb_insert","position":16035,"present_in":["9.6","10","11","12","13","14","15","16","17","18","19","20"],"signature":"jsonb_insert ( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb","signature_count":1,"slug":"jsonb-insert","source_rev":"2026-09-14T13:14:25.684213+00:00@99e6866c","summary":"Returns target with new_value inserted.","summary_zh":""}},"Definition":{"Collection":"func","Key":"jsonb-insert","SourceDatabase":"center","Version":"18","SourceTable":"func","SourceKey":"jsonb-insert","SourceRevision":"2026-09-14T13:14:25.684213+00:00@99e6866c","Facts":{"description":"Returns target with new_value inserted. If the item designated by the path is an array element, new_value 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, new_value will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the target 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.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e with \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e inserted. If the item designated by the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e is an array element, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e will be inserted before that item if \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e is false (which is the default), or after it if \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e is true. If the item designated by the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e is an object field, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e is returned unchanged. As with the path oriented operators, negative integers that appear in the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e 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.","description_zh":"","description_zh_html":"","doc":{"anchor":"FUNCTIONS-JSON-PROCESSING-TABLE","file":"functions-json.html","slug":"18"},"group":"json","group_label":"Json Functions And Operators","lang":"en","layout":"table-new","pages":["functions-json.html"],"prose_only":false,"signatures":[{"description":"Returns target with new_value inserted. If the item designated by the path is an array element, new_value 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, new_value will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the target 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.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e with \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e inserted. If the item designated by the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e is an array element, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e will be inserted before that item if \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e is false (which is the default), or after it if \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e is true. If the item designated by the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e is an object field, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e is returned unchanged. As with the path oriented operators, negative integers that appear in the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e 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.","description_zh":"","description_zh_html":"","examples":[{"expr":"jsonb_insert('{\"a\": [0,1,2]}', '{a, 1}', '\"new_value\"')","result":"{\"a\": [0, \"new_value\", 1, 2]}"},{"expr":"jsonb_insert('{\"a\": [0,1,2]}', '{a, 1}', '\"new_value\"', true)","result":"{\"a\": [0, 1, \"new_value\", 2]}"}],"html":"\u003ccode class=\"function\"\u003ejsonb_insert\u003c/code\u003e ( \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003etext[]\u003c/code\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/span\u003e ] ) → \u003ccode class=\"returnvalue\"\u003ejsonb\u003c/code\u003e","returns":"jsonb","text":"jsonb_insert ( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb","zh_from":""}],"zh_from":""},"ManualEvidence":{"doc":{"anchor":"FUNCTIONS-JSON-PROCESSING-TABLE","file":"functions-json.html","slug":"18"}},"MeasuredEvidence":{}},"Text":{"Collection":"func","Key":"jsonb-insert","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"jsonb_insert","Summary":"返回插入new_value的target。如果path指派的项是一个数组元素，则当 insert_after为假（此为默认值）时，new_value将被插入到该项之前；当 insert_after为真时，则插入到该项之后。如果由path指派的项是一个对象字段，则只在对象不包含该键时才插入 new_value。路径中的所有前面步骤都必须存在，否则将不加改变地返回target。与面向路径的操作符一样，path中的负整数从 JSON 数组末尾计数。如果最后一个路径步骤是超出范围的数组下标，那么当下标为负时，新值会被添加到数组开头；当下标为正时，新值会被添加到数组末尾。","BodyHTML":"返回插入\u003cem\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e的\u003cem\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。如果\u003cem\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个数组元素，则当 \u003cem\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为假（此为默认值）时，\u003cem\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e将被插入到该项之前；当 \u003cem\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为真时，则插入到该项之后。如果由\u003cem\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个对象字段，则只在对象不包含该键时才插入 \u003cem\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e。路径中的所有前面步骤都必须存在，否则将不加改变地返回\u003cem\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。与面向路径的操作符一样，\u003cem\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e中的负整数从 JSON 数组末尾计数。如果最后一个路径步骤是超出范围的数组下标，那么当下标为负时，新值会被添加到数组开头；当下标为正时，新值会被添加到数组末尾。\u003cpre\u003ejsonb_insert ( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb\u003c/pre\u003e返回插入\u003cem\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e的\u003cem\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。如果\u003cem\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个数组元素，则当 \u003cem\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为假（此为默认值）时，\u003cem\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e将被插入到该项之前；当 \u003cem\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为真时，则插入到该项之后。如果由\u003cem\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个对象字段，则只在对象不包含该键时才插入 \u003cem\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e。路径中的所有前面步骤都必须存在，否则将不加改变地返回\u003cem\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。与面向路径的操作符一样，\u003cem\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e中的负整数从 JSON 数组末尾计数。如果最后一个路径步骤是超出范围的数组下标，那么当下标为负时，新值会被添加到数组开头；当下标为正时，新值会被添加到数组末尾。","SourceRevision":"1b5ca64c","ContentHash":"473f0eb43cceb46924da3b9b8e66bd9bb718d15711af20e478c6ae9006fa8317","Payload":{"description_zh":"返回插入new_value的target。如果path指派的项是一个数组元素，则当 insert_after为假（此为默认值）时，new_value将被插入到该项之前；当 insert_after为真时，则插入到该项之后。如果由path指派的项是一个对象字段，则只在对象不包含该键时才插入 new_value。路径中的所有前面步骤都必须存在，否则将不加改变地返回target。与面向路径的操作符一样，path中的负整数从 JSON 数组末尾计数。如果最后一个路径步骤是超出范围的数组下标，那么当下标为负时，新值会被添加到数组开头；当下标为正时，新值会被添加到数组末尾。","description_zh_html":"返回插入\u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e的\u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。如果\u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个数组元素，则当 \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为假（此为默认值）时，\u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e将被插入到该项之前；当 \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为真时，则插入到该项之后。如果由\u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个对象字段，则只在对象不包含该键时才插入 \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e。路径中的所有前面步骤都必须存在，否则将不加改变地返回\u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。与面向路径的操作符一样，\u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e中的负整数从 JSON 数组末尾计数。如果最后一个路径步骤是超出范围的数组下标，那么当下标为负时，新值会被添加到数组开头；当下标为正时，新值会被添加到数组末尾。","signatures":[{"description_zh":"返回插入new_value的target。如果path指派的项是一个数组元素，则当 insert_after为假（此为默认值）时，new_value将被插入到该项之前；当 insert_after为真时，则插入到该项之后。如果由path指派的项是一个对象字段，则只在对象不包含该键时才插入 new_value。路径中的所有前面步骤都必须存在，否则将不加改变地返回target。与面向路径的操作符一样，path中的负整数从 JSON 数组末尾计数。如果最后一个路径步骤是超出范围的数组下标，那么当下标为负时，新值会被添加到数组开头；当下标为正时，新值会被添加到数组末尾。","description_zh_html":"返回插入\u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e的\u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。如果\u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个数组元素，则当 \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为假（此为默认值）时，\u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e将被插入到该项之前；当 \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e为真时，则插入到该项之后。如果由\u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e指派的项是一个对象字段，则只在对象不包含该键时才插入 \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e。路径中的所有前面步骤都必须存在，否则将不加改变地返回\u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e。与面向路径的操作符一样，\u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e中的负整数从 JSON 数组末尾计数。如果最后一个路径步骤是超出范围的数组下标，那么当下标为负时，新值会被添加到数组开头；当下标为正时，新值会被添加到数组末尾。","returns":"jsonb","text":"jsonb_insert ( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb","zh_from":"doc"}],"zh_from":"doc"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.6"],"Locales":["en","zh-Hans"],"Signatures":[{"Version":"18","Ordinal":0,"Hash":"de7a320711738661c552d226252b7dc3619e294200453d5f9b4599bb2f503b57","Text":"jsonb_insert ( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb","Returns":"jsonb","Payload":{"description":"Returns target with new_value inserted. If the item designated by the path is an array element, new_value 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, new_value will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the target 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.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e with \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e inserted. If the item designated by the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e is an array element, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e will be inserted before that item if \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e is false (which is the default), or after it if \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e is true. If the item designated by the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e is an object field, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e will be inserted only if the object does not already contain that key. All earlier steps in the path must exist, or the \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e is returned unchanged. As with the path oriented operators, negative integers that appear in the \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e 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.","description_zh":"","description_zh_html":"","examples":[{"expr":"jsonb_insert('{\"a\": [0,1,2]}', '{a, 1}', '\"new_value\"')","result":"{\"a\": [0, \"new_value\", 1, 2]}"},{"expr":"jsonb_insert('{\"a\": [0,1,2]}', '{a, 1}', '\"new_value\"', true)","result":"{\"a\": [0, 1, \"new_value\", 2]}"}],"html":"\u003ccode class=\"function\"\u003ejsonb_insert\u003c/code\u003e ( \u003cem class=\"parameter\"\u003e\u003ccode\u003etarget\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003epath\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003etext[]\u003c/code\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003enew_value\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003einsert_after\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/span\u003e ] ) → \u003ccode class=\"returnvalue\"\u003ejsonb\u003c/code\u003e","returns":"jsonb","text":"jsonb_insert ( target jsonb, path text[], new_value jsonb [, insert_after boolean ] ) → jsonb","zh_from":""}}],"Spellings":null,"SQLState":null,"Evidence":null}
