PostgreSQL Source Code: src/backend/utils/adt/jsonb.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
14
27
29{
35
37{
44
46 Node *escontext);
57 const Datum *vals, const bool *nulls, int *valcount,
62 bool key_scalar);
64 Oid val_type, bool key_scalar);
68
69
70
71
74{
76
77 return jsonb_from_cstring(json, strlen(json), false, fcinfo->context);
78}
79
80
81
82
83
84
85
86
87
90{
93 char *str;
94 int nbytes;
95
96 if (version == 1)
98 else
99 elog(ERROR, "unsupported jsonb version number %d", version);
100
102}
103
104
105
106
109{
111 char *out;
112
114
116}
117
118
119
120
121
122
125{
129 int version = 1;
130
132
137
139}
140
141
142
143
144
145
148{
151 unique_keys,
152 NULL);
153}
154
155
156
157
158static const char *
160{
162
166 return "array";
168 return "object";
169 else
170 {
171 elog(ERROR, "invalid jsonb container type: 0x%08x", jbc->header);
172 return "unknown";
173 }
174}
175
176
177
178
179const char *
181{
182 switch (val->type)
183 {
187 return "object";
189 return "array";
191 return "number";
193 return "string";
195 return "boolean";
197 return "null";
199 switch (val->val.datetime.typid)
200 {
201 case DATEOID:
202 return "date";
203 case TIMEOID:
204 return "time without time zone";
205 case TIMETZOID:
206 return "time with time zone";
207 case TIMESTAMPOID:
208 return "timestamp without time zone";
209 case TIMESTAMPTZOID:
210 return "timestamp with time zone";
211 default:
212 elog(ERROR, "unrecognized jsonb value datetime type: %d",
213 val->val.datetime.typid);
214 }
215 return "unknown";
216 default:
217 elog(ERROR, "unrecognized jsonb value type: %d", val->type);
218 return "unknown";
219 }
220}
221
222
223
224
225
226
227
230{
233
235}
236
237
238
239
240
241
242
243
244
245
246
247static inline Datum
249{
253
255 memset(&sem, 0, sizeof(sem));
257
258 state.unique_keys = unique_keys;
259 state.escontext = escontext;
261
268
270 return (Datum) 0;
271
272
274}
275
276static bool
278{
280 ereturn(escontext, false,
281 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
282 errmsg("string too long to represent as jsonb string"),
283 errdetail("Due to an implementation restriction, jsonb strings cannot exceed %d bytes.",
285
286 return true;
287}
288
291{
293
296
298}
299
302{
304
306
308}
309
312{
314
316
318}
319
322{
324
326
328}
329
332{
335
336 Assert(fname != NULL);
338 v.val.string.len = strlen(fname);
341 v.val.string.val = fname;
342
344
346}
347
348static void
350{
351 switch (scalarVal->type)
352 {
355 break;
358 break;
363 break;
365 if (scalarVal->val.boolean)
367 else
369 break;
370 default:
371 elog(ERROR, "unknown jsonb scalar type");
372 }
373}
374
375
376
377
380{
384
385 switch (tokentype)
386 {
387
391 v.val.string.len = strlen(token);
395 break;
397
398
399
400
401
407 &numd))
410 break;
413 v.val.boolean = true;
414 break;
417 v.val.boolean = false;
418 break;
421 break;
422 default:
423
424 elog(ERROR, "invalid json token type");
425 break;
426 }
427
429 {
430
432
434 va.val.array.rawScalar = true;
435 va.val.array.nElems = 1;
436
440 }
441 else
442 {
444
445 switch (o->type)
446 {
449 break;
452 break;
453 default:
454 elog(ERROR, "unexpected parent of nested structure");
455 }
456 }
457
459}
460
461
462
463
464
465
466
467
468
469
470
471
472char *
474{
476}
477
478
479
480
481char *
483{
485}
486
487
488
489
490static char *
492{
493 bool first = true;
497 int level = 0;
498 bool redo_switch = false;
499
500
501 int ispaces = indent ? 1 : 2;
502
503
504
505
506
507 bool use_indent = false;
508 bool raw_scalar = false;
509 bool last_was_key = false;
510
511 if (out == NULL)
513
514 enlargeStringInfo(out, (estimated_len >= 0) ? estimated_len : 64);
515
517
518 while (redo_switch ||
520 {
521 redo_switch = false;
522 switch (type)
523 {
525 if (!first)
527
528 if (!v.val.array.rawScalar)
529 {
530 add_indent(out, use_indent && !last_was_key, level);
532 }
533 else
534 raw_scalar = true;
535
536 first = true;
537 level++;
538 break;
540 if (!first)
542
543 add_indent(out, use_indent && !last_was_key, level);
545
546 first = true;
547 level++;
548 break;
550 if (!first)
552 first = true;
553
555
556
559
562 {
563 first = false;
565 }
566 else
567 {
569
570
571
572
573
574
575 redo_switch = true;
576 }
577 break;
579 if (!first)
581 first = false;
582
583 if (!raw_scalar)
586 break;
588 level--;
589 if (!raw_scalar)
590 {
593 }
594 first = false;
595 break;
597 level--;
600 first = false;
601 break;
602 default:
603 elog(ERROR, "unknown jsonb iterator token type");
604 }
605 use_indent = indent;
606 last_was_key = redo_switch;
607 }
608
610
611 return out->data;
612}
613
614static void
616{
617 if (indent)
618 {
621 }
622}
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637static void
640 bool key_scalar)
641{
642 char *outputstr;
643 bool numeric_error;
645 bool scalar_jsonb = false;
646
648
649
650 if (is_null)
651 {
654 }
655 else if (key_scalar &&
661 {
663 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
664 errmsg("key value must be scalar, not array, composite, or json")));
665 }
666 else
667 {
670
671 switch (tcategory)
672 {
675 break;
678 break;
680 if (key_scalar)
681 {
684 jb.val.string.len = strlen(outputstr);
685 jb.val.string.val = outputstr;
686 }
687 else
688 {
691 }
692 break;
695 if (key_scalar)
696 {
697
699 jb.val.string.len = strlen(outputstr);
700 jb.val.string.val = outputstr;
701 }
702 else
703 {
704
705
706
707
708
709 numeric_error = (strchr(outputstr, 'N') != NULL ||
710 strchr(outputstr, 'n') != NULL);
711 if (!numeric_error)
712 {
714
721 pfree(outputstr);
722 }
723 else
724 {
726 jb.val.string.len = strlen(outputstr);
727 jb.val.string.val = outputstr;
728 }
729 }
730 break;
734 DATEOID, NULL);
735 jb.val.string.len = strlen(jb.val.string.val);
736 break;
740 TIMESTAMPOID, NULL);
741 jb.val.string.len = strlen(jb.val.string.val);
742 break;
746 TIMESTAMPTZOID, NULL);
747 jb.val.string.len = strlen(jb.val.string.val);
748 break;
751 {
752
756
758
759 memset(&sem, 0, sizeof(sem));
760
762
769
772 }
773 break;
775 {
778
780
782 {
786 scalar_jsonb = true;
787 }
788 else
789 {
791
794 {
799 else
802 }
803 }
804 }
805 break;
806 default:
809 jb.val.string.len = strlen(outputstr);
811 jb.val.string.val = outputstr;
812 break;
813 }
814 }
815
816
817 if (!is_null && !scalar_jsonb &&
819 {
820
821 return;
822 }
824 {
825
827
829 va.val.array.rawScalar = true;
830 va.val.array.nElems = 1;
831
835 }
836 else
837 {
839
840 switch (o->type)
841 {
844 break;
848 &jb);
849 break;
850 default:
851 elog(ERROR, "unexpected parent of nested structure");
852 }
853 }
854}
855
856
857
858
859
860
861static void
863 const bool *nulls, int *valcount, JsonTypeCategory tcategory,
864 Oid outfuncoid)
865{
866 int i;
867
869
871
872 for (i = 1; i <= dims[dim]; i++)
873 {
874 if (dim + 1 == ndims)
875 {
877 outfuncoid, false);
878 (*valcount)++;
879 }
880 else
881 {
883 valcount, tcategory, outfuncoid);
884 }
885 }
886
888}
889
890
891
892
893static void
895{
898 int *dim;
899 int ndim;
901 int count = 0;
903 bool *nulls;
905 bool typbyval;
908 Oid outfuncoid;
909
913
915 {
918 return;
919 }
920
922 &typlen, &typbyval, &typalign);
923
925 &tcategory, &outfuncoid);
926
930
931 array_dim_to_jsonb(result, 0, ndim, dim, elements, nulls, &count, tcategory,
932 outfuncoid);
933
936}
937
938
939
940
941static void
943{
945 Oid tupType;
949 *tuple;
950 int i;
951
953
954
958
959
962 tuple = &tmptup;
963
965
966 for (i = 0; i < tupdesc->natts; i++)
967 {
969 bool isnull;
972 Oid outfuncoid;
975
976 if (att->attisdropped)
977 continue;
978
980
982
985
987
989
990 if (isnull)
991 {
994 }
995 else
997 &outfuncoid);
998
1000 false);
1001 }
1002
1005}
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015static void
1017 Oid val_type, bool key_scalar)
1018{
1020 Oid outfuncoid;
1021
1024 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1025 errmsg("could not determine input data type")));
1026
1027 if (is_null)
1028 {
1031 }
1032 else
1034 &tcategory, &outfuncoid);
1035
1037 key_scalar);
1038}
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048bool
1050{
1052 Oid outfuncoid;
1053
1055
1056 switch (tcategory)
1057 {
1062 return true;
1063
1067 return false;
1068
1070 return false;
1071
1073 return false;
1074
1078 return func_volatile(outfuncoid) == PROVOLATILE_IMMUTABLE;
1079 }
1080
1081 return false;
1082}
1083
1084
1085
1086
1089{
1093 Oid outfuncoid;
1094
1097 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1098 errmsg("could not determine input data type")));
1099
1101 &tcategory, &outfuncoid);
1102
1104}
1105
1106
1107
1108
1109
1110
1113{
1115
1117
1119 false);
1120
1122}
1123
1126 bool absent_on_null, bool unique_keys)
1127{
1128 int i;
1130
1131 if (nargs % 2 != 0)
1133 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1134 errmsg("argument list must have even number of elements"),
1135
1136 errhint("The arguments of %s must consist of alternating keys and values.",
1137 "jsonb_build_object()")));
1138
1140
1144
1145 for (i = 0; i < nargs; i += 2)
1146 {
1147
1149
1150 if (nulls[i])
1152 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1153 errmsg("argument %d: key must not be null", i + 1)));
1154
1155
1156 skip = absent_on_null && nulls[i + 1];
1157
1158
1159 if (skip && !unique_keys)
1160 continue;
1161
1163
1164
1166 }
1167
1169
1171}
1172
1173
1174
1175
1178{
1180 bool *nulls;
1182
1183
1186
1187 if (nargs < 0)
1189
1191}
1192
1193
1194
1195
1198{
1200
1202
1205
1207}
1208
1211 bool absent_on_null)
1212{
1213 int i;
1215
1217
1219
1220 for (i = 0; i < nargs; i++)
1221 {
1222 if (absent_on_null && nulls[i])
1223 continue;
1224
1226 }
1227
1229
1231}
1232
1233
1234
1235
1238{
1240 bool *nulls;
1242
1243
1246
1247 if (nargs < 0)
1249
1251}
1252
1253
1254
1255
1256
1259{
1261
1263
1266
1268}
1269
1270
1271
1272
1273
1274
1275
1276
1277
1280{
1282 int ndims = ARR_NDIM(in_array);
1283 Datum *in_datums;
1284 bool *in_nulls;
1285 int in_count,
1286 count,
1287 i;
1289
1291
1293
1294 switch (ndims)
1295 {
1296 case 0:
1297 goto close_object;
1298 break;
1299
1300 case 1:
1301 if ((ARR_DIMS(in_array)[0]) % 2)
1303 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1304 errmsg("array must have even number of elements")));
1305 break;
1306
1307 case 2:
1308 if ((ARR_DIMS(in_array)[1]) != 2)
1310 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1311 errmsg("array must have two columns")));
1312 break;
1313
1314 default:
1316 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1317 errmsg("wrong number of array subscripts")));
1318 }
1319
1321
1322 count = in_count / 2;
1323
1324 for (i = 0; i < count; ++i)
1325 {
1327 char *str;
1328 int len;
1329
1330 if (in_nulls[i * 2])
1332 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1333 errmsg("null value not allowed for object key")));
1334
1337
1339
1342
1344
1345 if (in_nulls[i * 2 + 1])
1346 {
1348 }
1349 else
1350 {
1353
1355
1358 }
1359
1361 }
1362
1363 pfree(in_datums);
1364 pfree(in_nulls);
1365
1366close_object:
1368
1370}
1371
1372
1373
1374
1375
1376
1377
1380{
1383 int nkdims = ARR_NDIM(key_array);
1384 int nvdims = ARR_NDIM(val_array);
1385 Datum *key_datums,
1386 *val_datums;
1387 bool *key_nulls,
1388 *val_nulls;
1389 int key_count,
1390 val_count,
1391 i;
1393
1395
1397
1398 if (nkdims > 1 || nkdims != nvdims)
1400 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1401 errmsg("wrong number of array subscripts")));
1402
1403 if (nkdims == 0)
1404 goto close_object;
1405
1408
1409 if (key_count != val_count)
1411 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1412 errmsg("mismatched array dimensions")));
1413
1414 for (i = 0; i < key_count; ++i)
1415 {
1417 char *str;
1418 int len;
1419
1420 if (key_nulls[i])
1422 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1423 errmsg("null value not allowed for object key")));
1424
1427
1429
1432
1434
1435 if (val_nulls[i])
1436 {
1438 }
1439 else
1440 {
1443
1445
1448 }
1449
1451 }
1452
1453 pfree(key_datums);
1454 pfree(key_nulls);
1455 pfree(val_datums);
1456 pfree(val_nulls);
1457
1458close_object:
1460
1462}
1463
1464
1465
1466
1467
1468
1469
1472{
1474 *icursor,
1475 *ocursor;
1476
1477 if (state == NULL)
1478 return NULL;
1479
1481 icursor = state;
1482 ocursor = result;
1483 for (;;)
1484 {
1486 ocursor->size = icursor->size;
1489 icursor = icursor->next;
1490 if (icursor == NULL)
1491 break;
1493 ocursor = ocursor->next;
1494 }
1495 ocursor->next = NULL;
1496
1497 return result;
1498}
1499
1502{
1504 aggcontext;
1509 bool single_scalar = false;
1514
1516 {
1517
1518 elog(ERROR, "jsonb_agg_transfn called in non-aggregate context");
1519 }
1520
1521
1522
1524 {
1526
1529 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1530 errmsg("could not determine input data type")));
1531
1535 state->res = result;
1539
1541 &state->val_output_func);
1542 }
1543 else
1544 {
1546 result = state->res;
1547 }
1548
1551
1552
1553
1555
1557
1559 state->val_output_func, false);
1560
1562
1563
1564
1566
1568
1570 {
1571 switch (type)
1572 {
1574 if (v.val.array.rawScalar)
1575 single_scalar = true;
1576 else
1578 type, NULL);
1579 break;
1581 if (!single_scalar)
1583 type, NULL);
1584 break;
1588 type, NULL);
1589 break;
1594 {
1595
1597
1600 }
1602 {
1603
1604 v.val.numeric =
1607 }
1610 break;
1611 default:
1612 elog(ERROR, "unknown jsonb iterator token type");
1613 }
1614 }
1615
1617
1619}
1620
1621
1622
1623
1626{
1628}
1629
1630
1631
1632
1635{
1637}
1638
1641{
1645
1646
1648
1650 PG_RETURN_NULL();
1651
1653
1654
1655
1656
1657
1658
1659
1661
1663
1666
1668
1670}
1671
1674 bool absent_on_null, bool unique_keys)
1675{
1677 aggcontext;
1682 bool single_scalar;
1685 *jbval;
1689
1691 {
1692
1693 elog(ERROR, "jsonb_object_agg_transfn called in non-aggregate context");
1694 }
1695
1696
1697
1699 {
1700 Oid arg_type;
1701
1705 state->res = result;
1710
1712
1714
1717 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1718 errmsg("could not determine input data type")));
1719
1721 &state->key_output_func);
1722
1724
1727 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1728 errmsg("could not determine input data type")));
1729
1731 &state->val_output_func);
1732 }
1733 else
1734 {
1736 result = state->res;
1737 }
1738
1739
1740
1743 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1744 errmsg("field name must not be null")));
1745
1746
1747
1748
1749
1751
1752 if (skip && !unique_keys)
1754
1756
1758
1760 state->key_output_func, true);
1761
1763
1765
1767
1769 state->val_output_func, false);
1770
1772
1774
1775
1776
1778
1779
1780
1781
1782
1783
1784
1786 {
1787 switch (type)
1788 {
1790 if (!v.val.array.rawScalar)
1791 elog(ERROR, "unexpected structure for key");
1792 break;
1795 {
1796
1798
1801 }
1802 else
1803 {
1805 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1806 errmsg("object keys must be strings")));
1807 }
1810
1812 {
1818 }
1819
1820 break;
1822 break;
1823 default:
1824 elog(ERROR, "unexpected structure for key");
1825 break;
1826 }
1827 }
1828
1830
1831 single_scalar = false;
1832
1833
1834
1835
1836
1837
1838
1840 {
1841 switch (type)
1842 {
1844 if (v.val.array.rawScalar)
1845 single_scalar = true;
1846 else
1848 type, NULL);
1849 break;
1851 if (!single_scalar)
1853 type, NULL);
1854 break;
1858 type, NULL);
1859 break;
1864 {
1865
1867
1870 }
1872 {
1873
1874 v.val.numeric =
1877 }
1880 &v);
1881 break;
1882 default:
1883 elog(ERROR, "unknown jsonb iterator token type");
1884 }
1885 }
1886
1888
1890}
1891
1892
1893
1894
1897{
1899}
1900
1901
1902
1903
1904
1907{
1909}
1910
1911
1912
1913
1916{
1918}
1919
1920
1921
1922
1925{
1927}
1928
1931{
1935
1936
1938
1940 PG_RETURN_NULL();
1941
1943
1944
1945
1946
1947
1948
1949
1950
1952
1954
1957
1959
1961}
1962
1963
1964
1965
1966
1967bool
1969{
1973
1975 {
1976
1978 return false;
1979 }
1980
1981
1982
1983
1984
1986
1989 Assert(tmp.val.array.nElems == 1 && tmp.val.array.rawScalar);
1990
1994
1997
2000
2001 return true;
2002}
2003
2004
2005
2006
2007static void
2009{
2010 static const struct
2011 {
2013 const char *msg;
2014 }
2015 messages[] =
2016 {
2024 };
2025 int i;
2026
2027 for (i = 0; i < lengthof(messages); i++)
2030 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2031 errmsg(messages[i].msg, sqltype)));
2032
2033
2034 elog(ERROR, "unknown jsonb type: %d", (int) type);
2035}
2036
2039{
2042
2045
2047 {
2050 }
2051
2054
2056
2058}
2059
2062{
2066
2069
2071 {
2074 }
2075
2078
2079
2080
2081
2082
2084
2086
2088}
2089
2092{
2096
2099
2101 {
2104 }
2105
2108
2111
2113
2115}
2116
2119{
2123
2126
2128 {
2131 }
2132
2135
2138
2140
2142}
2143
2146{
2150
2153
2155 {
2158 }
2159
2162
2165
2167
2169}
2170
2173{
2177
2180
2182 {
2185 }
2186
2189
2192
2194
2196}
2197
2200{
2204
2207
2209 {
2212 }
2213
2216
2219
2221
2223}
2224
2225
2226
2227
2228char *
2230{
2232 {
2234
2236
2238 return pnstrdup(v.val.string.val, v.val.string.len);
2240 return pstrdup(v.val.boolean ? "true" : "false");
2246 else
2247 {
2248 elog(ERROR, "unrecognized jsonb value type %d", v.type);
2249 return NULL;
2250 }
2251 }
2252 else
2254}
#define PG_GETARG_ARRAYTYPE_P(n)
#define DatumGetArrayTypeP(X)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
int ArrayGetNItems(int ndim, const int *dims)
Datum numeric_int8(PG_FUNCTION_ARGS)
Datum numeric_uplus(PG_FUNCTION_ARGS)
Datum numeric_int4(PG_FUNCTION_ARGS)
Datum numeric_out(PG_FUNCTION_ARGS)
Datum numeric_int2(PG_FUNCTION_ARGS)
Datum numeric_float8(PG_FUNCTION_ARGS)
Datum numeric_in(PG_FUNCTION_ARGS)
Datum numeric_float4(PG_FUNCTION_ARGS)
#define TextDatumGetCString(d)
#define PG_USED_FOR_ASSERTS_ONLY
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
char * OidOutputFunctionCall(Oid functionId, Datum val)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
bool DirectInputFunctionCallSafe(PGFunction func, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)
#define OidFunctionCall1(functionId, arg1)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_RETURN_BYTEA_P(x)
#define DatumGetHeapTupleHeader(X)
#define DatumGetTextPP(X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_DATUM(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
int extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start, bool convert_unknown, Datum **args, Oid **types, bool **nulls)
Assert(PointerIsAligned(start, uint64))
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
char * JsonEncodeDateTime(char *buf, Datum value, Oid typid, const int *tzp)
void escape_json_with_len(StringInfo buf, const char *str, int len)
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
void freeJsonLexContext(JsonLexContext *lex)
Datum jsonb_from_text(text *js, bool unique_keys)
static Datum jsonb_agg_transfn_worker(FunctionCallInfo fcinfo, bool absent_on_null)
static JsonParseErrorType jsonb_in_object_start(void *pstate)
Datum jsonb_int4(PG_FUNCTION_ARGS)
Datum jsonb_recv(PG_FUNCTION_ARGS)
Datum jsonb_object_agg_strict_transfn(PG_FUNCTION_ARGS)
Datum to_jsonb(PG_FUNCTION_ARGS)
char * JsonbUnquote(Jsonb *jb)
Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null)
static Datum jsonb_from_cstring(char *json, int len, bool unique_keys, Node *escontext)
static void datum_to_jsonb_internal(Datum val, bool is_null, JsonbInState *result, JsonTypeCategory tcategory, Oid outfuncoid, bool key_scalar)
Datum jsonb_build_array_noargs(PG_FUNCTION_ARGS)
Datum jsonb_object_agg_unique_strict_transfn(PG_FUNCTION_ARGS)
Datum jsonb_in(PG_FUNCTION_ARGS)
Datum jsonb_build_object_noargs(PG_FUNCTION_ARGS)
Datum jsonb_agg_transfn(PG_FUNCTION_ARGS)
Datum jsonb_object_two_arg(PG_FUNCTION_ARGS)
static const char * JsonbContainerTypeName(JsonbContainer *jbc)
Datum jsonb_object_agg_transfn(PG_FUNCTION_ARGS)
static JsonParseErrorType jsonb_in_array_end(void *pstate)
static char * JsonbToCStringWorker(StringInfo out, JsonbContainer *in, int estimated_len, bool indent)
Datum jsonb_build_array(PG_FUNCTION_ARGS)
Datum jsonb_int8(PG_FUNCTION_ARGS)
static void jsonb_put_escaped_value(StringInfo out, JsonbValue *scalarVal)
static void cannotCastJsonbValue(enum jbvType type, const char *sqltype)
static void add_jsonb(Datum val, bool is_null, JsonbInState *result, Oid val_type, bool key_scalar)
static JsonbParseState * clone_parse_state(JsonbParseState *state)
static JsonParseErrorType jsonb_in_object_field_start(void *pstate, char *fname, bool isnull)
char * JsonbToCString(StringInfo out, JsonbContainer *in, int estimated_len)
Datum jsonb_object_agg_unique_transfn(PG_FUNCTION_ARGS)
Datum jsonb_out(PG_FUNCTION_ARGS)
Datum jsonb_numeric(PG_FUNCTION_ARGS)
static void array_to_jsonb_internal(Datum array, JsonbInState *result)
const char * JsonbTypeName(JsonbValue *val)
struct JsonbAggState JsonbAggState
Datum jsonb_object(PG_FUNCTION_ARGS)
Datum jsonb_build_object_worker(int nargs, const Datum *args, const bool *nulls, const Oid *types, bool absent_on_null, bool unique_keys)
struct JsonbInState JsonbInState
Datum jsonb_int2(PG_FUNCTION_ARGS)
static void composite_to_jsonb(Datum composite, JsonbInState *result)
Datum jsonb_float4(PG_FUNCTION_ARGS)
Datum jsonb_agg_strict_transfn(PG_FUNCTION_ARGS)
static void add_indent(StringInfo out, bool indent, int level)
Datum jsonb_object_agg_finalfn(PG_FUNCTION_ARGS)
static JsonParseErrorType jsonb_in_array_start(void *pstate)
bool JsonbExtractScalar(JsonbContainer *jbc, JsonbValue *res)
Datum datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Datum jsonb_build_object(PG_FUNCTION_ARGS)
static Datum jsonb_object_agg_transfn_worker(FunctionCallInfo fcinfo, bool absent_on_null, bool unique_keys)
Datum jsonb_typeof(PG_FUNCTION_ARGS)
Datum jsonb_bool(PG_FUNCTION_ARGS)
char * JsonbToCStringIndent(StringInfo out, JsonbContainer *in, int estimated_len)
static JsonParseErrorType jsonb_in_object_end(void *pstate)
static JsonParseErrorType jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
Datum jsonb_agg_finalfn(PG_FUNCTION_ARGS)
Datum jsonb_float8(PG_FUNCTION_ARGS)
bool to_jsonb_is_immutable(Oid typoid)
static bool checkStringLen(size_t len, Node *escontext)
Datum jsonb_send(PG_FUNCTION_ARGS)
static void array_dim_to_jsonb(JsonbInState *result, int dim, int ndims, int *dims, const Datum *vals, const bool *nulls, int *valcount, JsonTypeCategory tcategory, Oid outfuncoid)
#define JsonContainerIsScalar(jc)
#define JsonContainerIsArray(jc)
static Datum JsonbPGetDatum(const Jsonb *p)
#define IsAJsonbScalar(jsonbval)
#define JENTRY_OFFLENMASK
#define PG_GETARG_JSONB_P(x)
#define JsonContainerIsObject(jc)
static Jsonb * DatumGetJsonbP(Datum d)
#define JB_ROOT_IS_SCALAR(jbp_)
JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)
JsonbIterator * JsonbIteratorInit(JsonbContainer *container)
JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
JsonLexContext * makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes)
void json_categorize_type(Oid typoid, bool is_jsonb, JsonTypeCategory *tcategory, Oid *outfuncoid)
bool pg_parse_json_or_errsave(JsonLexContext *lex, const JsonSemAction *sem, Node *escontext)
#define pg_parse_json_or_ereport(lex, sem)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
char func_volatile(Oid funcid)
int GetDatabaseEncoding(void)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
char * pnstrdup(const char *in, Size len)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
static Numeric DatumGetNumericCopy(Datum X)
static Numeric DatumGetNumeric(Datum X)
#define PG_RETURN_NUMERIC(x)
static Datum NumericGetDatum(Numeric X)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
FormData_pg_attribute * Form_pg_attribute
static const struct exclude_list_item skip[]
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
unsigned int pq_getmsgint(StringInfo msg, int b)
void pq_sendtext(StringInfo buf, const char *str, int slen)
char * pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
void pq_begintypsend(StringInfo buf)
bytea * pq_endtypsend(StringInfo buf)
static void pq_sendint8(StringInfo buf, uint8 i)
void check_stack_depth(void)
void destroyStringInfo(StringInfo str)
StringInfo makeStringInfo(void)
void enlargeStringInfo(StringInfo str, int needed)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoSpaces(StringInfo str, int count)
void appendStringInfoString(StringInfo str, const char *s)
StringInfoData * StringInfo
#define appendStringInfoCharMacro(str, ch)
json_struct_action array_end
json_struct_action object_start
json_ofield_action object_field_start
json_scalar_action scalar
json_struct_action array_start
json_struct_action object_end
JsonTypeCategory val_category
JsonTypeCategory key_category
JsonbParseState * parseState
struct JsonbParseState * next
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
#define VARSIZE_ANY_EXHDR(PTR)
text * cstring_to_text(const char *s)