File tree Expand file tree Collapse file tree 1 file changed +13
-23
lines changed Expand file tree Collapse file tree 1 file changed +13
-23
lines changed Original file line number Diff line number Diff line change @@ -4012,33 +4012,23 @@ Datum
40124012jsonb_get_element (Datum jsonbdatum , text * * path , int path_len , bool * is_null )
40134013{
40144014 Jsonb * jb = DatumGetJsonb (jsonbdatum );
4015- JsonbValue * v ;
4016- int level = 1 ;
4015+ JsonbValue vbuf ;
4016+ JsonbValue * v = JsonbToJsonbValue (jb , & vbuf );
4017+ int level ;
40174018
4018- if (! JB_ROOT_IS_OBJECT ( jb ) )
4019+ for ( level = 0 ; level < path_len ; level ++ )
40194020 {
4020- * is_null = true;
4021- return (Datum ) 0 ;
4022- }
4023-
4024- v = findJsonbValueFromContainerLen (& jb -> root , JB_FOBJECT ,
4025- VARDATA_ANY (path [0 ]),
4026- VARSIZE_ANY_EXHDR (path [0 ]));
4027-
4028- while (v != NULL &&
4029- v -> type == jbvBinary && level < path_len )
4030- {
4031- v = findJsonbValueFromContainerLen (v -> val .binary .data , JB_FOBJECT ,
4032- VARDATA_ANY (path [level ]),
4033- VARSIZE_ANY_EXHDR (path [level ]));
4034- level ++ ;
4021+ if (v -> type != jbvBinary ||
4022+ !(v = findJsonbValueFromContainerLen (v -> val .binary .data , JB_FOBJECT ,
4023+ VARDATA_ANY (path [level ]),
4024+ VARSIZE_ANY_EXHDR (path [level ]))))
4025+ {
4026+ * is_null = true;
4027+ return (Datum ) 0 ;
4028+ }
40354029 }
40364030
4037- if (v != NULL && level == path_len )
4038- PG_RETURN_JSONB (JsonbValueToJsonb (v ));
4039-
4040- * is_null = true;
4041- return (Datum ) 0 ;
4031+ PG_RETURN_JSONB (JsonbValueToJsonb (v ));
40424032}
40434033
40444034Datum
You can’t perform that action at this time.
0 commit comments