Skip to content

Commit f649da1

Browse files
author
Nikita Glukhov
committed
Add jsonb support for custom toasters
1 parent 694c56b commit f649da1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/backend/utils/adt/json_generic.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "postgres.h"
1212

13+
#include "access/toasterapi.h"
1314
#include "miscadmin.h"
1415
#include "utils/builtins.h"
1516
#include "utils/jsonb.h"
@@ -101,9 +102,24 @@ JsonExpandDatum(Datum value, JsonContainerOps *ops, Json *tmp)
101102
Json *
102103
DatumGetJson(Datum value, JsonContainerOps *ops, Json *tmp)
103104
{
104-
Json *json = JsonExpandDatum(value, ops, tmp);
105+
Json *json;
105106

106-
//JsonInit(json);
107+
if (VARATT_IS_CUSTOM(value))
108+
{
109+
Oid toasterid = VARATT_CUSTOM_GET_TOASTERID(value);
110+
TsrRoutine *toaster = SearchTsrCache(toasterid);
111+
JsonToastRoutine *routine = toaster->get_vtable(toasterid);
112+
113+
if (routine->magic == JSON_TOASTER_MAGIC)
114+
{
115+
json = JsonExpand(tmp, value, false, routine->ops);
116+
routine->ops->init(JsonRoot(json), value);
117+
118+
return json;
119+
}
120+
}
121+
122+
json = JsonExpandDatum(value, ops, tmp);
107123
json->root.ops->init(&json->root, json->obj.value);
108124

109125
return json;

src/include/utils/json_generic.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,12 @@ extern int lengthCompareJsonbString(const char *val1, int len1,
310310

311311
extern JsonContainerOps jsonbContainerOps;
312312

313+
#define JSON_TOASTER_MAGIC 0x20211223
314+
315+
typedef struct JsonToastRoutine
316+
{
317+
uint32 magic;
318+
JsonContainerOps *ops;
319+
} JsonToastRoutine;
320+
313321
#endif /* UTILS_JSON_GENERIC_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy