8000 Allow empty string object keys in json_object(). · postgres/postgres@a61f63d · GitHub
[go: up one dir, main page]

Skip to content
< 8000 script type="application/json" data-target="react-app.embeddedData">{"payload":{"commit":{"oid":"a61f63df7d19006b36adf7ee402999aa5243097d","url":"/postgres/postgres/commit/a61f63df7d19006b36adf7ee402999aa5243097d","authoredDate":"2014-07-22T11:22:47.000-04:00","committedDate":"2014-07-22T11:25:40.000-04:00","shortMessage":null,"shortMessageMarkdown":"\u003cdiv\u003eAllow empty string object keys in json_object().\u003c/div\u003e","shortMessageMarkdownLink":null,"bodyMessageHtml":"This makes the behaviour consistent with the json parser, other\njson-generating functions, and the JSON standards.","authors":[{"login":"adunstan","displayName":"Andrew Dunstan","avatarUrl":"https://avatars.githubusercontent.com/u/241593?v=4","path":"/adunstan","isGitHub":false}],"committerAttribution":false,"committer":{"login":"adunstan","displayName":"Andrew Dunstan","avatarUrl":"https://avatars.githubusercontent.com/u/241593?v=4","path":"/adunstan","isGitHub":false},"pusher":null,"pushedDate":null,"parents":["fd18965e33da9dc7326803e61cf28d82237e3bba"],"globalRelayId":"MDY6Q29tbWl0OTI3NDQyOmE2MWY2M2RmN2QxOTAwNmIzNmFkZjdlZTQwMjk5OWFhNTI0MzA5N2Q=","sha1":"fd18965e33da9dc7326803e61cf28d82237e3bba","sha2":"a61f63df7d19006b36adf7ee402999aa5243097d"},"currentUser":null,"repo":{"id":927442,"defaultBranch":"master","name":"postgres","ownerLogin":"postgres","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2010-09-21T11:35:45.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/177543?v=4","public":true,"private":false,"isOrgOwned":true},"diffEntryData":[{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":2183,"text":"@@ -2184,10 +2184,6 @@ json_object(PG_FUNCTION_ARGS)","html":"@@ -2184,10 +2184,6 @@ json_object(PG_FUNCTION_ARGS)","displayNoNewLineWarning":false,"position":0,"left":2183,"right":2183},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2184,"text":" \t\t\t\t\t errmsg(\"null value not allowed for object key\")));","html":" \t\t\t\t\t \u003cspan class=pl-en\u003eerrmsg\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026quot;null value not allowed for object key\u0026quot;\u003c/span\u003e)));","displayNoNewLineWarning":false,"position":1,"left":2184,"right":2184},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2185,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":2,"left":2185,"right":2185},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2186,"text":" \t\tv = TextDatumGetCString(in_datums[i * 2]);","html":" \t\t\u003cspan class=pl-s1\u003ev\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-en\u003eTextDatumGetCString\u003c/span\u003e(\u003cspan class=pl-s1\u003ein_datums\u003c/span\u003e[\u003cspan class=pl-s1\u003ei\u003c/span\u003e \u003cspan class=pl-c1\u003e*\u003c/span\u003e \u003cspan class=pl-c1\u003e2\u003c/span\u003e]);","displayNoNewLineWarning":false,"position":3,"left":2186,"right":2186},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2187,"text":"-\t\tif (v[0] == '\\0')","html":"-\t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003ev\u003c/span\u003e[\u003cspan class=pl-c1\u003e0\u003c/span\u003e] \u003cspan class=pl-c1\u003e==\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026#39;\\0\u0026#39;\u003c/span\u003e)","displayNoNewLineWarning":false,"position":4,"left":2187,"right":2186},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2188,"text":"-\t\t\tereport(ERROR,","html":"-\t\t\t\u003cspan class=pl-en\u003eereport\u003c/span\u003e(\u003cspan class=pl-c1\u003eERROR\u003c/span\u003e,","displayNoNewLineWarning":false,"position":5,"left":2188,"right":2186},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2189,"text":"-\t\t\t\t\t(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),","html":"-\t\t\t\t\t(\u003cspan class=pl-en\u003eerrcode\u003c/span\u003e(\u003cspan class=pl-c1\u003eERRCODE_NULL_VALUE_NOT_ALLOWED\u003c/span\u003e),","displayNoNewLineWarning":false,"position":6,"left":2189,"right":2186},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2190,"text":"-\t\t\t\t\t errmsg(\"empty value not allowed for object key\")));","html":"-\t\t\t\t\t \u003cspan class=pl-en\u003eerrmsg\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026quot;empty value not allowed for object key\u0026quot;\u003c/span\u003e)));","displayNoNewLineWarning":false,"position":7,"left":2190,"right":2186},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2187,"text":" \t\tif (i \u003e 0)","html":" \t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003ei\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026gt;\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e)","displayNoNewLineWarning":false,"position":8,"left":2191,"right":2187},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2188,"text":" \t\t\tappendStringInfoString(\u0026result, \", \");","html":" \t\t\t\u003cspan class=pl-en\u003eappendStringInfoString\u003c/span\u003e(\u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003eresult\u003c/span\u003e, \u003cspan class=pl-s\u003e\u0026quot;, \u0026quot;\u003c/span\u003e);","displayNoNewLineWarning":false,"position":9,"left":2192,"right":2188},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2189,"text":" \t\tescape_json(\u0026result, v);","html":" \t\t\u003cspan class=pl-en\u003eescape_json\u003c/span\u003e(\u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003eresult\u003c/span\u003e, \u003cspan class=pl-s1\u003ev\u003c/span\u003e);","displayNoNewLineWarning":false,"position":10,"left":2193,"right":2189},{"stylingDirective":null,"type":"HUNK","blobLineNumber":2267,"text":"@@ -2272,10 +2268,6 @@ json_object_two_arg(PG_FUNCTION_ARGS)","html":"@@ -2272,10 +2268,6 @@ json_object_two_arg(PG_FUNCTION_ARGS)","displayNoNewLineWarning":false,"position":11,"left":2271,"right":2267},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2268,"text":" \t\t\t\t\t errmsg(\"null value not allowed for object key\")));","html":" \t\t\t\t\t \u003cspan class=pl-en\u003eerrmsg\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026quot;null value not allowed for object key\u0026quot;\u003c/span\u003e)));","displayNoNewLineWarning":false,"position":12,"left":2272,"right":2268},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2269,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":13,"left":2273,"right":2269},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2270,"text":" \t\tv = TextDatumGetCString(key_datums[i]);","html":" \t\t\u003cspan class=pl-s1\u003ev\u003c/span\u003e \u003cspan class=pl-c1\u003e=\u003c/span\u003e \u003cspan class=pl-en\u003eTextDatumGetCString\u003c/span\u003e(\u003cspan class=pl-s1\u003ekey_datums\u003c/span\u003e[\u003cspan class=pl-s1\u003ei\u003c/span\u003e]);","displayNoNewLineWarning":false,"position":14,"left":2274,"right":2270},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2275,"text":"-\t\tif (v[0] == '\\0')","html":"-\t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003ev\u003c/span\u003e[\u003cspan class=pl-c1\u003e0\u003c/span\u003e] \u003cspan class=pl-c1\u003e==\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026#39;\\0\u0026#39;\u003c/span\u003e)","displayNoNewLineWarning":false,"position":15,"left":2275,"right":2270},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2276,"text":"-\t\t\tereport(ERROR,","html":"-\t\t\t\u003cspan class=pl-en\u003eereport\u003c/span\u003e(\u003cspan class=pl-c1\u003eERROR\u003c/span\u003e,","displayNoNewLineWarning":false,"position":16,"left":2276,"right":2270},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2277,"text":"-\t\t\t\t\t(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),","html":"-\t\t\t\t\t(\u003cspan class=pl-en\u003eerrcode\u003c/span\u003e(\u003cspan class=pl-c1\u003eERRCODE_NULL_VALUE_NOT_ALLOWED\u003c/span\u003e),","displayNoNewLineWarning":false,"position":17,"left":2277,"right":2270},{"stylingDirective":null,"type":"DELETION","blobLineNumber":2278,"text":"-\t\t\t\t\t errmsg(\"empty value not allowed for object key\")));","html":"-\t\t\t\t\t \u003cspan class=pl-en\u003eerrmsg\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026quot;empty value not allowed for object key\u0026quot;\u003c/span\u003e)));","displayNoNewLineWarning":false,"position":18,"left":2278,"right":2270},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2271,"text":" \t\tif (i \u003e 0)","html":" \t\t\u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-s1\u003ei\u003c/span\u003e \u003cspan class=pl-c1\u003e\u0026gt;\u003c/span\u003e \u003cspan class=pl-c1\u003e0\u003c/span\u003e)","displayNoNewLineWarning":false,"position":19,"left":2279,"right":2271},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2272,"text":" \t\t\tappendStringInfoString(\u0026result, \", \");","html":" \t\t\t\u003cspan class=pl-en\u003eappendStringInfoString\u003c/span\u003e(\u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003eresult\u003c/span\u003e, \u003cspan class=pl-s\u003e\u0026quot;, \u0026quot;\u003c/span\u003e);","displayNoNewLineWarning":false,"position":20,"left":2280,"right":2272},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":2273,"text":" \t\tescape_json(\u0026result, v);","html":" \t\t\u003cspan class=pl-en\u003eescape_json\u003c/span\u003e(\u003cspan class=pl-c1\u003e\u0026amp;\u003c/span\u003e\u003cspan class=pl-s1\u003eresult\u003c/span\u003e, \u003cspan class=pl-s1\u003ev\u003c/span\u003e);","displayNoNewLineWarning":false,"position":21,"left":2281,"right":2273}],"diffNumber":0,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":2421,"linesChanged":8,"newTreeEntry":{"lineCount":2421,"path":"src/backend/utils/adt/json.c","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"src/backend/utils/adt/json.c","mode":100644},"linesAdded":0,"linesDeleted":8,"path":"src/backend/utils/adt/json.c","pathDigest":"f37ef31ce752fb78ff488169ad9ecc35ae19f32561f0c5f96222c498525a2195","status":"MODIFIED","truncatedReason":null,"oldOid":"fd18965e33da9dc7326803e61cf28d82237e3bba","newOid":"a61f63df7d19006b36adf7ee402999aa5243097d","copilotChatReference":null,"deletedSha":"fd18965e33da9dc7326803e61cf28d82237e3bba","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null},{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":1212,"text":"@@ -1213,9 +1213,13 @@ ERROR: mismatched array dimensions","html":"@@ -1213,9 +1213,13 @@ ERROR: mismatched array dimensions","displayNoNewLineWarning":false,"position":0,"left":1212,"right":1212},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1213,"text":" -- null key error","html":" -- null key error","displayNoNewLineWarning":false,"position":1,"left":1213,"right":1213},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1214,"text":" select json_object('{a,b,NULL,\"d e f\"}','{1,2,3,\"a b c\"}');","html":" select json_object(\u0026#39;{a,b,NULL,\u0026quot;d e f\u0026quot;}\u0026#39;,\u0026#39;{1,2,3,\u0026quot;a b c\u0026quot;}\u0026#39;);","displayNoNewLineWarning":false,"position":2,"left":1214,"right":1214},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1215,"text":" ERROR: null value not allowed for object key","html":" ERROR: null value not allowed for object key","displayNoNewLineWarning":false,"position":3,"left":1215,"right":1215},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1216,"text":"--- empty key error","html":"--- empty key \u003cspan class=\"x x-first x-last\"\u003eerror\u003c/span\u003e","displayNoNewLineWarning":false,"position":4,"left":1216,"right":1215},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1216,"text":"+-- empty key is allowed","html":"+-- empty key \u003cspan class=\"x x-first x-last\"\u003eis allowed\u003c/span\u003e","displayNoNewLineWarning":false,"position":5,"left":1216,"right":1216},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1217,"text":" select json_object('{a,b,\"\",\"d e f\"}','{1,2,3,\"a b c\"}');","html":" select json_object(\u0026#39;{a,b,\u0026quot;\u0026quot;,\u0026quot;d e f\u0026quot;}\u0026#39;,\u0026#39;{1,2,3,\u0026quot;a b c\u0026quot;}\u0026#39;);","displayNoNewLineWarning":false,"position":6,"left":1217,"right":1217},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1218,"text":"-ERROR: empty value not allowed for object key","html":"-ERROR: empty value not allowed for object key","displayNoNewLineWarning":false,"position":7,"left":1218,"right":1217},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1218,"text":"+ json_object ","html":"+ json_object ","displayNoNewLineWarning":false,"position":8,"left":1218,"right":1218},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1219,"text":"+-----------------------------------------------------","html":"+-----------------------------------------------------","displayNoNewLineWarning":false,"position":9,"left":1218,"right":1219},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1220,"text":"+ {\"a\" : \"1\", \"b\" : \"2\", \"\" : \"3\", \"d e f\" : \"a b c\"}","html":"+ {\u0026quot;a\u0026quot; : \u0026quot;1\u0026quot;, \u0026quot;b\u0026quot; : \u0026quot;2\u0026quot;, \u0026quot;\u0026quot; : \u0026quot;3\u0026quot;, \u0026quot;d e f\u0026quot; : \u0026quot;a b c\u0026quot;}","displayNoNewLineWarning":false,"position":10,"left":1218,"right":1220},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1221,"text":"+(1 row)","html":"+(1 row)","displayNoNewLineWarning":false,"position":11,"left":1218,"right":1221},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1222,"text":"+","html":"+","displayNoNewLineWarning":false,"position":12,"left":1218,"right":1222},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1223,"text":" -- json_to_record and json_to_recordset","html":" -- json_to_record and json_to_recordset","displayNoNewLineWarning":false,"position":13,"left":1219,"right":1223},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1224,"text":" select * from json_to_record('{\"a\":1,\"b\":\"foo\",\"c\":\"bar\"}')","html":" select * from json_to_record(\u0026#39;{\u0026quot;a\u0026quot;:1,\u0026quot;b\u0026quot;:\u0026quot;foo\u0026quot;,\u0026quot;c\u0026quot;:\u0026quot;bar\u0026quot;}\u0026#39;)","displayNoNewLineWarning":false,"position":14,"left":1220,"right":1224},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1225,"text":" as x(a int, b text, d text);","html":" as x(a int, b text, d text);","displayNoNewLineWarning":false,"position":15,"left":1221,"right":1225}],"diffNumber":1,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":1246,"linesChanged":8,"newTreeEntry":{"lineCount":1246,"path":"src/test/regress/expected/json.out","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"src/test/regress/expected/json.out","mode":100644},"linesAdded":6,"linesDeleted":2,"path":"src/test/regress/expected/json.out","pathDigest":"1c6eb347f4feb4c774470b75cadca6ccfa48b17eb1b84cbaf00d948302a59dee","status":"MODIFIED","truncatedReason":null,"oldOid":"fd18965e33da9dc7326803e61cf28d82237e3bba","newOid":"a61f63df7d19006b36adf7ee402999aa5243097d","copilotChatReference":null,"deletedSha":"fd18965e33da9dc7326803e61cf28d82237e3bba","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null},{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":1208,"text":"@@ -1209,9 +1209,13 @@ ERROR: mismatched array dimensions","html":"@@ -1209,9 +1209,13 @@ ERROR: mismatched array dimensions","displayNoNewLineWarning":false,"position":0,"left":1208,"right":1208},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1209,"text":" -- null key error","html":" -- null key error","displayNoNewLineWarning":false,"position":1,"left":1209,"right":1209},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1210,"text":" select json_object('{a,b,NULL,\"d e f\"}','{1,2,3,\"a b c\"}');","html":" select json_object(\u0026#39;{a,b,NULL,\u0026quot;d e f\u0026quot;}\u0026#39;,\u0026#39;{1,2,3,\u0026quot;a b c\u0026quot;}\u0026#39;);","displayNoNewLineWarning":false,"position":2,"left":1210,"right":1210},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1211,"text":" ERROR: null value not allowed for object key","html":" ERROR: null value not allowed for object key","displayNoNewLineWarning":false,"position":3,"left":1211,"right":1211},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1212,"text":"--- empty key error","html":"--- empty key \u003cspan class=\"x x-first x-last\"\u003eerror\u003c/span\u003e","displayNoNewLineWarning":false,"position":4,"left":1212,"right":1211},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1212,"text":"+-- empty key is allowed","html":"+-- empty key \u003cspan class=\"x x-first x-last\"\u003eis allowed\u003c/span\u003e","displayNoNewLineWarning":false,"position":5,"left":1212,"right":1212},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1213,"text":" select json_object('{a,b,\"\",\"d e f\"}','{1,2,3,\"a b c\"}');","html":" select json_object(\u0026#39;{a,b,\u0026quot;\u0026quot;,\u0026quot;d e f\u0026quot;}\u0026#39;,\u0026#39;{1,2,3,\u0026quot;a b c\u0026quot;}\u0026#39;);","displayNoNewLineWarning":false,"position":6,"left":1213,"right":1213},{"stylingDirective":null,"type":"DELETION","blobLineNumber":1214,"text":"-ERROR: empty value not allowed for object key","html":"-ERROR: empty value not allowed for object key","displayNoNewLineWarning":false,"position":7,"left":1214,"right":1213},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1214,"text":"+ json_object ","html":"+ json_object ","displayNoNewLineWarning":false,"position":8,"left":1214,"right":1214},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1215,"text":"+-----------------------------------------------------","html":"+-----------------------------------------------------","displayNoNewLineWarning":false,"position":9,"left":1214,"right":1215},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1216,"text":"+ {\"a\" : \"1\", \"b\" : \"2\", \"\" : \"3\", \"d e f\" : \"a b c\"}","html":"+ {\u0026quot;a\u0026quot; : \u0026quot;1\u0026quot;, \u0026quot;b\u0026quot; : \u0026quot;2\u0026quot;, \u0026quot;\u0026quot; : \u0026quot;3\u0026quot;, \u0026quot;d e f\u0026quot; : \u0026quot;a b c\u0026quot;}","displayNoNewLineWarning":false,"position":10,"left":1214,"right":1216},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1217,"text":"+(1 row)","html":"+(1 row)","displayNoNewLineWarning":false,"position":11,"left":1214,"right":1217},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":1218,"text":"+","html":"+","displayNoNewLineWarning":false,"position":12,"left":1214,"right":1218},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1219,"text":" -- json_to_record and json_to_recordset","html":" -- json_to_record and json_to_recordset","displayNoNewLineWarning":false,"position":13,"left":1215,"right":1219},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1220,"text":" select * from json_to_record('{\"a\":1,\"b\":\"foo\",\"c\":\"bar\"}')","html":" select * from json_to_record(\u0026#39;{\u0026quot;a\u0026quot;:1,\u0026quot;b\u0026quot;:\u0026quot;foo\u0026quot;,\u0026quot;c\u0026quot;:\u0026quot;bar\u0026quot;}\u0026#39;)","displayNoNewLineWarning":false,"position":14,"left":1216,"right":1220},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":1221,"text":" as x(a int, b text, d text);","html":" as x(a int, b text, d text);","displayNoNewLineWarning":false,"position":15,"left":1217,"right":1221}],"diffNumber":2,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":1242,"linesChanged":8,"newTreeEntry":{"lineCount":1242,"path":"src/test/regress/expected/json_1.out","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"src/test/regress/expected/json_1.out","mode":100644},"linesAdded":6,"linesDeleted":2,"path":"src/test/regress/expected/json_1.out","pathDigest":"cc50820d853ad3be2058055f00c32de87ad4c5283a0f3bc6edeb96f91bc233ee","status":"MODIFIED","truncatedReason":null,"oldOid":"fd18965e33da9dc7326803e61cf28d82237e3bba","newOid":"a61f63df7d19006b36adf7ee402999aa5243097d","copilotChatReference":null,"deletedSha":"fd18965e33da9dc7326803e61cf28d82237e3bba","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null},{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":434,"text":"@@ -435,7 +435,7 @@ select json_object('{a,b,c,\"d e f\"}','{1,2,3,\"a b c\",g}');","html":"@@ -435,7 +435,7 @@ select json_object(\u0026#39;{a,b,c,\u0026quot;d e f\u0026quot;}\u0026#39;,\u0026#39;{1,2,3,\u0026quot;a b c\u0026quot;,g}\u0026#39;);","displayNoNewLineWarning":false,"position":0,"left":434,"right":434},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":435,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":1,"left":435,"right":435},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":436,"text":" select json_object('{a,b,NULL,\"d e f\"}','{1,2,3,\"a b c\"}');","html":" \u003cspan class=\"pl-k\"\u003eselect\u003c/span\u003e json_object(\u003cspan class=\"pl-s\"\u003e\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e{a,b,NULL,\u0026quot;d e f\u0026quot;}\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e\u003c/span\u003e,\u003cspan class=\"pl-s\"\u003e\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e{1,2,3,\u0026quot;a b c\u0026quot;}\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e\u003c/span\u003e);","displayNoNewLineWarning":false,"position":2,"left":436,"right":436},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":437,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":3,"left":437,"right":437},{"stylingDirective":null,"type":"DELETION","blobLineNumber":438,"text":"--- empty key error","html":"-\u003cspan class=\"pl-c\"\u003e\u003cspan class=\"pl-c\"\u003e--\u003c/span\u003e empty key \u003cspan class=\"x x-first x-last\"\u003eerror\u003c/span\u003e\u003c/span\u003e","displayNoNewLineWarning":false,"position":4,"left":438,"right":437},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":438,"text":"+-- empty key is allowed","html":"+\u003cspan class=\"pl-c\"\u003e\u003cspan class=\"pl-c\"\u003e--\u003c/span\u003e empty key \u003cspan class=\"x x-first x-last\"\u003eis allowed\u003c/span\u003e\u003c/span\u003e","displayNoNewLineWarning":false,"position":5,"left":438,"right":438},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":439,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":6,"left":439,"right":439},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":440,"text":" select json_object('{a,b,\"\",\"d e f\"}','{1,2,3,\"a b c\"}');","html":" \u003cspan class=\"pl-k\"\u003eselect\u003c/span\u003e json_object(\u003cspan class=\"pl-s\"\u003e\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e{a,b,\u0026quot;\u0026quot;,\u0026quot;d e f\u0026quot;}\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e\u003c/span\u003e,\u003cspan class=\"pl-s\"\u003e\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e{1,2,3,\u0026quot;a b c\u0026quot;}\u003cspan class=\"pl-pds\"\u003e\u0026#39;\u003c/span\u003e\u003c/span\u003e);","displayNoNewLineWarning":false,"position":7,"left":440,"right":440},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":441,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":8,"left":441,"right":441}],"diffNumber":3,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":452,"linesChanged":2,"newTreeEntry":{"lineCount":452,"path":"src/test/regress/sql/json.sql","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"src/test/regress/sql/json.sql","mode":100644},"linesAdded":1,"linesDeleted":1,"path":"src/test/regress/sql/json.sql","pathDigest":"94c0251a8746604d43229f39136eaa5fd53feb420e4133717942724667a571d8","status":"MODIFIED","truncatedReason":null,"oldOid":"fd18965e33da9dc7326803e61cf28d82237e3bba","newOid":"a61f63df7d19006b36adf7ee402999aa5243097d","copilotChatReference":null,"deletedSha":"fd18965e33da9dc7326803e61cf28d82237e3bba","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null}],"splitViewPreference":"unified","ignoreWhitespace":false,"repoOwnerGlobalRelayId":"MDEyOk9yZ2FuaXphdGlvbjE3NzU0Mw==","commentsPreference":"visible","diffLineSpacingPreference":"relaxed","useMonospaceFont":false,"pasteUrlLinkAsPlainText":false,"userNotices":[],"path":"/postgres/postgres/commit/a61f63df7d19006b36adf7ee402999aa5243097d","fileTreeExpanded":true,"headerInfo":{"additions":13,"deletions":13,"filesChanged":4,"filesChangedString":"4"},"moreDiffsToLoad":false,"asyncDiffLoadInfo":{"startIndex":4,"truncated":false,"byteCount":2333,"lineShownCount":63},"commentInfo":{"canComment":false,"locked":false,"canLock":false,"repoArchived":false},"csrf_tokens":{"/users/diffview?diff=split":{"post":"CG_GRykNJwKwFpUKJge6Epulpo01nc_td5pH8OiofO5vl5Jv5NrW6OayMQGJ8bKG1IPpr35cUa7bZIGxeWCusA"},"/users/diffview?diff=unified":{"post":"o89rQBllV51XLoX5AEyNkYQwShNpFwBj6ok9EJubw4TENz9o1LKmdwGKIfKvuoUFyxYFMSLWniBGd_tRClMR2g"},"/notifications/thread":{"post":"yCeEB5mgco8LFWlf84QtkKG1n69lp4VpiKYU9_qnegpx64s8Y0X30BrKhwghDKo5NwEL8hROlnxtOOAacJjYew"}}},"title":"Allow empty string object keys in json_object(). · postgres/postgres@a61f63d","appPayload":{"helpUrl":"https://docs.github.com","findInDiffWorkerPath":"/assets-cdn/worker/find-in-diff-worker-2bfe39677d14.js","enabled_features":{"diff_ux_refresh_beta":false,"diff_inline_comments":true,"diff_ux_refresh_ssr_five":false,"diff_ux_refresh_ssr_ten":false,"show_pusher_on_commit_detail":false}}}

Commit a61f63d

Browse files
committed
Allow empty string object keys in json_object().
This makes the behaviour consistent with the json parser, other json-generating functions, and the JSON standards.
1 parent fd18965 commit a61f63d

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/backend/utils/adt/json.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,10 +2184,6 @@ json_object(PG_FUNCTION_ARGS)
21842184
errmsg("null value not allowed for object key")));
21852185

21862186
v = TextDatumGetCString(in_datums[i * 2]);
2187-
if (v[0] == '\0')
2188-
ereport(ERROR,
2189-
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2190-
errmsg("empty value not allowed for object key")));
21912187
if (i > 0)
21922188
appendStringInfoString(&result, ", ");
21932189
escape_json(&result, v);
@@ -2272,10 +2268,6 @@ json_object_two_arg(PG_FUNCTION_ARGS)
22722268
errmsg("null value not allowed for object key")));
22732269

22742270
v = TextDatumGetCString(key_datums[i]);
2275-
if (v[0] == '\0')
2276-
ereport(ERROR,
2277-
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2278-
errmsg("empty value not allowed for object key")));
22792271
if (i > 0)
22802272
appendStringInfoString(&result, ", ");
22812273
escape_json(&result, v);

src/test/regress/expected/json.out

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,13 @@ ERROR: mismatched array dimensions
12131213
-- null key error
12141214
select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}');
12151215
ERROR: null value not allowed for object key
1216-
-- empty key error
1216+
-- empty key is allowed
12171217
select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}');
1218-
ERROR: empty value not allowed for object key
1218+
json_object
1219+
-----------------------------------------------------
1220+
{"a" : "1", "b" : "2", "" : "3", "d e f" : "a b c"}
1221+
(1 row)
1222+
12191223
-- json_to_record and json_to_recordset
12201224
select * from json_to_record('{"a":1,"b":"foo","c":"bar"}')
12211225
as x(a int, b text, d text);

src/test/regress/expected/json_1.out

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,13 @@ ERROR: mismatched array dimensions
12091209
-- null key error
12101210
select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}');
12111211
ERROR: null value not allowed for object key
1212-
-- empty key error
1212+
-- empty key is allowed
12131213
select json_object('{a,b,"","d e f"}','{ B723 1,2,3,"a b c"}');
1214-
ERROR: empty value not allowed for object key
1214+
json_object
1215+
-----------------------------------------------------
1216+
{"a" : "1", "b" : "2", "" : "3", "d e f" : "a b c"}
1217+
(1 row)
1218+
12151219
-- json_to_record and json_to_recordset
12161220
select * from json_to_record('{"a":1,"b":"foo","c":"bar"}')
12171221
as x(a int, b text, d text);

src/test/regress/sql/json.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ select json_object('{a,b,c,"d e f"}','{1,2,3,"a b c",g}');
435435

436436
select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}');
437437

438-
-- empty key error
438+
-- empty key is allowed
439439

440440
select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}');
441441

0 commit comments

Comments
 (0)
0