mirror of https://github.com/citusdata/citus.git
Add ExtractFieldInt32(..) to jsonbutils
parent
b989e8872c
commit
9d2d97fe67
|
@ -83,6 +83,25 @@ ExtractFieldBoolean(Datum jsonbDoc, const char *fieldName, bool defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ExtractFieldInt32 gets value of fieldName from jsonbDoc, or returns
|
||||||
|
* defaultValue if it doesn't exist.
|
||||||
|
*/
|
||||||
|
int32
|
||||||
|
ExtractFieldInt32(Datum jsonbDoc, const char *fieldName, int32 defaultValue)
|
||||||
|
{
|
||||||
|
Datum jsonbDatum = 0;
|
||||||
|
bool found = ExtractFieldJsonb(jsonbDoc, fieldName, &jsonbDatum, false);
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Datum int32Datum = DirectFunctionCall1(jsonb_int4, jsonbDatum);
|
||||||
|
return DatumGetInt32(int32Datum);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ExtractFieldTextP gets value of fieldName as text* from jsonbDoc, or
|
* ExtractFieldTextP gets value of fieldName as text* from jsonbDoc, or
|
||||||
* returns NULL if it doesn't exist.
|
* returns NULL if it doesn't exist.
|
||||||
|
|
|
@ -16,5 +16,6 @@
|
||||||
bool ExtractFieldJsonbDatum(Datum jsonbDoc, const char *fieldName, Datum *result);
|
bool ExtractFieldJsonbDatum(Datum jsonbDoc, const char *fieldName, Datum *result);
|
||||||
text * ExtractFieldTextP(Datum jsonbDoc, const char *fieldName);
|
text * ExtractFieldTextP(Datum jsonbDoc, const char *fieldName);
|
||||||
bool ExtractFieldBoolean(Datum jsonbDoc, const char *fieldName, bool defaultValue);
|
bool ExtractFieldBoolean(Datum jsonbDoc, const char *fieldName, bool defaultValue);
|
||||||
|
int32 ExtractFieldInt32(Datum jsonbDoc, const char *fieldName, int32 defaultValue);
|
||||||
|
|
||||||
#endif /* CITUS_JSONBUTILS_H */
|
#endif /* CITUS_JSONBUTILS_H */
|
||||||
|
|
Loading…
Reference in New Issue