PostgreSQL Source Code  git master
json.h File Reference
#include "lib/stringinfo.h"
Include dependency graph for json.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void escape_json (StringInfo buf, const char *str)
 
void escape_json_with_len (StringInfo buf, const char *str, int len)
 
void escape_json_text (StringInfo buf, const text *txt)
 
char * JsonEncodeDateTime (char *buf, Datum value, Oid typid, const int *tzp)
 
bool to_json_is_immutable (Oid typoid)
 
Datum json_build_object_worker (int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)
 
Datum json_build_array_worker (int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
 
bool json_validate (text *json, bool check_unique_keys, bool throw_error)
 

Function Documentation

◆ escape_json()

void escape_json ( StringInfo  buf,
const char *  str 
)

Definition at line 1602 of file json.c.

1603 {
1605 
1606  for (; *str != '\0'; str++)
1608 
1610 }
const char * str
static pg_attribute_always_inline void escape_json_char(StringInfo buf, char c)
Definition: json.c:1562
static char * buf
Definition: pg_test_fsync.c:72
#define appendStringInfoCharMacro(str, ch)
Definition: stringinfo.h:204

References appendStringInfoCharMacro, buf, escape_json_char(), and str.

Referenced by appendJSONKeyValue(), composite_to_json(), datum_to_json_internal(), escape_yaml(), ExplainDummyGroup(), ExplainOpenGroup(), ExplainProperty(), ExplainPropertyList(), ExplainPropertyListNested(), populate_scalar(), sn_object_field_start(), sn_scalar(), transform_string_values_object_field_start(), transformJsonTableColumn(), and write_jsonlog().

◆ escape_json_text()

void escape_json_text ( StringInfo  buf,
const text txt 
)

Definition at line 1736 of file json.c.

1737 {
1738  /* must cast away the const, unfortunately */
1739  text *tunpacked = pg_detoast_datum_packed(unconstify(text *, txt));
1740  int len = VARSIZE_ANY_EXHDR(tunpacked);
1741  char *str;
1742 
1743  str = VARDATA_ANY(tunpacked);
1744 
1746 
1747  /* pfree any detoasted values */
1748  if (tunpacked != txt)
1749  pfree(tunpacked);
1750 }
#define unconstify(underlying_type, expr)
Definition: c.h:1224
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1864
void escape_json_with_len(StringInfo buf, const char *str, int len)
Definition: json.c:1631
void pfree(void *pointer)
Definition: mcxt.c:1521
const void size_t len
Definition: c.h:666
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

References buf, escape_json_with_len(), len, pfree(), pg_detoast_datum_packed(), str, unconstify, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by datum_to_json_internal(), json_object(), json_object_two_arg(), and transform_string_values_scalar().

◆ escape_json_with_len()

void escape_json_with_len ( StringInfo  buf,
const char *  str,
int  len 
)

Definition at line 1631 of file json.c.

1632 {
1633  int vlen;
1634 
1635  Assert(len >= 0);
1636 
1637  /*
1638  * Since we know the minimum length we'll need to append, let's just
1639  * enlarge the buffer now rather than incrementally making more space when
1640  * we run out. Add two extra bytes for the enclosing quotes.
1641  */
1642  enlargeStringInfo(buf, len + 2);
1643 
1644  /*
1645  * Figure out how many bytes to process using SIMD. Round 'len' down to
1646  * the previous multiple of sizeof(Vector8), assuming that's a power-of-2.
1647  */
1648  vlen = len & (int) (~(sizeof(Vector8) - 1));
1649 
1651 
1652  for (int i = 0, copypos = 0;;)
1653  {
1654  /*
1655  * To speed this up, try searching sizeof(Vector8) bytes at once for
1656  * special characters that we need to escape. When we find one, we
1657  * fall out of the Vector8 loop and copy the portion we've vector
1658  * searched and then we process sizeof(Vector8) bytes one byte at a
1659  * time. Once done, come back and try doing vector searching again.
1660  * We'll also process any remaining bytes at the tail end of the
1661  * string byte-by-byte. This optimization assumes that most chunks of
1662  * sizeof(Vector8) bytes won't contain any special characters.
1663  */
1664  for (; i < vlen; i += sizeof(Vector8))
1665  {
1666  Vector8 chunk;
1667 
1668  vector8_load(&chunk, (const uint8 *) &str[i]);
1669 
1670  /*
1671  * Break on anything less than ' ' or if we find a '"' or '\\'.
1672  * Those need special handling. That's done in the per-byte loop.
1673  */
1674  if (vector8_has_le(chunk, (unsigned char) 0x1F) ||
1675  vector8_has(chunk, (unsigned char) '"') ||
1676  vector8_has(chunk, (unsigned char) '\\'))
1677  break;
1678 
1679 #ifdef ESCAPE_JSON_FLUSH_AFTER
1680 
1681  /*
1682  * Flush what's been checked so far out to the destination buffer
1683  * every so often to avoid having to re-read cachelines when
1684  * escaping large strings.
1685  */
1686  if (i - copypos >= ESCAPE_JSON_FLUSH_AFTER)
1687  {
1688  appendBinaryStringInfo(buf, &str[copypos], i - copypos);
1689  copypos = i;
1690  }
1691 #endif
1692  }
1693 
1694  /*
1695  * Write to the destination up to the point that we've vector searched
1696  * so far. Do this only when switching into per-byte mode rather than
1697  * once every sizeof(Vector8) bytes.
1698  */
1699  if (copypos < i)
1700  {
1701  appendBinaryStringInfo(buf, &str[copypos], i - copypos);
1702  copypos = i;
1703  }
1704 
1705  /*
1706  * Per-byte loop for Vector8s containing special chars and for
1707  * processing the tail of the string.
1708  */
1709  for (int b = 0; b < sizeof(Vector8); b++)
1710  {
1711  /* check if we've finished */
1712  if (i == len)
1713  goto done;
1714 
1715  Assert(i < len);
1716 
1717  escape_json_char(buf, str[i++]);
1718  }
1719 
1720  copypos = i;
1721  /* We're not done yet. Try the vector search again. */
1722  }
1723 
1724 done:
1726 }
#define Assert(condition)
Definition: c.h:837
unsigned char uint8
Definition: c.h:490
uint64 chunk
int b
Definition: isn.c:69
int i
Definition: isn.c:72
#define ESCAPE_JSON_FLUSH_AFTER
Definition: json.c:1622
static bool vector8_has_le(const Vector8 v, const uint8 c)
Definition: simd.h:213
static void vector8_load(Vector8 *v, const uint8 *s)
Definition: simd.h:108
uint64 Vector8
Definition: simd.h:60
static bool vector8_has(const Vector8 v, const uint8 c)
Definition: simd.h:162
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:286
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:230

References appendBinaryStringInfo(), appendStringInfoCharMacro, Assert, b, buf, chunk, enlargeStringInfo(), escape_json_char(), ESCAPE_JSON_FLUSH_AFTER, i, len, str, vector8_has(), vector8_has_le(), and vector8_load().

Referenced by AddFileToBackupManifest(), escape_json_text(), hstore_to_json(), hstore_to_json_loose(), jsonb_put_escaped_value(), populate_scalar(), and printJsonPathItem().

◆ json_build_array_worker()

Datum json_build_array_worker ( int  nargs,
const Datum args,
const bool *  nulls,
const Oid types,
bool  absent_on_null 
)

Definition at line 1344 of file json.c.

1346 {
1347  int i;
1348  const char *sep = "";
1349  StringInfo result;
1350 
1351  result = makeStringInfo();
1352 
1353  appendStringInfoChar(result, '[');
1354 
1355  for (i = 0; i < nargs; i++)
1356  {
1357  if (absent_on_null && nulls[i])
1358  continue;
1359 
1360  appendStringInfoString(result, sep);
1361  sep = ", ";
1362  add_json(args[i], nulls[i], result, types[i], false);
1363  }
1364 
1365  appendStringInfoChar(result, ']');
1366 
1367  return PointerGetDatum(cstring_to_text_with_len(result->data, result->len));
1368 }
struct typedefs * types
Definition: ecpg.c:30
static void add_json(Datum val, bool is_null, StringInfo result, Oid val_type, bool key_scalar)
Definition: json.c:602
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
StringInfo makeStringInfo(void)
Definition: stringinfo.c:38
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:179
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:191
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:196

References add_json(), appendStringInfoChar(), appendStringInfoString(), generate_unaccent_rules::args, cstring_to_text_with_len(), StringInfoData::data, i, StringInfoData::len, makeStringInfo(), PointerGetDatum(), and types.

Referenced by ExecEvalJsonConstructor(), and json_build_array().

◆ json_build_object_worker()

Datum json_build_object_worker ( int  nargs,
const Datum args,
const bool *  nulls,
const Oid types,
bool  absent_on_null,
bool  unique_keys 
)

Definition at line 1224 of file json.c.

1226 {
1227  int i;
1228  const char *sep = "";
1229  StringInfo result;
1230  JsonUniqueBuilderState unique_check;
1231 
1232  if (nargs % 2 != 0)
1233  ereport(ERROR,
1234  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1235  errmsg("argument list must have even number of elements"),
1236  /* translator: %s is a SQL function name */
1237  errhint("The arguments of %s must consist of alternating keys and values.",
1238  "json_build_object()")));
1239 
1240  result = makeStringInfo();
1241 
1242  appendStringInfoChar(result, '{');
1243 
1244  if (unique_keys)
1245  json_unique_builder_init(&unique_check);
1246 
1247  for (i = 0; i < nargs; i += 2)
1248  {
1249  StringInfo out;
1250  bool skip;
1251  int key_offset;
1252 
1253  /* Skip null values if absent_on_null */
1254  skip = absent_on_null && nulls[i + 1];
1255 
1256  if (skip)
1257  {
1258  /* If key uniqueness check is needed we must save skipped keys */
1259  if (!unique_keys)
1260  continue;
1261 
1262  out = json_unique_builder_get_throwawaybuf(&unique_check);
1263  }
1264  else
1265  {
1266  appendStringInfoString(result, sep);
1267  sep = ", ";
1268  out = result;
1269  }
1270 
1271  /* process key */
1272  if (nulls[i])
1273  ereport(ERROR,
1274  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1275  errmsg("null value not allowed for object key")));
1276 
1277  /* save key offset before appending it */
1278  key_offset = out->len;
1279 
1280  add_json(args[i], false, out, types[i], true);
1281 
1282  if (unique_keys)
1283  {
1284  /*
1285  * check key uniqueness after key appending
1286  *
1287  * Copy the key first, instead of pointing into the buffer. It
1288  * will be added to the hash table, but the buffer may get
1289  * reallocated as we're appending more data to it. That would
1290  * invalidate pointers to keys in the current buffer.
1291  */
1292  const char *key = pstrdup(&out->data[key_offset]);
1293 
1294  if (!json_unique_check_key(&unique_check.check, key, 0))
1295  ereport(ERROR,
1296  errcode(ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE),
1297  errmsg("duplicate JSON object key value: %s", key));
1298 
1299  if (skip)
1300  continue;
1301  }
1302 
1303  appendStringInfoString(result, " : ");
1304 
1305  /* process value */
1306  add_json(args[i + 1], nulls[i + 1], result, types[i + 1], false);
1307  }
1308 
1309  appendStringInfoChar(result, '}');
1310 
1311  return PointerGetDatum(cstring_to_text_with_len(result->data, result->len));
1312 }
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static StringInfo json_unique_builder_get_throwawaybuf(JsonUniqueBuilderState *cxt)
Definition: json.c:978
static bool json_unique_check_key(JsonUniqueCheckState *cxt, const char *key, int object_id)
Definition: json.c:958
static void json_unique_builder_init(JsonUniqueBuilderState *cxt)
Definition: json.c:950
char * pstrdup(const char *in)
Definition: mcxt.c:1696
static const struct exclude_list_item skip[]
Definition: pg_checksums.c:107
JsonUniqueCheckState check
Definition: json.c:71

References add_json(), appendStringInfoChar(), appendStringInfoString(), generate_unaccent_rules::args, JsonUniqueBuilderState::check, cstring_to_text_with_len(), StringInfoData::data, ereport, errcode(), errhint(), errmsg(), ERROR, i, json_unique_builder_get_throwawaybuf(), json_unique_builder_init(), json_unique_check_key(), sort-test::key, StringInfoData::len, makeStringInfo(), PointerGetDatum(), pstrdup(), skip, and types.

Referenced by ExecEvalJsonConstructor(), and json_build_object().

◆ json_validate()

bool json_validate ( text json,
bool  check_unique_keys,
bool  throw_error 
)

Definition at line 1812 of file json.c.

1813 {
1814  JsonLexContext lex;
1815  JsonSemAction uniqueSemAction = {0};
1817  JsonParseErrorType result;
1818 
1819  makeJsonLexContext(&lex, json, check_unique_keys);
1820 
1821  if (check_unique_keys)
1822  {
1823  state.lex = &lex;
1824  state.stack = NULL;
1825  state.id_counter = 0;
1826  state.unique = true;
1827  json_unique_check_init(&state.check);
1828 
1829  uniqueSemAction.semstate = &state;
1830  uniqueSemAction.object_start = json_unique_object_start;
1832  uniqueSemAction.object_end = json_unique_object_end;
1833  }
1834 
1835  result = pg_parse_json(&lex, check_unique_keys ? &uniqueSemAction : &nullSemAction);
1836 
1837  if (result != JSON_SUCCESS)
1838  {
1839  if (throw_error)
1840  json_errsave_error(result, &lex, NULL);
1841 
1842  return false; /* invalid json */
1843  }
1844 
1845  if (check_unique_keys && !state.unique)
1846  {
1847  if (throw_error)
1848  ereport(ERROR,
1849  (errcode(ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE),
1850  errmsg("duplicate JSON object key value")));
1851 
1852  return false; /* not unique keys */
1853  }
1854 
1855  if (check_unique_keys)
1856  freeJsonLexContext(&lex);
1857 
1858  return true; /* ok */
1859 }
static JsonParseErrorType json_unique_object_start(void *_state)
Definition: json.c:1754
static void json_unique_check_init(JsonUniqueCheckState *cxt)
Definition: json.c:932
static JsonParseErrorType json_unique_object_field_start(void *_state, char *field, bool isnull)
Definition: json.c:1787
static JsonParseErrorType json_unique_object_end(void *_state)
Definition: json.c:1772
JsonParseErrorType pg_parse_json(JsonLexContext *lex, const JsonSemAction *sem)
Definition: jsonapi.c:744
const JsonSemAction nullSemAction
Definition: jsonapi.c:287
void freeJsonLexContext(JsonLexContext *lex)
Definition: jsonapi.c:687
JsonParseErrorType
Definition: jsonapi.h:35
@ JSON_SUCCESS
Definition: jsonapi.h:36
JsonLexContext * makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes)
Definition: jsonfuncs.c:539
void json_errsave_error(JsonParseErrorType error, JsonLexContext *lex, Node *escontext)
Definition: jsonfuncs.c:640
json_struct_action object_start
Definition: jsonapi.h:148
json_ofield_action object_field_start
Definition: jsonapi.h:152
void * semstate
Definition: jsonapi.h:147
json_struct_action object_end
Definition: jsonapi.h:149
Definition: regguts.h:323

References ereport, errcode(), errmsg(), ERROR, freeJsonLexContext(), json_errsave_error(), JSON_SUCCESS, json_unique_check_init(), json_unique_object_end(), json_unique_object_field_start(), json_unique_object_start(), makeJsonLexContext(), nullSemAction, JsonSemAction::object_end, JsonSemAction::object_field_start, JsonSemAction::object_start, pg_parse_json(), and JsonSemAction::semstate.

Referenced by ExecEvalJsonConstructor(), and ExecEvalJsonIsPredicate().

◆ JsonEncodeDateTime()

char* JsonEncodeDateTime ( char *  buf,
Datum  value,
Oid  typid,
const int *  tzp 
)

Definition at line 310 of file json.c.

311 {
312  if (!buf)
313  buf = palloc(MAXDATELEN + 1);
314 
315  switch (typid)
316  {
317  case DATEOID:
318  {
319  DateADT date;
320  struct pg_tm tm;
321 
323 
324  /* Same as date_out(), but forcing DateStyle */
325  if (DATE_NOT_FINITE(date))
327  else
328  {
330  &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday));
332  }
333  }
334  break;
335  case TIMEOID:
336  {
337  TimeADT time = DatumGetTimeADT(value);
338  struct pg_tm tt,
339  *tm = &tt;
340  fsec_t fsec;
341 
342  /* Same as time_out(), but forcing DateStyle */
343  time2tm(time, tm, &fsec);
344  EncodeTimeOnly(tm, fsec, false, 0, USE_XSD_DATES, buf);
345  }
346  break;
347  case TIMETZOID:
348  {
350  struct pg_tm tt,
351  *tm = &tt;
352  fsec_t fsec;
353  int tz;
354 
355  /* Same as timetz_out(), but forcing DateStyle */
356  timetz2tm(time, tm, &fsec, &tz);
357  EncodeTimeOnly(tm, fsec, true, tz, USE_XSD_DATES, buf);
358  }
359  break;
360  case TIMESTAMPOID:
361  {
363  struct pg_tm tm;
364  fsec_t fsec;
365 
367  /* Same as timestamp_out(), but forcing DateStyle */
370  else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0)
371  EncodeDateTime(&tm, fsec, false, 0, NULL, USE_XSD_DATES, buf);
372  else
373  ereport(ERROR,
374  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
375  errmsg("timestamp out of range")));
376  }
377  break;
378  case TIMESTAMPTZOID:
379  {
381  struct pg_tm tm;
382  int tz;
383  fsec_t fsec;
384  const char *tzn = NULL;
385 
387 
388  /*
389  * If a time zone is specified, we apply the time-zone shift,
390  * convert timestamptz to pg_tm as if it were without a time
391  * zone, and then use the specified time zone for converting
392  * the timestamp into a string.
393  */
394  if (tzp)
395  {
396  tz = *tzp;
398  }
399 
400  /* Same as timestamptz_out(), but forcing DateStyle */
403  else if (timestamp2tm(timestamp, tzp ? NULL : &tz, &tm, &fsec,
404  tzp ? NULL : &tzn, NULL) == 0)
405  {
406  if (tzp)
407  tm.tm_isdst = 1; /* set time-zone presence flag */
408 
409  EncodeDateTime(&tm, fsec, true, tz, tzn, USE_XSD_DATES, buf);
410  }
411  else
412  ereport(ERROR,
413  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
414  errmsg("timestamp out of range")));
415  }
416  break;
417  default:
418  elog(ERROR, "unknown jsonb value datetime type oid %u", typid);
419  return NULL;
420  }
421 
422  return buf;
423 }
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:4312
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:311
void EncodeDateTime(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str)
Definition: datetime.c:4342
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
Definition: datetime.c:4227
void EncodeSpecialTimestamp(Timestamp dt, char *str)
Definition: timestamp.c:1586
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1891
int64 Timestamp
Definition: timestamp.h:38
int64 TimestampTz
Definition: timestamp.h:39
int32 fsec_t
Definition: timestamp.h:41
#define USECS_PER_SEC
Definition: timestamp.h:134
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:169
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:235
int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: date.c:2415
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1500
void EncodeSpecialDate(DateADT dt, char *str)
Definition: date.c:294
#define DATE_NOT_FINITE(j)
Definition: date.h:43
int32 DateADT
Definition: date.h:23
static DateADT DatumGetDateADT(Datum X)
Definition: date.h:54
static TimeADT DatumGetTimeADT(Datum X)
Definition: date.h:60
static TimeTzADT * DatumGetTimeTzADTP(Datum X)
Definition: date.h:66
int64 TimeADT
Definition: date.h:25
#define elog(elevel,...)
Definition: elog.h:225
#define MAXDATELEN
Definition: datetime.h:200
static struct @160 value
static struct pg_tm tm
Definition: localtime.c:104
void * palloc(Size size)
Definition: mcxt.c:1317
#define USE_XSD_DATES
Definition: miscadmin.h:239
long date
Definition: pgtypes_date.h:9
int64 timestamp
Definition: date.h:28
Definition: pgtime.h:35
int tm_mday
Definition: pgtime.h:39
int tm_mon
Definition: pgtime.h:40
int tm_isdst
Definition: pgtime.h:44
int tm_year
Definition: pgtime.h:41
static Timestamp DatumGetTimestamp(Datum X)
Definition: timestamp.h:28
static TimestampTz DatumGetTimestampTz(Datum X)
Definition: timestamp.h:34

References buf, DATE_NOT_FINITE, DatumGetDateADT(), DatumGetTimeADT(), DatumGetTimestamp(), DatumGetTimestampTz(), DatumGetTimeTzADTP(), elog, EncodeDateOnly(), EncodeDateTime(), EncodeSpecialDate(), EncodeSpecialTimestamp(), EncodeTimeOnly(), ereport, errcode(), errmsg(), ERROR, j2date(), MAXDATELEN, palloc(), POSTGRES_EPOCH_JDATE, time2tm(), timestamp2tm(), TIMESTAMP_NOT_FINITE, timetz2tm(), tm, pg_tm::tm_isdst, pg_tm::tm_mday, pg_tm::tm_mon, pg_tm::tm_year, USE_XSD_DATES, USECS_PER_SEC, and value.

Referenced by convertJsonbScalar(), datum_to_json_internal(), datum_to_jsonb_internal(), and executeItemOptUnwrapTarget().

◆ to_json_is_immutable()

bool to_json_is_immutable ( Oid  typoid)

Definition at line 700 of file json.c.

701 {
702  JsonTypeCategory tcategory;
703  Oid outfuncoid;
704 
705  json_categorize_type(typoid, false, &tcategory, &outfuncoid);
706 
707  switch (tcategory)
708  {
709  case JSONTYPE_BOOL:
710  case JSONTYPE_JSON:
711  case JSONTYPE_JSONB:
712  case JSONTYPE_NULL:
713  return true;
714 
715  case JSONTYPE_DATE:
716  case JSONTYPE_TIMESTAMP:
718  return false;
719 
720  case JSONTYPE_ARRAY:
721  return false; /* TODO recurse into elements */
722 
723  case JSONTYPE_COMPOSITE:
724  return false; /* TODO recurse into fields */
725 
726  case JSONTYPE_NUMERIC:
727  case JSONTYPE_CAST:
728  case JSONTYPE_OTHER:
729  return func_volatile(outfuncoid) == PROVOLATILE_IMMUTABLE;
730  }
731 
732  return false; /* not reached */
733 }
void json_categorize_type(Oid typoid, bool is_jsonb, JsonTypeCategory *tcategory, Oid *outfuncoid)
Definition: jsonfuncs.c:5976
JsonTypeCategory
Definition: jsonfuncs.h:69
@ JSONTYPE_JSON
Definition: jsonfuncs.h:76
@ JSONTYPE_NULL
Definition: jsonfuncs.h:70
@ JSONTYPE_TIMESTAMP
Definition: jsonfuncs.h:74
@ JSONTYPE_NUMERIC
Definition: jsonfuncs.h:72
@ JSONTYPE_DATE
Definition: jsonfuncs.h:73
@ JSONTYPE_BOOL
Definition: jsonfuncs.h:71
@ JSONTYPE_OTHER
Definition: jsonfuncs.h:81
@ JSONTYPE_CAST
Definition: jsonfuncs.h:80
@ JSONTYPE_COMPOSITE
Definition: jsonfuncs.h:79
@ JSONTYPE_ARRAY
Definition: jsonfuncs.h:78
@ JSONTYPE_TIMESTAMPTZ
Definition: jsonfuncs.h:75
@ JSONTYPE_JSONB
Definition: jsonfuncs.h:77
char func_volatile(Oid funcid)
Definition: lsyscache.c:1780
unsigned int Oid
Definition: postgres_ext.h:31

References func_volatile(), json_categorize_type(), JSONTYPE_ARRAY, JSONTYPE_BOOL, JSONTYPE_CAST, JSONTYPE_COMPOSITE, JSONTYPE_DATE, JSONTYPE_JSON, JSONTYPE_JSONB, JSONTYPE_NULL, JSONTYPE_NUMERIC, JSONTYPE_OTHER, JSONTYPE_TIMESTAMP, and JSONTYPE_TIMESTAMPTZ.

Referenced by contain_mutable_functions_walker().