Feature: Import PostgreSQL 17 RC1 new parser.
authorBo Peng <pengbo@sraoss.co.jp>
Mon, 21 Oct 2024 10:08:05 +0000 (19:08 +0900)
committerBo Peng <pengbo@sraoss.co.jp>
Mon, 21 Oct 2024 10:08:05 +0000 (19:08 +0900)
Major changes of PostgreSQL 17 parser include:

- Allow MERGE to use NOT MATCHED BY SOURCE and RETURNING clause:

    MERGE INTO ... WHEN NOT MATCHED BY SOURCE ...
    MERGE INTO ... RETURNING ...

- Add new COPY option ON_ERROR ignore and LOG_VERBOSITY:

  COPY ... WITH (ON_ERROR ignore);
  COPY ... WITH (LOG_VERBOSITY verbose);

- Allow to use '*' to specify the COPY FROM options FORCE_NOT_NULL and FORCE_NULL for all columns.

  COPY ... WITH (FORCE_NOT_NULL *);
  COPY ... WITH (FORCE_NULL *);

- Add EXPLAIN option SERIALIZE and MEMORY

  EXPLAIN (MEMORY) ...
  EXPLAIN (ANALYZE, SERIALIZE ...) ...

- Allow ALTER TABLE to use SET STATISTICS DEFAULT to set a column to the default statistics target

  ALTER TABLE ... ALTER COLUMN ... SET STATISTICS DEFAULT;

- Allow ALTER TABLE to change a column's generation expression

  ALTER TABLE ... ALTER COLUMN ... SET EXPRESSION;

- Add DEFAULT setting for ALTER TABLE .. SET ACCESS METHOD

  ALTER TABLE ... SET STATISTICS DEFAULT;

- Allow event triggers to use login event:

  CREATE EVENT TRIGGER ... ON login ...

- Add event trigger support for REINDEX.

38 files changed:
src/include/parser/gramparse.h
src/include/parser/keywords.h
src/include/parser/kwlist.h
src/include/parser/kwlist_d.h
src/include/parser/makefuncs.h
src/include/parser/nodes.h
src/include/parser/nodetags.h
src/include/parser/parsenodes.h
src/include/parser/parser.h
src/include/parser/pg_class.h
src/include/parser/pg_config_manual.h
src/include/parser/pg_list.h
src/include/parser/pg_trigger.h
src/include/parser/pg_wchar.h
src/include/parser/pool_parser.h
src/include/parser/primnodes.h
src/include/parser/scanner.h
src/include/parser/scansup.h
src/include/parser/stringinfo.h
src/include/parser/value.h
src/include/utils/palloc.h
src/parser/copyfuncs.c
src/parser/gram.y
src/parser/gram_minimal.y
src/parser/gram_template.y
src/parser/keywords.c
src/parser/kwlookup.c
src/parser/list.c
src/parser/makefuncs.c
src/parser/outfuncs.c
src/parser/parser.c
src/parser/scan.l
src/parser/scansup.c
src/parser/snprintf.c
src/parser/stringinfo.c
src/parser/value.c
src/parser/wchar.c
src/utils/mmgr/mcxt.c

index a56d756a016448f44607b1ee600d9e192ab1728c..db644c2781042acc3a551e01e35ebfcdcb63dffd 100644 (file)
@@ -8,8 +8,8 @@
  * Definitions that are needed outside the core parser should be in parser.h.
  *
  *
- * Portions Copyright (c) 2003-2022, PgPool Global Development Group
- * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/parser/gramparse.h
index bd059c67cae9529e2f7774ce45b33fc45f243ae4..9a989763f90841b23be8460bba75e45de437feba 100644 (file)
@@ -4,8 +4,8 @@
  *       PostgreSQL's list of SQL keywords
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/common/keywords.h
index c2a191bf4b70dc4f58b040e892737af890acf65a..bbf22fb524fb594f2957be5feb8d97ff2a2b5f9c 100644 (file)
@@ -7,8 +7,8 @@
  * by the PG_KEYWORD macro, which is not defined in this file; it can
  * be defined by the caller for special purposes.
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
@@ -94,6 +94,7 @@ PG_KEYWORD("commit", COMMIT, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("committed", COMMITTED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("compression", COMPRESSION, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("concurrently", CONCURRENTLY, TYPE_FUNC_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("conditional", CONDITIONAL, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("configuration", CONFIGURATION, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("conflict", CONFLICT, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("connection", CONNECTION, UNRESERVED_KEYWORD, BARE_LABEL)
@@ -148,11 +149,13 @@ PG_KEYWORD("double", DOUBLE_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("drop", DROP, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("each", EACH, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("else", ELSE, RESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("empty", EMPTY_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("enable", ENABLE_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("encoding", ENCODING, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("encrypted", ENCRYPTED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("end", END_P, RESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("enum", ENUM_P, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("error", ERROR_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("escape", ESCAPE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("event", EVENT, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("except", EXCEPT, RESERVED_KEYWORD, AS_LABEL)
@@ -231,11 +234,18 @@ PG_KEYWORD("is", IS, TYPE_FUNC_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("isnull", ISNULL, TYPE_FUNC_NAME_KEYWORD, AS_LABEL)
 PG_KEYWORD("isolation", ISOLATION, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("join", JOIN, TYPE_FUNC_NAME_KEYWORD, BARE_LABEL)
-PG_KEYWORD("json", JSON, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("json", JSON, COL_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("json_array", JSON_ARRAY, COL_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("json_arrayagg", JSON_ARRAYAGG, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("json_exists", JSON_EXISTS, COL_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("json_object", JSON_OBJECT, COL_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("json_objectagg", JSON_OBJECTAGG, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("json_query", JSON_QUERY, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("json_scalar", JSON_SCALAR, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("json_serialize", JSON_SERIALIZE, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("json_table", JSON_TABLE, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("json_value", JSON_VALUE, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("keep", KEEP, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("key", KEY, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("keys", KEYS, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("label", LABEL, UNRESERVED_KEYWORD, BARE_LABEL)
@@ -265,6 +275,7 @@ PG_KEYWORD("matched", MATCHED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("materialized", MATERIALIZED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("maxvalue", MAXVALUE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("merge", MERGE, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("merge_action", MERGE_ACTION, COL_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("method", METHOD, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("minute", MINUTE_P, UNRESERVED_KEYWORD, AS_LABEL)
 PG_KEYWORD("minvalue", MINVALUE, UNRESERVED_KEYWORD, BARE_LABEL)
@@ -276,6 +287,7 @@ PG_KEYWORD("names", NAMES, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("national", NATIONAL, COL_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("natural", NATURAL, TYPE_FUNC_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("nchar", NCHAR, COL_NAME_KEYWORD, BARE_LABEL)
+PG_KEYWORD("nested", NESTED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("new", NEW, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("next", NEXT, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("nfc", NFC, UNRESERVED_KEYWORD, BARE_LABEL)
@@ -301,6 +313,7 @@ PG_KEYWORD("off", OFF, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("offset", OFFSET, RESERVED_KEYWORD, AS_LABEL)
 PG_KEYWORD("oids", OIDS, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("old", OLD, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("omit", OMIT, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("on", ON, RESERVED_KEYWORD, AS_LABEL)
 PG_KEYWORD("only", ONLY, RESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("operator", OPERATOR, UNRESERVED_KEYWORD, BARE_LABEL)
@@ -325,8 +338,10 @@ PG_KEYWORD("partial", PARTIAL, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("partition", PARTITION, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("passing", PASSING, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("password", PASSWORD, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("path", PATH, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("pgpool", PGPOOL, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("placing", PLACING, RESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("plan", PLAN, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("plans", PLANS, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("policy", POLICY, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("position", POSITION, COL_NAME_KEYWORD, BARE_LABEL)
@@ -344,6 +359,7 @@ PG_KEYWORD("procedures", PROCEDURES, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("program", PROGRAM, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("publication", PUBLICATION, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("quote", QUOTE, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("quotes", QUOTES, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("range", RANGE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("read", READ, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("real", REAL, COL_NAME_KEYWORD, BARE_LABEL)
@@ -403,6 +419,7 @@ PG_KEYWORD("skip", SKIP, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("smallint", SMALLINT, COL_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("snapshot", SNAPSHOT, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("some", SOME, RESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("source", SOURCE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("sql", SQL_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("stable", STABLE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("standalone", STANDALONE_P, UNRESERVED_KEYWORD, BARE_LABEL)
@@ -414,6 +431,7 @@ PG_KEYWORD("stdout", STDOUT, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("storage", STORAGE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("stored", STORED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("strict", STRICT_P, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("string", STRING_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("strip", STRIP_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("subscription", SUBSCRIPTION, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("substring", SUBSTRING, COL_NAME_KEYWORD, BARE_LABEL)
@@ -426,6 +444,7 @@ PG_KEYWORD("table", TABLE, RESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("tables", TABLES, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("tablesample", TABLESAMPLE, TYPE_FUNC_NAME_KEYWORD, BARE_LABEL)
 PG_KEYWORD("tablespace", TABLESPACE, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("target", TARGET, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("temp", TEMP, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("template", TEMPLATE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("temporary", TEMPORARY, UNRESERVED_KEYWORD, BARE_LABEL)
@@ -449,6 +468,7 @@ PG_KEYWORD("types", TYPES_P, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("uescape", UESCAPE, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("unbounded", UNBOUNDED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("uncommitted", UNCOMMITTED, UNRESERVED_KEYWORD, BARE_LABEL)
+PG_KEYWORD("unconditional", UNCONDITIONAL, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("unencrypted", UNENCRYPTED, UNRESERVED_KEYWORD, BARE_LABEL)
 PG_KEYWORD("union", UNION, RESERVED_KEYWORD, AS_LABEL)
 PG_KEYWORD("unique", UNIQUE, RESERVED_KEYWORD, BARE_LABEL)
index 4a43a8960053c2d8b623e516c0afa43092cfab7b..7c917a89a1436c1aba89f5acd6c0bf862c0db715 100644 (file)
@@ -3,7 +3,7 @@
  * kwlist_d.h
  *    List of keywords represented as a ScanKeywordList.
  *
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * NOTES
@@ -90,6 +90,7 @@ static const char ScanKeywords_kw_string[] =
        "committed\0"
        "compression\0"
        "concurrently\0"
+       "conditional\0"
        "configuration\0"
        "conflict\0"
        "connection\0"
@@ -144,11 +145,13 @@ static const char ScanKeywords_kw_string[] =
        "drop\0"
        "each\0"
        "else\0"
+       "empty\0"
        "enable\0"
        "encoding\0"
        "encrypted\0"
        "end\0"
        "enum\0"
+       "error\0"
        "escape\0"
        "event\0"
        "except\0"
@@ -230,8 +233,15 @@ static const char ScanKeywords_kw_string[] =
        "json\0"
        "json_array\0"
        "json_arrayagg\0"
+       "json_exists\0"
        "json_object\0"
        "json_objectagg\0"
+       "json_query\0"
+       "json_scalar\0"
+       "json_serialize\0"
+       "json_table\0"
+       "json_value\0"
+       "keep\0"
        "key\0"
        "keys\0"
        "label\0"
@@ -261,6 +271,7 @@ static const char ScanKeywords_kw_string[] =
        "materialized\0"
        "maxvalue\0"
        "merge\0"
+       "merge_action\0"
        "method\0"
        "minute\0"
        "minvalue\0"
@@ -272,6 +283,7 @@ static const char ScanKeywords_kw_string[] =
        "national\0"
        "natural\0"
        "nchar\0"
+       "nested\0"
        "new\0"
        "next\0"
        "nfc\0"
@@ -297,6 +309,7 @@ static const char ScanKeywords_kw_string[] =
        "offset\0"
        "oids\0"
        "old\0"
+       "omit\0"
        "on\0"
        "only\0"
        "operator\0"
@@ -321,8 +334,10 @@ static const char ScanKeywords_kw_string[] =
        "partition\0"
        "passing\0"
        "password\0"
+       "path\0"
        "pgpool\0"
        "placing\0"
+       "plan\0"
        "plans\0"
        "policy\0"
        "position\0"
@@ -340,6 +355,7 @@ static const char ScanKeywords_kw_string[] =
        "program\0"
        "publication\0"
        "quote\0"
+       "quotes\0"
        "range\0"
        "read\0"
        "real\0"
@@ -399,6 +415,7 @@ static const char ScanKeywords_kw_string[] =
        "smallint\0"
        "snapshot\0"
        "some\0"
+       "source\0"
        "sql\0"
        "stable\0"
        "standalone\0"
@@ -410,6 +427,7 @@ static const char ScanKeywords_kw_string[] =
        "storage\0"
        "stored\0"
        "strict\0"
+       "string\0"
        "strip\0"
        "subscription\0"
        "substring\0"
@@ -422,6 +440,7 @@ static const char ScanKeywords_kw_string[] =
        "tables\0"
        "tablesample\0"
        "tablespace\0"
+       "target\0"
        "temp\0"
        "template\0"
        "temporary\0"
@@ -445,6 +464,7 @@ static const char ScanKeywords_kw_string[] =
        "uescape\0"
        "unbounded\0"
        "uncommitted\0"
+       "unconditional\0"
        "unencrypted\0"
        "union\0"
        "unique\0"
@@ -565,550 +585,575 @@ static const uint16 ScanKeywords_kw_offsets[] = {
        480,
        492,
        505,
-       519,
-       528,
-       539,
-       550,
+       517,
+       531,
+       540,
+       551,
        562,
-       570,
-       579,
-       590,
-       595,
-       600,
+       574,
+       582,
+       591,
+       602,
        607,
-       613,
-       617,
-       622,
-       630,
-       646,
-       659,
-       672,
-       687,
-       700,
-       718,
-       731,
-       738,
-       744,
-       749,
-       758,
-       762,
-       773,
-       777,
+       612,
+       619,
+       625,
+       629,
+       634,
+       642,
+       658,
+       671,
+       684,
+       699,
+       712,
+       730,
+       743,
+       750,
+       756,
+       761,
+       770,
+       774,
        785,
-       793,
-       801,
-       810,
-       821,
-       830,
-       838,
-       845,
-       855,
-       866,
-       874,
-       880,
-       885,
+       789,
+       797,
+       805,
+       813,
+       822,
+       833,
+       842,
+       850,
+       857,
+       867,
+       878,
+       886,
        892,
-       903,
-       911,
-       919,
-       928,
+       897,
+       904,
+       915,
+       923,
        931,
        940,
-       947,
-       954,
+       943,
+       952,
        959,
-       964,
-       969,
+       966,
+       971,
        976,
-       985,
-       995,
-       999,
-       1004,
-       1011,
+       981,
+       987,
+       994,
+       1003,
+       1013,
        1017,
-       1024,
-       1032,
-       1042,
-       1052,
-       1060,
-       1067,
-       1075,
-       1086,
-       1096,
-       1105,
-       1113,
-       1119,
-       1126,
-       1132,
-       1139,
-       1148,
-       1154,
-       1160,
-       1170,
-       1174,
-       1180,
-       1188,
-       1195,
-       1203,
-       1210,
-       1215,
-       1220,
-       1229,
+       1022,
+       1028,
+       1035,
+       1041,
+       1048,
+       1056,
+       1066,
+       1076,
+       1084,
+       1091,
+       1099,
+       1110,
+       1120,
+       1129,
+       1137,
+       1143,
+       1150,
+       1156,
+       1163,
+       1172,
+       1178,
+       1184,
+       1194,
+       1198,
+       1204,
+       1212,
+       1219,
+       1227,
+       1234,
        1239,
-       1249,
-       1256,
-       1262,
-       1270,
-       1279,
-       1285,
+       1244,
+       1253,
+       1263,
+       1273,
+       1280,
+       1286,
        1294,
-       1301,
+       1303,
        1309,
-       1316,
-       1323,
-       1328,
+       1318,
+       1325,
        1333,
-       1342,
-       1345,
-       1351,
-       1361,
-       1371,
-       1380,
-       1387,
-       1390,
-       1398,
-       1408,
-       1418,
-       1425,
-       1431,
-       1439,
-       1447,
-       1456,
-       1466,
-       1473,
-       1479,
-       1485,
-       1491,
+       1340,
+       1347,
+       1352,
+       1357,
+       1366,
+       1369,
+       1375,
+       1385,
+       1395,
+       1404,
+       1411,
+       1414,
+       1422,
+       1432,
+       1442,
+       1449,
+       1455,
+       1463,
+       1471,
+       1480,
+       1490,
+       1497,
        1503,
-       1510,
-       1518,
-       1522,
-       1530,
-       1540,
-       1549,
+       1509,
+       1515,
+       1527,
+       1534,
+       1542,
+       1546,
        1554,
-       1562,
-       1565,
-       1572,
-       1582,
-       1587,
-       1592,
-       1603,
-       1617,
-       1629,
-       1644,
-       1648,
+       1564,
+       1573,
+       1578,
+       1586,
+       1589,
+       1596,
+       1606,
+       1611,
+       1616,
+       1627,
+       1641,
        1653,
-       1659,
-       1668,
-       1674,
-       1679,
-       1687,
-       1695,
-       1705,
-       1711,
-       1716,
-       1722,
-       1727,
-       1733,
+       1665,
+       1680,
+       1691,
+       1703,
+       1718,
+       1729,
        1740,
        1745,
-       1751,
-       1761,
-       1776,
-       1785,
-       1790,
-       1797,
-       1804,
+       1749,
+       1754,
+       1760,
+       1769,
+       1775,
+       1780,
+       1788,
+       1796,
+       1806,
        1812,
-       1818,
-       1826,
-       1839,
-       1848,
-       1854,
-       1861,
-       1868,
+       1817,
+       1823,
+       1828,
+       1834,
+       1841,
+       1846,
+       1852,
+       1862,
        1877,
-       1882,
-       1888,
-       1893,
+       1886,
+       1891,
        1898,
-       1904,
+       1905,
        1913,
-       1921,
+       1919,
        1927,
-       1931,
-       1936,
        1940,
-       1944,
        1949,
-       1954,
-       1957,
-       1962,
-       1972,
-       1983,
-       1987,
-       1995,
+       1955,
+       1968,
+       1975,
+       1982,
+       1991,
+       1996,
        2002,
-       2010,
-       2017,
-       2022,
-       2029,
+       2007,
+       2012,
+       2018,
+       2027,
        2035,
-       2043,
-       2050,
-       2053,
+       2041,
+       2048,
+       2052,
        2057,
-       2064,
-       2069,
-       2073,
-       2076,
-       2081,
-       2090,
-       2097,
-       2105,
+       2061,
+       2065,
+       2070,
+       2075,
+       2078,
+       2083,
+       2093,
+       2104,
        2108,
-       2114,
-       2125,
-       2132,
-       2136,
-       2142,
-       2147,
+       2116,
+       2123,
+       2131,
+       2138,
+       2143,
+       2150,
        2156,
        2164,
-       2175,
-       2181,
-       2187,
-       2196,
-       2206,
-       2213,
-       2221,
+       2171,
+       2174,
+       2178,
+       2185,
+       2190,
+       2194,
+       2199,
+       2202,
+       2207,
+       2216,
+       2223,
        2231,
-       2239,
-       2248,
-       2255,
-       2263,
-       2269,
-       2276,
-       2285,
-       2295,
-       2305,
+       2234,
+       2240,
+       2251,
+       2258,
+       2262,
+       2268,
+       2273,
+       2282,
+       2290,
+       2301,
+       2307,
        2313,
        2322,
-       2331,
+       2332,
        2339,
-       2345,
-       2356,
-       2367,
-       2377,
-       2388,
-       2396,
-       2408,
-       2414,
-       2420,
-       2425,
-       2430,
-       2439,
-       2447,
-       2457,
-       2461,
-       2472,
-       2484,
+       2347,
+       2357,
+       2365,
+       2374,
+       2379,
+       2386,
+       2394,
+       2399,
+       2405,
+       2412,
+       2421,
+       2431,
+       2441,
+       2449,
+       2458,
+       2467,
+       2475,
+       2481,
        2492,
-       2500,
-       2509,
-       2517,
+       2503,
+       2513,
        2524,
-       2535,
-       2543,
-       2551,
+       2532,
+       2544,
+       2550,
        2557,
-       2565,
-       2574,
-       2581,
-       2591,
-       2599,
-       2606,
-       2612,
-       2617,
-       2626,
-       2633,
-       2641,
-       2650,
-       2654,
-       2659,
-       2664,
-       2674,
-       2681,
-       2688,
-       2696,
-       2703,
-       2710,
+       2563,
+       2568,
+       2573,
+       2582,
+       2590,
+       2600,
+       2604,
+       2615,
+       2627,
+       2635,
+       2643,
+       2652,
+       2660,
+       2667,
+       2678,
+       2686,
+       2694,
+       2700,
+       2708,
        2717,
-       2726,
-       2733,
+       2724,
+       2734,
        2742,
-       2752,
-       2765,
-       2772,
-       2780,
+       2749,
+       2755,
+       2760,
+       2769,
+       2776,
+       2784,
        2793,
        2797,
-       2803,
-       2808,
-       2814,
-       2819,
-       2827,
-       2834,
+       2802,
+       2807,
+       2817,
+       2824,
+       2831,
        2839,
-       2848,
-       2857,
-       2862,
-       2866,
-       2873,
-       2884,
-       2890,
-       2900,
-       2911,
-       2917,
-       2924,
-       2932,
-       2939,
+       2846,
+       2853,
+       2860,
+       2869,
+       2876,
+       2885,
+       2895,
+       2908,
+       2915,
+       2923,
+       2936,
+       2940,
        2946,
-       2952,
-       2965,
-       2975,
-       2983,
-       2993,
-       2999,
-       3006,
-       3018,
-       3024,
-       3031,
-       3043,
-       3054,
-       3059,
-       3068,
-       3078,
-       3083,
-       3088,
-       3093,
-       3098,
-       3108,
-       3111,
-       3120,
+       2951,
+       2957,
+       2962,
+       2970,
+       2977,
+       2982,
+       2991,
+       3000,
+       3005,
+       3012,
+       3016,
+       3023,
+       3034,
+       3040,
+       3050,
+       3061,
+       3067,
+       3074,
+       3082,
+       3089,
+       3096,
+       3103,
+       3109,
+       3122,
        3132,
-       3142,
-       3148,
+       3140,
+       3150,
        3156,
-       3161,
-       3166,
+       3163,
        3175,
-       3183,
+       3181,
        3188,
-       3194,
-       3202,
-       3212,
-       3224,
-       3236,
+       3200,
+       3211,
+       3218,
+       3223,
+       3232,
        3242,
-       3249,
+       3247,
+       3252,
        3257,
-       3266,
+       3262,
+       3272,
        3275,
-       3281,
-       3288,
-       3293,
-       3299,
+       3284,
+       3296,
        3306,
        3312,
-       3321,
-       3331,
-       3337,
-       3344,
+       3320,
+       3325,
+       3330,
+       3339,
+       3347,
        3352,
-       3361,
-       3369,
-       3377,
-       3385,
-       3390,
-       3396,
-       3405,
-       3410,
-       3416,
+       3358,
+       3366,
+       3376,
+       3388,
+       3402,
+       3414,
+       3420,
        3427,
-       3434,
-       3439,
-       3446,
-       3454,
+       3435,
+       3444,
+       3453,
        3459,
-       3467,
-       3473,
+       3466,
+       3471,
        3477,
-       3491,
-       3501,
-       3512,
+       3484,
+       3490,
+       3499,
+       3509,
+       3515,
        3522,
-       3532,
-       3546,
+       3530,
+       3539,
+       3547,
        3555,
-       3561,
-       3569,
-       3582,
-       3591,
-       3596,
-       3600,
+       3563,
+       3568,
+       3574,
+       3583,
+       3588,
+       3594,
+       3605,
+       3612,
+       3617,
+       3624,
+       3632,
+       3637,
+       3645,
+       3651,
+       3655,
+       3669,
+       3679,
+       3690,
+       3700,
+       3710,
+       3724,
+       3733,
+       3739,
+       3747,
+       3760,
+       3769,
+       3774,
+       3778,
 };
 
-#define SCANKEYWORDS_NUM_KEYWORDS 472
+#define SCANKEYWORDS_NUM_KEYWORDS 492
 
 static int
 ScanKeywords_hash_func(const void *key, size_t keylen)
 {
-       static const int16 h[945] = {
-               144,   0,     32767, -20,   -69,   -122,  566,   32767,
-               213,   0,     411,   32767, -82,   32767, 378,   -161,
-               394,   233,   4,     32767, 32767, 32767, 32767, -91,
-               32767, 32767, 0,     32767, 70,    32767, 32767, 0,
-               203,   32767, 32767, 401,   32767, -230,  32767, 32767,
-               983,   803,   32767, 348,   -285,  257,   422,   32767,
-               -82,   540,   -251,  32767, 32767, 32767, 32767, 32767,
-               -591,  32767, 428,   57,    32767, 32767, 32767, 32767,
-               0,     0,     66,    -57,   32767, 0,     22,    -214,
-               32767, 0,     -107,  32767, 49,    -25,   32767, 32767,
-               32767, 200,   32767, 334,   -287,  268,   247,   32767,
-               0,     460,   32767, 211,   0,     214,   275,   34,
-               0,     -3,    0,     32767, 32767, 232,   -118,  249,
-               355,   732,   32767, 32767, -46,   32767, 353,   -193,
-               9,     0,     32767, 0,     207,   32767, 32767, 98,
-               32767, 44,    -43,   0,     334,   235,   499,   -1,
-               -156,  157,   16,    341,   625,   32767, 32767, 61,
-               32767, -134,  32767, -233,  -366,  32767, 32767, -16,
-               -444,  32767, 32767, 86,    32767, 32767, 303,   101,
-               0,     32767, 337,   214,   181,   -82,   -261,  0,
-               32767, 0,     32767, 438,   32767, 32767, 389,   32767,
-               642,   363,   444,   417,   32767, 32767, 0,     32767,
-               365,   211,   396,   458,   -241,  -40,   -407,  32767,
-               118,   32767, 32767, -39,   -137,  159,   32767, 40,
-               234,   626,   56,    70,    32767, 56,    43,    32767,
-               19,    404,   0,     32767, 156,   240,   9,     405,
-               0,     24,    32767, -46,   0,     0,     24,    468,
-               32767, 419,   517,   6,     93,    -269,  0,     204,
-               -174,  32767, 32767, 32767, 227,   119,   0,     32767,
-               32767, 32767, 217,   32767, 32767, 321,   0,     -124,
-               -57,   32767, 162,   32767, 89,    421,   534,   -663,
-               32767, 0,     32767, 624,   32767, 375,   261,   0,
-               294,   287,   -157,  32767, 32767, 0,     32767, 32,
-               0,     235,   281,   236,   32767, -369,  32767, 32767,
-               32767, 206,   32767, -120,  32767, 32767, 343,   270,
-               -152,  376,   877,   366,   196,   338,   -124,  275,
-               -81,   -147,  0,     280,   455,   0,     467,   32767,
-               115,   -26,   32767, 32767, 32767, 32767, 88,    32767,
-               32767, 32767, 32767, 337,   32767, 311,   32767, 0,
-               32767, 32767, 32767, 32767, -256,  32767, 32767, 32767,
-               287,   32767, 32767, -198,  18,    32767, 0,     367,
-               32767, 0,     80,    32767, 32767, 244,   334,   32767,
-               3,     68,    32767, 32767, -173,  29,    638,   32767,
-               32767, 650,   1,     0,     0,     0,     319,   32767,
-               32767, 32767, 0,     336,   -30,   418,   320,   32767,
-               32767, 32767, 32767, 101,   117,   32767, 32767, 0,
-               -176,  -211,  -58,   78,    276,   32767, 32767, 352,
-               0,     -236,  32767, -147,  32767, 109,   65,    562,
-               295,   32767, 32767, 370,   154,   77,    32767, 32767,
-               32767, -16,   0,     -156,  391,   32767, 32767, 70,
-               32767, 374,   -87,   189,   395,   -214,  32767, 67,
-               32767, 465,   327,   211,   32767, 32767, 0,     -18,
-               291,   32767, -90,   32767, 32767, 32767, 352,   32767,
-               396,   -48,   0,     32767, 377,   161,   14,    32767,
-               362,   32767, -342,  32767, -315,  32767, 32767, 294,
-               -202,  32767, 0,     401,   222,   241,   28,    253,
-               -132,  343,   32767, 372,   128,   32767, 212,   32767,
-               269,   32767, 32767, -345,  1,     32767, 0,     0,
-               249,   32767, 244,   0,     32767, 188,   54,    131,
-               -81,   -75,   18,    0,     32767, 32767, 32767, 0,
-               226,   32767, 89,    32767, 32767, 251,   0,     32767,
-               215,   380,   52,    32767, 89,    -105,  32767, 362,
-               32767, 51,    32767, 32767, 32767, 446,   364,   19,
-               103,   32767, 32767, -69,   6,     57,    32767, 32767,
-               32767, 32767, 32767, 0,     32767, 32767, -29,   32767,
-               218,   36,    32767, 367,   377,   32767, 152,   1,
-               32767, 0,     32767, 0,     32767, 66,    32767, 32767,
-               139,   0,     -52,   32767, -306,  0,     110,   186,
-               0,     -18,   419,   134,   316,   27,    470,   1,
-               32767, 0,     0,     32767, 32767, -103,  237,   32767,
-               32767, 760,   173,   0,     107,   32767, 208,   0,
-               168,   735,   32767, 32767, 211,   212,   32767, 32767,
-               0,     32767, 604,   32767, 196,   32767, 569,   32767,
-               32767, -24,   21,    32767, 32767, 32767, 32767, 32767,
-               0,     32767, 32767, 32767, 0,     -146,  -151,  32767,
-               277,   32767, 251,   385,   -99,   32767, 32767, 155,
-               140,   32767, -213,  -292,  -51,   0,     0,     82,
-               117,   -385,  300,   0,     145,   577,   0,     -21,
-               32767, -215,  32767, -195,  -148,  -100,  54,    31,
-               0,     32767, 32767, 178,   32767, 32767, 32767, 16,
-               62,    397,   -158,  0,     0,     216,   299,   32767,
-               384,   32767, 31,    0,     32767, 32767, 419,   -295,
-               32767, 32767, 32767, 32767, 0,     248,   32767, 32767,
-               32767, 176,   107,   -559,  -221,  252,   116,   -203,
-               400,   32767, 32767, 32767, -167,  0,     84,    -68,
-               0,     32767, 0,     57,    382,   32767, 213,   32767,
-               330,   0,     296,   32767, 248,   32767, 285,   0,
-               702,   32767, 0,     33,    32767, 124,   32767, 32767,
-               443,   32767, 0,     -128,  365,   32767, 32767, 5,
-               -162,  445,   32767, 32767, 32767, 32767, 32767, 312,
-               0,     32767, 83,    32767, 32767, 0,     190,   32767,
-               32767, 32767, -84,   0,     32767, 451,   71,    32767,
-               -192,  39,    483,   0,     282,   32767, 0,     32767,
-               32767, 297,   0,     348,   307,   132,   280,   287,
-               368,   199,   0,     0,     261,   61,    32767, -91,
-               0,     32767, 76,    0,     501,   80,    32767, 0,
-               109,   41,    167,   195,   32767, 200,   80,    152,
-               -40,   32767, 0,     12,    357,   -158,  32767, 32767,
-               312,   32767, 318,   32767, 104,   176,   560,   185,
-               32767, 397,   187,   32767, 32767, 0,     32767, 227,
-               445,   281,   32767, 32767, 379,   386,   254,   -39,
-               0,     27,    0,     32767, 0,     32767, 0,     32767,
-               347,   589,   0,     0,     32767, -263,  32767, 32767,
-               260,   32767, 32767, 264,   32767, 32767, 0,     0,
-               -361,  -175,  32767, 387,   326,   32767, 308,   32767,
-               32767, 310,   32767, 32767, 32767, 32767, 32767, 30,
-               0,     393,   0,     258,   256,   -324,  0,     0,
-               0,     332,   556,   0,     -39,   32767, 32767, 32767,
-               0,     -327,  0,     32767, 32767, 32767, 179,   32767,
-               32767, 55,    283,   32767, -216,  32767, 32767, 132,
-               32767, 564,   -359,  5,     32767, 0,     126,   32767,
-               0,     411,   32767, 32767, 0,     304,   0,     294,
-               0,     -133,  32767, 0,     32767, 32767, 32767, 153,
-               37,    32767, 0,     -8,    141,   32767, 32767, 32767,
-               32767, 0,     32767, 420,   32767, 169,   32767, 32767,
-               32767, 97,    449,   32767, 156,   32767, 32767, 33,
-               346,   32767, 271,   -46,   0,     32767, 32767, 0,
-               32767, 32767, 464,   58,    32767, 205,   102,   100,
+       static const int16 h[985] = {
+               -2,    143,   32767, 200,   0,     0,     448,   302,
+               769,   -52,   32767, 0,     32767, 0,     32767, 0,
+               281,   253,   248,   612,   32767, 8,     -436,  0,
+               32767, 0,     32767, 354,   -267,  362,   32767, 32767,
+               568,   32767, 0,     32767, 289,   32767, 75,    32767,
+               32767, 33,    32767, 165,   0,     32767, 32767, 32767,
+               32767, -97,   32767, 358,   78,    -272,  73,    339,
+               2,     386,   43,    32767, 0,     32767, 508,   -93,
+               -589,  -159,  -10,   0,     -8,    32767, -359,  32767,
+               288,   -224,  58,    32767, -226,  -10,   201,   32767,
+               347,   32767, 255,   0,     464,   -8,    0,     32767,
+               225,   32767, -118,  32767, -658,  305,   297,   -235,
+               32767, 177,   -393,  0,     -43,   136,   32767, 32767,
+               32767, 0,     270,   -106,  190,   32767, 65,    32767,
+               32767, 32767, 32767, -77,   32767, 148,   -179,  334,
+               0,     32767, 0,     32767, 32767, 280,   477,   346,
+               32767, 148,   335,   66,    265,   -204,  32767, 9,
+               -158,  32767, 372,   16,    32767, 227,   -247,  0,
+               228,   -598,  32767, 257,   32767, 32767, 32767, 32767,
+               32767, 402,   32767, 32767, 332,   -42,   603,   32767,
+               32767, 32767, 971,   -38,   32767, 242,   0,     221,
+               -109,  459,   310,   126,   32767, 32767, 114,   -410,
+               130,   0,     32767, 312,   32767, 313,   32767, 392,
+               516,   217,   32767, 0,     70,    32767, 478,   33,
+               32767, 303,   32767, 0,     59,    194,   32767, 32767,
+               0,     116,   0,     32767, 0,     32767, 32767, -325,
+               81,    -325,  32767, 0,     -204,  0,     0,     32767,
+               460,   32767, 0,     379,   375,   32767, 303,   159,
+               32767, -24,   32767, 32767, 32767, 511,   32767, -185,
+               -622,  32767, 32767, 32767, 304,   1204,  0,     520,
+               542,   593,   -52,   32767, 32767, 291,   32767, 344,
+               0,     31,    -121,  0,     32767, 32767, 32767, 347,
+               0,     32767, 32767, -1259, 0,     32767, 32767, 32767,
+               480,   40,    153,   35,    582,   32767, 34,    115,
+               32767, -83,   32767, 32767, 36,    324,   -434,  32767,
+               430,   -24,   -95,   32767, 32767, 32767, 172,   -1264,
+               -236,  -110,  32767, 87,    -227,  179,   305,   0,
+               32767, 32767, 32767, 32767, 32767, 32767, 0,     134,
+               32767, 299,   32767, 32767, 25,    0,     14,    -38,
+               32767, 105,   392,   32767, 32767, 437,   32767, 32767,
+               446,   32767, 358,   264,   209,   32767, 238,   596,
+               156,   -689,  32767, 435,   32767, 85,    -9,    -155,
+               414,   0,     65,    32767, 32767, -94,   354,   46,
+               69,    -119,  185,   275,   1727,  32767, 32767, -99,
+               32767, 445,   32767, -975,  -183,  32767, 32767, 479,
+               78,    32767, 0,     32767, 32767, 32767, 452,   252,
+               32767, 0,     378,   32767, 32767, -34,   88,    13,
+               32767, 32767, 32767, 32767, 107,   32767, 32767, -86,
+               298,   1307,  180,   32767, 32767, 32767, 32767, -150,
+               95,    0,     32767, 377,   32767, 182,   32767, -1192,
+               287,   32767, 0,     554,   -1011, 32767, 346,   26,
+               0,     32767, 338,   426,   32767, 652,   240,   -244,
+               0,     118,   32767, -203,  133,   32767, 79,    0,
+               94,    32767, 456,   32767, -657,  462,   32767, 266,
+               158,   781,   32767, -273,  32767, 351,   0,     32767,
+               392,   0,     89,    32767, 41,    370,   32767, 61,
+               -148,  32767, 32767, -37,   32767, -76,   315,   32767,
+               32767, 32767, 358,   139,   56,    458,   32767, 415,
+               32767, 32767, 653,   32767, 32767, 32767, -236,  32767,
+               0,     0,     615,   32767, 0,     32767, 55,    -912,
+               32767, 113,   206,   32767, 32767, 32767, 32767, 0,
+               32767, 96,    32767, 396,   175,   129,   32767, 32767,
+               138,   -147,  32767, 32767, -157,  270,   32767, -460,
+               263,   448,   32767, 32767, 0,     371,   32767, 32767,
+               32767, 32767, -283,  32767, 32767, 197,   0,     32767,
+               374,   581,   -549,  32767, 32767, 56,    32767, 0,
+               234,   -115,  32767, -439,  466,   32767, 32767, 0,
+               388,   184,   32767, 32767, 83,    32767, 32767, 120,
+               -277,  0,     32767, 0,     180,   32767, 0,     205,
+               32767, 32767, 219,   0,     32767, 32767, -32,   159,
+               32767, 204,   0,     826,   495,   32767, 190,   0,
+               400,   379,   32767, 32767, -108,  72,    459,   32767,
+               32767, 0,     92,    32767, 276,   133,   32767, 32767,
+               160,   -36,   32767, 70,    871,   32767, 32767, -436,
+               32767, 32767, 980,   385,   0,     9,     32767, 327,
+               519,   0,     32767, 0,     -31,   0,     11,    0,
+               32767, 412,   124,   -121,  377,   0,     32767, 32767,
+               0,     137,   32767, 66,    -123,  264,   -50,   3,
+               -190,  21,    32767, 267,   32767, 0,     0,     32767,
+               32767, 32767, 221,   32767, 32767, -301,  38,    -319,
+               389,   32767, 32767, 275,   964,   -30,   330,   172,
+               32767, 329,   -299,  32767, 524,   341,   32767, 32767,
+               123,   -76,   415,   151,   32767, 179,   0,     -365,
+               32767, -268,  32767, -425,  203,   0,     146,   32767,
+               290,   32767, 259,   32767, 0,     1,     32767, 239,
+               160,   914,   39,    32767, -194,  104,   0,     0,
+               32767, 32767, 32767, 0,     32767, 32767, 10,    487,
+               0,     279,   32767, 223,   32767, 32767, 0,     -286,
+               -510,  151,   429,   32767, 0,     115,   32767, -66,
+               647,   291,   32767, -290,  32767, 0,     -433,  0,
+               180,   32767, 116,   32767, 301,   32767, 282,   294,
+               0,     32767, -126,  0,     -412,  0,     315,   32767,
+               400,   0,     32767, 32767, 32767, 109,   -227,  0,
+               -352,  32767, 112,   0,     471,   0,     32767, 32767,
+               461,   32767, 32767, 233,   32767, 32767, 406,   32767,
+               464,   32767, 118,   382,   0,     32767, 0,     32767,
+               32767, 541,   -305,  814,   0,     268,   0,     403,
+               268,   372,   84,    32767, -91,   32767, 0,     32767,
+               208,   467,   0,     32767, 32767, 32767, -236,  32767,
+               32767, -53,   -317,  32767, 338,   0,     0,     646,
+               32767, 78,    32767, 158,   399,   0,     32767, 0,
+               -269,  32767, 32767, -213,  -786,  32767, 162,   32767,
+               32767, -259,  401,   383,   453,   0,     32767, 0,
+               -232,  -159,  322,   32767, 32767, 203,   0,     32767,
+               183,   314,   32767, -86,   32767, 377,   195,   878,
+               93,    -80,   212,   32767, 49,    32767, 614,   337,
+               32767, 318,   -59,   285,   32767, 0,     32767, 0,
+               98,    17,    32767, 0,     -192,  482,   0,     32767,
+               102,   32767, 331,   366,   0,     -325,  -143,  438,
+               465,   35,    472,   32767, 670,   32767, 0,     0,
+               32767, 32767, 32767, 0,     109,   226,   32767, 32767,
+               25,    -227,  0,     0,     768,   32767, -363,  32767,
+               245,   129,   32767, 405,   95,    407,   345,   1494,
+               32767, 0,     473,   32767, 32767, 32767, 32767, 0,
+               0,     32767, 32767, 244,   32767, 82,    32767, 38,
+               32767, 97,    -39,   397,   32767, 32767, 32767, 32767,
+               32767, 90,    605,   105,   32767, 0,     0,     0,
+               250,   32767, 372,   32767, 32767, 0,     -434,  0,
+               32767, 216,   32767, 443,   32767, 185,   51,    367,
+               32767, 87,    0,     560,   0,     0,     0,     0,
+               349,   -120,  32767, 32767, 408,   32767, 32767, 0,
+               32767, 0,     32767, 32767, 32767, 744,   250,   -146,
+               32767, 142,   0,     -492,  32767, 334,   441,   32767,
                0
        };
 
        const unsigned char *k = (const unsigned char *) key;
        uint32          a = 0;
-       uint32          b = 1;
+       uint32          b = 0;
 
        while (keylen--)
        {
                unsigned char c = *k++ | 0x20;
 
                a = a * 257 + c;
-               b = b * 8191 + c;
+               b = b * 31 + c;
        }
-       return h[a % 945] + h[b % 945];
+       return h[a % 985] + h[b % 985];
 }
 
 const ScanKeywordList ScanKeywords = {
index 922122ca03e28ead1049b5527a1dfaf0d9dfee24..1086b1f555bd35486947a7511d3f2a49b49f1c52 100644 (file)
@@ -4,8 +4,8 @@
  *       prototypes for the creator functions of various nodes
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/nodes/makefuncs.h
@@ -82,6 +82,7 @@ extern FuncExpr *makeFuncExpr(Oid funcid, Oid rettype, List *args,
 extern FuncCall *makeFuncCall(List *name, List *args,
                                                          CoercionForm funcformat, int location);
 
+extern Node *makeStringConst(char *str, int location);
 extern DefElem *makeDefElem(char *name, Node *arg, int location);
 extern DefElem *makeDefElemExtended(char *nameSpace, char *name, Node *arg,
                                                                        DefElemAction defaction, int location);
@@ -98,6 +99,11 @@ extern Node *makeJsonKeyValue(Node *key, Node *value);
 extern Node *makeJsonIsPredicate(Node *expr, JsonFormat *format,
                                                                 JsonValueType item_type, bool unique_keys,
                                                                 int location);
-extern JsonEncoding makeJsonEncoding(char *name);
+extern JsonBehavior *makeJsonBehavior(JsonBehaviorType btype, Node *expr,
+                                                                         int location);
+extern JsonTablePath *makeJsonTablePath(Const *pathvalue, char *pathname);
+extern JsonTablePathSpec *makeJsonTablePathSpec(char *string, char *name,
+                                                                                               int string_location,
+                                                                                               int name_location);
 
 #endif                                                 /* MAKEFUNC_H */
index 828a70a212435c1ba6b69cb79d7866b1e04b5328..734faa48f348a90c2f8f9b4a3bcd932e8ea6bb84 100644 (file)
@@ -4,8 +4,8 @@
  *       Definitions for tagged nodes.
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/nodes/nodes.h
@@ -16,6 +16,7 @@
 #define NODES_H
 
 #include <stdint.h>
+#include "utils/palloc.h"
 
 /*
  * The first field of every node is NodeTag. Each node created (with makeNode)
@@ -145,39 +146,18 @@ typedef struct Node
  *
  * !WARNING!: Avoid using newNode directly. You should be using the
  *       macro makeNode.  eg. to create a Query node, use makeNode(Query)
- *
- * Note: the size argument should always be a compile-time constant, so the
- * apparent risk of multiple evaluation doesn't matter in practice.
- */
-#ifdef __GNUC__
-
-/* With GCC, we can use a compound statement within an expression */
-#define newNode(size, tag) \
-({     Node   *_result; \
-       AssertMacro((size) >= sizeof(Node));            /* need the tag, at least */ \
-       _result = (Node *) palloc0fast(size); \
-       _result->type = (tag); \
-       _result; \
-})
-#else
-
-/*
- *     There is no way to dereference the palloc'ed pointer to assign the
- *     tag, and also return the pointer itself, so we need a holder variable.
- *     Fortunately, this macro isn't recursive so we just define
- *     a global variable for this purpose.
  */
-extern Node *newNodeMacroHolder;
+static inline Node *
+newNode(size_t size, NodeTag tag)
+{
+       Node       *result;
 
-#define newNode(size, tag) \
-( \
-       AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
-       newNodeMacroHolder = (Node *) palloc0fast(size), \
-       newNodeMacroHolder->type = (tag), \
-       newNodeMacroHolder \
-)
-#endif                                                 /* __GNUC__ */
+       Assert(size >= sizeof(Node));   /* need the tag, at least */
+       result = (Node *) palloc0(size);
+       result->type = tag;
 
+       return result;
+}
 
 #define makeNode(_type_)               ((_type_ *) newNode(sizeof(_type_),T_##_type_))
 #define NodeSetTag(nodeptr,t)  (((Node*)(nodeptr))->type = (t))
@@ -222,6 +202,7 @@ extern void outBitmapset(struct StringInfoData *str,
 extern void outDatum(struct StringInfoData *str, uintptr_t value,
                      int typlen, bool typbyval);
 extern char *nodeToString(const void *obj);
+extern char *nodeToStringWithLocations(const void *obj);
 extern char *bmsToString(const struct Bitmapset *bms);
 
 /*
@@ -257,9 +238,18 @@ extern bool equal(const void *a, const void *b);
 
 
 /*
- * Typedefs for identifying qualifier selectivities and plan costs as such.
- * These are just plain "double"s, but declaring a variable as Selectivity
- * or Cost makes the intent more obvious.
+ * Typedef for parse location.  This is just an int, but this way
+ * gen_node_support.pl knows which fields should get special treatment for
+ * location values.
+ *
+ * -1 is used for unknown.
+ */
+typedef int ParseLoc;
+
+/*
+ * Typedefs for identifying qualifier selectivities, plan costs, and row
+ * counts as such.  These are just plain "double"s, but declaring a variable
+ * as Selectivity, Cost, or Cardinality makes the intent more obvious.
  *
  * These could have gone into plannodes.h or some such, but many files
  * depend on them...
@@ -286,7 +276,7 @@ typedef enum CmdType
        CMD_MERGE,                                      /* merge stmt */
        CMD_UTILITY,                            /* cmds like create, destroy, copy, vacuum,
                                                                 * etc. */
-       CMD_NOTHING                                     /* dummy command for instead nothing rules
+       CMD_NOTHING,                            /* dummy command for instead nothing rules
                                                                 * with qual */
 } CmdType;
 
@@ -330,7 +320,7 @@ typedef enum JoinType
         * by the executor (nor, indeed, by most of the planner).
         */
        JOIN_UNIQUE_OUTER,                      /* LHS path must be made unique */
-       JOIN_UNIQUE_INNER                       /* RHS path must be made unique */
+       JOIN_UNIQUE_INNER,                      /* RHS path must be made unique */
 
        /*
         * We might need additional join types someday.
@@ -370,7 +360,7 @@ typedef enum AggStrategy
        AGG_PLAIN,                                      /* simple agg across all input rows */
        AGG_SORTED,                                     /* grouped agg, input must be sorted */
        AGG_HASHED,                                     /* grouped agg, use internal hashtable */
-       AGG_MIXED                                       /* grouped agg, hash and sort both used */
+       AGG_MIXED,                                      /* grouped agg, hash and sort both used */
 } AggStrategy;
 
 /*
@@ -394,7 +384,7 @@ typedef enum AggSplit
        /* Initial phase of partial aggregation, with serialization: */
        AGGSPLIT_INITIAL_SERIAL = AGGSPLITOP_SKIPFINAL | AGGSPLITOP_SERIALIZE,
        /* Final phase of partial aggregation, with deserialization: */
-       AGGSPLIT_FINAL_DESERIAL = AGGSPLITOP_COMBINE | AGGSPLITOP_DESERIALIZE
+       AGGSPLIT_FINAL_DESERIAL = AGGSPLITOP_COMBINE | AGGSPLITOP_DESERIALIZE,
 } AggSplit;
 
 /* Test whether an AggSplit value selects each primitive option: */
@@ -414,13 +404,13 @@ typedef enum SetOpCmd
        SETOPCMD_INTERSECT,
        SETOPCMD_INTERSECT_ALL,
        SETOPCMD_EXCEPT,
-       SETOPCMD_EXCEPT_ALL
+       SETOPCMD_EXCEPT_ALL,
 } SetOpCmd;
 
 typedef enum SetOpStrategy
 {
        SETOP_SORTED,                           /* input must be sorted */
-       SETOP_HASHED                            /* use internal hashtable */
+       SETOP_HASHED,                           /* use internal hashtable */
 } SetOpStrategy;
 
 /*
@@ -433,7 +423,7 @@ typedef enum OnConflictAction
 {
        ONCONFLICT_NONE,                        /* No "ON CONFLICT" clause */
        ONCONFLICT_NOTHING,                     /* ON CONFLICT ... DO NOTHING */
-       ONCONFLICT_UPDATE                       /* ON CONFLICT ... DO UPDATE */
+       ONCONFLICT_UPDATE,                      /* ON CONFLICT ... DO UPDATE */
 } OnConflictAction;
 
 /*
@@ -446,7 +436,6 @@ typedef enum LimitOption
 {
        LIMIT_OPTION_COUNT,                     /* FETCH FIRST... ONLY */
        LIMIT_OPTION_WITH_TIES,         /* FETCH FIRST... WITH TIES */
-       LIMIT_OPTION_DEFAULT,           /* No limit present */
 } LimitOption;
 
 #endif                                                 /* NODES_H */
index f75ac7a05ee403bee3b2bab97a535dce21e71962..ee1fb29ce50ecda78e491a2698ac2a5074666eb2 100644 (file)
@@ -3,7 +3,7 @@
  * nodetags.h
  *    Generated node infrastructure code
  *
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * NOTES
        T_Aggref = 9,
        T_GroupingFunc = 10,
        T_WindowFunc = 11,
-       T_SubscriptingRef = 12,
-       T_FuncExpr = 13,
-       T_NamedArgExpr = 14,
-       T_OpExpr = 15,
-       T_DistinctExpr = 16,
-       T_NullIfExpr = 17,
-       T_ScalarArrayOpExpr = 18,
-       T_BoolExpr = 19,
-       T_SubLink = 20,
-       T_SubPlan = 21,
-       T_AlternativeSubPlan = 22,
-       T_FieldSelect = 23,
-       T_FieldStore = 24,
-       T_RelabelType = 25,
-       T_CoerceViaIO = 26,
-       T_ArrayCoerceExpr = 27,
-       T_ConvertRowtypeExpr = 28,
-       T_CollateExpr = 29,
-       T_CaseExpr = 30,
-       T_CaseWhen = 31,
-       T_CaseTestExpr = 32,
-       T_ArrayExpr = 33,
-       T_RowExpr = 34,
-       T_RowCompareExpr = 35,
-       T_CoalesceExpr = 36,
-       T_MinMaxExpr = 37,
-       T_SQLValueFunction = 38,
-       T_XmlExpr = 39,
-       T_JsonFormat = 40,
-       T_JsonReturning = 41,
-       T_JsonValueExpr = 42,
-       T_JsonConstructorExpr = 43,
-       T_JsonIsPredicate = 44,
-       T_NullTest = 45,
-       T_BooleanTest = 46,
-       T_CoerceToDomain = 47,
-       T_CoerceToDomainValue = 48,
-       T_SetToDefault = 49,
-       T_CurrentOfExpr = 50,
-       T_NextValueExpr = 51,
-       T_InferenceElem = 52,
-       T_TargetEntry = 53,
-       T_RangeTblRef = 54,
-       T_JoinExpr = 55,
-       T_FromExpr = 56,
-       T_OnConflictExpr = 57,
-       T_Query = 58,
-       T_TypeName = 59,
-       T_ColumnRef = 60,
-       T_ParamRef = 61,
-       T_A_Expr = 62,
-       T_A_Const = 63,
-       T_TypeCast = 64,
-       T_CollateClause = 65,
-       T_RoleSpec = 66,
-       T_FuncCall = 67,
-       T_A_Star = 68,
-       T_A_Indices = 69,
-       T_A_Indirection = 70,
-       T_A_ArrayExpr = 71,
-       T_ResTarget = 72,
-       T_MultiAssignRef = 73,
-       T_SortBy = 74,
-       T_WindowDef = 75,
-       T_RangeSubselect = 76,
-       T_RangeFunction = 77,
-       T_RangeTableFunc = 78,
-       T_RangeTableFuncCol = 79,
-       T_RangeTableSample = 80,
-       T_ColumnDef = 81,
-       T_TableLikeClause = 82,
-       T_IndexElem = 83,
-       T_DefElem = 84,
-       T_LockingClause = 85,
-       T_XmlSerialize = 86,
-       T_PartitionElem = 87,
-       T_PartitionSpec = 88,
-       T_PartitionBoundSpec = 89,
-       T_PartitionRangeDatum = 90,
-       T_PartitionCmd = 91,
-       T_RangeTblEntry = 92,
-       T_RTEPermissionInfo = 93,
-       T_RangeTblFunction = 94,
-       T_TableSampleClause = 95,
-       T_WithCheckOption = 96,
-       T_SortGroupClause = 97,
-       T_GroupingSet = 98,
-       T_WindowClause = 99,
-       T_RowMarkClause = 100,
-       T_WithClause = 101,
-       T_InferClause = 102,
-       T_OnConflictClause = 103,
-       T_CTESearchClause = 104,
-       T_CTECycleClause = 105,
-       T_CommonTableExpr = 106,
-       T_MergeWhenClause = 107,
-       T_MergeAction = 108,
-       T_TriggerTransition = 109,
-       T_JsonOutput = 110,
-       T_JsonKeyValue = 111,
-       T_JsonObjectConstructor = 112,
-       T_JsonArrayConstructor = 113,
-       T_JsonArrayQueryConstructor = 114,
-       T_JsonAggConstructor = 115,
-       T_JsonObjectAgg = 116,
-       T_JsonArrayAgg = 117,
-       T_RawStmt = 118,
-       T_InsertStmt = 119,
-       T_DeleteStmt = 120,
-       T_UpdateStmt = 121,
-       T_MergeStmt = 122,
-       T_SelectStmt = 123,
-       T_SetOperationStmt = 124,
-       T_ReturnStmt = 125,
-       T_PLAssignStmt = 126,
-       T_CreateSchemaStmt = 127,
-       T_AlterTableStmt = 128,
-       T_ReplicaIdentityStmt = 129,
-       T_AlterTableCmd = 130,
-       T_AlterCollationStmt = 131,
-       T_AlterDomainStmt = 132,
-       T_GrantStmt = 133,
-       T_ObjectWithArgs = 134,
-       T_AccessPriv = 135,
-       T_GrantRoleStmt = 136,
-       T_AlterDefaultPrivilegesStmt = 137,
-       T_CopyStmt = 138,
-       T_VariableSetStmt = 139,
-       T_VariableShowStmt = 140,
-       T_CreateStmt = 141,
-       T_Constraint = 142,
-       T_CreateTableSpaceStmt = 143,
-       T_DropTableSpaceStmt = 144,
-       T_AlterTableSpaceOptionsStmt = 145,
-       T_AlterTableMoveAllStmt = 146,
-       T_CreateExtensionStmt = 147,
-       T_AlterExtensionStmt = 148,
-       T_AlterExtensionContentsStmt = 149,
-       T_CreateFdwStmt = 150,
-       T_AlterFdwStmt = 151,
-       T_CreateForeignServerStmt = 152,
-       T_AlterForeignServerStmt = 153,
-       T_CreateForeignTableStmt = 154,
-       T_CreateUserMappingStmt = 155,
-       T_AlterUserMappingStmt = 156,
-       T_DropUserMappingStmt = 157,
-       T_ImportForeignSchemaStmt = 158,
-       T_CreatePolicyStmt = 159,
-       T_AlterPolicyStmt = 160,
-       T_CreateAmStmt = 161,
-       T_CreateTrigStmt = 162,
-       T_CreateEventTrigStmt = 163,
-       T_AlterEventTrigStmt = 164,
-       T_CreatePLangStmt = 165,
-       T_CreateRoleStmt = 166,
-       T_AlterRoleStmt = 167,
-       T_AlterRoleSetStmt = 168,
-       T_DropRoleStmt = 169,
-       T_CreateSeqStmt = 170,
-       T_AlterSeqStmt = 171,
-       T_DefineStmt = 172,
-       T_CreateDomainStmt = 173,
-       T_CreateOpClassStmt = 174,
-       T_CreateOpClassItem = 175,
-       T_CreateOpFamilyStmt = 176,
-       T_AlterOpFamilyStmt = 177,
-       T_DropStmt = 178,
-       T_TruncateStmt = 179,
-       T_CommentStmt = 180,
-       T_SecLabelStmt = 181,
-       T_DeclareCursorStmt = 182,
-       T_ClosePortalStmt = 183,
-       T_FetchStmt = 184,
-       T_IndexStmt = 185,
-       T_CreateStatsStmt = 186,
-       T_StatsElem = 187,
-       T_AlterStatsStmt = 188,
-       T_CreateFunctionStmt = 189,
-       T_FunctionParameter = 190,
-       T_AlterFunctionStmt = 191,
-       T_DoStmt = 192,
-       T_InlineCodeBlock = 193,
-       T_CallStmt = 194,
-       T_CallContext = 195,
-       T_RenameStmt = 196,
-       T_AlterObjectDependsStmt = 197,
-       T_AlterObjectSchemaStmt = 198,
-       T_AlterOwnerStmt = 199,
-       T_AlterOperatorStmt = 200,
-       T_AlterTypeStmt = 201,
-       T_RuleStmt = 202,
-       T_NotifyStmt = 203,
-       T_ListenStmt = 204,
-       T_UnlistenStmt = 205,
-       T_TransactionStmt = 206,
-       T_CompositeTypeStmt = 207,
-       T_CreateEnumStmt = 208,
-       T_CreateRangeStmt = 209,
-       T_AlterEnumStmt = 210,
-       T_ViewStmt = 211,
-       T_LoadStmt = 212,
-       T_CreatedbStmt = 213,
-       T_AlterDatabaseStmt = 214,
-       T_AlterDatabaseRefreshCollStmt = 215,
-       T_AlterDatabaseSetStmt = 216,
-       T_DropdbStmt = 217,
-       T_AlterSystemStmt = 218,
-       T_ClusterStmt = 219,
-       T_VacuumStmt = 220,
-       T_VacuumRelation = 221,
-       T_ExplainStmt = 222,
-       T_CreateTableAsStmt = 223,
-       T_RefreshMatViewStmt = 224,
-       T_CheckPointStmt = 225,
-       T_DiscardStmt = 226,
-       T_LockStmt = 227,
-       T_ConstraintsSetStmt = 228,
-       T_ReindexStmt = 229,
-       T_CreateConversionStmt = 230,
-       T_CreateCastStmt = 231,
-       T_CreateTransformStmt = 232,
-       T_PrepareStmt = 233,
-       T_ExecuteStmt = 234,
-       T_DeallocateStmt = 235,
-       T_DropOwnedStmt = 236,
-       T_ReassignOwnedStmt = 237,
-       T_AlterTSDictionaryStmt = 238,
-       T_AlterTSConfigurationStmt = 239,
-       T_PublicationTable = 240,
-       T_PublicationObjSpec = 241,
-       T_CreatePublicationStmt = 242,
-       T_AlterPublicationStmt = 243,
-       T_CreateSubscriptionStmt = 244,
-       T_AlterSubscriptionStmt = 245,
-       T_DropSubscriptionStmt = 246,
-       T_PlannerGlobal = 247,
-       T_PlannerInfo = 248,
-       T_RelOptInfo = 249,
-       T_IndexOptInfo = 250,
-       T_ForeignKeyOptInfo = 251,
-       T_StatisticExtInfo = 252,
-       T_JoinDomain = 253,
-       T_EquivalenceClass = 254,
-       T_EquivalenceMember = 255,
-       T_PathKey = 256,
-       T_PathTarget = 257,
-       T_ParamPathInfo = 258,
-       T_Path = 259,
-       T_IndexPath = 260,
-       T_IndexClause = 261,
-       T_BitmapHeapPath = 262,
-       T_BitmapAndPath = 263,
-       T_BitmapOrPath = 264,
-       T_TidPath = 265,
-       T_TidRangePath = 266,
-       T_SubqueryScanPath = 267,
-       T_ForeignPath = 268,
-       T_CustomPath = 269,
-       T_AppendPath = 270,
-       T_MergeAppendPath = 271,
-       T_GroupResultPath = 272,
-       T_MaterialPath = 273,
-       T_MemoizePath = 274,
-       T_UniquePath = 275,
-       T_GatherPath = 276,
-       T_GatherMergePath = 277,
-       T_NestPath = 278,
-       T_MergePath = 279,
-       T_HashPath = 280,
-       T_ProjectionPath = 281,
-       T_ProjectSetPath = 282,
-       T_SortPath = 283,
-       T_IncrementalSortPath = 284,
-       T_GroupPath = 285,
-       T_UpperUniquePath = 286,
-       T_AggPath = 287,
-       T_GroupingSetData = 288,
-       T_RollupData = 289,
-       T_GroupingSetsPath = 290,
-       T_MinMaxAggPath = 291,
-       T_WindowAggPath = 292,
-       T_SetOpPath = 293,
-       T_RecursiveUnionPath = 294,
-       T_LockRowsPath = 295,
-       T_ModifyTablePath = 296,
-       T_LimitPath = 297,
-       T_RestrictInfo = 298,
-       T_PlaceHolderVar = 299,
-       T_SpecialJoinInfo = 300,
-       T_OuterJoinClauseInfo = 301,
-       T_AppendRelInfo = 302,
-       T_RowIdentityVarInfo = 303,
-       T_PlaceHolderInfo = 304,
-       T_MinMaxAggInfo = 305,
-       T_PlannerParamItem = 306,
-       T_AggInfo = 307,
-       T_AggTransInfo = 308,
-       T_PlannedStmt = 309,
-       T_Result = 310,
-       T_ProjectSet = 311,
-       T_ModifyTable = 312,
-       T_Append = 313,
-       T_MergeAppend = 314,
-       T_RecursiveUnion = 315,
-       T_BitmapAnd = 316,
-       T_BitmapOr = 317,
-       T_SeqScan = 318,
-       T_SampleScan = 319,
-       T_IndexScan = 320,
-       T_IndexOnlyScan = 321,
-       T_BitmapIndexScan = 322,
-       T_BitmapHeapScan = 323,
-       T_TidScan = 324,
-       T_TidRangeScan = 325,
-       T_SubqueryScan = 326,
-       T_FunctionScan = 327,
-       T_ValuesScan = 328,
-       T_TableFuncScan = 329,
-       T_CteScan = 330,
-       T_NamedTuplestoreScan = 331,
-       T_WorkTableScan = 332,
-       T_ForeignScan = 333,
-       T_CustomScan = 334,
-       T_NestLoop = 335,
-       T_NestLoopParam = 336,
-       T_MergeJoin = 337,
-       T_HashJoin = 338,
-       T_Material = 339,
-       T_Memoize = 340,
-       T_Sort = 341,
-       T_IncrementalSort = 342,
-       T_Group = 343,
-       T_Agg = 344,
-       T_WindowAgg = 345,
-       T_Unique = 346,
-       T_Gather = 347,
-       T_GatherMerge = 348,
-       T_Hash = 349,
-       T_SetOp = 350,
-       T_LockRows = 351,
-       T_Limit = 352,
-       T_PlanRowMark = 353,
-       T_PartitionPruneInfo = 354,
-       T_PartitionedRelPruneInfo = 355,
-       T_PartitionPruneStepOp = 356,
-       T_PartitionPruneStepCombine = 357,
-       T_PlanInvalItem = 358,
-       T_ExprState = 359,
-       T_IndexInfo = 360,
-       T_ExprContext = 361,
-       T_ReturnSetInfo = 362,
-       T_ProjectionInfo = 363,
-       T_JunkFilter = 364,
-       T_OnConflictSetState = 365,
-       T_MergeActionState = 366,
-       T_ResultRelInfo = 367,
-       T_EState = 368,
-       T_WindowFuncExprState = 369,
-       T_SetExprState = 370,
-       T_SubPlanState = 371,
-       T_DomainConstraintState = 372,
-       T_ResultState = 373,
-       T_ProjectSetState = 374,
-       T_ModifyTableState = 375,
-       T_AppendState = 376,
-       T_MergeAppendState = 377,
-       T_RecursiveUnionState = 378,
-       T_BitmapAndState = 379,
-       T_BitmapOrState = 380,
-       T_ScanState = 381,
-       T_SeqScanState = 382,
-       T_SampleScanState = 383,
-       T_IndexScanState = 384,
-       T_IndexOnlyScanState = 385,
-       T_BitmapIndexScanState = 386,
-       T_BitmapHeapScanState = 387,
-       T_TidScanState = 388,
-       T_TidRangeScanState = 389,
-       T_SubqueryScanState = 390,
-       T_FunctionScanState = 391,
-       T_ValuesScanState = 392,
-       T_TableFuncScanState = 393,
-       T_CteScanState = 394,
-       T_NamedTuplestoreScanState = 395,
-       T_WorkTableScanState = 396,
-       T_ForeignScanState = 397,
-       T_CustomScanState = 398,
-       T_JoinState = 399,
-       T_NestLoopState = 400,
-       T_MergeJoinState = 401,
-       T_HashJoinState = 402,
-       T_MaterialState = 403,
-       T_MemoizeState = 404,
-       T_SortState = 405,
-       T_IncrementalSortState = 406,
-       T_GroupState = 407,
-       T_AggState = 408,
-       T_WindowAggState = 409,
-       T_UniqueState = 410,
-       T_GatherState = 411,
-       T_GatherMergeState = 412,
-       T_HashState = 413,
-       T_SetOpState = 414,
-       T_LockRowsState = 415,
-       T_LimitState = 416,
-       T_IndexAmRoutine = 417,
-       T_TableAmRoutine = 418,
-       T_TsmRoutine = 419,
-       T_EventTriggerData = 420,
-       T_TriggerData = 421,
-       T_TupleTableSlot = 422,
-       T_FdwRoutine = 423,
-       T_Bitmapset = 424,
-       T_ExtensibleNode = 425,
-       T_ErrorSaveContext = 426,
-       T_IdentifySystemCmd = 427,
-       T_BaseBackupCmd = 428,
-       T_CreateReplicationSlotCmd = 429,
-       T_DropReplicationSlotCmd = 430,
-       T_StartReplicationCmd = 431,
-       T_ReadReplicationSlotCmd = 432,
-       T_TimeLineHistoryCmd = 433,
-       T_SupportRequestSimplify = 434,
-       T_SupportRequestSelectivity = 435,
-       T_SupportRequestCost = 436,
-       T_SupportRequestRows = 437,
-       T_SupportRequestIndexCondition = 438,
-       T_SupportRequestWFuncMonotonic = 439,
-       T_SupportRequestOptimizeWindowClause = 440,
-       T_Integer = 441,
-       T_Float = 442,
-       T_Boolean = 443,
-       T_String = 444,
-       T_BitString = 445,
-       T_ForeignKeyCacheInfo = 446,
-       T_IntList = 447,
-       T_OidList = 448,
-       T_XidList = 449,
-       T_AllocSetContext = 450,
-       T_GenerationContext = 451,
-       T_SlabContext = 452,
-       T_TIDBitmap = 453,
-       T_WindowObjectData = 454,
+       T_WindowFuncRunCondition = 12,
+       T_MergeSupportFunc = 13,
+       T_SubscriptingRef = 14,
+       T_FuncExpr = 15,
+       T_NamedArgExpr = 16,
+       T_OpExpr = 17,
+       T_DistinctExpr = 18,
+       T_NullIfExpr = 19,
+       T_ScalarArrayOpExpr = 20,
+       T_BoolExpr = 21,
+       T_SubLink = 22,
+       T_SubPlan = 23,
+       T_AlternativeSubPlan = 24,
+       T_FieldSelect = 25,
+       T_FieldStore = 26,
+       T_RelabelType = 27,
+       T_CoerceViaIO = 28,
+       T_ArrayCoerceExpr = 29,
+       T_ConvertRowtypeExpr = 30,
+       T_CollateExpr = 31,
+       T_CaseExpr = 32,
+       T_CaseWhen = 33,
+       T_CaseTestExpr = 34,
+       T_ArrayExpr = 35,
+       T_RowExpr = 36,
+       T_RowCompareExpr = 37,
+       T_CoalesceExpr = 38,
+       T_MinMaxExpr = 39,
+       T_SQLValueFunction = 40,
+       T_XmlExpr = 41,
+       T_JsonFormat = 42,
+       T_JsonReturning = 43,
+       T_JsonValueExpr = 44,
+       T_JsonConstructorExpr = 45,
+       T_JsonIsPredicate = 46,
+       T_JsonBehavior = 47,
+       T_JsonExpr = 48,
+       T_JsonTablePath = 49,
+       T_JsonTablePathScan = 50,
+       T_JsonTableSiblingJoin = 51,
+       T_NullTest = 52,
+       T_BooleanTest = 53,
+       T_MergeAction = 54,
+       T_CoerceToDomain = 55,
+       T_CoerceToDomainValue = 56,
+       T_SetToDefault = 57,
+       T_CurrentOfExpr = 58,
+       T_NextValueExpr = 59,
+       T_InferenceElem = 60,
+       T_TargetEntry = 61,
+       T_RangeTblRef = 62,
+       T_JoinExpr = 63,
+       T_FromExpr = 64,
+       T_OnConflictExpr = 65,
+       T_Query = 66,
+       T_TypeName = 67,
+       T_ColumnRef = 68,
+       T_ParamRef = 69,
+       T_A_Expr = 70,
+       T_A_Const = 71,
+       T_TypeCast = 72,
+       T_CollateClause = 73,
+       T_RoleSpec = 74,
+       T_FuncCall = 75,
+       T_A_Star = 76,
+       T_A_Indices = 77,
+       T_A_Indirection = 78,
+       T_A_ArrayExpr = 79,
+       T_ResTarget = 80,
+       T_MultiAssignRef = 81,
+       T_SortBy = 82,
+       T_WindowDef = 83,
+       T_RangeSubselect = 84,
+       T_RangeFunction = 85,
+       T_RangeTableFunc = 86,
+       T_RangeTableFuncCol = 87,
+       T_RangeTableSample = 88,
+       T_ColumnDef = 89,
+       T_TableLikeClause = 90,
+       T_IndexElem = 91,
+       T_DefElem = 92,
+       T_LockingClause = 93,
+       T_XmlSerialize = 94,
+       T_PartitionElem = 95,
+       T_PartitionSpec = 96,
+       T_PartitionBoundSpec = 97,
+       T_PartitionRangeDatum = 98,
+       T_SinglePartitionSpec = 99,
+       T_PartitionCmd = 100,
+       T_RangeTblEntry = 101,
+       T_RTEPermissionInfo = 102,
+       T_RangeTblFunction = 103,
+       T_TableSampleClause = 104,
+       T_WithCheckOption = 105,
+       T_SortGroupClause = 106,
+       T_GroupingSet = 107,
+       T_WindowClause = 108,
+       T_RowMarkClause = 109,
+       T_WithClause = 110,
+       T_InferClause = 111,
+       T_OnConflictClause = 112,
+       T_CTESearchClause = 113,
+       T_CTECycleClause = 114,
+       T_CommonTableExpr = 115,
+       T_MergeWhenClause = 116,
+       T_TriggerTransition = 117,
+       T_JsonOutput = 118,
+       T_JsonArgument = 119,
+       T_JsonFuncExpr = 120,
+       T_JsonTablePathSpec = 121,
+       T_JsonTable = 122,
+       T_JsonTableColumn = 123,
+       T_JsonKeyValue = 124,
+       T_JsonParseExpr = 125,
+       T_JsonScalarExpr = 126,
+       T_JsonSerializeExpr = 127,
+       T_JsonObjectConstructor = 128,
+       T_JsonArrayConstructor = 129,
+       T_JsonArrayQueryConstructor = 130,
+       T_JsonAggConstructor = 131,
+       T_JsonObjectAgg = 132,
+       T_JsonArrayAgg = 133,
+       T_RawStmt = 134,
+       T_InsertStmt = 135,
+       T_DeleteStmt = 136,
+       T_UpdateStmt = 137,
+       T_MergeStmt = 138,
+       T_SelectStmt = 139,
+       T_SetOperationStmt = 140,
+       T_ReturnStmt = 141,
+       T_PLAssignStmt = 142,
+       T_CreateSchemaStmt = 143,
+       T_AlterTableStmt = 144,
+       T_ReplicaIdentityStmt = 145,
+       T_AlterTableCmd = 146,
+       T_AlterCollationStmt = 147,
+       T_AlterDomainStmt = 148,
+       T_GrantStmt = 149,
+       T_ObjectWithArgs = 150,
+       T_AccessPriv = 151,
+       T_GrantRoleStmt = 152,
+       T_AlterDefaultPrivilegesStmt = 153,
+       T_CopyStmt = 154,
+       T_VariableSetStmt = 155,
+       T_VariableShowStmt = 156,
+       T_CreateStmt = 157,
+       T_Constraint = 158,
+       T_CreateTableSpaceStmt = 159,
+       T_DropTableSpaceStmt = 160,
+       T_AlterTableSpaceOptionsStmt = 161,
+       T_AlterTableMoveAllStmt = 162,
+       T_CreateExtensionStmt = 163,
+       T_AlterExtensionStmt = 164,
+       T_AlterExtensionContentsStmt = 165,
+       T_CreateFdwStmt = 166,
+       T_AlterFdwStmt = 167,
+       T_CreateForeignServerStmt = 168,
+       T_AlterForeignServerStmt = 169,
+       T_CreateForeignTableStmt = 170,
+       T_CreateUserMappingStmt = 171,
+       T_AlterUserMappingStmt = 172,
+       T_DropUserMappingStmt = 173,
+       T_ImportForeignSchemaStmt = 174,
+       T_CreatePolicyStmt = 175,
+       T_AlterPolicyStmt = 176,
+       T_CreateAmStmt = 177,
+       T_CreateTrigStmt = 178,
+       T_CreateEventTrigStmt = 179,
+       T_AlterEventTrigStmt = 180,
+       T_CreatePLangStmt = 181,
+       T_CreateRoleStmt = 182,
+       T_AlterRoleStmt = 183,
+       T_AlterRoleSetStmt = 184,
+       T_DropRoleStmt = 185,
+       T_CreateSeqStmt = 186,
+       T_AlterSeqStmt = 187,
+       T_DefineStmt = 188,
+       T_CreateDomainStmt = 189,
+       T_CreateOpClassStmt = 190,
+       T_CreateOpClassItem = 191,
+       T_CreateOpFamilyStmt = 192,
+       T_AlterOpFamilyStmt = 193,
+       T_DropStmt = 194,
+       T_TruncateStmt = 195,
+       T_CommentStmt = 196,
+       T_SecLabelStmt = 197,
+       T_DeclareCursorStmt = 198,
+       T_ClosePortalStmt = 199,
+       T_FetchStmt = 200,
+       T_IndexStmt = 201,
+       T_CreateStatsStmt = 202,
+       T_StatsElem = 203,
+       T_AlterStatsStmt = 204,
+       T_CreateFunctionStmt = 205,
+       T_FunctionParameter = 206,
+       T_AlterFunctionStmt = 207,
+       T_DoStmt = 208,
+       T_InlineCodeBlock = 209,
+       T_CallStmt = 210,
+       T_CallContext = 211,
+       T_RenameStmt = 212,
+       T_AlterObjectDependsStmt = 213,
+       T_AlterObjectSchemaStmt = 214,
+       T_AlterOwnerStmt = 215,
+       T_AlterOperatorStmt = 216,
+       T_AlterTypeStmt = 217,
+       T_RuleStmt = 218,
+       T_NotifyStmt = 219,
+       T_ListenStmt = 220,
+       T_UnlistenStmt = 221,
+       T_TransactionStmt = 222,
+       T_CompositeTypeStmt = 223,
+       T_CreateEnumStmt = 224,
+       T_CreateRangeStmt = 225,
+       T_AlterEnumStmt = 226,
+       T_ViewStmt = 227,
+       T_LoadStmt = 228,
+       T_CreatedbStmt = 229,
+       T_AlterDatabaseStmt = 230,
+       T_AlterDatabaseRefreshCollStmt = 231,
+       T_AlterDatabaseSetStmt = 232,
+       T_DropdbStmt = 233,
+       T_AlterSystemStmt = 234,
+       T_ClusterStmt = 235,
+       T_VacuumStmt = 236,
+       T_VacuumRelation = 237,
+       T_ExplainStmt = 238,
+       T_CreateTableAsStmt = 239,
+       T_RefreshMatViewStmt = 240,
+       T_CheckPointStmt = 241,
+       T_DiscardStmt = 242,
+       T_LockStmt = 243,
+       T_ConstraintsSetStmt = 244,
+       T_ReindexStmt = 245,
+       T_CreateConversionStmt = 246,
+       T_CreateCastStmt = 247,
+       T_CreateTransformStmt = 248,
+       T_PrepareStmt = 249,
+       T_ExecuteStmt = 250,
+       T_DeallocateStmt = 251,
+       T_DropOwnedStmt = 252,
+       T_ReassignOwnedStmt = 253,
+       T_AlterTSDictionaryStmt = 254,
+       T_AlterTSConfigurationStmt = 255,
+       T_PublicationTable = 256,
+       T_PublicationObjSpec = 257,
+       T_CreatePublicationStmt = 258,
+       T_AlterPublicationStmt = 259,
+       T_CreateSubscriptionStmt = 260,
+       T_AlterSubscriptionStmt = 261,
+       T_DropSubscriptionStmt = 262,
+       T_PlannerGlobal = 263,
+       T_PlannerInfo = 264,
+       T_RelOptInfo = 265,
+       T_IndexOptInfo = 266,
+       T_ForeignKeyOptInfo = 267,
+       T_StatisticExtInfo = 268,
+       T_JoinDomain = 269,
+       T_EquivalenceClass = 270,
+       T_EquivalenceMember = 271,
+       T_PathKey = 272,
+       T_GroupByOrdering = 273,
+       T_PathTarget = 274,
+       T_ParamPathInfo = 275,
+       T_Path = 276,
+       T_IndexPath = 277,
+       T_IndexClause = 278,
+       T_BitmapHeapPath = 279,
+       T_BitmapAndPath = 280,
+       T_BitmapOrPath = 281,
+       T_TidPath = 282,
+       T_TidRangePath = 283,
+       T_SubqueryScanPath = 284,
+       T_ForeignPath = 285,
+       T_CustomPath = 286,
+       T_AppendPath = 287,
+       T_MergeAppendPath = 288,
+       T_GroupResultPath = 289,
+       T_MaterialPath = 290,
+       T_MemoizePath = 291,
+       T_UniquePath = 292,
+       T_GatherPath = 293,
+       T_GatherMergePath = 294,
+       T_NestPath = 295,
+       T_MergePath = 296,
+       T_HashPath = 297,
+       T_ProjectionPath = 298,
+       T_ProjectSetPath = 299,
+       T_SortPath = 300,
+       T_IncrementalSortPath = 301,
+       T_GroupPath = 302,
+       T_UpperUniquePath = 303,
+       T_AggPath = 304,
+       T_GroupingSetData = 305,
+       T_RollupData = 306,
+       T_GroupingSetsPath = 307,
+       T_MinMaxAggPath = 308,
+       T_WindowAggPath = 309,
+       T_SetOpPath = 310,
+       T_RecursiveUnionPath = 311,
+       T_LockRowsPath = 312,
+       T_ModifyTablePath = 313,
+       T_LimitPath = 314,
+       T_RestrictInfo = 315,
+       T_PlaceHolderVar = 316,
+       T_SpecialJoinInfo = 317,
+       T_OuterJoinClauseInfo = 318,
+       T_AppendRelInfo = 319,
+       T_RowIdentityVarInfo = 320,
+       T_PlaceHolderInfo = 321,
+       T_MinMaxAggInfo = 322,
+       T_PlannerParamItem = 323,
+       T_AggInfo = 324,
+       T_AggTransInfo = 325,
+       T_PlannedStmt = 326,
+       T_Result = 327,
+       T_ProjectSet = 328,
+       T_ModifyTable = 329,
+       T_Append = 330,
+       T_MergeAppend = 331,
+       T_RecursiveUnion = 332,
+       T_BitmapAnd = 333,
+       T_BitmapOr = 334,
+       T_SeqScan = 335,
+       T_SampleScan = 336,
+       T_IndexScan = 337,
+       T_IndexOnlyScan = 338,
+       T_BitmapIndexScan = 339,
+       T_BitmapHeapScan = 340,
+       T_TidScan = 341,
+       T_TidRangeScan = 342,
+       T_SubqueryScan = 343,
+       T_FunctionScan = 344,
+       T_ValuesScan = 345,
+       T_TableFuncScan = 346,
+       T_CteScan = 347,
+       T_NamedTuplestoreScan = 348,
+       T_WorkTableScan = 349,
+       T_ForeignScan = 350,
+       T_CustomScan = 351,
+       T_NestLoop = 352,
+       T_NestLoopParam = 353,
+       T_MergeJoin = 354,
+       T_HashJoin = 355,
+       T_Material = 356,
+       T_Memoize = 357,
+       T_Sort = 358,
+       T_IncrementalSort = 359,
+       T_Group = 360,
+       T_Agg = 361,
+       T_WindowAgg = 362,
+       T_Unique = 363,
+       T_Gather = 364,
+       T_GatherMerge = 365,
+       T_Hash = 366,
+       T_SetOp = 367,
+       T_LockRows = 368,
+       T_Limit = 369,
+       T_PlanRowMark = 370,
+       T_PartitionPruneInfo = 371,
+       T_PartitionedRelPruneInfo = 372,
+       T_PartitionPruneStepOp = 373,
+       T_PartitionPruneStepCombine = 374,
+       T_PlanInvalItem = 375,
+       T_ExprState = 376,
+       T_IndexInfo = 377,
+       T_ExprContext = 378,
+       T_ReturnSetInfo = 379,
+       T_ProjectionInfo = 380,
+       T_JunkFilter = 381,
+       T_OnConflictSetState = 382,
+       T_MergeActionState = 383,
+       T_ResultRelInfo = 384,
+       T_EState = 385,
+       T_WindowFuncExprState = 386,
+       T_SetExprState = 387,
+       T_SubPlanState = 388,
+       T_DomainConstraintState = 389,
+       T_ResultState = 390,
+       T_ProjectSetState = 391,
+       T_ModifyTableState = 392,
+       T_AppendState = 393,
+       T_MergeAppendState = 394,
+       T_RecursiveUnionState = 395,
+       T_BitmapAndState = 396,
+       T_BitmapOrState = 397,
+       T_ScanState = 398,
+       T_SeqScanState = 399,
+       T_SampleScanState = 400,
+       T_IndexScanState = 401,
+       T_IndexOnlyScanState = 402,
+       T_BitmapIndexScanState = 403,
+       T_BitmapHeapScanState = 404,
+       T_TidScanState = 405,
+       T_TidRangeScanState = 406,
+       T_SubqueryScanState = 407,
+       T_FunctionScanState = 408,
+       T_ValuesScanState = 409,
+       T_TableFuncScanState = 410,
+       T_CteScanState = 411,
+       T_NamedTuplestoreScanState = 412,
+       T_WorkTableScanState = 413,
+       T_ForeignScanState = 414,
+       T_CustomScanState = 415,
+       T_JoinState = 416,
+       T_NestLoopState = 417,
+       T_MergeJoinState = 418,
+       T_HashJoinState = 419,
+       T_MaterialState = 420,
+       T_MemoizeState = 421,
+       T_SortState = 422,
+       T_IncrementalSortState = 423,
+       T_GroupState = 424,
+       T_AggState = 425,
+       T_WindowAggState = 426,
+       T_UniqueState = 427,
+       T_GatherState = 428,
+       T_GatherMergeState = 429,
+       T_HashState = 430,
+       T_SetOpState = 431,
+       T_LockRowsState = 432,
+       T_LimitState = 433,
+       T_IndexAmRoutine = 434,
+       T_TableAmRoutine = 435,
+       T_TsmRoutine = 436,
+       T_EventTriggerData = 437,
+       T_TriggerData = 438,
+       T_TupleTableSlot = 439,
+       T_FdwRoutine = 440,
+       T_Bitmapset = 441,
+       T_ExtensibleNode = 442,
+       T_ErrorSaveContext = 443,
+       T_IdentifySystemCmd = 444,
+       T_BaseBackupCmd = 445,
+       T_CreateReplicationSlotCmd = 446,
+       T_DropReplicationSlotCmd = 447,
+       T_AlterReplicationSlotCmd = 448,
+       T_StartReplicationCmd = 449,
+       T_ReadReplicationSlotCmd = 450,
+       T_TimeLineHistoryCmd = 451,
+       T_UploadManifestCmd = 452,
+       T_SupportRequestSimplify = 453,
+       T_SupportRequestSelectivity = 454,
+       T_SupportRequestCost = 455,
+       T_SupportRequestRows = 456,
+       T_SupportRequestIndexCondition = 457,
+       T_SupportRequestWFuncMonotonic = 458,
+       T_SupportRequestOptimizeWindowClause = 459,
+       T_Integer = 460,
+       T_Float = 461,
+       T_Boolean = 462,
+       T_String = 463,
+       T_BitString = 464,
+       T_ForeignKeyCacheInfo = 465,
+       T_IntList = 466,
+       T_OidList = 467,
+       T_XidList = 468,
+       T_AllocSetContext = 469,
+       T_GenerationContext = 470,
+       T_SlabContext = 471,
+       T_BumpContext = 472,
+       T_TIDBitmap = 473,
+       T_WindowObjectData = 474,
index 727012209d235d832439541d4b9945d9ab24fdb1..1593bad655dd4064c68d3ca2b0cba6c6b13fa90f 100644 (file)
@@ -12,8 +12,8 @@
  * identifying statement boundaries in multi-statement source strings.
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/nodes/parsenodes.h
 #include "primnodes.h"
 #include "value.h"
 
-typedef enum OverridingKind
-{
-       OVERRIDING_NOT_SET = 0,
-       OVERRIDING_USER_VALUE,
-       OVERRIDING_SYSTEM_VALUE
-} OverridingKind;
-
 /* Possible sources of a Query */
 typedef enum QuerySource
 {
@@ -42,7 +35,7 @@ typedef enum QuerySource
        QSRC_PARSER,                            /* added by parse analysis (now unused) */
        QSRC_INSTEAD_RULE,                      /* added by unconditional INSTEAD rule */
        QSRC_QUAL_INSTEAD_RULE,         /* added by conditional INSTEAD rule */
-       QSRC_NON_INSTEAD_RULE           /* added by non-INSTEAD rule */
+       QSRC_NON_INSTEAD_RULE,          /* added by non-INSTEAD rule */
 } QuerySource;
 
 /* Sort ordering options for ORDER BY and CREATE INDEX */
@@ -51,14 +44,14 @@ typedef enum SortByDir
        SORTBY_DEFAULT,
        SORTBY_ASC,
        SORTBY_DESC,
-       SORTBY_USING                            /* not allowed in CREATE INDEX ... */
+       SORTBY_USING,                           /* not allowed in CREATE INDEX ... */
 } SortByDir;
 
 typedef enum SortByNulls
 {
        SORTBY_NULLS_DEFAULT,
        SORTBY_NULLS_FIRST,
-       SORTBY_NULLS_LAST
+       SORTBY_NULLS_LAST,
 } SortByNulls;
 
 /* Options for [ ALL | DISTINCT ] */
@@ -66,7 +59,7 @@ typedef enum SetQuantifier
 {
        SET_QUANTIFIER_DEFAULT,
        SET_QUANTIFIER_ALL,
-       SET_QUANTIFIER_DISTINCT
+       SET_QUANTIFIER_DISTINCT,
 } SetQuantifier;
 
 /*
@@ -92,7 +85,8 @@ typedef uint64 AclMode;                       /* a bitmask of privilege bits */
 #define ACL_CONNECT            (1<<11) /* for databases */
 #define ACL_SET                        (1<<12) /* for configuration parameters */
 #define ACL_ALTER_SYSTEM (1<<13)       /* for configuration parameters */
-#define N_ACL_RIGHTS   14              /* 1 plus the last 1<<x */
+#define ACL_MAINTAIN   (1<<14) /* for relations */
+#define N_ACL_RIGHTS   15              /* 1 plus the last 1<<x */
 #define ACL_NO_RIGHTS  0
 /* Currently, SELECT ... FOR [KEY] UPDATE/SHARE requires UPDATE privileges */
 #define ACL_SELECT_FOR_UPDATE  ACL_UPDATE
@@ -165,7 +159,7 @@ typedef struct Query
        bool            hasDistinctOn pg_node_attr(query_jumble_ignore);
        /* WITH RECURSIVE was specified */
        bool            hasRecursive pg_node_attr(query_jumble_ignore);
-       /* has INSERT/UPDATE/DELETE in WITH */
+       /* has INSERT/UPDATE/DELETE/MERGE in WITH */
        bool            hasModifyingCTE pg_node_attr(query_jumble_ignore);
        /* FOR [KEY] UPDATE/SHARE was specified */
        bool            hasForUpdate pg_node_attr(query_jumble_ignore);
@@ -187,8 +181,17 @@ typedef struct Query
                                                                 * also USING clause for MERGE */
 
        List       *mergeActionList;    /* list of actions for MERGE (only) */
-       /* whether to use outer join */
-       bool            mergeUseOuterJoin pg_node_attr(query_jumble_ignore);
+
+       /*
+        * rtable index of target relation for MERGE to pull data. Initially, this
+        * is the same as resultRelation, but after query rewriting, if the target
+        * relation is a trigger-updatable view, this is the index of the expanded
+        * view subquery, whereas resultRelation is the index of the target view.
+        */
+       int                     mergeTargetRelation pg_node_attr(query_jumble_ignore);
+
+       /* join condition between source and target for MERGE */
+       Node       *mergeJoinCondition;
 
        List       *targetList;         /* target list (of TargetEntry) */
 
@@ -237,9 +240,9 @@ typedef struct Query
         * both be -1 meaning "unknown".
         */
        /* start location, or -1 if unknown */
-       int                     stmt_location;
+       ParseLoc        stmt_location;
        /* length in bytes; 0 means "rest of string" */
-       int                     stmt_len pg_node_attr(query_jumble_ignore);
+       ParseLoc        stmt_len pg_node_attr(query_jumble_ignore);
 } Query;
 
 
@@ -274,7 +277,7 @@ typedef struct TypeName
        List       *typmods;            /* type modifier expression(s) */
        int32           typemod;                /* prespecified type modifier */
        List       *arrayBounds;        /* array bounds */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } TypeName;
 
 /*
@@ -294,7 +297,7 @@ typedef struct ColumnRef
 {
        NodeTag         type;
        List       *fields;                     /* field names (String nodes) or A_Star */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } ColumnRef;
 
 /*
@@ -304,7 +307,7 @@ typedef struct ParamRef
 {
        NodeTag         type;
        int                     number;                 /* the number of the parameter */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } ParamRef;
 
 /*
@@ -325,7 +328,7 @@ typedef enum A_Expr_Kind
        AEXPR_BETWEEN,                          /* name must be "BETWEEN" */
        AEXPR_NOT_BETWEEN,                      /* name must be "NOT BETWEEN" */
        AEXPR_BETWEEN_SYM,                      /* name must be "BETWEEN SYMMETRIC" */
-       AEXPR_NOT_BETWEEN_SYM           /* name must be "NOT BETWEEN SYMMETRIC" */
+       AEXPR_NOT_BETWEEN_SYM,          /* name must be "NOT BETWEEN SYMMETRIC" */
 } A_Expr_Kind;
 
 typedef struct A_Expr
@@ -337,7 +340,7 @@ typedef struct A_Expr
        List       *name;                       /* possibly-qualified name of operator */
        Node       *lexpr;                      /* left argument, or NULL if none */
        Node       *rexpr;                      /* right argument, or NULL if none */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } A_Expr;
 
 /*
@@ -363,7 +366,7 @@ typedef struct A_Const
        NodeTag         type;
        union ValUnion val;
        bool            isnull;                 /* SQL NULL constant */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } A_Const;
 
 /*
@@ -374,7 +377,7 @@ typedef struct TypeCast
        NodeTag         type;
        Node       *arg;                        /* the expression being casted */
        TypeName   *typeName;           /* the target type */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } TypeCast;
 
 /*
@@ -385,7 +388,7 @@ typedef struct CollateClause
        NodeTag         type;
        Node       *arg;                        /* input expression */
        List       *collname;           /* possibly-qualified collation name */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } CollateClause;
 
 /*
@@ -397,7 +400,7 @@ typedef enum RoleSpecType
        ROLESPEC_CURRENT_ROLE,          /* role spec is CURRENT_ROLE */
        ROLESPEC_CURRENT_USER,          /* role spec is CURRENT_USER */
        ROLESPEC_SESSION_USER,          /* role spec is SESSION_USER */
-       ROLESPEC_PUBLIC                         /* role name is "public" */
+       ROLESPEC_PUBLIC,                        /* role name is "public" */
 } RoleSpecType;
 
 typedef struct RoleSpec
@@ -405,7 +408,7 @@ typedef struct RoleSpec
        NodeTag         type;
        RoleSpecType roletype;          /* Type of this rolespec */
        char       *rolename;           /* filled only for ROLESPEC_CSTRING */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } RoleSpec;
 
 /*
@@ -435,7 +438,7 @@ typedef struct FuncCall
        bool            agg_distinct;   /* arguments were labeled DISTINCT */
        bool            func_variadic;  /* last argument was labeled VARIADIC */
        CoercionForm funcformat;        /* how to display this node */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } FuncCall;
 
 /*
@@ -492,7 +495,7 @@ typedef struct A_ArrayExpr
 {
        NodeTag         type;
        List       *elements;           /* array element expressions */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } A_ArrayExpr;
 
 /*
@@ -519,7 +522,7 @@ typedef struct ResTarget
        char       *name;                       /* column name or NULL */
        List       *indirection;        /* subscripts, field names, and '*', or NIL */
        Node       *val;                        /* the value expression to compute or assign */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } ResTarget;
 
 /*
@@ -549,7 +552,7 @@ typedef struct SortBy
        SortByDir       sortby_dir;             /* ASC/DESC/USING/default */
        SortByNulls sortby_nulls;       /* NULLS FIRST/LAST */
        List       *useOp;                      /* name of op to use, if SORTBY_USING */
-       int                     location;               /* operator location, or -1 if none/unknown */
+       ParseLoc        location;               /* operator location, or -1 if none/unknown */
 } SortBy;
 
 /*
@@ -570,7 +573,7 @@ typedef struct WindowDef
        int                     frameOptions;   /* frame_clause options, see below */
        Node       *startOffset;        /* expression for starting bound, if any */
        Node       *endOffset;          /* expression for ending bound, if any */
-       int                     location;               /* parse location, or -1 if none/unknown */
+       ParseLoc        location;               /* parse location, or -1 if none/unknown */
 } WindowDef;
 
 /*
@@ -650,6 +653,9 @@ typedef struct RangeFunction
 
 /*
  * RangeTableFunc - raw form of "table functions" such as XMLTABLE
+ *
+ * Note: JSON_TABLE is also a "table function", but it uses JsonTable node,
+ * not RangeTableFunc.
  */
 typedef struct RangeTableFunc
 {
@@ -660,7 +666,7 @@ typedef struct RangeTableFunc
        List       *namespaces;         /* list of namespaces as ResTarget */
        List       *columns;            /* list of RangeTableFuncCol */
        Alias      *alias;                      /* table alias & optional column aliases */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } RangeTableFunc;
 
 /*
@@ -678,7 +684,7 @@ typedef struct RangeTableFuncCol
        bool            is_not_null;    /* does it have NOT NULL? */
        Node       *colexpr;            /* column filter expression */
        Node       *coldefexpr;         /* column default value expression */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } RangeTableFuncCol;
 
 /*
@@ -698,7 +704,7 @@ typedef struct RangeTableSample
        List       *method;                     /* sampling method name (possibly qualified) */
        List       *args;                       /* argument(s) for sampling method */
        Node       *repeatable;         /* REPEATABLE expression, or NULL if none */
-       int                     location;               /* method name location, or -1 if unknown */
+       ParseLoc        location;               /* method name location, or -1 if unknown */
 } RangeTableSample;
 
 /*
@@ -741,7 +747,7 @@ typedef struct ColumnDef
        Oid                     collOid;                /* collation OID (InvalidOid if not set) */
        List       *constraints;        /* other constraints on column */
        List       *fdwoptions;         /* per-column FDW options */
-       int                     location;               /* parse location, or -1 if none/unknown */
+       ParseLoc        location;               /* parse location, or -1 if none/unknown */
 } ColumnDef;
 
 /*
@@ -804,7 +810,7 @@ typedef enum DefElemAction
        DEFELEM_UNSPEC,                         /* no action given */
        DEFELEM_SET,
        DEFELEM_ADD,
-       DEFELEM_DROP
+       DEFELEM_DROP,
 } DefElemAction;
 
 typedef struct DefElem
@@ -815,7 +821,7 @@ typedef struct DefElem
        Node       *arg;                        /* typically Integer, Float, String, or
                                                                 * TypeName */
        DefElemAction defaction;        /* unspecified action, or SET/ADD/DROP */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } DefElem;
 
 /*
@@ -845,7 +851,7 @@ typedef struct XmlSerialize
        Node       *expr;
        TypeName   *typeName;
        bool            indent;                 /* [NO] INDENT */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } XmlSerialize;
 
 /* Partitioning related definitions */
@@ -863,14 +869,14 @@ typedef struct PartitionElem
        Node       *expr;                       /* expression to partition on, or NULL */
        List       *collation;          /* name of collation; NIL = default */
        List       *opclass;            /* name of desired opclass; NIL = default */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } PartitionElem;
 
 typedef enum PartitionStrategy
 {
        PARTITION_STRATEGY_LIST = 'l',
        PARTITION_STRATEGY_RANGE = 'r',
-       PARTITION_STRATEGY_HASH = 'h'
+       PARTITION_STRATEGY_HASH = 'h',
 } PartitionStrategy;
 
 /*
@@ -883,7 +889,7 @@ typedef struct PartitionSpec
        NodeTag         type;
        PartitionStrategy strategy;
        List       *partParams;         /* List of PartitionElems */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } PartitionSpec;
 
 /*
@@ -910,7 +916,7 @@ typedef struct PartitionBoundSpec
        List       *lowerdatums;        /* List of PartitionRangeDatums */
        List       *upperdatums;        /* List of PartitionRangeDatums */
 
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc    location;           /* token location, or -1 if unknown */
 } PartitionBoundSpec;
 
 /*
@@ -922,7 +928,7 @@ typedef enum PartitionRangeDatumKind
 {
        PARTITION_RANGE_DATUM_MINVALUE = -1,    /* less than any other value */
        PARTITION_RANGE_DATUM_VALUE = 0,        /* a specific (bounded) value */
-       PARTITION_RANGE_DATUM_MAXVALUE = 1      /* greater than any other value */
+       PARTITION_RANGE_DATUM_MAXVALUE = 1, /* greater than any other value */
 } PartitionRangeDatumKind;
 
 typedef struct PartitionRangeDatum
@@ -933,9 +939,19 @@ typedef struct PartitionRangeDatum
        Node       *value;                      /* Const (or A_Const in raw tree), if kind is
                                                                 * PARTITION_RANGE_DATUM_VALUE, else NULL */
 
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } PartitionRangeDatum;
 
+/*
+ * PartitionDesc - used in reverted ALTER TABLE SPLIT PARTITION command
+ *
+ * Kept as a stub for nodetag ABI compatibility.
+ */
+typedef struct SinglePartitionSpec
+{
+       NodeTag         type;
+}                      SinglePartitionSpec;
+
 /*
  * PartitionCmd - info for ALTER TABLE/INDEX ATTACH/DETACH PARTITION commands
  */
@@ -993,10 +1009,6 @@ typedef struct PartitionCmd
  *       them from the joinaliasvars list, because that would affect the attnums
  *       of Vars referencing the rest of the list.)
  *
- *       inh is true for relation references that should be expanded to include
- *       inheritance children, if the rel has any.  This *must* be false for
- *       RTEs other than RTE_RELATION entries.
- *
  *       inFromCl marks those range variables that are listed in the FROM clause.
  *       It's false for RTEs that are added to a query behind the scenes, such
  *       as the NEW and OLD variables for a rule, or the subqueries of a UNION.
@@ -1023,28 +1035,39 @@ typedef enum RTEKind
        RTE_VALUES,                                     /* VALUES (<exprlist>), (<exprlist>), ... */
        RTE_CTE,                                        /* common table expr (WITH list element) */
        RTE_NAMEDTUPLESTORE,            /* tuplestore, e.g. for AFTER triggers */
-       RTE_RESULT                                      /* RTE represents an empty FROM clause; such
+       RTE_RESULT,                                     /* RTE represents an empty FROM clause; such
                                                                 * RTEs are added by the planner, they're not
                                                                 * present during parsing or rewriting */
 } RTEKind;
 
 typedef struct RangeTblEntry
 {
-       pg_node_attr(custom_read_write, custom_query_jumble)
+       pg_node_attr(custom_read_write)
 
        NodeTag         type;
 
-       RTEKind         rtekind;                /* see above */
-
        /*
-        * XXX the fields applicable to only some rte kinds should be merged into
-        * a union.  I didn't do this yet because the diffs would impact a lot of
-        * code that is being actively worked on.  FIXME someday.
+        * Fields valid in all RTEs:
+        *
+        * put alias + eref first to make dump more legible
         */
+       /* user-written alias clause, if any */
+       Alias      *alias pg_node_attr(query_jumble_ignore);
+       /* expanded reference names */
+       Alias      *eref pg_node_attr(query_jumble_ignore);
+
+       RTEKind         rtekind;                /* see above */
 
        /*
         * Fields valid for a plain relation RTE (else zero):
         *
+        * inh is true for relation references that should be expanded to include
+        * inheritance children, if the rel has any.  In the parser, this will
+        * only be true for RTE_RELATION entries.  The planner also uses this
+        * field to mark RTE_SUBQUERY entries that contain UNION ALL queries that
+        * it has flattened into pulled-up subqueries (creating a structure much
+        * like the effects of inheritance).
+        *
         * rellockmode is really LOCKMODE, but it's declared int to avoid having
         * to include lock-related headers here.  It must be RowExclusiveLock if
         * the RTE is an INSERT/UPDATE/DELETE/MERGE target, else RowShareLock if
@@ -1073,17 +1096,26 @@ typedef struct RangeTblEntry
         * relation.  This allows plans referencing AFTER trigger transition
         * tables to be invalidated if the underlying table is altered.
         */
-       Oid                     relid;                  /* OID of the relation */
-       char            relkind;                /* relation kind (see pg_class.relkind) */
-       int                     rellockmode;    /* lock level that query requires on the rel */
-       struct TableSampleClause *tablesample;  /* sampling info, or NULL */
-       Index           perminfoindex;
+       /* OID of the relation */
+       Oid                     relid;
+       /* inheritance requested? */
+       bool            inh;
+       /* relation kind (see pg_class.relkind) */
+       char            relkind pg_node_attr(query_jumble_ignore);
+       /* lock level that query requires on the rel */
+       int                     rellockmode pg_node_attr(query_jumble_ignore);
+       /* index of RTEPermissionInfo entry, or 0 */
+       Index           perminfoindex pg_node_attr(query_jumble_ignore);
+       /* sampling info, or NULL */
+       struct TableSampleClause *tablesample;
 
        /*
         * Fields valid for a subquery RTE (else NULL):
         */
-       Query      *subquery;           /* the sub-query */
-       bool            security_barrier;       /* is from security_barrier view? */
+       /* the sub-query */
+       Query      *subquery;
+       /* is from security_barrier view? */
+       bool            security_barrier pg_node_attr(query_jumble_ignore);
 
        /*
         * Fields valid for a join RTE (else NULL/zero):
@@ -1128,18 +1160,22 @@ typedef struct RangeTblEntry
         * merged columns could not be dropped); this is not accounted for in
         * joinleftcols/joinrightcols.
         */
-       JoinType        jointype;               /* type of join */
-       int                     joinmergedcols; /* number of merged (JOIN USING) columns */
-       List       *joinaliasvars;      /* list of alias-var expansions */
-       List       *joinleftcols;       /* left-side input column numbers */
-       List       *joinrightcols;      /* right-side input column numbers */
+       JoinType        jointype;
+       /* number of merged (JOIN USING) columns */
+       int                     joinmergedcols pg_node_attr(query_jumble_ignore);
+       /* list of alias-var expansions */
+       List       *joinaliasvars pg_node_attr(query_jumble_ignore);
+       /* left-side input column numbers */
+       List       *joinleftcols pg_node_attr(query_jumble_ignore);
+       /* right-side input column numbers */
+       List       *joinrightcols pg_node_attr(query_jumble_ignore);
 
        /*
         * join_using_alias is an alias clause attached directly to JOIN/USING. It
         * is different from the alias field (below) in that it does not hide the
         * range variables of the tables being joined.
         */
-       Alias      *join_using_alias;
+       Alias      *join_using_alias pg_node_attr(query_jumble_ignore);
 
        /*
         * Fields valid for a function RTE (else NIL/zero):
@@ -1149,8 +1185,10 @@ typedef struct RangeTblEntry
         * implicit, and must be accounted for "by hand" in places such as
         * expandRTE().
         */
-       List       *functions;          /* list of RangeTblFunction nodes */
-       bool            funcordinality; /* is this called WITH ORDINALITY? */
+       /* list of RangeTblFunction nodes */
+       List       *functions;
+       /* is this called WITH ORDINALITY? */
+       bool            funcordinality;
 
        /*
         * Fields valid for a TableFunc RTE (else NULL):
@@ -1160,14 +1198,18 @@ typedef struct RangeTblEntry
        /*
         * Fields valid for a values RTE (else NIL):
         */
-       List       *values_lists;       /* list of expression lists */
+       /* list of expression lists */
+       List       *values_lists;
 
        /*
         * Fields valid for a CTE RTE (else NULL/zero):
         */
-       char       *ctename;            /* name of the WITH list item */
-       Index           ctelevelsup;    /* number of query levels up */
-       bool            self_reference; /* is this a recursive self-reference? */
+       /* name of the WITH list item */
+       char       *ctename;
+       /* number of query levels up */
+       Index           ctelevelsup;
+       /* is this a recursive self-reference? */
+       bool            self_reference pg_node_attr(query_jumble_ignore);
 
        /*
         * Fields valid for CTE, VALUES, ENR, and TableFunc RTEs (else NIL):
@@ -1187,25 +1229,30 @@ typedef struct RangeTblEntry
         * all three lists (as well as an empty-string entry in eref).  Testing
         * for zero coltype is the standard way to detect a dropped column.
         */
-       List       *coltypes;           /* OID list of column type OIDs */
-       List       *coltypmods;         /* integer list of column typmods */
-       List       *colcollations;      /* OID list of column collation OIDs */
+       /* OID list of column type OIDs */
+       List       *coltypes pg_node_attr(query_jumble_ignore);
+       /* integer list of column typmods */
+       List       *coltypmods pg_node_attr(query_jumble_ignore);
+       /* OID list of column collation OIDs */
+       List       *colcollations pg_node_attr(query_jumble_ignore);
 
        /*
         * Fields valid for ENR RTEs (else NULL/zero):
         */
-       char       *enrname;            /* name of ephemeral named relation */
-       Cardinality enrtuples;          /* estimated or actual from caller */
+       /* name of ephemeral named relation */
+       char       *enrname;
+       /* estimated or actual from caller */
+       Cardinality enrtuples pg_node_attr(query_jumble_ignore);
 
        /*
         * Fields valid in all RTEs:
         */
-       Alias      *alias;                      /* user-written alias clause, if any */
-       Alias      *eref;                       /* expanded reference names */
-       bool            lateral;                /* subquery, function, or values is LATERAL? */
-       bool            inh;                    /* inheritance requested? */
-       bool            inFromCl;               /* present in FROM clause? */
-       List       *securityQuals;      /* security barrier quals to apply, if any */
+       /* was LATERAL specified? */
+       bool            lateral pg_node_attr(query_jumble_ignore);
+       /* present in FROM clause? */
+       bool            inFromCl pg_node_attr(query_jumble_ignore);
+       /* security barrier quals to apply, if any */
+       List       *securityQuals pg_node_attr(query_jumble_ignore);
 } RangeTblEntry;
 
 /*
@@ -1320,7 +1367,7 @@ typedef enum WCOKind
        WCO_RLS_UPDATE_CHECK,           /* RLS UPDATE WITH CHECK policy */
        WCO_RLS_CONFLICT_CHECK,         /* RLS ON CONFLICT DO UPDATE USING policy */
        WCO_RLS_MERGE_UPDATE_CHECK, /* RLS MERGE UPDATE USING policy */
-       WCO_RLS_MERGE_DELETE_CHECK      /* RLS MERGE DELETE USING policy */
+       WCO_RLS_MERGE_DELETE_CHECK, /* RLS MERGE DELETE USING policy */
 } WCOKind;
 
 typedef struct WithCheckOption
@@ -1458,7 +1505,7 @@ typedef enum GroupingSetKind
        GROUPING_SET_SIMPLE,
        GROUPING_SET_ROLLUP,
        GROUPING_SET_CUBE,
-       GROUPING_SET_SETS
+       GROUPING_SET_SETS,
 } GroupingSetKind;
 
 typedef struct GroupingSet
@@ -1466,7 +1513,7 @@ typedef struct GroupingSet
        NodeTag         type;
        GroupingSetKind kind pg_node_attr(query_jumble_ignore);
        List       *content;
-       int                     location;
+       ParseLoc        location;
 } GroupingSet;
 
 /*
@@ -1477,6 +1524,8 @@ typedef struct GroupingSet
  * if the clause originally came from WINDOW, and is NULL if it originally
  * was an OVER clause (but note that we collapse out duplicate OVERs).
  * partitionClause and orderClause are lists of SortGroupClause structs.
+ * partitionClause is sanitized by the query planner to remove any columns or
+ * expressions belonging to redundant PathKeys.
  * If we have RANGE with offset PRECEDING/FOLLOWING, the semantics of that are
  * specified by startInRangeFunc/inRangeColl/inRangeAsc/inRangeNullsFirst
  * for the start offset, or endInRangeFunc/inRange* for the end offset.
@@ -1502,8 +1551,6 @@ typedef struct WindowClause
        int                     frameOptions;   /* frame_clause options, see WindowDef */
        Node       *startOffset;        /* expression for starting bound, if any */
        Node       *endOffset;          /* expression for ending bound, if any */
-       /* qual to help short-circuit execution */
-       List       *runCondition pg_node_attr(query_jumble_ignore);
        /* in_range function for startOffset */
        Oid                     startInRangeFunc pg_node_attr(query_jumble_ignore);
        /* in_range function for endOffset */
@@ -1552,7 +1599,7 @@ typedef struct WithClause
        NodeTag         type;
        List       *ctes;                       /* list of CommonTableExprs */
        bool            recursive;              /* true = WITH RECURSIVE */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } WithClause;
 
 /*
@@ -1567,7 +1614,7 @@ typedef struct InferClause
        List       *indexElems;         /* IndexElems to infer unique index */
        Node       *whereClause;        /* qualification (partial-index predicate) */
        char       *conname;            /* Constraint name, or NULL if unnamed */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } InferClause;
 
 /*
@@ -1583,7 +1630,7 @@ typedef struct OnConflictClause
        InferClause *infer;                     /* Optional index inference clause */
        List       *targetList;         /* the target list (of ResTarget) */
        Node       *whereClause;        /* qualifications */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } OnConflictClause;
 
 /*
@@ -1595,7 +1642,7 @@ typedef enum CTEMaterialize
 {
        CTEMaterializeDefault,          /* no option specified */
        CTEMaterializeAlways,           /* MATERIALIZED */
-       CTEMaterializeNever                     /* NOT MATERIALIZED */
+       CTEMaterializeNever,            /* NOT MATERIALIZED */
 } CTEMaterialize;
 
 typedef struct CTESearchClause
@@ -1604,7 +1651,7 @@ typedef struct CTESearchClause
        List       *search_col_list;
        bool            search_breadth_first;
        char       *search_seq_column;
-       int                     location;
+       ParseLoc        location;
 } CTESearchClause;
 
 typedef struct CTECycleClause
@@ -1615,7 +1662,7 @@ typedef struct CTECycleClause
        Node       *cycle_mark_value;
        Node       *cycle_mark_default;
        char       *cycle_path_column;
-       int                     location;
+       ParseLoc        location;
        /* These fields are set during parse analysis: */
        Oid                     cycle_mark_type;        /* common type of _value and _default */
        int                     cycle_mark_typmod;
@@ -1639,7 +1686,7 @@ typedef struct CommonTableExpr
        Node       *ctequery;           /* the CTE's subquery */
        CTESearchClause *search_clause pg_node_attr(query_jumble_ignore);
        CTECycleClause *cycle_clause pg_node_attr(query_jumble_ignore);
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
        /* These fields are set during parse analysis: */
        /* is this CTE actually recursive? */
        bool            cterecursive pg_node_attr(query_jumble_ignore);
@@ -1675,7 +1722,7 @@ typedef struct CommonTableExpr
 typedef struct MergeWhenClause
 {
        NodeTag         type;
-       bool            matched;                /* true=MATCHED, false=NOT MATCHED */
+       MergeMatchKind matchKind;       /* MATCHED/NOT MATCHED BY SOURCE/TARGET */
        CmdType         commandType;    /* INSERT/UPDATE/DELETE/DO NOTHING */
        OverridingKind override;        /* OVERRIDING clause */
        Node       *condition;          /* WHEN conditions (raw parser) */
@@ -1684,23 +1731,6 @@ typedef struct MergeWhenClause
        List       *values;                     /* VALUES to INSERT, or NULL */
 } MergeWhenClause;
 
-/*
- * MergeAction -
- *             Transformed representation of a WHEN clause in a MERGE statement
- */
-typedef struct MergeAction
-{
-       NodeTag         type;
-       bool            matched;                /* true=MATCHED, false=NOT MATCHED */
-       CmdType         commandType;    /* INSERT/UPDATE/DELETE/DO NOTHING */
-       /* OVERRIDING clause */
-       OverridingKind override pg_node_attr(query_jumble_ignore);
-       Node       *qual;                       /* transformed WHEN conditions */
-       List       *targetList;         /* the target list (of TargetEntry) */
-       /* target attribute numbers of an UPDATE */
-       List       *updateColnos pg_node_attr(query_jumble_ignore);
-} MergeAction;
-
 /*
  * TriggerTransition -
  *        representation of transition row or table naming clause
@@ -1730,6 +1760,115 @@ typedef struct JsonOutput
        JsonReturning *returning;       /* RETURNING FORMAT clause and type Oids */
 } JsonOutput;
 
+/*
+ * JsonArgument -
+ *             representation of argument from JSON PASSING clause
+ */
+typedef struct JsonArgument
+{
+       NodeTag         type;
+       JsonValueExpr *val;                     /* argument value expression */
+       char       *name;                       /* argument name */
+} JsonArgument;
+
+/*
+ * JsonQuotes -
+ *             representation of [KEEP|OMIT] QUOTES clause for JSON_QUERY()
+ */
+typedef enum JsonQuotes
+{
+       JS_QUOTES_UNSPEC,                       /* unspecified */
+       JS_QUOTES_KEEP,                         /* KEEP QUOTES */
+       JS_QUOTES_OMIT,                         /* OMIT QUOTES */
+} JsonQuotes;
+
+/*
+ * JsonFuncExpr -
+ *             untransformed representation of function expressions for
+ *             SQL/JSON query functions
+ */
+typedef struct JsonFuncExpr
+{
+       NodeTag         type;
+       JsonExprOp      op;                             /* expression type */
+       char       *column_name;        /* JSON_TABLE() column name or NULL if this is
+                                                                * not for a JSON_TABLE() */
+       JsonValueExpr *context_item;    /* context item expression */
+       Node       *pathspec;           /* JSON path specification expression */
+       List       *passing;            /* list of PASSING clause arguments, if any */
+       JsonOutput *output;                     /* output clause, if specified */
+       JsonBehavior *on_empty;         /* ON EMPTY behavior */
+       JsonBehavior *on_error;         /* ON ERROR behavior */
+       JsonWrapper wrapper;            /* array wrapper behavior (JSON_QUERY only) */
+       JsonQuotes      quotes;                 /* omit or keep quotes? (JSON_QUERY only) */
+       ParseLoc        location;               /* token location, or -1 if unknown */
+} JsonFuncExpr;
+
+/*
+ * JsonTablePathSpec
+ *             untransformed specification of JSON path expression with an optional
+ *             name
+ */
+typedef struct JsonTablePathSpec
+{
+       NodeTag         type;
+
+       Node       *string;
+       char       *name;
+       ParseLoc        name_location;
+       ParseLoc        location;               /* location of 'string' */
+} JsonTablePathSpec;
+
+/*
+ * JsonTable -
+ *             untransformed representation of JSON_TABLE
+ */
+typedef struct JsonTable
+{
+       NodeTag         type;
+       JsonValueExpr *context_item;    /* context item expression */
+       JsonTablePathSpec *pathspec;    /* JSON path specification */
+       List       *passing;            /* list of PASSING clause arguments, if any */
+       List       *columns;            /* list of JsonTableColumn */
+       JsonBehavior *on_error;         /* ON ERROR behavior */
+       Alias      *alias;                      /* table alias in FROM clause */
+       bool            lateral;                /* does it have LATERAL prefix? */
+       ParseLoc        location;               /* token location, or -1 if unknown */
+} JsonTable;
+
+/*
+ * JsonTableColumnType -
+ *             enumeration of JSON_TABLE column types
+ */
+typedef enum JsonTableColumnType
+{
+       JTC_FOR_ORDINALITY,
+       JTC_REGULAR,
+       JTC_EXISTS,
+       JTC_FORMATTED,
+       JTC_NESTED,
+} JsonTableColumnType;
+
+/*
+ * JsonTableColumn -
+ *             untransformed representation of JSON_TABLE column
+ */
+typedef struct JsonTableColumn
+{
+       NodeTag         type;
+       JsonTableColumnType coltype;    /* column type */
+       char       *name;                       /* column name */
+       TypeName   *typeName;           /* column type name */
+       JsonTablePathSpec *pathspec;    /* JSON path specification */
+       JsonFormat *format;                     /* JSON format clause, if specified */
+       JsonWrapper wrapper;            /* WRAPPER behavior for formatted columns */
+       JsonQuotes      quotes;                 /* omit or keep quotes on scalar strings? */
+       List       *columns;            /* nested columns */
+       JsonBehavior *on_empty;         /* ON EMPTY behavior */
+       JsonBehavior *on_error;         /* ON ERROR behavior */
+       ParseLoc        location;               /* token location, or -1 if unknown */
+} JsonTableColumn;
+
 /*
  * JsonKeyValue -
  *             untransformed representation of JSON object key-value pair for
@@ -1742,6 +1881,43 @@ typedef struct JsonKeyValue
        JsonValueExpr *value;           /* JSON value expression */
 } JsonKeyValue;
 
+/*
+ * JsonParseExpr -
+ *             untransformed representation of JSON()
+ */
+typedef struct JsonParseExpr
+{
+       NodeTag         type;
+       JsonValueExpr *expr;            /* string expression */
+       JsonOutput *output;                     /* RETURNING clause, if specified */
+       bool            unique_keys;    /* WITH UNIQUE KEYS? */
+       ParseLoc        location;               /* token location, or -1 if unknown */
+} JsonParseExpr;
+
+/*
+ * JsonScalarExpr -
+ *             untransformed representation of JSON_SCALAR()
+ */
+typedef struct JsonScalarExpr
+{
+       NodeTag         type;
+       Expr       *expr;                       /* scalar expression */
+       JsonOutput *output;                     /* RETURNING clause, if specified */
+       ParseLoc        location;               /* token location, or -1 if unknown */
+} JsonScalarExpr;
+
+/*
+ * JsonSerializeExpr -
+ *             untransformed representation of JSON_SERIALIZE() function
+ */
+typedef struct JsonSerializeExpr
+{
+       NodeTag         type;
+       JsonValueExpr *expr;            /* json value expression */
+       JsonOutput *output;                     /* RETURNING clause, if specified  */
+       ParseLoc        location;               /* token location, or -1 if unknown */
+} JsonSerializeExpr;
+
 /*
  * JsonObjectConstructor -
  *             untransformed representation of JSON_OBJECT() constructor
@@ -1753,7 +1929,7 @@ typedef struct JsonObjectConstructor
        JsonOutput *output;                     /* RETURNING clause, if specified  */
        bool            absent_on_null; /* skip NULL values? */
        bool            unique;                 /* check key uniqueness? */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } JsonObjectConstructor;
 
 /*
@@ -1766,7 +1942,7 @@ typedef struct JsonArrayConstructor
        List       *exprs;                      /* list of JsonValueExpr elements */
        JsonOutput *output;                     /* RETURNING clause, if specified  */
        bool            absent_on_null; /* skip NULL elements? */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } JsonArrayConstructor;
 
 /*
@@ -1780,7 +1956,7 @@ typedef struct JsonArrayQueryConstructor
        JsonOutput *output;                     /* RETURNING clause, if specified  */
        JsonFormat *format;                     /* FORMAT clause for subquery, if specified */
        bool            absent_on_null; /* skip NULL elements? */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } JsonArrayQueryConstructor;
 
 /*
@@ -1795,7 +1971,7 @@ typedef struct JsonAggConstructor
        Node       *agg_filter;         /* FILTER clause, if any */
        List       *agg_order;          /* ORDER BY clause, if any */
        struct WindowDef *over;         /* OVER clause, if any */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } JsonAggConstructor;
 
 /*
@@ -1849,8 +2025,8 @@ typedef struct RawStmt
 
        NodeTag         type;
        Node       *stmt;                       /* raw parse tree */
-       int                     stmt_location;  /* start location, or -1 if unknown */
-       int                     stmt_len;               /* length in bytes; 0 means "rest of string" */
+       ParseLoc        stmt_location;  /* start location, or -1 if unknown */
+       ParseLoc        stmt_len;               /* length in bytes; 0 means "rest of string" */
 } RawStmt;
 
 /*****************************************************************************
@@ -1917,6 +2093,7 @@ typedef struct MergeStmt
        Node       *sourceRelation; /* source relation */
        Node       *joinCondition;      /* join condition between source and target */
        List       *mergeWhenClauses;   /* list of MergeWhenClause(es) */
+       List       *returningList;      /* list of expressions to return */
        WithClause *withClause;         /* WITH clause */
 } MergeStmt;
 
@@ -1938,7 +2115,7 @@ typedef enum SetOperation
        SETOP_NONE = 0,
        SETOP_UNION,
        SETOP_INTERSECT,
-       SETOP_EXCEPT
+       SETOP_EXCEPT,
 } SetOperation;
 
 typedef struct SelectStmt
@@ -2057,7 +2234,7 @@ typedef struct PLAssignStmt
        List       *indirection;        /* subscripts and field names, if any */
        int                     nnames;                 /* number of names to use in ColumnRef */
        SelectStmt *val;                        /* the PL/pgSQL expression to assign */
-       int                     location;               /* name's token location, or -1 if unknown */
+       ParseLoc        location;               /* name's token location, or -1 if unknown */
 } PLAssignStmt;
 
 
@@ -2134,7 +2311,7 @@ typedef enum ObjectType
        OBJECT_TSTEMPLATE,
        OBJECT_TYPE,
        OBJECT_USER_MAPPING,
-       OBJECT_VIEW
+       OBJECT_VIEW,
 } ObjectType;
 
 /* ----------------------
@@ -2157,7 +2334,7 @@ typedef struct CreateSchemaStmt
 typedef enum DropBehavior
 {
        DROP_RESTRICT,                          /* drop fails if any dependent objects */
-       DROP_CASCADE                            /* remove dependent objects too */
+       DROP_CASCADE,                           /* remove dependent objects too */
 } DropBehavior;
 
 /* ----------------------
@@ -2181,6 +2358,7 @@ typedef enum AlterTableType
        AT_CookedColumnDefault,         /* add a pre-cooked column default */
        AT_DropNotNull,                         /* alter column drop not null */
        AT_SetNotNull,                          /* alter column set not null */
+       AT_SetExpression,                       /* alter column set expression */
        AT_DropExpression,                      /* alter column drop expression */
        AT_CheckNotNull,                        /* check column is already marked not null */
        AT_SetStatistics,                       /* alter column set statistics */
@@ -2240,7 +2418,7 @@ typedef enum AlterTableType
        AT_AddIdentity,                         /* ADD IDENTITY */
        AT_SetIdentity,                         /* SET identity column options */
        AT_DropIdentity,                        /* DROP IDENTITY */
-       AT_ReAddStatistics                      /* internal to commands/tablecmds.c */
+       AT_ReAddStatistics,                     /* internal to commands/tablecmds.c */
 } AlterTableType;
 
 typedef struct ReplicaIdentityStmt
@@ -2255,7 +2433,7 @@ typedef struct AlterTableCmd      /* one subcommand of an ALTER TABLE */
        NodeTag         type;
        AlterTableType subtype;         /* Type of table alteration to apply */
        char       *name;                       /* column, constraint, or trigger to act on,
-                                                                * or tablespace */
+                                                                * or tablespace, access method */
        int16           num;                    /* attribute number for columns referenced by
                                                                 * number */
        RoleSpec   *newowner;
@@ -2312,7 +2490,7 @@ typedef enum GrantTargetType
 {
        ACL_TARGET_OBJECT,                      /* grant on specific named object(s) */
        ACL_TARGET_ALL_IN_SCHEMA,       /* grant on all objects in given schema(s) */
-       ACL_TARGET_DEFAULTS                     /* ALTER DEFAULT PRIVILEGES */
+       ACL_TARGET_DEFAULTS,            /* ALTER DEFAULT PRIVILEGES */
 } GrantTargetType;
 
 typedef struct GrantStmt
@@ -2439,7 +2617,7 @@ typedef enum VariableSetKind
        VAR_SET_CURRENT,                        /* SET var FROM CURRENT */
        VAR_SET_MULTI,                          /* special case for SET TRANSACTION ... */
        VAR_RESET,                                      /* RESET var */
-       VAR_RESET_ALL                           /* RESET ALL */
+       VAR_RESET_ALL,                          /* RESET ALL */
 } VariableSetKind;
 
 typedef struct VariableSetStmt
@@ -2537,7 +2715,7 @@ typedef enum ConstrType                   /* types of constraints */
        CONSTR_ATTR_DEFERRABLE,         /* attributes for previous constraint node */
        CONSTR_ATTR_NOT_DEFERRABLE,
        CONSTR_ATTR_DEFERRED,
-       CONSTR_ATTR_IMMEDIATE
+       CONSTR_ATTR_IMMEDIATE,
 } ConstrType;
 
 /* Foreign key action codes */
@@ -2554,40 +2732,33 @@ typedef enum ConstrType                 /* types of constraints */
 
 typedef struct Constraint
 {
-       pg_node_attr(custom_read_write)
-
        NodeTag         type;
        ConstrType      contype;                /* see above */
-
-       /* Fields used for most/all constraint types: */
        char       *conname;            /* Constraint name, or NULL if unnamed */
        bool            deferrable;             /* DEFERRABLE? */
        bool            initdeferred;   /* INITIALLY DEFERRED? */
-       int                     location;               /* token location, or -1 if unknown */
-
-       /* Fields used for constraints with expressions (CHECK and DEFAULT): */
+       bool            skip_validation;        /* skip validation of existing rows? */
+       bool            initially_valid;        /* mark the new constraint as valid? */
        bool            is_no_inherit;  /* is constraint non-inheritable? */
-       Node       *raw_expr;           /* expr, as untransformed parse tree */
-       char       *cooked_expr;        /* expr, as nodeToString representation */
+       Node       *raw_expr;           /* CHECK or DEFAULT expression, as
+                                                                * untransformed parse tree */
+       char       *cooked_expr;        /* CHECK or DEFAULT expression, as
+                                                                * nodeToString representation */
        char            generated_when; /* ALWAYS or BY DEFAULT */
-
-       /* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */
+       int                     inhcount;               /* initial inheritance count to apply, for
+                                                                * "raw" NOT NULL constraints */
        bool            nulls_not_distinct; /* null treatment for UNIQUE constraints */
        List       *keys;                       /* String nodes naming referenced key
-                                                                * column(s) */
+                                                                * column(s); for UNIQUE/PK/NOT NULL */
        List       *including;          /* String nodes naming referenced nonkey
-                                                                * column(s) */
-
-       /* Fields used for EXCLUSION constraints: */
-       List       *exclusions;         /* list of (IndexElem, operator name) pairs */
-
-       /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */
+                                                                * column(s); for UNIQUE/PK */
+       List       *exclusions;         /* list of (IndexElem, operator name) pairs;
+                                                                * for exclusion constraints */
        List       *options;            /* options from WITH clause */
        char       *indexname;          /* existing index to use; otherwise NULL */
        char       *indexspace;         /* index tablespace; NULL for default */
        bool            reset_default_tblspc;   /* reset default_tablespace prior to
                                                                                 * creating the index */
-       /* These could be, but currently are not, used for UNIQUE/PKEY: */
        char       *access_method;      /* index access method; NULL for default */
        Node       *where_clause;       /* partial index predicate */
 
@@ -2603,9 +2774,7 @@ typedef struct Constraint
        Oid                     old_pktable_oid;        /* pg_constraint.confrelid of my former
                                                                         * self */
 
-       /* Fields used for constraints that allow a NOT VALID specification */
-       bool            skip_validation;        /* skip validation of existing rows? */
-       bool            initially_valid;        /* mark the new constraint as valid? */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } Constraint;
 
 /* ----------------------
@@ -2774,7 +2943,7 @@ typedef enum ImportForeignSchemaType
 {
        FDW_IMPORT_SCHEMA_ALL,          /* all relations wanted */
        FDW_IMPORT_SCHEMA_LIMIT_TO, /* include only listed tables in import */
-       FDW_IMPORT_SCHEMA_EXCEPT        /* exclude listed tables from import */
+       FDW_IMPORT_SCHEMA_EXCEPT,       /* exclude listed tables from import */
 } ImportForeignSchemaType;
 
 typedef struct ImportForeignSchemaStmt
@@ -2911,7 +3080,7 @@ typedef enum RoleStmtType
 {
        ROLESTMT_ROLE,
        ROLESTMT_USER,
-       ROLESTMT_GROUP
+       ROLESTMT_GROUP,
 } RoleStmtType;
 
 typedef struct CreateRoleStmt
@@ -3156,7 +3325,7 @@ typedef enum FetchDirection
        FETCH_BACKWARD,
        /* for these, howMany indicates a position; only one row is fetched */
        FETCH_ABSOLUTE,
-       FETCH_RELATIVE
+       FETCH_RELATIVE,
 } FetchDirection;
 
 #define FETCH_ALL      LONG_MAX
@@ -3252,7 +3421,7 @@ typedef struct AlterStatsStmt
 {
        NodeTag         type;
        List       *defnames;           /* qualified name (list of String) */
-       int                     stxstattarget;  /* statistics target */
+       Node       *stxstattarget;      /* statistics target */
        bool            missing_ok;             /* skip error if statistics object is missing */
 } AlterStatsStmt;
 
@@ -3281,7 +3450,7 @@ typedef enum FunctionParameterMode
        FUNC_PARAM_VARIADIC = 'v',      /* variadic (always input) */
        FUNC_PARAM_TABLE = 't',         /* table function output column */
        /* this is not used in pg_proc: */
-       FUNC_PARAM_DEFAULT = 'd'        /* default; effectively same as IN */
+       FUNC_PARAM_DEFAULT = 'd',       /* default; effectively same as IN */
 } FunctionParameterMode;
 
 typedef struct FunctionParameter
@@ -3338,11 +3507,12 @@ typedef struct InlineCodeBlock
 typedef struct CallStmt
 {
        NodeTag         type;
-       FuncCall   *funccall;           /* from the parser */
+       /* from the parser */
+       FuncCall   *funccall pg_node_attr(query_jumble_ignore);
        /* transformed call, with only input args */
-       FuncExpr   *funcexpr pg_node_attr(query_jumble_ignore);
+       FuncExpr   *funcexpr;
        /* transformed output-argument expressions */
-       List       *outargs pg_node_attr(query_jumble_ignore);
+       List       *outargs;
 } CallStmt;
 
 typedef struct CallContext
@@ -3496,7 +3666,7 @@ typedef enum TransactionStmtKind
        TRANS_STMT_ROLLBACK_TO,
        TRANS_STMT_PREPARE,
        TRANS_STMT_COMMIT_PREPARED,
-       TRANS_STMT_ROLLBACK_PREPARED
+       TRANS_STMT_ROLLBACK_PREPARED,
 } TransactionStmtKind;
 
 typedef struct TransactionStmt
@@ -3504,9 +3674,13 @@ typedef struct TransactionStmt
        NodeTag         type;
        TransactionStmtKind kind;       /* see above */
        List       *options;            /* for BEGIN/START commands */
-       char       *savepoint_name; /* for savepoint commands */
-       char       *gid;                        /* for two-phase-commit related commands */
+       /* for savepoint commands */
+       char       *savepoint_name pg_node_attr(query_jumble_ignore);
+       /* for two-phase-commit related commands */
+       char       *gid pg_node_attr(query_jumble_ignore);
        bool            chain;                  /* AND CHAIN option */
+       /* token location, or -1 if unknown */
+       ParseLoc        location pg_node_attr(query_jumble_location);
 } TransactionStmt;
 
 /* ----------------------
@@ -3565,7 +3739,7 @@ typedef enum ViewCheckOption
 {
        NO_CHECK_OPTION,
        LOCAL_CHECK_OPTION,
-       CASCADED_CHECK_OPTION
+       CASCADED_CHECK_OPTION,
 } ViewCheckOption;
 
 typedef struct ViewStmt
@@ -3807,7 +3981,7 @@ typedef enum DiscardMode
        DISCARD_ALL,
        DISCARD_PLANS,
        DISCARD_SEQUENCES,
-       DISCARD_TEMP
+       DISCARD_TEMP,
 } DiscardMode;
 
 typedef struct DiscardStmt
@@ -3849,7 +4023,7 @@ typedef enum ReindexObjectType
        REINDEX_OBJECT_TABLE,           /* table or materialized view */
        REINDEX_OBJECT_SCHEMA,          /* schema */
        REINDEX_OBJECT_SYSTEM,          /* system catalogs */
-       REINDEX_OBJECT_DATABASE         /* database */
+       REINDEX_OBJECT_DATABASE,        /* database */
 } ReindexObjectType;
 
 typedef struct ReindexStmt
@@ -3937,8 +4111,17 @@ typedef struct ExecuteStmt
 typedef struct DeallocateStmt
 {
        NodeTag         type;
-       char       *name;                       /* The name of the plan to remove */
-       /* NULL means DEALLOCATE ALL */
+       /* The name of the plan to remove, NULL if DEALLOCATE ALL */
+       char       *name pg_node_attr(query_jumble_ignore);
+
+       /*
+        * True if DEALLOCATE ALL.  This is redundant with "name == NULL", but we
+        * make it a separate field so that exactly this condition (and not the
+        * precise name) will be accounted for in query jumbling.
+        */
+       bool            isall;
+       /* token location, or -1 if unknown */
+       ParseLoc        location pg_node_attr(query_jumble_location);
 } DeallocateStmt;
 
 /*
@@ -3980,7 +4163,7 @@ typedef enum AlterTSConfigType
        ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN,
        ALTER_TSCONFIG_REPLACE_DICT,
        ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN,
-       ALTER_TSCONFIG_DROP_MAPPING
+       ALTER_TSCONFIG_DROP_MAPPING,
 } AlterTSConfigType;
 
 typedef struct AlterTSConfigurationStmt
@@ -4017,7 +4200,7 @@ typedef enum PublicationObjSpecType
        PUBLICATIONOBJ_TABLES_IN_SCHEMA,        /* All tables in schema */
        PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA,    /* All tables in first element of
                                                                                         * search_path */
-       PUBLICATIONOBJ_CONTINUATION /* Continuation of previous type */
+       PUBLICATIONOBJ_CONTINUATION,    /* Continuation of previous type */
 } PublicationObjSpecType;
 
 typedef struct PublicationObjSpec
@@ -4026,7 +4209,7 @@ typedef struct PublicationObjSpec
        PublicationObjSpecType pubobjtype;      /* type of this publication object */
        char       *name;
        PublicationTable *pubtable;
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } PublicationObjSpec;
 
 typedef struct CreatePublicationStmt
@@ -4042,7 +4225,7 @@ typedef enum AlterPublicationAction
 {
        AP_AddObjects,                          /* add objects to publication */
        AP_DropObjects,                         /* remove objects from publication */
-       AP_SetObjects                           /* set list of objects */
+       AP_SetObjects,                          /* set list of objects */
 } AlterPublicationAction;
 
 typedef struct AlterPublicationStmt
@@ -4081,7 +4264,7 @@ typedef enum AlterSubscriptionType
        ALTER_SUBSCRIPTION_DROP_PUBLICATION,
        ALTER_SUBSCRIPTION_REFRESH,
        ALTER_SUBSCRIPTION_ENABLED,
-       ALTER_SUBSCRIPTION_SKIP
+       ALTER_SUBSCRIPTION_SKIP,
 } AlterSubscriptionType;
 
 typedef struct AlterSubscriptionStmt
index c8b4e61f8d4f12060fa5941fbd4d72bc70e6b092..9e9384d867ae275e0507a930c1b5344144f6991b 100644 (file)
@@ -5,8 +5,8 @@
  *
  * This is the external API for the raw lexing/parsing functions.
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/parser/parser.h
@@ -42,7 +42,7 @@ typedef enum
        RAW_PARSE_PLPGSQL_EXPR,
        RAW_PARSE_PLPGSQL_ASSIGN1,
        RAW_PARSE_PLPGSQL_ASSIGN2,
-       RAW_PARSE_PLPGSQL_ASSIGN3
+       RAW_PARSE_PLPGSQL_ASSIGN3,
 } RawParseMode;
 
 /* Values for the backslash_quote GUC */
@@ -50,7 +50,7 @@ typedef enum
 {
        BACKSLASH_QUOTE_OFF,
        BACKSLASH_QUOTE_ON,
-       BACKSLASH_QUOTE_SAFE_ENCODING
+       BACKSLASH_QUOTE_SAFE_ENCODING,
 }                      BackslashQuoteType;
 
 /* GUC variables in scan.l (every one of these is a bad idea :-() */
index f52fa429faa0c7bc84b1c684de29358b763d2e60..eb5c48ccfee98fcb275e0c491be9e69710c63ab1 100644 (file)
@@ -4,8 +4,8 @@
  *       definition of the "relation" system catalog (pg_class)
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/catalog/pg_class.h
@@ -147,9 +147,12 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat
  */
 typedef FormData_pg_class *Form_pg_class;
 
-DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, on pg_class using btree(oid oid_ops));
-DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, on pg_class using btree(relname name_ops, relnamespace oid_ops));
-DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, on pg_class using btree(reltablespace oid_ops, relfilenode oid_ops));
+DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, pg_class, btree(oid oid_ops));
+DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, pg_class, btree(relname name_ops, relnamespace oid_ops));
+DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, pg_class, btree(reltablespace oid_ops, relfilenode oid_ops));
+
+MAKE_SYSCACHE(RELOID, pg_class_oid_index, 128);
+MAKE_SYSCACHE(RELNAMENSP, pg_class_relname_nsp_index, 128);
 
 #define                  RELKIND_RELATION                'r'   /* ordinary table */
 #define                  RELKIND_INDEX                   'i'   /* secondary index */
@@ -215,7 +218,9 @@ DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeInd
 /*
  * Relation kinds with a table access method (rd_tableam).  Although sequences
  * use the heap table AM, they are enough of a special case in most uses that
- * they are not included here.
+ * they are not included here.  Likewise, partitioned tables can have an access
+ * method defined so that their partitions can inherit it, but they do not set
+ * rd_tableam; hence, this is handled specially outside of this macro.
  */
 #define RELKIND_HAS_TABLE_AM(relkind) \
        ((relkind) == RELKIND_RELATION || \
@@ -233,6 +238,9 @@ extern int  errdetail_relkind_not_supported(char relkind);
 #define DATEOID                        1082
 #define TIMEOID                        1083
 
+/* OIDS 0 - 99 */
+#define TEXTOID 25
+
 /* OIDS 1100 - 1199 */
 #define TIMESTAMPOID   1114
 #define TIMESTAMPTZOID 1184
index a1b35fcb62076eb3ff0e14e3f52c69710d382d91..f522dc2a09af5120c86c53f52b86c4355d022579 100644 (file)
@@ -6,8 +6,8 @@
  * for developers.  If you edit any of these, be sure to do a *full*
  * rebuild (and an initdb if noted).
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/pg_config_manual.h
 #define DEFAULT_EVENT_SOURCE  "PostgreSQL"
 
 /*
- * Assumed cache line size. This doesn't affect correctness, but can be used
- * for low-level optimizations. Currently, this is used to pad some data
- * structures in xlog.c, to ensure that highly-contended fields are on
- * different cache lines. Too small a value can hurt performance due to false
- * sharing, while the only downside of too large a value is a few bytes of
- * wasted memory. The default is 128, which should be large enough for all
- * supported platforms.
+ * Assumed cache line size.  This doesn't affect correctness, but can be used
+ * for low-level optimizations.  This is mostly used to pad various data
+ * structures, to ensure that highly-contended fields are on different cache
+ * lines.  Too small a value can hurt performance due to false sharing, while
+ * the only downside of too large a value is a few bytes of wasted memory.
+ * The default is 128, which should be large enough for all supported
+ * platforms.
  */
 #define PG_CACHE_LINE_SIZE             128
 
  *------------------------------------------------------------------------
  */
 
+/*
+ * Force use of the non-recursive JSON parser in all cases. This is useful
+ * to validate the working of the parser, and the regression tests should
+ * pass except for some different error messages about the stack limit.
+ */
+/* #define FORCE_JSON_PSTACK */
+
 /*
  * Include Valgrind "client requests", mostly in the memory allocator, so
  * Valgrind understands PostgreSQL memory contexts.  This permits detecting
  */
 /* #define COPY_PARSE_PLAN_TREES */
 
+/*
+ * Define this to force Bitmapset reallocation on each modification.  Helps
+ * to find dangling pointers to Bitmapset's.
+ */
+/* #define REALLOCATE_BITMAPSETS */
+
 /*
  * Define this to force all parse and plan trees to be passed through
  * outfuncs.c/readfuncs.c, to facilitate catching errors and omissions in
index 8694a3079baac73bf2f7362083d2c69afefb4223..738185c198f770fa4892997ecb660a83ad4774d2 100644 (file)
@@ -29,8 +29,8 @@
  * always be so; be careful to use the appropriate list type for your data.)
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/nodes/pg_list.h
@@ -389,26 +389,26 @@ lnext(const List *l, const ListCell *c)
 /*
  * foreach_delete_current -
  *       delete the current list element from the List associated with a
- *       surrounding foreach() loop, returning the new List pointer.
+ *       surrounding foreach() or foreach_*() loop, returning the new List
+ *       pointer; pass the name of the iterator variable.
  *
- * This is equivalent to list_delete_cell(), but it also adjusts the foreach
- * loop's state so that no list elements will be missed.  Do not delete
- * elements from an active foreach loop's list in any other way!
+ * This is similar to list_delete_cell(), but it also adjusts the loop's state
+ * so that no list elements will be missed.  Do not delete elements from an
+ * active foreach or foreach_* loop's list in any other way!
  */
-#define foreach_delete_current(lst, cell)      \
-       (cell##__state.i--, \
-        (List *) (cell##__state.l = list_delete_cell(lst, cell)))
+#define foreach_delete_current(lst, var_or_cell)       \
+       ((List *) (var_or_cell##__state.l = list_delete_nth_cell(lst, var_or_cell##__state.i--)))
 
 /*
  * foreach_current_index -
- *       get the zero-based list index of a surrounding foreach() loop's
- *       current element; pass the name of the "ListCell *" iterator variable.
+ *       get the zero-based list index of a surrounding foreach() or foreach_*()
+ *       loop's current element; pass the name of the iterator variable.
  *
  * Beware of using this after foreach_delete_current(); the value will be
  * out of sync for the rest of the current loop iteration.  Anyway, since
  * you just deleted the current element, the value is pretty meaningless.
  */
-#define foreach_current_index(cell)  (cell##__state.i)
+#define foreach_current_index(var_or_cell)  (var_or_cell##__state.i)
 
 /*
  * for_each_from -
@@ -460,6 +460,57 @@ for_each_cell_setup(const List *lst, const ListCell *initcell)
        return r;
 }
 
+/*
+ * Convenience macros that loop through a list without needing a separate
+ * "ListCell *" variable.  Instead, the macros declare a locally-scoped loop
+ * variable with the provided name and the appropriate type.
+ *
+ * Since the variable is scoped to the loop, it's not possible to detect an
+ * early break by checking its value after the loop completes, as is common
+ * practice.  If you need to do this, you can either use foreach() instead or
+ * manually track early breaks with a separate variable declared outside of the
+ * loop.
+ *
+ * Note that the caveats described in the comment above the foreach() macro
+ * also apply to these convenience macros.
+ */
+#define foreach_ptr(type, var, lst) foreach_internal(type, *, var, lst, lfirst)
+#define foreach_int(var, lst)  foreach_internal(int, , var, lst, lfirst_int)
+#define foreach_oid(var, lst)  foreach_internal(Oid, , var, lst, lfirst_oid)
+#define foreach_xid(var, lst)  foreach_internal(TransactionId, , var, lst, lfirst_xid)
+
+/*
+ * The internal implementation of the above macros.  Do not use directly.
+ *
+ * This macro actually generates two loops in order to declare two variables of
+ * different types.  The outer loop only iterates once, so we expect optimizing
+ * compilers will unroll it, thereby optimizing it away.
+ */
+#define foreach_internal(type, pointer, var, lst, func) \
+       for (type pointer var = 0, pointer var##__outerloop = (type pointer) 1; \
+                var##__outerloop; \
+                var##__outerloop = 0) \
+               for (ForEachState var##__state = {(lst), 0}; \
+                        (var##__state.l != NIL && \
+                         var##__state.i < var##__state.l->length && \
+                        (var = func(&var##__state.l->elements[var##__state.i]), true)); \
+                        var##__state.i++)
+
+/*
+ * foreach_node -
+ *       The same as foreach_ptr, but asserts that the element is of the specified
+ *       node type.
+ */
+#define foreach_node(type, var, lst) \
+       for (type * var = 0, *var##__outerloop = (type *) 1; \
+                var##__outerloop; \
+                var##__outerloop = 0) \
+               for (ForEachState var##__state = {(lst), 0}; \
+                        (var##__state.l != NIL && \
+                         var##__state.i < var##__state.l->length && \
+                        (var = lfirst_node(type, &var##__state.l->elements[var##__state.i]), true)); \
+                        var##__state.i++)
+
 /*
  * forboth -
  *       a convenience macro for advancing through two linked lists
index 5ddad3e7d0219b66fb126438e8aa28ab226007e7..8756f7560ef63cf77659b0f7aab03702a6616125 100644 (file)
@@ -4,8 +4,8 @@
  *       definition of the "trigger" system catalog (pg_trigger)
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/catalog/pg_trigger.h
@@ -83,9 +83,9 @@ typedef FormData_pg_trigger *Form_pg_trigger;
 
 DECLARE_TOAST(pg_trigger, 2336, 2337);
 
-DECLARE_INDEX(pg_trigger_tgconstraint_index, 2699, TriggerConstraintIndexId, on pg_trigger using btree(tgconstraint oid_ops));
-DECLARE_UNIQUE_INDEX(pg_trigger_tgrelid_tgname_index, 2701, TriggerRelidNameIndexId, on pg_trigger using btree(tgrelid oid_ops, tgname name_ops));
-DECLARE_UNIQUE_INDEX_PKEY(pg_trigger_oid_index, 2702, TriggerOidIndexId, on pg_trigger using btree(oid oid_ops));
+DECLARE_INDEX(pg_trigger_tgconstraint_index, 2699, TriggerConstraintIndexId, pg_trigger, btree(tgconstraint oid_ops));
+DECLARE_UNIQUE_INDEX(pg_trigger_tgrelid_tgname_index, 2701, TriggerRelidNameIndexId, pg_trigger, btree(tgrelid oid_ops, tgname name_ops));
+DECLARE_UNIQUE_INDEX_PKEY(pg_trigger_oid_index, 2702, TriggerOidIndexId, pg_trigger, btree(oid oid_ops));
 
 DECLARE_ARRAY_FOREIGN_KEY((tgrelid, tgattr), pg_attribute, (attrelid, attnum));
 #endif
index c82ca14a5e50e7290e80fd128a1d1fae453bda93..807e2df83a000e00d0800dab38f6e1c7eaafe933 100644 (file)
@@ -3,8 +3,8 @@
  * pg_wchar.h
  *       multibyte-character support
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/mb/pg_wchar.h
@@ -14,6 +14,9 @@
  *             included by libpq client programs.  In particular, a libpq client
  *             should not assume that the encoding IDs used by the version of libpq
  *             it's linked to match up with the IDs declared here.
+ *             To help prevent mistakes, relevant functions that are exported by
+ *             libpq have a physically different name when being referenced
+ *             statically.
  *
  *-------------------------------------------------------------------------
  */
@@ -222,11 +225,10 @@ typedef unsigned int pg_wchar;
 /*
  * PostgreSQL encoding identifiers
  *
- * WARNING: the order of this enum must be same as order of entries
- *                     in the pg_enc2name_tbl[] array (in src/common/encnames.c), and
- *                     in the pg_wchar_table[] array (in src/common/wchar.c)!
- *
- *                     If you add some encoding don't forget to check
+ * WARNING: If you add some encoding don't forget to update
+ *                     the pg_enc2name_tbl[] array (in src/common/encnames.c),
+ *                     the pg_enc2gettext_tbl[] array (in src/common/encnames.c) and
+ *                     the pg_wchar_table[] array (in src/common/wchar.c) and to check
  *                     PG_ENCODING_BE_LAST macro.
  *
  * PG_SQL_ASCII is default encoding and must be = 0.
@@ -365,13 +367,7 @@ extern PGDLLIMPORT const pg_enc2name pg_enc2name_tbl[];
 /*
  * Encoding names for gettext
  */
-typedef struct pg_enc2gettext
-{
-       pg_enc          encoding;
-       const char *name;
-} pg_enc2gettext;
-
-extern PGDLLIMPORT const pg_enc2gettext pg_enc2gettext_tbl[];
+extern PGDLLIMPORT const char *pg_enc2gettext_tbl[];
 
 /*
  * pg_wchar stuff
@@ -560,6 +556,99 @@ surrogate_pair_to_codepoint(pg_wchar first, pg_wchar second)
        return ((first & 0x3FF) << 10) + 0x10000 + (second & 0x3FF);
 }
 
+/*
+ * Convert a UTF-8 character to a Unicode code point.
+ * This is a one-character version of pg_utf2wchar_with_len.
+ *
+ * No error checks here, c must point to a long-enough string.
+ */
+static inline pg_wchar
+utf8_to_unicode(const unsigned char *c)
+{
+       if ((*c & 0x80) == 0)
+               return (pg_wchar) c[0];
+       else if ((*c & 0xe0) == 0xc0)
+               return (pg_wchar) (((c[0] & 0x1f) << 6) |
+                                                  (c[1] & 0x3f));
+       else if ((*c & 0xf0) == 0xe0)
+               return (pg_wchar) (((c[0] & 0x0f) << 12) |
+                                                  ((c[1] & 0x3f) << 6) |
+                                                  (c[2] & 0x3f));
+       else if ((*c & 0xf8) == 0xf0)
+               return (pg_wchar) (((c[0] & 0x07) << 18) |
+                                                  ((c[1] & 0x3f) << 12) |
+                                                  ((c[2] & 0x3f) << 6) |
+                                                  (c[3] & 0x3f));
+       else
+               /* that is an invalid code on purpose */
+               return 0xffffffff;
+}
+
+/*
+ * Map a Unicode code point to UTF-8.  utf8string must have at least
+ * unicode_utf8len(c) bytes available.
+ */
+static inline unsigned char *
+unicode_to_utf8(pg_wchar c, unsigned char *utf8string)
+{
+       if (c <= 0x7F)
+       {
+               utf8string[0] = c;
+       }
+       else if (c <= 0x7FF)
+       {
+               utf8string[0] = 0xC0 | ((c >> 6) & 0x1F);
+               utf8string[1] = 0x80 | (c & 0x3F);
+       }
+       else if (c <= 0xFFFF)
+       {
+               utf8string[0] = 0xE0 | ((c >> 12) & 0x0F);
+               utf8string[1] = 0x80 | ((c >> 6) & 0x3F);
+               utf8string[2] = 0x80 | (c & 0x3F);
+       }
+       else
+       {
+               utf8string[0] = 0xF0 | ((c >> 18) & 0x07);
+               utf8string[1] = 0x80 | ((c >> 12) & 0x3F);
+               utf8string[2] = 0x80 | ((c >> 6) & 0x3F);
+               utf8string[3] = 0x80 | (c & 0x3F);
+       }
+
+       return utf8string;
+}
+
+/*
+ * Number of bytes needed to represent the given char in UTF8.
+ */
+static inline int
+unicode_utf8len(pg_wchar c)
+{
+       if (c <= 0x7F)
+               return 1;
+       else if (c <= 0x7FF)
+               return 2;
+       else if (c <= 0xFFFF)
+               return 3;
+       else
+               return 4;
+}
+
+/*
+ * The functions in this list are exported by libpq, and we need to be sure
+ * that we know which calls are satisfied by libpq and which are satisfied
+ * by static linkage to libpgcommon.  (This is because we might be using a
+ * libpq.so that's of a different major version and has encoding IDs that
+ * differ from the current version's.)  The nominal function names are what
+ * are actually used in and exported by libpq, while the names exported by
+ * libpgcommon.a and libpgcommon_srv.a end in "_private".
+ */
+#if defined(USE_PRIVATE_ENCODING_FUNCS) || !defined(FRONTEND)
+#define pg_char_to_encoding                    pg_char_to_encoding_private
+#define pg_encoding_to_char                    pg_encoding_to_char_private
+#define pg_valid_server_encoding       pg_valid_server_encoding_private
+#define pg_valid_server_encoding_id    pg_valid_server_encoding_id_private
+#define pg_utf_mblen                           pg_utf_mblen_private
+#endif
 
 /*
  * These functions are considered part of libpq's exported API and
index b0045d3f0e092ed8fa0ff6aecbdbada48660fcf4..1c1e46c25171d85388ceefa59ad01881af5f1b5c 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * $Header$
  *
- * Copyright (c) 2006-2023, pgpool Global Development Group
+ * Copyright (c) 2006-2024, pgpool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
index af735ee17adf5be579d2aa21b9b25d786674eabf..09be5529b09f9c96db0a0396f09f0fc3fe25899d 100644 (file)
@@ -6,8 +6,8 @@
  *       Currently, these are mostly nodes for executable expressions
  *       and join trees.
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/nodes/primnodes.h
 typedef uint32 SubTransactionId;
 #define InvalidSubTransactionId     ((SubTransactionId) 0)
 
+typedef enum OverridingKind
+{
+       OVERRIDING_NOT_SET = 0,
+       OVERRIDING_USER_VALUE,
+       OVERRIDING_SYSTEM_VALUE,
+} OverridingKind;
+
+
 /* ----------------------------------------------------------------
  *                                             node definitions
  * ----------------------------------------------------------------
@@ -68,7 +76,7 @@ typedef enum OnCommitAction
        ONCOMMIT_NOOP,                          /* No ON COMMIT clause (do nothing) */
        ONCOMMIT_PRESERVE_ROWS,         /* ON COMMIT PRESERVE ROWS (do nothing) */
        ONCOMMIT_DELETE_ROWS,           /* ON COMMIT DELETE ROWS */
-       ONCOMMIT_DROP                           /* ON COMMIT DROP */
+       ONCOMMIT_DROP,                          /* ON COMMIT DROP */
 } OnCommitAction;
 
 /*
@@ -102,11 +110,17 @@ typedef struct RangeVar
        Alias      *alias;
 
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } RangeVar;
 
+typedef enum TableFuncType
+{
+       TFT_XMLTABLE,
+       TFT_JSON_TABLE,
+} TableFuncType;
+
 /*
- * TableFunc - node for a table function, such as XMLTABLE.
+ * TableFunc - node for a table function, such as XMLTABLE and JSON_TABLE.
  *
  * Entries in the ns_names list are either String nodes containing
  * literal namespace names, or NULL pointers to represent DEFAULT.
@@ -114,6 +128,8 @@ typedef struct RangeVar
 typedef struct TableFunc
 {
        NodeTag         type;
+       /* XMLTABLE or JSON_TABLE */
+       TableFuncType functype;
        /* list of namespace URI expressions */
        List       *ns_uris pg_node_attr(query_jumble_ignore);
        /* list of namespace names or NULL */
@@ -134,12 +150,18 @@ typedef struct TableFunc
        List       *colexprs;
        /* list of column default expressions */
        List       *coldefexprs pg_node_attr(query_jumble_ignore);
+       /* JSON_TABLE: list of column value expressions */
+       List       *colvalexprs pg_node_attr(query_jumble_ignore);
+       /* JSON_TABLE: list of PASSING argument expressions */
+       List       *passingvalexprs pg_node_attr(query_jumble_ignore);
        /* nullability flag for each output column */
        Bitmapset  *notnulls pg_node_attr(query_jumble_ignore);
+       /* JSON_TABLE plan */
+       Node       *plan pg_node_attr(query_jumble_ignore);
        /* counts from 0; -1 if none specified */
        int                     ordinalitycol pg_node_attr(query_jumble_ignore);
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } TableFunc;
 
 /*
@@ -287,7 +309,7 @@ typedef struct Var
        AttrNumber      varattnosyn pg_node_attr(equal_ignore, query_jumble_ignore);
 
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } Var;
 
 /*
@@ -329,7 +351,7 @@ typedef struct Const
         * token location, or -1 if unknown.  All constants are tracked as
         * locations in query jumbling, to be marked as parameters.
         */
-       int                     location pg_node_attr(query_jumble_location);
+       ParseLoc        location pg_node_attr(query_jumble_location);
 } Const;
 
 /*
@@ -364,7 +386,7 @@ typedef enum ParamKind
        PARAM_EXTERN,
        PARAM_EXEC,
        PARAM_SUBLINK,
-       PARAM_MULTIEXPR
+       PARAM_MULTIEXPR,
 } ParamKind;
 
 typedef struct Param
@@ -378,7 +400,7 @@ typedef struct Param
        /* OID of collation, or InvalidOid if none */
        Oid                     paramcollid pg_node_attr(query_jumble_ignore);
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } Param;
 
 /*
@@ -501,7 +523,7 @@ typedef struct Aggref
        int                     aggtransno pg_node_attr(query_jumble_ignore);
 
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } Aggref;
 
 /*
@@ -548,7 +570,7 @@ typedef struct GroupingFunc
        Index           agglevelsup;
 
        /* token location */
-       int                     location;
+       ParseLoc        location;
 } GroupingFunc;
 
 /*
@@ -572,6 +594,8 @@ typedef struct WindowFunc
        List       *args;
        /* FILTER expression, if any */
        Expr       *aggfilter;
+       /* List of WindowFuncRunConditions to help short-circuit execution */
+       List       *runCondition pg_node_attr(query_jumble_ignore);
        /* index of associated WindowClause */
        Index           winref;
        /* true if argument list was really '*' */
@@ -579,9 +603,58 @@ typedef struct WindowFunc
        /* is function a simple aggregate? */
        bool            winagg pg_node_attr(query_jumble_ignore);
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } WindowFunc;
 
+/*
+ * WindowFuncRunCondition
+ *
+ * Represents intermediate OpExprs which will be used by WindowAgg to
+ * short-circuit execution.
+ */
+typedef struct WindowFuncRunCondition
+{
+       Expr            xpr;
+
+       /* PG_OPERATOR OID of the operator */
+       Oid                     opno;
+       /* OID of collation that operator should use */
+       Oid                     inputcollid pg_node_attr(query_jumble_ignore);
+
+       /*
+        * true of WindowFunc belongs on the left of the resulting OpExpr or false
+        * if the WindowFunc is on the right.
+        */
+       bool            wfunc_left;
+
+       /*
+        * The Expr being compared to the WindowFunc to use in the OpExpr in the
+        * WindowAgg's runCondition
+        */
+       Expr       *arg;
+} WindowFuncRunCondition;
+
+/*
+ * MergeSupportFunc
+ *
+ * A MergeSupportFunc is a merge support function expression that can only
+ * appear in the RETURNING list of a MERGE command.  It returns information
+ * about the currently executing merge action.
+ *
+ * Currently, the only supported function is MERGE_ACTION(), which returns the
+ * command executed ("INSERT", "UPDATE", or "DELETE").
+ */
+typedef struct MergeSupportFunc
+{
+       Expr            xpr;
+       /* type Oid of result */
+       Oid                     msftype;
+       /* OID of collation, or InvalidOid if none */
+       Oid                     msfcollid;
+       /* token location, or -1 if unknown */
+       ParseLoc        location;
+} MergeSupportFunc;
+
 /*
  * SubscriptingRef: describes a subscripting operation over a container
  * (array, etc).
@@ -660,7 +733,7 @@ typedef enum CoercionContext
        COERCION_IMPLICIT,                      /* coercion in context of expression */
        COERCION_ASSIGNMENT,            /* coercion in context of assignment */
        COERCION_PLPGSQL,                       /* if no assignment cast, use CoerceViaIO */
-       COERCION_EXPLICIT                       /* explicit cast operation */
+       COERCION_EXPLICIT,                      /* explicit cast operation */
 } CoercionContext;
 
 /*
@@ -680,7 +753,7 @@ typedef enum CoercionForm
        COERCE_EXPLICIT_CALL,           /* display as a function call */
        COERCE_EXPLICIT_CAST,           /* display as an explicit cast */
        COERCE_IMPLICIT_CAST,           /* implicit cast, so hide it */
-       COERCE_SQL_SYNTAX                       /* display with SQL-mandated special syntax */
+       COERCE_SQL_SYNTAX,                      /* display with SQL-mandated special syntax */
 } CoercionForm;
 
 /*
@@ -713,7 +786,7 @@ typedef struct FuncExpr
        /* arguments to the function */
        List       *args;
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } FuncExpr;
 
 /*
@@ -740,7 +813,7 @@ typedef struct NamedArgExpr
        /* argument's number in positional notation */
        int                     argnumber;
        /* argument name location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } NamedArgExpr;
 
 /*
@@ -782,7 +855,7 @@ typedef struct OpExpr
        List       *args;
 
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } OpExpr;
 
 /*
@@ -862,7 +935,7 @@ typedef struct ScalarArrayOpExpr
        List       *args;
 
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } ScalarArrayOpExpr;
 
 /*
@@ -884,7 +957,7 @@ typedef struct BoolExpr
        Expr            xpr;
        BoolExprType boolop;
        List       *args;                       /* arguments to this expression */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } BoolExpr;
 
 /*
@@ -947,7 +1020,7 @@ typedef enum SubLinkType
        EXPR_SUBLINK,
        MULTIEXPR_SUBLINK,
        ARRAY_SUBLINK,
-       CTE_SUBLINK                                     /* for SubPlans only */
+       CTE_SUBLINK,                            /* for SubPlans only */
 } SubLinkType;
 
 
@@ -961,7 +1034,7 @@ typedef struct SubLink
        List       *operName pg_node_attr(query_jumble_ignore);
        /* subselect as Query* or raw parsetree */
        Node       *subselect;
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } SubLink;
 
 /*
@@ -1135,7 +1208,7 @@ typedef struct RelabelType
        Oid                     resultcollid pg_node_attr(query_jumble_ignore);
        /* how to display this node */
        CoercionForm relabelformat pg_node_attr(query_jumble_ignore);
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } RelabelType;
 
 /* ----------------
@@ -1157,7 +1230,7 @@ typedef struct CoerceViaIO
        Oid                     resultcollid pg_node_attr(query_jumble_ignore);
        /* how to display this node */
        CoercionForm coerceformat pg_node_attr(query_jumble_ignore);
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } CoerceViaIO;
 
 /* ----------------
@@ -1185,7 +1258,7 @@ typedef struct ArrayCoerceExpr
        Oid                     resultcollid pg_node_attr(query_jumble_ignore);
        /* how to display this node */
        CoercionForm coerceformat pg_node_attr(query_jumble_ignore);
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } ArrayCoerceExpr;
 
 /* ----------------
@@ -1209,7 +1282,7 @@ typedef struct ConvertRowtypeExpr
        /* Like RowExpr, we deliberately omit a typmod and collation here */
        /* how to display this node */
        CoercionForm convertformat pg_node_attr(query_jumble_ignore);
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } ConvertRowtypeExpr;
 
 /*----------
@@ -1224,7 +1297,7 @@ typedef struct CollateExpr
        Expr            xpr;
        Expr       *arg;                        /* input expression */
        Oid                     collOid;                /* collation's OID */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } CollateExpr;
 
 /*----------
@@ -1259,7 +1332,7 @@ typedef struct CaseExpr
        Expr       *arg;                        /* implicit equality comparison argument */
        List       *args;                       /* the arguments (list of WHEN clauses) */
        Expr       *defresult;          /* the default result (ELSE clause) */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } CaseExpr;
 
 /*
@@ -1270,7 +1343,7 @@ typedef struct CaseWhen
        Expr            xpr;
        Expr       *expr;                       /* condition expression */
        Expr       *result;                     /* substitution result */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } CaseWhen;
 
 /*
@@ -1327,7 +1400,7 @@ typedef struct ArrayExpr
        /* true if elements are sub-arrays */
        bool            multidims pg_node_attr(query_jumble_ignore);
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } ArrayExpr;
 
 /*
@@ -1378,7 +1451,7 @@ typedef struct RowExpr
        /* list of String, or NIL */
        List       *colnames pg_node_attr(query_jumble_ignore);
 
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } RowExpr;
 
 /*
@@ -1403,7 +1476,7 @@ typedef enum RowCompareType
        ROWCOMPARE_EQ = 3,                      /* BTEqualStrategyNumber */
        ROWCOMPARE_GE = 4,                      /* BTGreaterEqualStrategyNumber */
        ROWCOMPARE_GT = 5,                      /* BTGreaterStrategyNumber */
-       ROWCOMPARE_NE = 6                       /* no such btree strategy */
+       ROWCOMPARE_NE = 6,                      /* no such btree strategy */
 } RowCompareType;
 
 typedef struct RowCompareExpr
@@ -1437,7 +1510,7 @@ typedef struct CoalesceExpr
        /* the arguments */
        List       *args;
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } CoalesceExpr;
 
 /*
@@ -1463,7 +1536,7 @@ typedef struct MinMaxExpr
        /* the arguments */
        List       *args;
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } MinMaxExpr;
 
 /*
@@ -1493,7 +1566,7 @@ typedef enum SQLValueFunctionOp
        SVFOP_USER,
        SVFOP_SESSION_USER,
        SVFOP_CURRENT_CATALOG,
-       SVFOP_CURRENT_SCHEMA
+       SVFOP_CURRENT_SCHEMA,
 } SQLValueFunctionOp;
 
 typedef struct SQLValueFunction
@@ -1507,7 +1580,7 @@ typedef struct SQLValueFunction
         */
        Oid                     type pg_node_attr(query_jumble_ignore);
        int32           typmod;
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } SQLValueFunction;
 
 /*
@@ -1530,13 +1603,13 @@ typedef enum XmlExprOp
        IS_XMLPI,                                       /* XMLPI(name [, args]) */
        IS_XMLROOT,                                     /* XMLROOT(xml, version, standalone) */
        IS_XMLSERIALIZE,                        /* XMLSERIALIZE(is_document, xmlval, indent) */
-       IS_DOCUMENT                                     /* xmlval IS DOCUMENT */
+       IS_DOCUMENT,                            /* xmlval IS DOCUMENT */
 } XmlExprOp;
 
 typedef enum XmlOptionType
 {
        XMLOPTION_DOCUMENT,
-       XMLOPTION_CONTENT
+       XMLOPTION_CONTENT,
 } XmlOptionType;
 
 typedef struct XmlExpr
@@ -1560,7 +1633,7 @@ typedef struct XmlExpr
        Oid                     type pg_node_attr(query_jumble_ignore);
        int32           typmod pg_node_attr(query_jumble_ignore);
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } XmlExpr;
 
 /*
@@ -1583,7 +1656,7 @@ typedef enum JsonFormatType
 {
        JS_FORMAT_DEFAULT,                      /* unspecified */
        JS_FORMAT_JSON,                         /* FORMAT JSON [ENCODING ...] */
-       JS_FORMAT_JSONB                         /* implicit internal format for RETURNING
+       JS_FORMAT_JSONB,                        /* implicit internal format for RETURNING
                                                                 * jsonb */
 } JsonFormatType;
 
@@ -1596,7 +1669,7 @@ typedef struct JsonFormat
        NodeTag         type;
        JsonFormatType format_type; /* format type */
        JsonEncoding encoding;          /* JSON encoding */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } JsonFormat;
 
 /*
@@ -1617,7 +1690,7 @@ typedef struct JsonReturning
  *
  * The actual value is obtained by evaluating formatted_expr.  raw_expr is
  * only there for displaying the original user-written expression and is not
- * evaluated by ExecInterpExpr() and eval_const_exprs_mutator().
+ * evaluated by ExecInterpExpr() and eval_const_expressions_mutator().
  */
 typedef struct JsonValueExpr
 {
@@ -1632,7 +1705,10 @@ typedef enum JsonConstructorType
        JSCTOR_JSON_OBJECT = 1,
        JSCTOR_JSON_ARRAY = 2,
        JSCTOR_JSON_OBJECTAGG = 3,
-       JSCTOR_JSON_ARRAYAGG = 4
+       JSCTOR_JSON_ARRAYAGG = 4,
+       JSCTOR_JSON_PARSE = 5,
+       JSCTOR_JSON_SCALAR = 6,
+       JSCTOR_JSON_SERIALIZE = 7,
 } JsonConstructorType;
 
 /*
@@ -1649,7 +1725,7 @@ typedef struct JsonConstructorExpr
        JsonReturning *returning;       /* RETURNING clause */
        bool            absent_on_null; /* ABSENT ON NULL? */
        bool            unique;                 /* WITH UNIQUE KEYS? (JSON_OBJECT[AGG] only) */
-       int                     location;
+       ParseLoc        location;
 } JsonConstructorExpr;
 
 /*
@@ -1661,7 +1737,7 @@ typedef enum JsonValueType
        JS_TYPE_ANY,                            /* IS JSON [VALUE] */
        JS_TYPE_OBJECT,                         /* IS JSON OBJECT */
        JS_TYPE_ARRAY,                          /* IS JSON ARRAY */
-       JS_TYPE_SCALAR                          /* IS JSON SCALAR */
+       JS_TYPE_SCALAR,                         /* IS JSON SCALAR */
 } JsonValueType;
 
 /*
@@ -1675,9 +1751,198 @@ typedef struct JsonIsPredicate
        JsonFormat *format;                     /* FORMAT clause, if specified */
        JsonValueType item_type;        /* JSON item type */
        bool            unique_keys;    /* check key uniqueness? */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } JsonIsPredicate;
 
+/* Nodes used in SQL/JSON query functions */
+
+/*
+ * JsonWrapper -
+ *             representation of WRAPPER clause for JSON_QUERY()
+ */
+typedef enum JsonWrapper
+{
+       JSW_UNSPEC,
+       JSW_NONE,
+       JSW_CONDITIONAL,
+       JSW_UNCONDITIONAL,
+} JsonWrapper;
+
+/*
+ * JsonBehaviorType -
+ *             enumeration of behavior types used in SQL/JSON ON ERROR/EMPTY clauses
+ *
+ *             If enum members are reordered, get_json_behavior() from ruleutils.c
+ *             must be updated accordingly.
+ */
+typedef enum JsonBehaviorType
+{
+       JSON_BEHAVIOR_NULL = 0,
+       JSON_BEHAVIOR_ERROR,
+       JSON_BEHAVIOR_EMPTY,
+       JSON_BEHAVIOR_TRUE,
+       JSON_BEHAVIOR_FALSE,
+       JSON_BEHAVIOR_UNKNOWN,
+       JSON_BEHAVIOR_EMPTY_ARRAY,
+       JSON_BEHAVIOR_EMPTY_OBJECT,
+       JSON_BEHAVIOR_DEFAULT,
+} JsonBehaviorType;
+
+/*
+ * JsonBehavior
+ *             Specifications for ON ERROR / ON EMPTY behaviors of SQL/JSON
+ *             query functions specified by a JsonExpr
+ *
+ * 'expr' is the expression to emit when a given behavior (EMPTY or ERROR)
+ * occurs on evaluating the SQL/JSON query function.  'coerce' is set to true
+ * if 'expr' isn't already of the expected target type given by
+ * JsonExpr.returning.
+ */
+typedef struct JsonBehavior
+{
+       NodeTag         type;
+
+       JsonBehaviorType btype;
+       Node       *expr;
+       bool            coerce;
+       ParseLoc        location;               /* token location, or -1 if unknown */
+} JsonBehavior;
+
+/*
+ * JsonExprOp -
+ *             enumeration of SQL/JSON query function types
+ */
+typedef enum JsonExprOp
+{
+       JSON_EXISTS_OP,                         /* JSON_EXISTS() */
+       JSON_QUERY_OP,                          /* JSON_QUERY() */
+       JSON_VALUE_OP,                          /* JSON_VALUE() */
+       JSON_TABLE_OP,                          /* JSON_TABLE() */
+} JsonExprOp;
+
+/*
+ * JsonExpr -
+ *             Transformed representation of JSON_VALUE(), JSON_QUERY(), and
+ *             JSON_EXISTS()
+ */
+typedef struct JsonExpr
+{
+       Expr            xpr;
+
+       JsonExprOp      op;
+
+       char       *column_name;        /* JSON_TABLE() column name or NULL if this is
+                                                                * not for a JSON_TABLE() */
+
+       /* jsonb-valued expression to query */
+       Node       *formatted_expr;
+
+       /* Format of the above expression needed by ruleutils.c */
+       JsonFormat *format;
+
+       /* jsonpath-valued expression containing the query pattern */
+       Node       *path_spec;
+
+       /* Expected type/format of the output. */
+       JsonReturning *returning;
+
+       /* Information about the PASSING argument expressions */
+       List       *passing_names;
+       List       *passing_values;
+
+       /* User-specified or default ON EMPTY and ON ERROR behaviors */
+       JsonBehavior *on_empty;
+       JsonBehavior *on_error;
+
+       /*
+        * Information about converting the result of jsonpath functions
+        * JsonPathQuery() and JsonPathValue() to the RETURNING type.
+        */
+       bool            use_io_coercion;
+       bool            use_json_coercion;
+
+       /* WRAPPER specification for JSON_QUERY */
+       JsonWrapper wrapper;
+
+       /* KEEP or OMIT QUOTES for singleton scalars returned by JSON_QUERY() */
+       bool            omit_quotes;
+
+       /* JsonExpr's collation. */
+       Oid                     collation;
+
+       /* Original JsonFuncExpr's location */
+       ParseLoc        location;
+} JsonExpr;
+
+/*
+ * JsonTablePath
+ *             A JSON path expression to be computed as part of evaluating
+ *             a JSON_TABLE plan node
+ */
+typedef struct JsonTablePath
+{
+       NodeTag         type;
+
+       Const      *value;
+       char       *name;
+} JsonTablePath;
+
+/*
+ * JsonTablePlan -
+ *             Abstract class to represent different types of JSON_TABLE "plans".
+ *             A plan is used to generate a "row pattern" value by evaluating a JSON
+ *             path expression against an input JSON document, which is then used for
+ *             populating JSON_TABLE() columns
+ */
+typedef struct JsonTablePlan
+{
+       pg_node_attr(abstract)
+
+       NodeTag         type;
+} JsonTablePlan;
+
+/*
+ * JSON_TABLE plan to evaluate a JSON path expression and NESTED paths, if
+ * any.
+ */
+typedef struct JsonTablePathScan
+{
+       JsonTablePlan plan;
+
+       /* JSON path to evaluate */
+       JsonTablePath *path;
+
+       /*
+        * ERROR/EMPTY ON ERROR behavior; only significant in the plan for the
+        * top-level path.
+        */
+       bool            errorOnError;
+
+       /* Plan(s) for nested columns, if any. */
+       JsonTablePlan *child;
+
+       /*
+        * 0-based index in TableFunc.colvalexprs of the 1st and the last column
+        * covered by this plan.  Both are -1 if all columns are nested and thus
+        * computed by the child plan(s).
+        */
+       int                     colMin;
+       int                     colMax;
+} JsonTablePathScan;
+
+/*
+ * JsonTableSiblingJoin -
+ *             Plan to join rows of sibling NESTED COLUMNS clauses in the same parent
+ *             COLUMNS clause
+ */
+typedef struct JsonTableSiblingJoin
+{
+       JsonTablePlan plan;
+
+       JsonTablePlan *lplan;
+       JsonTablePlan *rplan;
+} JsonTableSiblingJoin;
+
 /* ----------------
  * NullTest
  *
@@ -1709,7 +1974,7 @@ typedef struct NullTest
        NullTestType nulltesttype;      /* IS NULL, IS NOT NULL */
        /* T to perform field-by-field null checks */
        bool            argisrow pg_node_attr(query_jumble_ignore);
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } NullTest;
 
 /*
@@ -1731,9 +1996,38 @@ typedef struct BooleanTest
        Expr            xpr;
        Expr       *arg;                        /* input expression */
        BoolTestType booltesttype;      /* test type */
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } BooleanTest;
 
+
+/*
+ * MergeAction
+ *
+ * Transformed representation of a WHEN clause in a MERGE statement
+ */
+
+typedef enum MergeMatchKind
+{
+       MERGE_WHEN_MATCHED,
+       MERGE_WHEN_NOT_MATCHED_BY_SOURCE,
+       MERGE_WHEN_NOT_MATCHED_BY_TARGET
+} MergeMatchKind;
+
+#define NUM_MERGE_MATCH_KINDS (MERGE_WHEN_NOT_MATCHED_BY_TARGET + 1)
+
+typedef struct MergeAction
+{
+       NodeTag         type;
+       MergeMatchKind matchKind;       /* MATCHED/NOT MATCHED BY SOURCE/TARGET */
+       CmdType         commandType;    /* INSERT/UPDATE/DELETE/DO NOTHING */
+       /* OVERRIDING clause */
+       OverridingKind override pg_node_attr(query_jumble_ignore);
+       Node       *qual;                       /* transformed WHEN conditions */
+       List       *targetList;         /* the target list (of TargetEntry) */
+       /* target attribute numbers of an UPDATE */
+       List       *updateColnos pg_node_attr(query_jumble_ignore);
+} MergeAction;
+
 /*
  * CoerceToDomain
  *
@@ -1754,7 +2048,7 @@ typedef struct CoerceToDomain
        Oid                     resultcollid pg_node_attr(query_jumble_ignore);
        /* how to display this node */
        CoercionForm coercionformat pg_node_attr(query_jumble_ignore);
-       int                     location;               /* token location, or -1 if unknown */
+       ParseLoc        location;               /* token location, or -1 if unknown */
 } CoerceToDomain;
 
 /*
@@ -1776,7 +2070,7 @@ typedef struct CoerceToDomainValue
        /* collation for the substituted value */
        Oid                     collation pg_node_attr(query_jumble_ignore);
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } CoerceToDomainValue;
 
 /*
@@ -1796,7 +2090,7 @@ typedef struct SetToDefault
        /* collation for the substituted value */
        Oid                     collation pg_node_attr(query_jumble_ignore);
        /* token location, or -1 if unknown */
-       int                     location;
+       ParseLoc        location;
 } SetToDefault;
 
 /*
index 2b935e22b00b8cd2ec0ff77f2fc467e574682fe8..4c6953a314db9d1f8fa882d5a82f4ea8411e3b2c 100644 (file)
@@ -8,8 +8,8 @@
  * higher-level API provided by parser.h.
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/parser/scanner.h
index 3e7943977cecec06fe9706ce3bba3c89713df128..319b12800224a52253d8d79d07ee4578ac04c3a8 100644 (file)
@@ -3,8 +3,8 @@
  * scansup.h
  *       scanner support routines used by the core lexer
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/parser/scansup.h
index 1ec9474be371c267f548431f3999750abeca94b3..16515b0b1f6951e9c9f7c2539e038d581e85b9a4 100644 (file)
@@ -8,8 +8,8 @@
  * (null-terminated text) or arbitrary binary data.  All storage is allocated
  * with palloc() (falling back to malloc in frontend code).
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/lib/stringinfo.h
@@ -69,17 +69,27 @@ extern int  pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 
 /*-------------------------
  * StringInfoData holds information about an extensible string.
- *             data    is the current buffer for the string (allocated with palloc).
- *             len             is the current string length.  There is guaranteed to be
- *                             a terminating '\0' at data[len], although this is not very
- *                             useful when the string holds binary data rather than text.
+ *             data    is the current buffer for the string.
+ *             len             is the current string length.  Except in the case of read-only
+ *                             strings described below, there is guaranteed to be a
+ *                             terminating '\0' at data[len].
  *             maxlen  is the allocated size in bytes of 'data', i.e. the maximum
  *                             string size (including the terminating '\0' char) that we can
  *                             currently store in 'data' without having to reallocate
- *                             more space.  We must always have maxlen > len.
- *             cursor  is initialized to zero by makeStringInfo or initStringInfo,
- *                             but is not otherwise touched by the stringinfo.c routines.
- *                             Some routines use it to scan through a StringInfo.
+ *                             more space.  We must always have maxlen > len, except
+ *                             in the read-only case described below.
+ *             cursor  is initialized to zero by makeStringInfo, initStringInfo,
+ *                             initReadOnlyStringInfo and initStringInfoFromString but is not
+ *                             otherwise touched by the stringinfo.c routines.  Some routines
+ *                             use it to scan through a StringInfo.
+ *
+ * As a special case, a StringInfoData can be initialized with a read-only
+ * string buffer.  In this case "data" does not necessarily point at a
+ * palloc'd chunk, and management of the buffer storage is the caller's
+ * responsibility.  maxlen is set to zero to indicate that this is the case.
+ * Read-only StringInfoDatas cannot be appended to or reset.
+ * Also, it is caller's option whether a read-only string buffer has a
+ * terminating '\0' or not.  This depends on the intended usage.
  *-------------------------
  */
 typedef struct StringInfoData
@@ -94,7 +104,7 @@ typedef StringInfoData *StringInfo;
 
 
 /*------------------------
- * There are two ways to create a StringInfo object initially:
+ * There are four ways to create a StringInfo object initially:
  *
  * StringInfo stringptr = makeStringInfo();
  *             Both the StringInfoData and the data buffer are palloc'd.
@@ -105,8 +115,32 @@ typedef StringInfoData *StringInfo;
  *             This is the easiest approach for a StringInfo object that will
  *             only live as long as the current routine.
  *
+ * StringInfoData string;
+ * initReadOnlyStringInfo(&string, existingbuf, len);
+ *             The StringInfoData's data field is set to point directly to the
+ *             existing buffer and the StringInfoData's len is set to the given len.
+ *             The given buffer can point to memory that's not managed by palloc or
+ *             is pointing partway through a palloc'd chunk.  The maxlen field is set
+ *             to 0.  A read-only StringInfo cannot be appended to using any of the
+ *             appendStringInfo functions or reset with resetStringInfo().  The given
+ *             buffer can optionally omit the trailing NUL.
+ *
+ * StringInfoData string;
+ * initStringInfoFromString(&string, palloced_buf, len);
+ *             The StringInfoData's data field is set to point directly to the given
+ *             buffer and the StringInfoData's len is set to the given len.  This
+ *             method of initialization is useful when the buffer already exists.
+ *             StringInfos initialized this way can be appended to using the
+ *             appendStringInfo functions and reset with resetStringInfo().  The
+ *             given buffer must be NUL-terminated.  The palloc'd buffer is assumed
+ *             to be len + 1 in size.
+ *
  * To destroy a StringInfo, pfree() the data buffer, and then pfree() the
- * StringInfoData if it was palloc'd.  There's no special support for this.
+ * StringInfoData if it was palloc'd.  For StringInfos created with
+ * makeStringInfo(), destroyStringInfo() is provided for this purpose.
+ * However, if the StringInfo was initialized using initReadOnlyStringInfo()
+ * then the caller will need to consider if it is safe to pfree the data
+ * buffer.
  *
  * NOTE: some routines build up a string using StringInfo, and then
  * release the StringInfoData but return the data string itself to their
@@ -128,6 +162,48 @@ extern StringInfo makeStringInfo(void);
  */
 extern void initStringInfo(StringInfo str);
 
+/*------------------------
+ * initReadOnlyStringInfo
+ * Initialize a StringInfoData struct from an existing string without copying
+ * the string.  The caller is responsible for ensuring the given string
+ * remains valid as long as the StringInfoData does.  Calls to this are used
+ * in performance critical locations where allocating a new buffer and copying
+ * would be too costly.  Read-only StringInfoData's may not be appended to
+ * using any of the appendStringInfo functions or reset with
+ * resetStringInfo().
+ *
+ * 'data' does not need to point directly to a palloc'd chunk of memory and may
+ * omit the NUL termination character at data[len].
+ */
+static inline void
+initReadOnlyStringInfo(StringInfo str, char *data, int len)
+{
+       str->data = data;
+       str->len = len;
+       str->maxlen = 0;                        /* read-only */
+       str->cursor = 0;
+}
+
+/*------------------------
+ * initStringInfoFromString
+ * Initialize a StringInfoData struct from an existing string without copying
+ * the string.  'data' must be a valid palloc'd chunk of memory that can have
+ * repalloc() called should more space be required during a call to any of the
+ * appendStringInfo functions.
+ *
+ * 'data' must be NUL terminated at 'len' bytes.
+ */
+static inline void
+initStringInfoFromString(StringInfo str, char *data, int len)
+{
+       Assert(data[len] == '\0');
+
+       str->data = data;
+       str->len = len;
+       str->maxlen = len + 1;
+       str->cursor = 0;
+}
+
 /*------------------------
  * resetStringInfo
  * Clears the current content of the StringInfo, if any. The
@@ -207,4 +283,10 @@ extern void appendBinaryStringInfoNT(StringInfo str,
  */
 extern void enlargeStringInfo(StringInfo str, int needed);
 
+/*------------------------
+ * destroyStringInfo
+ * Frees a StringInfo and its buffer (opposite of makeStringInfo()).
+ */
+extern void destroyStringInfo(StringInfo str);
+
 #endif                                                 /* STRINGINFO_H */
index 9942f1c891c75b430bef1e5527a0f12ba5fb1f46..f6fafb5c3351b161322c3b986af5cf39ac502ede 100644 (file)
@@ -4,8 +4,8 @@
  *       interface for value nodes
  *
  *
- * Copyright (c) 2003-2023, PgPool Global Development Group
- * Copyright (c) 2003-2023, PostgreSQL Global Development Group
+ * Copyright (c) 2003-2024, PgPool Global Development Group
+ * Copyright (c) 2003-2024, PostgreSQL Global Development Group
  *
  * src/include/nodes/value.h
  *
index bf6cdb2eff376b4f87dd06c2426962d2ed6b2b1e..b6d0718fd743610d0ea6e03ac2a7f7971dfabedf 100644 (file)
@@ -75,7 +75,6 @@ extern MemoryContext CurrentMemoryContext;
  */
 extern void *MemoryContextAlloc(MemoryContext context, Size size);
 extern void *MemoryContextAllocZero(MemoryContext context, Size size);
-extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size);
 extern void *MemoryContextAllocExtended(MemoryContext context,
                                                   Size size, int flags);
 
@@ -85,19 +84,6 @@ extern void *palloc_extended(Size size, int flags);
 extern void *repalloc(void *pointer, Size size);
 extern void pfree(void *pointer);
 
-/*
- * The result of palloc() is always word-aligned, so we can skip testing
- * alignment of the pointer when deciding which MemSet variant to use.
- * Note that this variant does not offer any advantage, and should not be
- * used, unless its "sz" argument is a compile-time constant; therefore, the
- * issue that it evaluates the argument multiple times isn't a problem in
- * practice.
- */
-#define palloc0fast(sz) \
-       ( MemSetTest(0, sz) ? \
-               MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \
-               MemoryContextAllocZero(CurrentMemoryContext, sz) )
-
 /* Higher-limit allocators. */
 extern void *MemoryContextAllocHuge(MemoryContext context, Size size);
 extern void *repalloc_huge(void *pointer, Size size);
index 4906ca361734ec11a891b03d69a9520a5043e082..b9262aec7007043f7808a3ca18edbda536b23c84 100644 (file)
@@ -11,8 +11,8 @@
  * be handled easily in a simple depth-first traversal.
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
@@ -109,7 +109,7 @@ _copyPlannedStmt(const PlannedStmt *from)
        COPY_NODE_FIELD(paramExecTypes);
        COPY_NODE_FIELD(utilityStmt);
        COPY_LOCATION_FIELD(stmt_location);
-       COPY_SCALAR_FIELD(stmt_len);
+       COPY_LOCATION_FIELD(stmt_len);
 
        return newnode;
 }
@@ -231,6 +231,7 @@ _copyModifyTable(const ModifyTable *from)
        COPY_SCALAR_FIELD(exclRelRTI);
        COPY_NODE_FIELD(exclRelTlist);
        COPY_NODE_FIELD(mergeActionLists);
+       COPY_NODE_FIELD(mergeJoinConditions);
 
        return newnode;
 }
@@ -1399,6 +1400,7 @@ _copyTableFunc(const TableFunc *from)
 {
        TableFunc  *newnode = makeNode(TableFunc);
 
+       COPY_SCALAR_FIELD(functype);
        COPY_NODE_FIELD(ns_uris);
        COPY_NODE_FIELD(ns_names);
        COPY_NODE_FIELD(docexpr);
@@ -1409,7 +1411,10 @@ _copyTableFunc(const TableFunc *from)
        COPY_NODE_FIELD(colcollations);
        COPY_NODE_FIELD(colexprs);
        COPY_NODE_FIELD(coldefexprs);
+       COPY_NODE_FIELD(colvalexprs);
+       COPY_NODE_FIELD(passingvalexprs);
        COPY_BITMAPSET_FIELD(notnulls);
+       COPY_NODE_FIELD(plan);
        COPY_SCALAR_FIELD(ordinalitycol);
        COPY_LOCATION_FIELD(location);
 
@@ -1584,6 +1589,7 @@ _copyWindowFunc(const WindowFunc *from)
        COPY_SCALAR_FIELD(inputcollid);
        COPY_NODE_FIELD(args);
        COPY_NODE_FIELD(aggfilter);
+       COPY_NODE_FIELD(runCondition);
        COPY_SCALAR_FIELD(winref);
        COPY_SCALAR_FIELD(winstar);
        COPY_SCALAR_FIELD(winagg);
@@ -1592,6 +1598,31 @@ _copyWindowFunc(const WindowFunc *from)
        return newnode;
 }
 
+static WindowFuncRunCondition *
+_copyWindowFuncRunCondition(const WindowFuncRunCondition *from)
+{
+       WindowFuncRunCondition *newnode = makeNode(WindowFuncRunCondition);
+
+       COPY_SCALAR_FIELD(opno);
+       COPY_SCALAR_FIELD(inputcollid);
+       COPY_SCALAR_FIELD(wfunc_left);
+       COPY_NODE_FIELD(arg);
+
+       return newnode;
+}
+
+static MergeSupportFunc *
+_copyMergeSupportFunc(const MergeSupportFunc *from)
+{
+       MergeSupportFunc *newnode = makeNode(MergeSupportFunc);
+
+       COPY_SCALAR_FIELD(msftype);
+       COPY_SCALAR_FIELD(msfcollid);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
 /*
  * _copySubscriptingRef
  */
@@ -2094,6 +2125,147 @@ _copyXmlExpr(const XmlExpr *from)
        return newnode;
 }
 
+static JsonFormat *
+_copyJsonFormat(const JsonFormat *from)
+{
+       JsonFormat *newnode = makeNode(JsonFormat);
+
+       COPY_SCALAR_FIELD(format_type);
+       COPY_SCALAR_FIELD(encoding);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonReturning *
+_copyJsonReturning(const JsonReturning *from)
+{
+       JsonReturning *newnode = makeNode(JsonReturning);
+
+       COPY_NODE_FIELD(format);
+       COPY_SCALAR_FIELD(typid);
+       COPY_SCALAR_FIELD(typmod);
+
+       return newnode;
+}
+
+static JsonValueExpr *
+_copyJsonValueExpr(const JsonValueExpr *from)
+{
+       JsonValueExpr *newnode = makeNode(JsonValueExpr);
+
+       COPY_NODE_FIELD(raw_expr);
+       COPY_NODE_FIELD(formatted_expr);
+       COPY_NODE_FIELD(format);
+
+       return newnode;
+}
+
+static JsonConstructorExpr *
+_copyJsonConstructorExpr(const JsonConstructorExpr *from)
+{
+       JsonConstructorExpr *newnode = makeNode(JsonConstructorExpr);
+
+       COPY_SCALAR_FIELD(type);
+       COPY_NODE_FIELD(args);
+       COPY_NODE_FIELD(func);
+       COPY_NODE_FIELD(coercion);
+       COPY_NODE_FIELD(returning);
+       COPY_SCALAR_FIELD(absent_on_null);
+       COPY_SCALAR_FIELD(unique);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonIsPredicate *
+_copyJsonIsPredicate(const JsonIsPredicate *from)
+{
+       JsonIsPredicate *newnode = makeNode(JsonIsPredicate);
+
+       COPY_NODE_FIELD(expr);
+       COPY_NODE_FIELD(format);
+       COPY_SCALAR_FIELD(item_type);
+       COPY_SCALAR_FIELD(unique_keys);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonBehavior *
+_copyJsonBehavior(const JsonBehavior *from)
+{
+       JsonBehavior *newnode = makeNode(JsonBehavior);
+
+       COPY_SCALAR_FIELD(btype);
+       COPY_NODE_FIELD(expr);
+       COPY_SCALAR_FIELD(coerce);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonExpr *
+_copyJsonExpr(const JsonExpr *from)
+{
+       JsonExpr *newnode = makeNode(JsonExpr);
+
+       COPY_SCALAR_FIELD(op);
+       COPY_STRING_FIELD(column_name);
+       COPY_NODE_FIELD(formatted_expr);
+       COPY_NODE_FIELD(format);
+       COPY_NODE_FIELD(path_spec);
+       COPY_NODE_FIELD(returning);
+       COPY_NODE_FIELD(passing_names);
+       COPY_NODE_FIELD(passing_values);
+       COPY_NODE_FIELD(on_empty);
+       COPY_NODE_FIELD(on_error);
+       COPY_SCALAR_FIELD(use_io_coercion);
+       COPY_SCALAR_FIELD(use_json_coercion);
+       COPY_SCALAR_FIELD(wrapper);
+       COPY_SCALAR_FIELD(omit_quotes);
+       COPY_SCALAR_FIELD(collation);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonTablePath *
+_copyJsonTablePath(const JsonTablePath *from)
+{
+       JsonTablePath *newnode = makeNode(JsonTablePath);
+
+       COPY_NODE_FIELD(value);
+       COPY_STRING_FIELD(name);
+
+       return newnode;
+}
+
+static JsonTablePathScan *
+_copyJsonTablePathScan(const JsonTablePathScan *from)
+{
+       JsonTablePathScan *newnode = makeNode(JsonTablePathScan);
+
+       COPY_NODE_FIELD(path);
+       COPY_SCALAR_FIELD(errorOnError);
+       COPY_NODE_FIELD(child);
+       COPY_SCALAR_FIELD(colMin);
+       COPY_SCALAR_FIELD(colMax);
+
+       return newnode;
+}
+
+static JsonTableSiblingJoin *
+_copyJsonTableSiblingJoin(const JsonTableSiblingJoin *from)
+{
+       JsonTableSiblingJoin *newnode = makeNode(JsonTableSiblingJoin);
+
+       COPY_NODE_FIELD(lplan);
+       COPY_NODE_FIELD(rplan);
+
+       return newnode;
+}
+
 /*
  * _copyNullTest
  */
@@ -2125,6 +2297,21 @@ _copyBooleanTest(const BooleanTest *from)
        return newnode;
 }
 
+static MergeAction *
+_copyMergeAction(const MergeAction *from)
+{
+       MergeAction *newnode = makeNode(MergeAction);
+
+       COPY_SCALAR_FIELD(matchKind);
+       COPY_SCALAR_FIELD(commandType);
+       COPY_SCALAR_FIELD(override);
+       COPY_NODE_FIELD(qual);
+       COPY_NODE_FIELD(targetList);
+       COPY_NODE_FIELD(updateColnos);
+
+       return newnode;
+}
+
 /*
  * _copyCoerceToDomain
  */
@@ -2332,6 +2519,17 @@ _copyPathKey(const PathKey *from)
        return newnode;
 }
 
+static GroupByOrdering *
+_copyGroupByOrdering(const GroupByOrdering *from)
+{
+       GroupByOrdering *newnode = makeNode(GroupByOrdering);
+
+       COPY_NODE_FIELD(pathkeys);
+       COPY_NODE_FIELD(clauses);
+
+       return newnode;
+}
+
 /*
  * _copyRestrictInfo
  */
@@ -2468,10 +2666,14 @@ _copyRangeTblEntry(const RangeTblEntry *from)
 {
        RangeTblEntry *newnode = makeNode(RangeTblEntry);
 
+       COPY_NODE_FIELD(alias);
+       COPY_NODE_FIELD(eref);
        COPY_SCALAR_FIELD(rtekind);
        COPY_SCALAR_FIELD(relid);
+       COPY_SCALAR_FIELD(inh);
        COPY_SCALAR_FIELD(relkind);
        COPY_SCALAR_FIELD(rellockmode);
+       COPY_SCALAR_FIELD(perminfoindex);
        COPY_NODE_FIELD(tablesample);
        COPY_NODE_FIELD(subquery);
        COPY_SCALAR_FIELD(security_barrier);
@@ -2493,10 +2695,7 @@ _copyRangeTblEntry(const RangeTblEntry *from)
        COPY_NODE_FIELD(colcollations);
        COPY_STRING_FIELD(enrname);
        COPY_SCALAR_FIELD(enrtuples);
-       COPY_NODE_FIELD(alias);
-       COPY_NODE_FIELD(eref);
        COPY_SCALAR_FIELD(lateral);
-       COPY_SCALAR_FIELD(inh);
        COPY_SCALAR_FIELD(inFromCl);
        COPY_NODE_FIELD(securityQuals);
 
@@ -2583,7 +2782,6 @@ _copyWindowClause(const WindowClause *from)
        COPY_SCALAR_FIELD(frameOptions);
        COPY_NODE_FIELD(startOffset);
        COPY_NODE_FIELD(endOffset);
-       COPY_NODE_FIELD(runCondition);
        COPY_SCALAR_FIELD(startInRangeFunc);
        COPY_SCALAR_FIELD(endInRangeFunc);
        COPY_SCALAR_FIELD(inRangeColl);
@@ -2706,7 +2904,7 @@ _copyMergeWhenClause(const MergeWhenClause *from)
 {
        MergeWhenClause *newnode = makeNode(MergeWhenClause);
 
-       COPY_SCALAR_FIELD(matched);
+       COPY_SCALAR_FIELD(matchKind);
        COPY_SCALAR_FIELD(commandType);
        COPY_SCALAR_FIELD(override);
        COPY_NODE_FIELD(condition);
@@ -2715,21 +2913,6 @@ _copyMergeWhenClause(const MergeWhenClause *from)
        return newnode;
 }
 
-static MergeAction *
-_copyMergeAction(const MergeAction *from)
-{
-       MergeAction *newnode = makeNode(MergeAction);
-
-       COPY_SCALAR_FIELD(matched);
-       COPY_SCALAR_FIELD(commandType);
-       COPY_SCALAR_FIELD(override);
-       COPY_NODE_FIELD(qual);
-       COPY_NODE_FIELD(targetList);
-       COPY_NODE_FIELD(updateColnos);
-
-       return newnode;
-}
-
 static A_Expr *
 _copyA_Expr(const A_Expr *from)
 {
@@ -3101,11 +3284,13 @@ _copyConstraint(const Constraint *from)
        COPY_STRING_FIELD(conname);
        COPY_SCALAR_FIELD(deferrable);
        COPY_SCALAR_FIELD(initdeferred);
-       COPY_LOCATION_FIELD(location);
+       COPY_SCALAR_FIELD(skip_validation);
+       COPY_SCALAR_FIELD(initially_valid);
        COPY_SCALAR_FIELD(is_no_inherit);
        COPY_NODE_FIELD(raw_expr);
        COPY_STRING_FIELD(cooked_expr);
        COPY_SCALAR_FIELD(generated_when);
+       COPY_SCALAR_FIELD(inhcount);
        COPY_SCALAR_FIELD(nulls_not_distinct);
        COPY_NODE_FIELD(keys);
        COPY_NODE_FIELD(including);
@@ -3125,8 +3310,7 @@ _copyConstraint(const Constraint *from)
        COPY_NODE_FIELD(fk_del_set_cols);
        COPY_NODE_FIELD(old_conpfeqop);
        COPY_SCALAR_FIELD(old_pktable_oid);
-       COPY_SCALAR_FIELD(skip_validation);
-       COPY_SCALAR_FIELD(initially_valid);
+       COPY_LOCATION_FIELD(location);
 
        return newnode;
 }
@@ -3194,6 +3378,226 @@ _copyTriggerTransition(const TriggerTransition *from)
        return newnode;
 }
 
+static JsonOutput *
+_copyJsonOutput(const JsonOutput *from)
+{
+       JsonOutput *newnode = makeNode(JsonOutput);
+
+       COPY_NODE_FIELD(typeName);
+       COPY_NODE_FIELD(returning);
+
+       return newnode;
+}
+
+static JsonArgument *
+_copyJsonArgument(const JsonArgument *from)
+{
+       JsonArgument *newnode = makeNode(JsonArgument);
+
+       COPY_NODE_FIELD(val);
+       COPY_STRING_FIELD(name);
+
+       return newnode;
+}
+
+static JsonFuncExpr *
+_copyJsonFuncExpr(const JsonFuncExpr *from)
+{
+       JsonFuncExpr *newnode = makeNode(JsonFuncExpr);
+
+       COPY_SCALAR_FIELD(op);
+       COPY_STRING_FIELD(column_name);
+       COPY_NODE_FIELD(context_item);
+       COPY_NODE_FIELD(pathspec);
+       COPY_NODE_FIELD(passing);
+       COPY_NODE_FIELD(output);
+       COPY_NODE_FIELD(on_empty);
+       COPY_NODE_FIELD(on_error);
+       COPY_SCALAR_FIELD(wrapper);
+       COPY_SCALAR_FIELD(quotes);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonTablePathSpec *
+_copyJsonTablePathSpec(const JsonTablePathSpec *from)
+{
+       JsonTablePathSpec *newnode = makeNode(JsonTablePathSpec);
+
+       COPY_NODE_FIELD(string);
+       COPY_STRING_FIELD(name);
+       COPY_LOCATION_FIELD(name_location);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonTable *
+_copyJsonTable(const JsonTable *from)
+{
+       JsonTable *newnode = makeNode(JsonTable);
+
+       COPY_NODE_FIELD(context_item);
+       COPY_NODE_FIELD(pathspec);
+       COPY_NODE_FIELD(passing);
+       COPY_NODE_FIELD(columns);
+       COPY_NODE_FIELD(on_error);
+       COPY_NODE_FIELD(alias);
+       COPY_SCALAR_FIELD(lateral);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonTableColumn *
+_copyJsonTableColumn(const JsonTableColumn *from)
+{
+       JsonTableColumn *newnode = makeNode(JsonTableColumn);
+
+       COPY_SCALAR_FIELD(coltype);
+       COPY_STRING_FIELD(name);
+       COPY_NODE_FIELD(typeName);
+       COPY_NODE_FIELD(pathspec);
+       COPY_NODE_FIELD(format);
+       COPY_SCALAR_FIELD(wrapper);
+       COPY_SCALAR_FIELD(quotes);
+       COPY_NODE_FIELD(columns);
+       COPY_NODE_FIELD(on_empty);
+       COPY_NODE_FIELD(on_error);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonKeyValue *
+_copyJsonKeyValue(const JsonKeyValue *from)
+{
+       JsonKeyValue *newnode = makeNode(JsonKeyValue);
+
+       COPY_NODE_FIELD(key);
+       COPY_NODE_FIELD(value);
+
+       return newnode;
+}
+
+static JsonParseExpr *
+_copyJsonParseExpr(const JsonParseExpr *from)
+{
+       JsonParseExpr *newnode = makeNode(JsonParseExpr);
+
+       COPY_NODE_FIELD(expr);
+       COPY_NODE_FIELD(output);
+       COPY_SCALAR_FIELD(unique_keys);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonScalarExpr *
+_copyJsonScalarExpr(const JsonScalarExpr *from)
+{
+       JsonScalarExpr *newnode = makeNode(JsonScalarExpr);
+
+       COPY_NODE_FIELD(expr);
+       COPY_NODE_FIELD(output);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonSerializeExpr *
+_copyJsonSerializeExpr(const JsonSerializeExpr *from)
+{
+       JsonSerializeExpr *newnode = makeNode(JsonSerializeExpr);
+
+       COPY_NODE_FIELD(expr);
+       COPY_NODE_FIELD(output);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonObjectConstructor *
+_copyJsonObjectConstructor(const JsonObjectConstructor *from)
+{
+       JsonObjectConstructor *newnode = makeNode(JsonObjectConstructor);
+
+       COPY_NODE_FIELD(exprs);
+       COPY_NODE_FIELD(output);
+       COPY_SCALAR_FIELD(absent_on_null);
+       COPY_SCALAR_FIELD(unique);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonArrayConstructor *
+_copyJsonArrayConstructor(const JsonArrayConstructor *from)
+{
+       JsonArrayConstructor *newnode = makeNode(JsonArrayConstructor);
+
+       COPY_NODE_FIELD(exprs);
+       COPY_NODE_FIELD(output);
+       COPY_SCALAR_FIELD(absent_on_null);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonArrayQueryConstructor *
+_copyJsonArrayQueryConstructor(const JsonArrayQueryConstructor *from)
+{
+       JsonArrayQueryConstructor *newnode = makeNode(JsonArrayQueryConstructor);
+
+       COPY_NODE_FIELD(query);
+       COPY_NODE_FIELD(output);
+       COPY_NODE_FIELD(format);
+       COPY_SCALAR_FIELD(absent_on_null);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonAggConstructor *
+_copyJsonAggConstructor(const JsonAggConstructor *from)
+{
+       JsonAggConstructor *newnode = makeNode(JsonAggConstructor);
+
+       COPY_NODE_FIELD(output);
+       COPY_NODE_FIELD(agg_filter);
+       COPY_NODE_FIELD(agg_order);
+       COPY_NODE_FIELD(over);
+       COPY_LOCATION_FIELD(location);
+
+       return newnode;
+}
+
+static JsonObjectAgg *
+_copyJsonObjectAgg(const JsonObjectAgg *from)
+{
+       JsonObjectAgg *newnode = makeNode(JsonObjectAgg);
+
+       COPY_NODE_FIELD(constructor);
+       COPY_NODE_FIELD(arg);
+       COPY_SCALAR_FIELD(absent_on_null);
+       COPY_SCALAR_FIELD(unique);
+
+       return newnode;
+}
+
+static JsonArrayAgg *
+_copyJsonArrayAgg(const JsonArrayAgg *from)
+{
+       JsonArrayAgg *newnode = makeNode(JsonArrayAgg);
+
+       COPY_NODE_FIELD(constructor);
+       COPY_NODE_FIELD(arg);
+       COPY_SCALAR_FIELD(absent_on_null);
+
+       return newnode;
+}
+
 static Query *
 _copyQuery(const Query *from)
 {
@@ -3217,7 +3621,11 @@ _copyQuery(const Query *from)
        COPY_SCALAR_FIELD(isReturn);
        COPY_NODE_FIELD(cteList);
        COPY_NODE_FIELD(rtable);
+       COPY_NODE_FIELD(rteperminfos);
        COPY_NODE_FIELD(jointree);
+       COPY_NODE_FIELD(mergeActionList);
+       COPY_SCALAR_FIELD(mergeTargetRelation);
+       COPY_NODE_FIELD(mergeJoinCondition);
        COPY_NODE_FIELD(targetList);
        COPY_SCALAR_FIELD(override);
        COPY_NODE_FIELD(onConflict);
@@ -3236,10 +3644,8 @@ _copyQuery(const Query *from)
        COPY_NODE_FIELD(setOperations);
        COPY_NODE_FIELD(constraintDeps);
        COPY_NODE_FIELD(withCheckOptions);
-       COPY_NODE_FIELD(mergeActionList);
-       COPY_SCALAR_FIELD(mergeUseOuterJoin);
        COPY_LOCATION_FIELD(stmt_location);
-       COPY_SCALAR_FIELD(stmt_len);
+       COPY_LOCATION_FIELD(stmt_len);
 
        return newnode;
 }
@@ -3251,7 +3657,7 @@ _copyRawStmt(const RawStmt *from)
 
        COPY_NODE_FIELD(stmt);
        COPY_LOCATION_FIELD(stmt_location);
-       COPY_SCALAR_FIELD(stmt_len);
+       COPY_LOCATION_FIELD(stmt_len);
 
        return newnode;
 }
@@ -3310,6 +3716,7 @@ _copyMergeStmt(const MergeStmt *from)
        COPY_NODE_FIELD(sourceRelation);
        COPY_NODE_FIELD(joinCondition);
        COPY_NODE_FIELD(mergeWhenClauses);
+       COPY_NODE_FIELD(returningList);
        COPY_NODE_FIELD(withClause);
 
        return newnode;
@@ -3751,7 +4158,7 @@ _copyAlterStatsStmt(const AlterStatsStmt *from)
        AlterStatsStmt *newnode = makeNode(AlterStatsStmt);
 
        COPY_NODE_FIELD(defnames);
-       COPY_SCALAR_FIELD(stxstattarget);
+       COPY_NODE_FIELD(stxstattarget);
        COPY_SCALAR_FIELD(missing_ok);
 
        return newnode;
@@ -3945,6 +4352,7 @@ _copyTransactionStmt(const TransactionStmt *from)
        COPY_STRING_FIELD(savepoint_name);
        COPY_STRING_FIELD(gid);
        COPY_SCALAR_FIELD(chain);
+       COPY_LOCATION_FIELD(location);
 
        return newnode;
 }
@@ -4731,6 +5139,8 @@ _copyDeallocateStmt(const DeallocateStmt *from)
        DeallocateStmt *newnode = makeNode(DeallocateStmt);
 
        COPY_STRING_FIELD(name);
+       COPY_SCALAR_FIELD(isall);
+       COPY_LOCATION_FIELD(location);
 
        return newnode;
 }
@@ -4869,6 +5279,15 @@ _copyPartitionRangeDatum(const PartitionRangeDatum *from)
        return newnode;
 }
 
+static SinglePartitionSpec *
+_copySinglePartitionSpec(const SinglePartitionSpec *from)
+{
+       SinglePartitionSpec *newnode = makeNode(SinglePartitionSpec);
+
+
+       return newnode;
+}
+
 static PartitionCmd *
 _copyPartitionCmd(const PartitionCmd *from)
 {
@@ -5289,6 +5708,12 @@ copyObjectImpl(const void *from)
                case T_WindowFunc:
                        retval = _copyWindowFunc(from);
                        break;
+               case T_WindowFuncRunCondition:
+                       retval = _copyWindowFuncRunCondition(from);
+                       break;
+               case T_MergeSupportFunc:
+                       retval = _copyMergeSupportFunc(from);
+                       break;
                case T_SubscriptingRef:
                        retval = _copySubscriptingRef(from);
                        break;
@@ -5373,12 +5798,45 @@ copyObjectImpl(const void *from)
                case T_XmlExpr:
                        retval = _copyXmlExpr(from);
                        break;
+               case T_JsonFormat:
+                       retval = _copyJsonFormat(from);
+                       break;
+               case T_JsonReturning:
+                       retval = _copyJsonReturning(from);
+                       break;
+               case T_JsonValueExpr:
+                       retval = _copyJsonValueExpr(from);
+                       break;
+               case T_JsonConstructorExpr:
+                       retval = _copyJsonConstructorExpr(from);
+                       break;
+               case T_JsonIsPredicate:
+                       retval = _copyJsonIsPredicate(from);
+                       break;
+               case T_JsonBehavior:
+                       retval = _copyJsonBehavior(from);
+                       break;
+               case T_JsonExpr:
+                       retval = _copyJsonExpr(from);
+                       break;
+               case T_JsonTablePath:
+                       retval = _copyJsonTablePath(from);
+                       break;
+               case T_JsonTablePathScan:
+                       retval = _copyJsonTablePathScan(from);
+                       break;
+               case T_JsonTableSiblingJoin:
+                       retval = _copyJsonTableSiblingJoin(from);
+                       break;
                case T_NullTest:
                        retval = _copyNullTest(from);
                        break;
                case T_BooleanTest:
                        retval = _copyBooleanTest(from);
                        break;
+               case T_MergeAction:
+                       retval = _copyMergeAction(from);
+                       break;
                case T_CoerceToDomain:
                        retval = _copyCoerceToDomain(from);
                        break;
@@ -5421,6 +5879,9 @@ copyObjectImpl(const void *from)
                case T_PathKey:
                        retval = _copyPathKey(from);
                        break;
+               case T_GroupByOrdering:
+                       retval = _copyGroupByOrdering(from);
+                       break;
                case T_RestrictInfo:
                        retval = _copyRestrictInfo(from);
                        break;
@@ -5471,6 +5932,7 @@ copyObjectImpl(const void *from)
                         */
                case T_IntList:
                case T_OidList:
+               case T_XidList:
                        retval = list_copy(from);
                        break;
 
@@ -5982,9 +6444,6 @@ copyObjectImpl(const void *from)
                case T_MergeWhenClause:
                        retval = _copyMergeWhenClause(from);
                        break;
-               case T_MergeAction:
-                       retval = _copyMergeAction(from);
-                       break;
                case T_ObjectWithArgs:
                        retval = _copyObjectWithArgs(from);
                        break;
@@ -6000,6 +6459,54 @@ copyObjectImpl(const void *from)
                case T_TriggerTransition:
                        retval = _copyTriggerTransition(from);
                        break;
+        case T_JsonOutput:
+            retval = _copyJsonOutput(from);
+            break;
+        case T_JsonArgument:
+            retval = _copyJsonArgument(from);
+            break;
+        case T_JsonFuncExpr:
+            retval = _copyJsonFuncExpr(from);
+            break;
+        case T_JsonTablePathSpec:
+            retval = _copyJsonTablePathSpec(from);
+            break;
+        case T_JsonTable:
+            retval = _copyJsonTable(from);
+            break;
+        case T_JsonTableColumn:
+            retval = _copyJsonTableColumn(from);
+            break;
+        case T_JsonKeyValue:
+            retval = _copyJsonKeyValue(from);
+            break;
+        case T_JsonParseExpr:
+            retval = _copyJsonParseExpr(from);
+            break;
+        case T_JsonScalarExpr:
+            retval = _copyJsonScalarExpr(from);
+            break;
+        case T_JsonSerializeExpr:
+            retval = _copyJsonSerializeExpr(from);
+            break;
+        case T_JsonObjectConstructor:
+            retval = _copyJsonObjectConstructor(from);
+            break;
+        case T_JsonArrayConstructor:
+            retval = _copyJsonArrayConstructor(from);
+            break;
+        case T_JsonArrayQueryConstructor:
+            retval = _copyJsonArrayQueryConstructor(from);
+            break;
+        case T_JsonAggConstructor:
+            retval = _copyJsonAggConstructor(from);
+            break;
+        case T_JsonObjectAgg:
+            retval = _copyJsonObjectAgg(from);
+            break;
+        case T_JsonArrayAgg:
+            retval = _copyJsonArrayAgg(from);
+            break;
                case T_PartitionElem:
                        retval = _copyPartitionElem(from);
                        break;
@@ -6012,6 +6519,9 @@ copyObjectImpl(const void *from)
                case T_PartitionRangeDatum:
                        retval = _copyPartitionRangeDatum(from);
                        break;
+               case T_SinglePartitionSpec:
+                       retval = _copySinglePartitionSpec(from);
+                       break;
                case T_PartitionCmd:
                        retval = _copyPartitionCmd(from);
                        break;
index e672ae1e01544a12184a232b129874aa500d62ba..a39f98991740638d25b68080f3205088415914df 100644 (file)
@@ -6,8 +6,8 @@
  * gram.y
  *       POSTGRESQL BISON rules/actions
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -204,7 +204,6 @@ static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
 static void updateRawStmtEnd(RawStmt *rs, int end_location);
 static Node *makeColumnRef(char *colname, List *indirection,
                                                   int location, core_yyscan_t yyscanner);
-static Node *makeStringConst(char *str, int location);
 static Node *makeFloatConst(char *str, int location);
 static Node *makeBoolAConst(bool state, int location);
 static Node *makeBitStringConst(char *str, int location);
@@ -307,6 +306,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        struct SelectLimit *selectlimit;
        SetQuantifier setquantifier;
        struct GroupClause *groupclause;
+       MergeMatchKind mergematch;
        MergeWhenClause *mergewhen;
        struct KeyActions *keyactions;
        struct KeyAction *keyaction;
@@ -370,6 +370,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <list>   alter_table_cmds alter_type_cmds
 %type <list>    alter_identity_column_option_list
 %type <defelt>  alter_identity_column_option
+%type <node>   set_statistics_value
+%type <str>            set_access_method_name
 
 %type <list>   createdb_opt_list createdb_opt_items copy_opt_list
                                transaction_mode_list
@@ -547,13 +549,14 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <onconflict> opt_on_conflict
 %type <mergewhen>      merge_insert merge_update merge_delete
 
+%type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
 %type <node>   merge_when_clause opt_merge_when_condition
 %type <list>   merge_when_list
 
 %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
                                 SetResetClause FunctionSetResetClause
 
-%type <node>   TableElement TypedTableElement ConstraintElem TableFuncElement
+%type <node>   TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
 %type <node>   columnDef columnOptions
 %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
 %type <node>   def_arg columnElem where_clause where_or_current_clause
@@ -599,7 +602,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <list>   copy_options
 
 %type <typnam> Typename SimpleTypename ConstTypename
-                               GenericType Numeric opt_float
+                               GenericType Numeric opt_float JsonType
                                Character ConstCharacter
                                CharacterWithLength CharacterWithoutLength
                                ConstDatetime ConstInterval
@@ -624,7 +627,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <keyword> col_name_keyword reserved_keyword
 %type <keyword> bare_label_keyword
 
-%type <node>   TableConstraint TableLikeClause
+%type <node>   DomainConstraint TableConstraint TableLikeClause
 %type <ival>   TableLikeOptionList TableLikeOption
 %type <str>            column_compression opt_column_compression column_storage opt_column_storage
 %type <list>   ColQualList
@@ -678,16 +681,30 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <list>           hash_partbound
 %type <defelt>         hash_partbound_elem
 
-%type <node>   json_format_clause_opt
+%type <node>   json_format_clause
+                               json_format_clause_opt
                                json_value_expr
-                               json_output_clause_opt
+                               json_returning_clause_opt
                                json_name_and_value
                                json_aggregate_func
+                               json_argument
+                               json_behavior
+                               json_on_error_clause_opt
+                               json_table
+                               json_table_column_definition
+                               json_table_column_path_clause_opt
 %type <list>   json_name_and_value_list
                                json_value_expr_list
                                json_array_aggregate_order_by_clause_opt
-%type <ival>   json_encoding_clause_opt
+                               json_arguments
+                               json_behavior_clause_opt
+                               json_passing_clause_opt
+                               json_table_column_definition_list
+%type <str>            json_table_path_name_opt
+%type <ival>   json_behavior_type
                                json_predicate_type_constraint
+                               json_quotes_clause_opt
+                               json_wrapper_behavior
 %type <boolean>        json_key_uniqueness_constraint_opt
                                json_object_constructor_null_clause_opt
                                json_array_constructor_null_clause_opt
@@ -728,7 +745,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
        CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
        CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
-       COMMITTED COMPRESSION CONCURRENTLY CONFIGURATION CONFLICT
+       COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
        CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
        COST CREATE CROSS CSV CUBE CURRENT_P
        CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
@@ -739,8 +756,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
        DOUBLE_P DROP
 
-       EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
-       EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
+       EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ERROR_P ESCAPE
+       EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
        EXTENSION EXTERNAL EXTRACT
 
        FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
@@ -755,32 +772,33 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
        INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
 
-       JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_OBJECT JSON_OBJECTAGG
+       JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
+       JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
 
-       KEY KEYS
+       KEEP KEY KEYS
 
        LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
        LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
        LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
 
-       MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE METHOD
+       MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
        MINUTE_P MINVALUE MODE MONTH_P MOVE
 
-       NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NFC NFD NFKC NFKD NO NONE
-       NORMALIZE NORMALIZED
+       NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
+       NONE NORMALIZE NORMALIZED
        NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
        NULLS_P NUMERIC
 
-       OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
+       OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
        ORDER ORDINALITY OTHERS OUT_P OUTER_P
        OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
 
-       PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PGPOOL
-       PLACING PLANS POLICY
+       PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH PGPOOL
+       PLACING PLAN PLANS POLICY
        POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
        PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
 
-       QUOTE
+       QUOTE QUOTES
 
        RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING
        REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
@@ -790,16 +808,16 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
        SEQUENCE SEQUENCES
        SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
-       SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P
-       START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRIP_P
+       SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
+       START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
        SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
 
-       TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
+       TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
        TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
        TREAT TRIGGER TRIM TRUE_P
        TRUNCATE TRUSTED TYPE_P TYPES_P
 
-       UESCAPE UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
+       UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
        UNLISTEN UNLOGGED UNTIL UPDATE USER USING
 
        VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
@@ -842,7 +860,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 
 
 /* Precedence: lowest to highest */
-%nonassoc      SET                             /* see relation_expr_opt_alias */
 %left          UNION EXCEPT
 %left          INTERSECT
 %left          OR
@@ -853,18 +870,23 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %nonassoc      BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
 %nonassoc      ESCAPE                  /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
 
-/* SQL/JSON related keywords */
-%nonassoc      UNIQUE JSON
-%nonassoc      KEYS OBJECT_P SCALAR VALUE_P
-%nonassoc      WITH WITHOUT
-
 /*
- * To support target_el without AS, it used to be necessary to assign IDENT an
- * explicit precedence just less than Op.  While that's not really necessary
- * since we removed postfix operators, it's still helpful to do so because
- * there are some other unreserved keywords that need precedence assignments.
- * If those keywords have the same precedence as IDENT then they clearly act
- * the same as non-keywords, reducing the risk of unwanted precedence effects.
+ * Sometimes it is necessary to assign precedence to keywords that are not
+ * really part of the operator hierarchy, in order to resolve grammar
+ * ambiguities.  It's best to avoid doing so whenever possible, because such
+ * assignments have global effect and may hide ambiguities besides the one
+ * you intended to solve.  (Attaching a precedence to a single rule with
+ * %prec is far safer and should be preferred.)  If you must give precedence
+ * to a new keyword, try very hard to give it the same precedence as IDENT.
+ * If the keyword has IDENT's precedence then it clearly acts the same as
+ * non-keywords and other similar keywords, thus reducing the risk of
+ * unexpected precedence effects.
+ *
+ * We used to need to assign IDENT an explicit precedence just less than Op,
+ * to support target_el without AS.  While that's not really necessary since
+ * we removed postfix operators, we continue to do so because it provides a
+ * reference point for a precedence level that we can assign to other
+ * keywords that lack a natural precedence level.
  *
  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
  * opt_existing_window_name (see comment there).
@@ -882,15 +904,27 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
  * rather than reducing a conflicting rule that takes CUBE as a function name.
  * Using the same precedence as IDENT seems right for the reasons given above.
+ *
+ * SET is likewise assigned the same precedence as IDENT, to support the
+ * relation_expr_opt_alias production (see comment there).
+ *
+ * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
+ * the same precedence as IDENT.  This allows resolving conflicts in the
+ * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
+ * productions (see comments there).
+ *
+ * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
+ * precedence than PATH to fix ambiguity in the json_table production.
  */
-%nonassoc      UNBOUNDED               /* ideally would have same precedence as IDENT */
+%nonassoc      UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
 %nonassoc      IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
+                       SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
 %left          Op OPERATOR             /* multi-character ops and user-defined operators */
 %left          '+' '-'
 %left          '*' '/' '%'
 %left          '^'
 /* Unary Operators */
-%left          AT                              /* sets precedence for AT TIME ZONE */
+%left          AT                              /* sets precedence for AT TIME ZONE, AT LOCAL */
 %left          COLLATE
 %right         UMINUS
 %left          '[' ']'
@@ -2462,6 +2496,16 @@ alter_table_cmd:
                                        n->name = $3;
                                        $$ = (Node *) n;
                                }
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
+                       | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
+                               {
+                                       AlterTableCmd *n = makeNode(AlterTableCmd);
+
+                                       n->subtype = AT_SetExpression;
+                                       n->name = $3;
+                                       n->def = $8;
+                                       $$ = (Node *) n;
+                               }
                        /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
                        | ALTER opt_column ColId DROP EXPRESSION
                                {
@@ -2481,18 +2525,18 @@ alter_table_cmd:
                                        n->missing_ok = true;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
-                       | ALTER opt_column ColId SET STATISTICS SignedIconst
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
+                       | ALTER opt_column ColId SET STATISTICS set_statistics_value
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
                                        n->subtype = AT_SetStatistics;
                                        n->name = $3;
-                                       n->def = (Node *) makeInteger($6);
+                                       n->def = $6;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS <SignedIconst> */
-                       | ALTER opt_column Iconst SET STATISTICS SignedIconst
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
+                       | ALTER opt_column Iconst SET STATISTICS set_statistics_value
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
@@ -2504,7 +2548,7 @@ alter_table_cmd:
 
                                        n->subtype = AT_SetStatistics;
                                        n->num = (int16) $3;
-                                       n->def = (Node *) makeInteger($6);
+                                       n->def = $6;
                                        $$ = (Node *) n;
                                }
                        /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
@@ -2891,8 +2935,8 @@ alter_table_cmd:
                                        n->newowner = $3;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> SET ACCESS METHOD <amname> */
-                       | SET ACCESS METHOD name
+                       /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
+                       | SET ACCESS METHOD set_access_method_name
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
@@ -3103,6 +3147,16 @@ alter_identity_column_option:
                                }
                ;
 
+set_statistics_value:
+                       SignedIconst                                    { $$ = (Node *) makeInteger($1); }
+                       | DEFAULT                                               { $$ = NULL; }
+               ;
+
+set_access_method_name:
+                       ColId                                                   { $$ = $1; }
+                       | DEFAULT                                               { $$ = NULL; }
+               ;
+
 PartitionBoundSpec:
                        /* a HASH partition */
                        FOR VALUES WITH '(' hash_partbound ')'
@@ -3475,10 +3529,18 @@ copy_opt_item:
                                {
                                        $$ = makeDefElem("force_not_null", (Node *) $4, @1);
                                }
+                       | FORCE NOT NULL_P '*'
+                               {
+                                       $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
+                               }
                        | FORCE NULL_P columnList
                                {
                                        $$ = makeDefElem("force_null", (Node *) $3, @1);
                                }
+                       | FORCE NULL_P '*'
+                               {
+                                       $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
+                               }
                        | ENCODING Sconst
                                {
                                        $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
@@ -3531,6 +3593,7 @@ copy_generic_opt_arg:
                        opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
                        | NumericOnly                                   { $$ = (Node *) $1; }
                        | '*'                                                   { $$ = (Node *) makeNode(A_Star); }
+                       | DEFAULT                       { $$ = (Node *) makeString("default"); }
                        | '(' copy_generic_opt_arg_list ')'             { $$ = (Node *) $2; }
                        | /* EMPTY */                                   { $$ = NULL; }
                ;
@@ -4247,6 +4310,60 @@ ConstraintElem:
                                }
                ;
 
+/*
+ * DomainConstraint is separate from TableConstraint because the syntax for
+ * NOT NULL constraints is different.  For table constraints, we need to
+ * accept a column name, but for domain constraints, we don't.  (We could
+ * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
+ * (which uses ColQualList) has for a long time accepted NOT NULL without a
+ * column name, so it makes sense that ALTER DOMAIN (which uses
+ * DomainConstraint) does as well.  None of these syntaxes are per SQL
+ * standard; we are just living with the bits of inconsistency that have built
+ * up over time.
+ */
+DomainConstraint:
+                       CONSTRAINT name DomainConstraintElem
+                               {
+                                       Constraint *n = castNode(Constraint, $3);
+
+                                       n->conname = $2;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | DomainConstraintElem                                  { $$ = $1; }
+               ;
+
+DomainConstraintElem:
+                       CHECK '(' a_expr ')' ConstraintAttributeSpec
+                               {
+                                       Constraint *n = makeNode(Constraint);
+
+                                       n->contype = CONSTR_CHECK;
+                                       n->location = @1;
+                                       n->raw_expr = $3;
+                                       n->cooked_expr = NULL;
+                                       processCASbits($5, @5, "CHECK",
+                                                                  NULL, NULL, &n->skip_validation,
+                                                                  &n->is_no_inherit, yyscanner);
+                                       n->initially_valid = !n->skip_validation;
+                                       $$ = (Node *) n;
+                               }
+                       | NOT NULL_P ConstraintAttributeSpec
+                               {
+                                       Constraint *n = makeNode(Constraint);
+
+                                       n->contype = CONSTR_NOTNULL;
+                                       n->location = @1;
+                                       n->keys = list_make1(makeString("value"));
+                                       /* no NOT VALID support yet */
+                                       processCASbits($3, @3, "NOT NULL",
+                                                                  NULL, NULL, NULL,
+                                                                  &n->is_no_inherit, yyscanner);
+                                       n->initially_valid = true;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
 opt_no_inherit:        NO INHERIT                                                      {  $$ = true; }
                        | /* EMPTY */                                                   {  $$ = false; }
                ;
@@ -4601,7 +4718,7 @@ stats_param:      ColId
  *****************************************************************************/
 
 AlterStatsStmt:
-                       ALTER STATISTICS any_name SET STATISTICS SignedIconst
+                       ALTER STATISTICS any_name SET STATISTICS set_statistics_value
                                {
                                        AlterStatsStmt *n = makeNode(AlterStatsStmt);
 
@@ -4610,7 +4727,7 @@ AlterStatsStmt:
                                        n->stxstattarget = $6;
                                        $$ = (Node *) n;
                                }
-                       | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS SignedIconst
+                       | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
                                {
                                        AlterStatsStmt *n = makeNode(AlterStatsStmt);
 
@@ -6445,6 +6562,33 @@ AlterEnumStmt:
                                n->skipIfNewValExists = false;
                                $$ = (Node *) n;
                        }
+                | ALTER TYPE_P any_name DROP VALUE_P Sconst
+                       {
+                               /*
+                                * The following problems must be solved before this can be
+                                * implemented:
+                                *
+                                * - There must be no instance of the target value in
+                                *   any table.
+                                *
+                                * - The value must not appear in any catalog metadata,
+                                *   such as stored view expressions or column defaults.
+                                *
+                                * - The value must not appear in any non-leaf page of a
+                                *   btree (and similar issues with other index types).
+                                *   This is problematic because a value could persist
+                                *   there long after it's gone from user-visible data.
+                                *
+                                * - Concurrent sessions must not be able to insert the
+                                *   value while the preceding conditions are being checked.
+                                *
+                                * - Possibly more...
+                                */
+                               ereport(ERROR,
+                                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                errmsg("dropping an enum value is not implemented"),
+                                                parser_errposition(@4)));
+                       }
                 ;
 
 opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
@@ -10157,6 +10301,8 @@ operator_def_elem: ColLabel '=' NONE
                                                { $$ = makeDefElem($1, NULL, @1); }
                                   | ColLabel '=' operator_def_arg
                                                { $$ = makeDefElem($1, (Node *) $3, @1); }
+                                  | ColLabel
+                                               { $$ = makeDefElem($1, NULL, @1); }
                ;
 
 /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
@@ -10899,6 +11045,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_ROLLBACK;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | START TRANSACTION transaction_mode_list_or_empty
@@ -10907,6 +11054,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_START;
                                        n->options = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | COMMIT opt_transaction opt_transaction_chain
@@ -10916,6 +11064,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_COMMIT;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction opt_transaction_chain
@@ -10925,6 +11074,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_ROLLBACK;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | SAVEPOINT ColId
@@ -10933,6 +11083,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_SAVEPOINT;
                                        n->savepoint_name = $2;
+                                       n->location = @2;
                                        $$ = (Node *) n;
                                }
                        | RELEASE SAVEPOINT ColId
@@ -10941,6 +11092,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_RELEASE;
                                        n->savepoint_name = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | RELEASE ColId
@@ -10949,6 +11101,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_RELEASE;
                                        n->savepoint_name = $2;
+                                       n->location = @2;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction TO SAVEPOINT ColId
@@ -10957,6 +11110,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_TO;
                                        n->savepoint_name = $5;
+                                       n->location = @5;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction TO ColId
@@ -10965,6 +11119,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_TO;
                                        n->savepoint_name = $4;
+                                       n->location = @4;
                                        $$ = (Node *) n;
                                }
                        | PREPARE TRANSACTION Sconst
@@ -10973,6 +11128,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_PREPARE;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | COMMIT PREPARED Sconst
@@ -10981,6 +11137,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_COMMIT_PREPARED;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK PREPARED Sconst
@@ -10989,6 +11146,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_PREPARED;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                ;
@@ -11000,6 +11158,7 @@ TransactionStmtLegacy:
 
                                        n->kind = TRANS_STMT_BEGIN;
                                        n->options = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | END_P opt_transaction opt_transaction_chain
@@ -11009,6 +11168,7 @@ TransactionStmtLegacy:
                                        n->kind = TRANS_STMT_COMMIT;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                ;
@@ -11441,7 +11601,7 @@ AlterDomainStmt:
                                        $$ = (Node *) n;
                                }
                        /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
-                       | ALTER DOMAIN_P any_name ADD_P TableConstraint
+                       | ALTER DOMAIN_P any_name ADD_P DomainConstraint
                                {
                                        AlterDomainStmt *n = makeNode(AlterDomainStmt);
 
@@ -11612,35 +11772,44 @@ CreateConversionStmt:
 /*****************************************************************************
  *
  *             QUERY:
- *                             CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
- *                             CLUSTER [ (options) ] <qualified_name> [ USING <index_name> ]
- *                             CLUSTER [VERBOSE]
+ *                             CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
+ *                             CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
  *                             CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
  *
  *****************************************************************************/
 
 ClusterStmt:
-                       CLUSTER opt_verbose qualified_name cluster_index_specification
+                       CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
 
-                                       n->relation = $3;
-                                       n->indexname = $4;
-                                       n->params = NIL;
-                                       if ($2)
-                                               n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
+                                       n->relation = $5;
+                                       n->indexname = $6;
+                                       n->params = $3;
                                        $$ = (Node *) n;
                                }
-
-                       | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
+                       | CLUSTER '(' utility_option_list ')'
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
 
-                                       n->relation = $5;
-                                       n->indexname = $6;
+                                       n->relation = NULL;
+                                       n->indexname = NULL;
                                        n->params = $3;
                                        $$ = (Node *) n;
                                }
+                       /* unparenthesized VERBOSE kept for pre-14 compatibility */
+                       | CLUSTER opt_verbose qualified_name cluster_index_specification
+                               {
+                                       ClusterStmt *n = makeNode(ClusterStmt);
+
+                                       n->relation = $3;
+                                       n->indexname = $4;
+                                       n->params = NIL;
+                                       if ($2)
+                                               n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
+                                       $$ = (Node *) n;
+                               }
+                       /* unparenthesized VERBOSE kept for pre-17 compatibility */
                        | CLUSTER opt_verbose
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
@@ -11971,6 +12140,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = $2;
+                                               n->isall = false;
+                                               n->location = @2;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE PREPARE name
@@ -11978,6 +12149,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = $3;
+                                               n->isall = false;
+                                               n->location = @3;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE ALL
@@ -11985,6 +12158,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = NULL;
+                                               n->isall = true;
+                                               n->location = -1;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE PREPARE ALL
@@ -11992,6 +12167,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = NULL;
+                                               n->isall = true;
+                                               n->location = -1;
                                                $$ = (Node *) n;
                                        }
                ;
@@ -12304,6 +12481,7 @@ MergeStmt:
                        USING table_ref
                        ON a_expr
                        merge_when_list
+                       returning_clause
                                {
                                        MergeStmt  *m = makeNode(MergeStmt);
 
@@ -12312,6 +12490,7 @@ MergeStmt:
                                        m->sourceRelation = $6;
                                        m->joinCondition = $8;
                                        m->mergeWhenClauses = $9;
+                                       m->returningList = $10;
 
                                        $$ = (Node *) m;
                                }
@@ -12322,50 +12501,66 @@ merge_when_list:
                        | merge_when_list merge_when_clause             { $$ = lappend($1,$2); }
                ;
 
+/*
+ * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
+ * MATCHED [BY TARGET]. The first two cases match target tuples, and support
+ * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
+ * tuples, and only supports INSERT/DO NOTHING actions.
+ */
 merge_when_clause:
-                       WHEN MATCHED opt_merge_when_condition THEN merge_update
+                       merge_when_tgt_matched opt_merge_when_condition THEN merge_update
                                {
-                                       $5->matched = true;
-                                       $5->condition = $3;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $5;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN MATCHED opt_merge_when_condition THEN merge_delete
+                       | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
                                {
-                                       $5->matched = true;
-                                       $5->condition = $3;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $5;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN NOT MATCHED opt_merge_when_condition THEN merge_insert
+                       | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
                                {
-                                       $6->matched = false;
-                                       $6->condition = $4;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $6;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN MATCHED opt_merge_when_condition THEN DO NOTHING
+                       | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
                                {
                                        MergeWhenClause *m = makeNode(MergeWhenClause);
 
-                                       m->matched = true;
+                                       m->matchKind = $1;
                                        m->commandType = CMD_NOTHING;
-                                       m->condition = $3;
+                                       m->condition = $2;
 
                                        $$ = (Node *) m;
                                }
-                       | WHEN NOT MATCHED opt_merge_when_condition THEN DO NOTHING
+                       | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
                                {
                                        MergeWhenClause *m = makeNode(MergeWhenClause);
 
-                                       m->matched = false;
+                                       m->matchKind = $1;
                                        m->commandType = CMD_NOTHING;
-                                       m->condition = $4;
+                                       m->condition = $2;
 
                                        $$ = (Node *) m;
                                }
                ;
 
+merge_when_tgt_matched:
+                       WHEN MATCHED                                    { $$ = MERGE_WHEN_MATCHED; }
+                       | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
+               ;
+
+merge_when_tgt_not_matched:
+                       WHEN NOT MATCHED                                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
+                       | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
+               ;
+
 opt_merge_when_condition:
                        AND a_expr                              { $$ = $2; }
                        |                                               { $$ = NULL; }
@@ -13372,6 +13567,21 @@ table_ref:     relation_expr opt_alias_clause
                                        $2->alias = $4;
                                        $$ = (Node *) $2;
                                }
+                       | json_table opt_alias_clause
+                               {
+                                       JsonTable  *jt = castNode(JsonTable, $1);
+
+                                       jt->alias = $2;
+                                       $$ = (Node *) jt;
+                               }
+                       | LATERAL_P json_table opt_alias_clause
+                               {
+                                       JsonTable  *jt = castNode(JsonTable, $2);
+
+                                       jt->alias = $3;
+                                       jt->lateral = true;
+                                       $$ = (Node *) jt;
+                               }
                ;
 
 
@@ -13939,6 +14149,8 @@ xmltable_column_option_el:
                                { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
                        | NULL_P
                                { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
+                       | PATH b_expr
+                               { $$ = makeDefElem("path", $2, @1); }
                ;
 
 xml_namespace_list:
@@ -13967,6 +14179,152 @@ xml_namespace_el:
                                }
                ;
 
+json_table:
+                       JSON_TABLE '('
+                               json_value_expr ',' a_expr json_table_path_name_opt
+                               json_passing_clause_opt
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               json_on_error_clause_opt
+                       ')'
+                               {
+                                       JsonTable *n = makeNode(JsonTable);
+                                       char      *pathstring;
+
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       if (!IsA($5, A_Const) ||
+                                               castNode(A_Const, $5)->val.node.type != T_String)
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                                errmsg("only string constants are supported in JSON_TABLE path specification"),
+                                                                parser_errposition(@5)));
+                                       pathstring = castNode(A_Const, $5)->val.sval.sval;
+                                       n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
+                                       n->passing = $7;
+                                       n->columns = $10;
+                                       n->on_error = (JsonBehavior *) $12;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
+json_table_path_name_opt:
+                       AS name                 { $$ = $2; }
+                       | /* empty */   { $$ = NULL; }
+               ;
+
+json_table_column_definition_list:
+                       json_table_column_definition
+                               { $$ = list_make1($1); }
+                       | json_table_column_definition_list ',' json_table_column_definition
+                               { $$ = lappend($1, $3); }
+               ;
+
+json_table_column_definition:
+                       ColId FOR ORDINALITY
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_FOR_ORDINALITY;
+                                       n->name = $1;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename
+                               json_table_column_path_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_REGULAR;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
+                                       n->pathspec = (JsonTablePathSpec *) $3;
+                                       n->wrapper = $4;
+                                       n->quotes = $5;
+                                       n->on_empty = (JsonBehavior *) linitial($6);
+                                       n->on_error = (JsonBehavior *) lsecond($6);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename json_format_clause
+                               json_table_column_path_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_FORMATTED;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = (JsonFormat *) $3;
+                                       n->pathspec = (JsonTablePathSpec *) $4;
+                                       n->wrapper = $5;
+                                       n->quotes = $6;
+                                       n->on_empty = (JsonBehavior *) linitial($7);
+                                       n->on_error = (JsonBehavior *) lsecond($7);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename
+                               EXISTS json_table_column_path_clause_opt
+                               json_on_error_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_EXISTS;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
+                                       n->wrapper = JSW_NONE;
+                                       n->quotes = JS_QUOTES_UNSPEC;
+                                       n->pathspec = (JsonTablePathSpec *) $4;
+                                       n->on_empty = NULL;
+                                       n->on_error = (JsonBehavior *) $5;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | NESTED path_opt Sconst
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_NESTED;
+                                       n->pathspec = (JsonTablePathSpec *)
+                                               makeJsonTablePathSpec($3, NULL, @3, -1);
+                                       n->columns = $6;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | NESTED path_opt Sconst AS name
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_NESTED;
+                                       n->pathspec = (JsonTablePathSpec *)
+                                               makeJsonTablePathSpec($3, $5, @3, @5);
+                                       n->columns = $8;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
+path_opt:
+                       PATH
+                       | /* EMPTY */
+               ;
+
+json_table_column_path_clause_opt:
+                       PATH Sconst
+                               { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
+                       | /* EMPTY */
+                               { $$ = NULL; }
+               ;
+
 /*****************************************************************************
  *
  *     Type syntax
@@ -14039,6 +14397,7 @@ SimpleTypename:
                                        $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
                                                                                         makeIntConst($3, @3));
                                }
+                       | JsonType                                                              { $$ = $1; }
                ;
 
 /* We have a separate ConstTypename to allow defaulting fixed-length
@@ -14057,6 +14416,7 @@ ConstTypename:
                        | ConstBit                                                              { $$ = $1; }
                        | ConstCharacter                                                { $$ = $1; }
                        | ConstDatetime                                                 { $$ = $1; }
+                       | JsonType                                                              { $$ = $1; }
                ;
 
 /*
@@ -14425,6 +14785,13 @@ interval_second:
                                }
                ;
 
+JsonType:
+                       JSON
+                               {
+                                       $$ = SystemTypeName("json");
+                                       $$->location = @1;
+                               }
+               ;
 
 /*****************************************************************************
  *
@@ -14473,6 +14840,13 @@ a_expr:                c_expr                                                                  { $$ = $1; }
                                                                                           COERCE_SQL_SYNTAX,
                                                                                           @2);
                                }
+                       | a_expr AT LOCAL                                               %prec AT
+                               {
+                                       $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
+                                                                                          list_make1($1),
+                                                                                          COERCE_SQL_SYNTAX,
+                                                                                          -1);
+                               }
                /*
                 * These operators must be called out explicitly in order to make use
                 * of bison's automatic operator-precedence handling.  All other
@@ -14905,12 +15279,11 @@ a_expr:               c_expr                                                                  { $$ = $1; }
                        /*
                         * Required by SQL/JSON, but there are conflicts
                        | a_expr
-                               FORMAT_LA JSON json_encoding_clause_opt
+                               json_format_clause
                                IS  json_predicate_type_constraint
                                        json_key_uniqueness_constraint_opt              %prec IS
                                {
-                                       $3.location = @2;
-                                       $$ = makeJsonIsPredicate($1, $3, $5, $6, @1);
+                                       $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
                                }
                        */
                        | a_expr IS NOT
@@ -14924,13 +15297,12 @@ a_expr:               c_expr                                                                  { $$ = $1; }
                        /*
                         * Required by SQL/JSON, but there are conflicts
                        | a_expr
-                               FORMAT_LA JSON json_encoding_clause_opt
+                               json_format_clause
                                IS NOT
                                        json_predicate_type_constraint
                                        json_key_uniqueness_constraint_opt              %prec IS
                                {
-                                       $3.location = @2;
-                                       $$ = makeNotExpr(makeJsonIsPredicate($1, $3, $6, $7, @1), @1);
+                                       $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
                                }
                        */
                        | DEFAULT
@@ -15301,7 +15673,7 @@ func_expr: func_application within_group_clause filter_clause over_clause
                ;
 
 /*
- * As func_expr but does not accept WINDOW functions directly
+ * Like func_expr but does not accept WINDOW functions directly
  * (but they can still be contained in arguments for functions etc).
  * Use this when window expressions are not allowed, where needed to
  * disambiguate the grammar (e.g. in CREATE INDEX).
@@ -15619,7 +15991,7 @@ func_expr_common_subexpr:
                        | JSON_OBJECT '(' json_name_and_value_list
                                json_object_constructor_null_clause_opt
                                json_key_uniqueness_constraint_opt
-                               json_output_clause_opt ')'
+                               json_returning_clause_opt ')'
                                {
                                        JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
 
@@ -15630,7 +16002,7 @@ func_expr_common_subexpr:
                                        n->location = @1;
                                        $$ = (Node *) n;
                                }
-                       | JSON_OBJECT '(' json_output_clause_opt ')'
+                       | JSON_OBJECT '(' json_returning_clause_opt ')'
                                {
                                        JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
 
@@ -15644,7 +16016,7 @@ func_expr_common_subexpr:
                        | JSON_ARRAY '('
                                json_value_expr_list
                                json_array_constructor_null_clause_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
@@ -15659,7 +16031,7 @@ func_expr_common_subexpr:
                                select_no_parens
                                json_format_clause_opt
                                /* json_array_constructor_null_clause_opt */
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
@@ -15672,7 +16044,7 @@ func_expr_common_subexpr:
                                        $$ = (Node *) n;
                                }
                        | JSON_ARRAY '('
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
@@ -15683,7 +16055,100 @@ func_expr_common_subexpr:
                                        n->location = @1;
                                        $$ = (Node *) n;
                                }
-               ;
+                       | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
+                               {
+                                       JsonParseExpr *n = makeNode(JsonParseExpr);
+
+                                       n->expr = (JsonValueExpr *) $3;
+                                       n->unique_keys = $4;
+                                       n->output = NULL;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_SCALAR '(' a_expr ')'
+                               {
+                                       JsonScalarExpr *n = makeNode(JsonScalarExpr);
+
+                                       n->expr = (Expr *) $3;
+                                       n->output = NULL;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
+                               {
+                                       JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
+
+                                       n->expr = (JsonValueExpr *) $3;
+                                       n->output = (JsonOutput *) $4;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | MERGE_ACTION '(' ')'
+                               {
+                                       MergeSupportFunc *m = makeNode(MergeSupportFunc);
+
+                                       m->msftype = TEXTOID;
+                                       m->location = @1;
+                                       $$ = (Node *) m;
+                               }
+                       | JSON_QUERY '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_returning_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_QUERY_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = (JsonOutput *) $7;
+                                       n->wrapper = $8;
+                                       n->quotes = $9;
+                                       n->on_empty = (JsonBehavior *) linitial($10);
+                                       n->on_error = (JsonBehavior *) lsecond($10);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_EXISTS '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_on_error_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_EXISTS_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = NULL;
+                                       n->on_error = (JsonBehavior *) $7;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_VALUE '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_returning_clause_opt
+                               json_behavior_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_VALUE_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = (JsonOutput *) $7;
+                                       n->on_empty = (JsonBehavior *) linitial($8);
+                                       n->on_error = (JsonBehavior *) lsecond($8);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       ;
+
 
 /*
  * SQL/XML support
@@ -16408,6 +16873,77 @@ opt_asymmetric: ASYMMETRIC
                ;
 
 /* SQL/JSON support */
+json_passing_clause_opt:
+                       PASSING json_arguments                                  { $$ = $2; }
+                       | /*EMPTY*/                                                             { $$ = NIL; }
+               ;
+
+json_arguments:
+                       json_argument                                                   { $$ = list_make1($1); }
+                       | json_arguments ',' json_argument              { $$ = lappend($1, $3); }
+               ;
+
+json_argument:
+                       json_value_expr AS ColLabel
+                       {
+                               JsonArgument *n = makeNode(JsonArgument);
+
+                               n->val = (JsonValueExpr *) $1;
+                               n->name = $3;
+                               $$ = (Node *) n;
+                       }
+               ;
+
+/* ARRAY is a noise word */
+json_wrapper_behavior:
+                         WITHOUT WRAPPER                                       { $$ = JSW_NONE; }
+                       | WITHOUT ARRAY WRAPPER                         { $$ = JSW_NONE; }
+                       | WITH WRAPPER                                          { $$ = JSW_UNCONDITIONAL; }
+                       | WITH ARRAY WRAPPER                            { $$ = JSW_UNCONDITIONAL; }
+                       | WITH CONDITIONAL ARRAY WRAPPER        { $$ = JSW_CONDITIONAL; }
+                       | WITH UNCONDITIONAL ARRAY WRAPPER      { $$ = JSW_UNCONDITIONAL; }
+                       | WITH CONDITIONAL WRAPPER                      { $$ = JSW_CONDITIONAL; }
+                       | WITH UNCONDITIONAL WRAPPER            { $$ = JSW_UNCONDITIONAL; }
+                       | /* empty */                                           { $$ = JSW_UNSPEC; }
+               ;
+
+json_behavior:
+                       DEFAULT a_expr
+                               { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
+                       | json_behavior_type
+                               { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
+               ;
+
+json_behavior_type:
+                       ERROR_P         { $$ = JSON_BEHAVIOR_ERROR; }
+                       | NULL_P        { $$ = JSON_BEHAVIOR_NULL; }
+                       | TRUE_P        { $$ = JSON_BEHAVIOR_TRUE; }
+                       | FALSE_P       { $$ = JSON_BEHAVIOR_FALSE; }
+                       | UNKNOWN       { $$ = JSON_BEHAVIOR_UNKNOWN; }
+                       | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
+                       | EMPTY_P OBJECT_P      { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
+                       /* non-standard, for Oracle compatibility only */
+                       | EMPTY_P       { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
+               ;
+
+json_behavior_clause_opt:
+                       json_behavior ON EMPTY_P
+                               { $$ = list_make2($1, NULL); }
+                       | json_behavior ON ERROR_P
+                               { $$ = list_make2(NULL, $1); }
+                       | json_behavior ON EMPTY_P json_behavior ON ERROR_P
+                               { $$ = list_make2($1, $4); }
+                       | /* EMPTY */
+                               { $$ = list_make2(NULL, NULL); }
+               ;
+
+json_on_error_clause_opt:
+                       json_behavior ON ERROR_P
+                               { $$ = $1; }
+                       | /* EMPTY */
+                               { $$ = NULL; }
+               ;
+
 json_value_expr:
                        a_expr json_format_clause_opt
                        {
@@ -16417,10 +16953,34 @@ json_value_expr:
                        }
                ;
 
+json_format_clause:
+                       FORMAT_LA JSON ENCODING name
+                               {
+                                       int             encoding;
+
+                                       if (!pg_strcasecmp($4, "utf8"))
+                                               encoding = JS_ENC_UTF8;
+                                       else if (!pg_strcasecmp($4, "utf16"))
+                                               encoding = JS_ENC_UTF16;
+                                       else if (!pg_strcasecmp($4, "utf32"))
+                                               encoding = JS_ENC_UTF32;
+                                       else
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                                                errmsg("unrecognized JSON encoding: %s", $4)));
+
+                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
+                               }
+                       | FORMAT_LA JSON
+                               {
+                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
+                               }
+               ;
+
 json_format_clause_opt:
-                       FORMAT_LA JSON json_encoding_clause_opt
+                       json_format_clause
                                {
-                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, $3, @1);
+                                       $$ = $1;
                                }
                        | /* EMPTY */
                                {
@@ -16428,12 +16988,15 @@ json_format_clause_opt:
                                }
                ;
 
-json_encoding_clause_opt:
-                       ENCODING name                                   { $$ = makeJsonEncoding($2); }
-                       | /* EMPTY */                                   { $$ = JS_ENC_DEFAULT; }
+json_quotes_clause_opt:
+                       KEEP QUOTES ON SCALAR STRING_P          { $$ = JS_QUOTES_KEEP; }
+                       | KEEP QUOTES                                           { $$ = JS_QUOTES_KEEP; }
+                       | OMIT QUOTES ON SCALAR STRING_P        { $$ = JS_QUOTES_OMIT; }
+                       | OMIT QUOTES                                           { $$ = JS_QUOTES_OMIT; }
+                       | /* EMPTY */                                           { $$ = JS_QUOTES_UNSPEC; }
                ;
 
-json_output_clause_opt:
+json_returning_clause_opt:
                        RETURNING Typename json_format_clause_opt
                                {
                                        JsonOutput *n = makeNode(JsonOutput);
@@ -16446,21 +17009,35 @@ json_output_clause_opt:
                        | /* EMPTY */                                                   { $$ = NULL; }
                ;
 
+/*
+ * We must assign the only-JSON production a precedence less than IDENT in
+ * order to favor shifting over reduction when JSON is followed by VALUE_P,
+ * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
+ * fully reserved word.)  Because json_predicate_type_constraint is always
+ * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
+ * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
+ * really related to this syntax, but it's a convenient choice because it
+ * already has a precedence less than IDENT for other reasons.
+ */
 json_predicate_type_constraint:
-                       JSON                                                                    { $$ = JS_TYPE_ANY; }
+                       JSON                                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
                        | JSON VALUE_P                                                  { $$ = JS_TYPE_ANY; }
                        | JSON ARRAY                                                    { $$ = JS_TYPE_ARRAY; }
                        | JSON OBJECT_P                                                 { $$ = JS_TYPE_OBJECT; }
                        | JSON SCALAR                                                   { $$ = JS_TYPE_SCALAR; }
                ;
 
-/* KEYS is a noise word here */
+/*
+ * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
+ * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
+ * This prevents reducing them when the next token is KEYS.
+ */
 json_key_uniqueness_constraint_opt:
                        WITH UNIQUE KEYS                                                        { $$ = true; }
-                       | WITH UNIQUE                                                           { $$ = true; }
+                       | WITH UNIQUE                           %prec UNBOUNDED { $$ = true; }
                        | WITHOUT UNIQUE KEYS                                           { $$ = false; }
-                       | WITHOUT UNIQUE                                                        { $$ = false; }
-                       | /* EMPTY */                           %prec KEYS              { $$ = false; }
+                       | WITHOUT UNIQUE                        %prec UNBOUNDED { $$ = false; }
+                       | /* EMPTY */                           %prec UNBOUNDED { $$ = false; }
                ;
 
 json_name_and_value_list:
@@ -16506,7 +17083,7 @@ json_aggregate_func:
                                json_name_and_value
                                json_object_constructor_null_clause_opt
                                json_key_uniqueness_constraint_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonObjectAgg *n = makeNode(JsonObjectAgg);
@@ -16524,7 +17101,7 @@ json_aggregate_func:
                                json_value_expr
                                json_array_aggregate_order_by_clause_opt
                                json_array_constructor_null_clause_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayAgg *n = makeNode(JsonArrayAgg);
@@ -17035,6 +17612,7 @@ unreserved_keyword:
                        | COMMIT
                        | COMMITTED
                        | COMPRESSION
+                       | CONDITIONAL
                        | CONFIGURATION
                        | CONFLICT
                        | CONNECTION
@@ -17071,10 +17649,12 @@ unreserved_keyword:
                        | DOUBLE_P
                        | DROP
                        | EACH
+                       | EMPTY_P
                        | ENABLE_P
                        | ENCODING
                        | ENCRYPTED
                        | ENUM_P
+                       | ERROR_P
                        | ESCAPE
                        | EVENT
                        | EXCLUDE
@@ -17124,7 +17704,7 @@ unreserved_keyword:
                        | INSTEAD
                        | INVOKER
                        | ISOLATION
-                       | JSON
+                       | KEEP
                        | KEY
                        | KEYS
                        | LABEL
@@ -17154,6 +17734,7 @@ unreserved_keyword:
                        | MOVE
                        | NAME_P
                        | NAMES
+                       | NESTED
                        | NEW
                        | NEXT
                        | NFC
@@ -17171,6 +17752,7 @@ unreserved_keyword:
                        | OFF
                        | OIDS
                        | OLD
+                       | OMIT
                        | OPERATOR
                        | OPTION
                        | OPTIONS
@@ -17187,6 +17769,8 @@ unreserved_keyword:
                        | PARTITION
                        | PASSING
                        | PASSWORD
+                       | PATH
+                       | PLAN
                        | PLANS
                        | POLICY
                        | PRECEDING
@@ -17201,6 +17785,7 @@ unreserved_keyword:
                        | PROGRAM
                        | PUBLICATION
                        | QUOTE
+                       | QUOTES
                        | RANGE
                        | READ
                        | REASSIGN
@@ -17249,6 +17834,7 @@ unreserved_keyword:
                        | SIMPLE
                        | SKIP
                        | SNAPSHOT
+                       | SOURCE
                        | SQL_P
                        | STABLE
                        | STANDALONE_P
@@ -17260,6 +17846,7 @@ unreserved_keyword:
                        | STORAGE
                        | STORED
                        | STRICT_P
+                       | STRING_P
                        | STRIP_P
                        | SUBSCRIPTION
                        | SUPPORT
@@ -17267,6 +17854,7 @@ unreserved_keyword:
                        | SYSTEM_P
                        | TABLES
                        | TABLESPACE
+                       | TARGET
                        | TEMP
                        | TEMPLATE
                        | TEMPORARY
@@ -17282,6 +17870,7 @@ unreserved_keyword:
                        | UESCAPE
                        | UNBOUNDED
                        | UNCOMMITTED
+                       | UNCONDITIONAL
                        | UNENCRYPTED
                        | UNKNOWN
                        | UNLISTEN
@@ -17339,11 +17928,19 @@ col_name_keyword:
                        | INT_P
                        | INTEGER
                        | INTERVAL
+                       | JSON
                        | JSON_ARRAY
                        | JSON_ARRAYAGG
+                       | JSON_EXISTS
                        | JSON_OBJECT
                        | JSON_OBJECTAGG
+                       | JSON_QUERY
+                       | JSON_SCALAR
+                       | JSON_SERIALIZE
+                       | JSON_TABLE
+                       | JSON_VALUE
                        | LEAST
+                       | MERGE_ACTION
                        | NATIONAL
                        | NCHAR
                        | NONE
@@ -17575,6 +18172,7 @@ bare_label_keyword:
                        | COMMITTED
                        | COMPRESSION
                        | CONCURRENTLY
+                       | CONDITIONAL
                        | CONFIGURATION
                        | CONFLICT
                        | CONNECTION
@@ -17627,11 +18225,13 @@ bare_label_keyword:
                        | DROP
                        | EACH
                        | ELSE
+                       | EMPTY_P
                        | ENABLE_P
                        | ENCODING
                        | ENCRYPTED
                        | END_P
                        | ENUM_P
+                       | ERROR_P
                        | ESCAPE
                        | EVENT
                        | EXCLUDE
@@ -17701,8 +18301,15 @@ bare_label_keyword:
                        | JSON
                        | JSON_ARRAY
                        | JSON_ARRAYAGG
+                       | JSON_EXISTS
                        | JSON_OBJECT
                        | JSON_OBJECTAGG
+                       | JSON_QUERY
+                       | JSON_SCALAR
+                       | JSON_SERIALIZE
+                       | JSON_TABLE
+                       | JSON_VALUE
+                       | KEEP
                        | KEY
                        | KEYS
                        | LABEL
@@ -17731,6 +18338,7 @@ bare_label_keyword:
                        | MATERIALIZED
                        | MAXVALUE
                        | MERGE
+                       | MERGE_ACTION
                        | METHOD
                        | MINVALUE
                        | MODE
@@ -17740,6 +18348,7 @@ bare_label_keyword:
                        | NATIONAL
                        | NATURAL
                        | NCHAR
+                       | NESTED
                        | NEW
                        | NEXT
                        | NFC
@@ -17763,6 +18372,7 @@ bare_label_keyword:
                        | OFF
                        | OIDS
                        | OLD
+                       | OMIT
                        | ONLY
                        | OPERATOR
                        | OPTION
@@ -17783,7 +18393,9 @@ bare_label_keyword:
                        | PARTITION
                        | PASSING
                        | PASSWORD
+                       | PATH
                        | PLACING
+                       | PLAN
                        | PLANS
                        | POLICY
                        | POSITION
@@ -17800,6 +18412,7 @@ bare_label_keyword:
                        | PROGRAM
                        | PUBLICATION
                        | QUOTE
+                       | QUOTES
                        | RANGE
                        | READ
                        | REAL
@@ -17857,6 +18470,7 @@ bare_label_keyword:
                        | SMALLINT
                        | SNAPSHOT
                        | SOME
+                       | SOURCE
                        | SQL_P
                        | STABLE
                        | STANDALONE_P
@@ -17868,6 +18482,7 @@ bare_label_keyword:
                        | STORAGE
                        | STORED
                        | STRICT_P
+                       | STRING_P
                        | STRIP_P
                        | SUBSCRIPTION
                        | SUBSTRING
@@ -17880,6 +18495,7 @@ bare_label_keyword:
                        | TABLES
                        | TABLESAMPLE
                        | TABLESPACE
+                       | TARGET
                        | TEMP
                        | TEMPLATE
                        | TEMPORARY
@@ -17902,6 +18518,7 @@ bare_label_keyword:
                        | UESCAPE
                        | UNBOUNDED
                        | UNCOMMITTED
+                       | UNCONDITIONAL
                        | UNENCRYPTED
                        | UNIQUE
                        | UNKNOWN
@@ -18048,18 +18665,6 @@ makeTypeCast(Node *arg, TypeName *typename, int location)
        return (Node *) n;
 }
 
-static Node *
-makeStringConst(char *str, int location)
-{
-       A_Const    *n = makeNode(A_Const);
-
-       n->val.sval.type = T_String;
-       n->val.sval.sval = str;
-       n->location = location;
-
-       return (Node *) n;
-}
-
 Node *
 makeStringConstCast(char *str, int location, TypeName *typename)
 {
@@ -18339,7 +18944,7 @@ insertSelectOptions(SelectStmt *stmt,
                                         parser_errposition(exprLocation(limitClause->limitCount))));
                stmt->limitCount = limitClause->limitCount;
        }
-       if (limitClause && limitClause->limitOption != LIMIT_OPTION_DEFAULT)
+       if (limitClause)
        {
                if (stmt->limitOption)
                        ereport(ERROR,
index e897f373a639c94c74bd44c21d8172f1a2bea49b..e11074e1f08bfa27b14348307a51bf39954b5f95 100644 (file)
@@ -6,8 +6,8 @@
  * gram.y
  *       POSTGRESQL BISON rules/actions
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -204,7 +204,6 @@ static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
 static void updateRawStmtEnd(RawStmt *rs, int end_location);
 static Node *makeColumnRef(char *colname, List *indirection,
                                                   int location, core_yyscan_t yyscanner);
-static Node *makeStringConst(char *str, int location);
 static Node *makeFloatConst(char *str, int location);
 static Node *makeBoolAConst(bool state, int location);
 static Node *makeBitStringConst(char *str, int location);
@@ -307,6 +306,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        struct SelectLimit *selectlimit;
        SetQuantifier setquantifier;
        struct GroupClause *groupclause;
+       MergeMatchKind mergematch;
        MergeWhenClause *mergewhen;
        struct KeyActions *keyactions;
        struct KeyAction *keyaction;
@@ -372,6 +372,8 @@ UpdateStmtShort
 %type <list>   alter_table_cmds alter_type_cmds
 %type <list>    alter_identity_column_option_list
 %type <defelt>  alter_identity_column_option
+%type <node>   set_statistics_value
+%type <str>            set_access_method_name
 
 %type <list>   createdb_opt_list createdb_opt_items copy_opt_list
                                transaction_mode_list
@@ -549,13 +551,14 @@ UpdateStmtShort
 %type <onconflict> opt_on_conflict
 %type <mergewhen>      merge_insert merge_update merge_delete
 
+%type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
 %type <node>   merge_when_clause opt_merge_when_condition
 %type <list>   merge_when_list
 
 %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
                                 SetResetClause FunctionSetResetClause
 
-%type <node>   TableElement TypedTableElement ConstraintElem TableFuncElement
+%type <node>   TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
 %type <node>   columnDef columnOptions
 %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
 %type <node>   def_arg columnElem where_clause where_or_current_clause
@@ -601,7 +604,7 @@ UpdateStmtShort
 %type <list>   copy_options
 
 %type <typnam> Typename SimpleTypename ConstTypename
-                               GenericType Numeric opt_float
+                               GenericType Numeric opt_float JsonType
                                Character ConstCharacter
                                CharacterWithLength CharacterWithoutLength
                                ConstDatetime ConstInterval
@@ -626,7 +629,7 @@ UpdateStmtShort
 %type <keyword> col_name_keyword reserved_keyword
 %type <keyword> bare_label_keyword
 
-%type <node>   TableConstraint TableLikeClause
+%type <node>   DomainConstraint TableConstraint TableLikeClause
 %type <ival>   TableLikeOptionList TableLikeOption
 %type <str>            column_compression opt_column_compression column_storage opt_column_storage
 %type <list>   ColQualList
@@ -680,16 +683,30 @@ UpdateStmtShort
 %type <list>           hash_partbound
 %type <defelt>         hash_partbound_elem
 
-%type <node>   json_format_clause_opt
+%type <node>   json_format_clause
+                               json_format_clause_opt
                                json_value_expr
-                               json_output_clause_opt
+                               json_returning_clause_opt
                                json_name_and_value
                                json_aggregate_func
+                               json_argument
+                               json_behavior
+                               json_on_error_clause_opt
+                               json_table
+                               json_table_column_definition
+                               json_table_column_path_clause_opt
 %type <list>   json_name_and_value_list
                                json_value_expr_list
                                json_array_aggregate_order_by_clause_opt
-%type <ival>   json_encoding_clause_opt
+                               json_arguments
+                               json_behavior_clause_opt
+                               json_passing_clause_opt
+                               json_table_column_definition_list
+%type <str>            json_table_path_name_opt
+%type <ival>   json_behavior_type
                                json_predicate_type_constraint
+                               json_quotes_clause_opt
+                               json_wrapper_behavior
 %type <boolean>        json_key_uniqueness_constraint_opt
                                json_object_constructor_null_clause_opt
                                json_array_constructor_null_clause_opt
@@ -730,7 +747,7 @@ UpdateStmtShort
        CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
        CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
        CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
-       COMMITTED COMPRESSION CONCURRENTLY CONFIGURATION CONFLICT
+       COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
        CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
        COST CREATE CROSS CSV CUBE CURRENT_P
        CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
@@ -741,8 +758,8 @@ UpdateStmtShort
        DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
        DOUBLE_P DROP
 
-       EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
-       EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
+       EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ERROR_P ESCAPE
+       EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
        EXTENSION EXTERNAL EXTRACT
 
        FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
@@ -757,32 +774,33 @@ UpdateStmtShort
        INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
        INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
 
-       JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_OBJECT JSON_OBJECTAGG
+       JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
+       JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
 
-       KEY KEYS
+       KEEP KEY KEYS
 
        LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
        LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
        LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
 
-       MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE METHOD
+       MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
        MINUTE_P MINVALUE MODE MONTH_P MOVE
 
-       NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NFC NFD NFKC NFKD NO NONE
-       NORMALIZE NORMALIZED
+       NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
+       NONE NORMALIZE NORMALIZED
        NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
        NULLS_P NUMERIC
 
-       OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
+       OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
        ORDER ORDINALITY OTHERS OUT_P OUTER_P
        OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
 
-       PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PGPOOL
-       PLACING PLANS POLICY
+       PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH PGPOOL
+       PLACING PLAN PLANS POLICY
        POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
        PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
 
-       QUOTE
+       QUOTE QUOTES
 
        RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING
        REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
@@ -792,16 +810,16 @@ UpdateStmtShort
        SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
        SEQUENCE SEQUENCES
        SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
-       SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P
-       START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRIP_P
+       SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
+       START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
        SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
 
-       TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
+       TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
        TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
        TREAT TRIGGER TRIM TRUE_P
        TRUNCATE TRUSTED TYPE_P TYPES_P
 
-       UESCAPE UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
+       UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
        UNLISTEN UNLOGGED UNTIL UPDATE USER USING
 
        VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
@@ -844,7 +862,6 @@ UpdateStmtShort
 
 
 /* Precedence: lowest to highest */
-%nonassoc      SET                             /* see relation_expr_opt_alias */
 %left          UNION EXCEPT
 %left          INTERSECT
 %left          OR
@@ -855,18 +872,23 @@ UpdateStmtShort
 %nonassoc      BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
 %nonassoc      ESCAPE                  /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
 
-/* SQL/JSON related keywords */
-%nonassoc      UNIQUE JSON
-%nonassoc      KEYS OBJECT_P SCALAR VALUE_P
-%nonassoc      WITH WITHOUT
-
 /*
- * To support target_el without AS, it used to be necessary to assign IDENT an
- * explicit precedence just less than Op.  While that's not really necessary
- * since we removed postfix operators, it's still helpful to do so because
- * there are some other unreserved keywords that need precedence assignments.
- * If those keywords have the same precedence as IDENT then they clearly act
- * the same as non-keywords, reducing the risk of unwanted precedence effects.
+ * Sometimes it is necessary to assign precedence to keywords that are not
+ * really part of the operator hierarchy, in order to resolve grammar
+ * ambiguities.  It's best to avoid doing so whenever possible, because such
+ * assignments have global effect and may hide ambiguities besides the one
+ * you intended to solve.  (Attaching a precedence to a single rule with
+ * %prec is far safer and should be preferred.)  If you must give precedence
+ * to a new keyword, try very hard to give it the same precedence as IDENT.
+ * If the keyword has IDENT's precedence then it clearly acts the same as
+ * non-keywords and other similar keywords, thus reducing the risk of
+ * unexpected precedence effects.
+ *
+ * We used to need to assign IDENT an explicit precedence just less than Op,
+ * to support target_el without AS.  While that's not really necessary since
+ * we removed postfix operators, we continue to do so because it provides a
+ * reference point for a precedence level that we can assign to other
+ * keywords that lack a natural precedence level.
  *
  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
  * opt_existing_window_name (see comment there).
@@ -884,15 +906,27 @@ UpdateStmtShort
  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
  * rather than reducing a conflicting rule that takes CUBE as a function name.
  * Using the same precedence as IDENT seems right for the reasons given above.
+ *
+ * SET is likewise assigned the same precedence as IDENT, to support the
+ * relation_expr_opt_alias production (see comment there).
+ *
+ * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
+ * the same precedence as IDENT.  This allows resolving conflicts in the
+ * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
+ * productions (see comments there).
+ *
+ * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
+ * precedence than PATH to fix ambiguity in the json_table production.
  */
-%nonassoc      UNBOUNDED               /* ideally would have same precedence as IDENT */
+%nonassoc      UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
 %nonassoc      IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
+                       SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
 %left          Op OPERATOR             /* multi-character ops and user-defined operators */
 %left          '+' '-'
 %left          '*' '/' '%'
 %left          '^'
 /* Unary Operators */
-%left          AT                              /* sets precedence for AT TIME ZONE */
+%left          AT                              /* sets precedence for AT TIME ZONE, AT LOCAL */
 %left          COLLATE
 %right         UMINUS
 %left          '[' ']'
@@ -2464,6 +2498,16 @@ alter_table_cmd:
                                        n->name = $3;
                                        $$ = (Node *) n;
                                }
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
+                       | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
+                               {
+                                       AlterTableCmd *n = makeNode(AlterTableCmd);
+
+                                       n->subtype = AT_SetExpression;
+                                       n->name = $3;
+                                       n->def = $8;
+                                       $$ = (Node *) n;
+                               }
                        /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
                        | ALTER opt_column ColId DROP EXPRESSION
                                {
@@ -2483,18 +2527,18 @@ alter_table_cmd:
                                        n->missing_ok = true;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
-                       | ALTER opt_column ColId SET STATISTICS SignedIconst
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
+                       | ALTER opt_column ColId SET STATISTICS set_statistics_value
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
                                        n->subtype = AT_SetStatistics;
                                        n->name = $3;
-                                       n->def = (Node *) makeInteger($6);
+                                       n->def = $6;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS <SignedIconst> */
-                       | ALTER opt_column Iconst SET STATISTICS SignedIconst
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
+                       | ALTER opt_column Iconst SET STATISTICS set_statistics_value
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
@@ -2506,7 +2550,7 @@ alter_table_cmd:
 
                                        n->subtype = AT_SetStatistics;
                                        n->num = (int16) $3;
-                                       n->def = (Node *) makeInteger($6);
+                                       n->def = $6;
                                        $$ = (Node *) n;
                                }
                        /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
@@ -2893,8 +2937,8 @@ alter_table_cmd:
                                        n->newowner = $3;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> SET ACCESS METHOD <amname> */
-                       | SET ACCESS METHOD name
+                       /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
+                       | SET ACCESS METHOD set_access_method_name
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
@@ -3105,6 +3149,16 @@ alter_identity_column_option:
                                }
                ;
 
+set_statistics_value:
+                       SignedIconst                                    { $$ = (Node *) makeInteger($1); }
+                       | DEFAULT                                               { $$ = NULL; }
+               ;
+
+set_access_method_name:
+                       ColId                                                   { $$ = $1; }
+                       | DEFAULT                                               { $$ = NULL; }
+               ;
+
 PartitionBoundSpec:
                        /* a HASH partition */
                        FOR VALUES WITH '(' hash_partbound ')'
@@ -3477,10 +3531,18 @@ copy_opt_item:
                                {
                                        $$ = makeDefElem("force_not_null", (Node *) $4, @1);
                                }
+                       | FORCE NOT NULL_P '*'
+                               {
+                                       $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
+                               }
                        | FORCE NULL_P columnList
                                {
                                        $$ = makeDefElem("force_null", (Node *) $3, @1);
                                }
+                       | FORCE NULL_P '*'
+                               {
+                                       $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
+                               }
                        | ENCODING Sconst
                                {
                                        $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
@@ -3533,6 +3595,7 @@ copy_generic_opt_arg:
                        opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
                        | NumericOnly                                   { $$ = (Node *) $1; }
                        | '*'                                                   { $$ = (Node *) makeNode(A_Star); }
+                       | DEFAULT                       { $$ = (Node *) makeString("default"); }
                        | '(' copy_generic_opt_arg_list ')'             { $$ = (Node *) $2; }
                        | /* EMPTY */                                   { $$ = NULL; }
                ;
@@ -4249,6 +4312,60 @@ ConstraintElem:
                                }
                ;
 
+/*
+ * DomainConstraint is separate from TableConstraint because the syntax for
+ * NOT NULL constraints is different.  For table constraints, we need to
+ * accept a column name, but for domain constraints, we don't.  (We could
+ * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
+ * (which uses ColQualList) has for a long time accepted NOT NULL without a
+ * column name, so it makes sense that ALTER DOMAIN (which uses
+ * DomainConstraint) does as well.  None of these syntaxes are per SQL
+ * standard; we are just living with the bits of inconsistency that have built
+ * up over time.
+ */
+DomainConstraint:
+                       CONSTRAINT name DomainConstraintElem
+                               {
+                                       Constraint *n = castNode(Constraint, $3);
+
+                                       n->conname = $2;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | DomainConstraintElem                                  { $$ = $1; }
+               ;
+
+DomainConstraintElem:
+                       CHECK '(' a_expr ')' ConstraintAttributeSpec
+                               {
+                                       Constraint *n = makeNode(Constraint);
+
+                                       n->contype = CONSTR_CHECK;
+                                       n->location = @1;
+                                       n->raw_expr = $3;
+                                       n->cooked_expr = NULL;
+                                       processCASbits($5, @5, "CHECK",
+                                                                  NULL, NULL, &n->skip_validation,
+                                                                  &n->is_no_inherit, yyscanner);
+                                       n->initially_valid = !n->skip_validation;
+                                       $$ = (Node *) n;
+                               }
+                       | NOT NULL_P ConstraintAttributeSpec
+                               {
+                                       Constraint *n = makeNode(Constraint);
+
+                                       n->contype = CONSTR_NOTNULL;
+                                       n->location = @1;
+                                       n->keys = list_make1(makeString("value"));
+                                       /* no NOT VALID support yet */
+                                       processCASbits($3, @3, "NOT NULL",
+                                                                  NULL, NULL, NULL,
+                                                                  &n->is_no_inherit, yyscanner);
+                                       n->initially_valid = true;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
 opt_no_inherit:        NO INHERIT                                                      {  $$ = true; }
                        | /* EMPTY */                                                   {  $$ = false; }
                ;
@@ -4603,7 +4720,7 @@ stats_param:      ColId
  *****************************************************************************/
 
 AlterStatsStmt:
-                       ALTER STATISTICS any_name SET STATISTICS SignedIconst
+                       ALTER STATISTICS any_name SET STATISTICS set_statistics_value
                                {
                                        AlterStatsStmt *n = makeNode(AlterStatsStmt);
 
@@ -4612,7 +4729,7 @@ AlterStatsStmt:
                                        n->stxstattarget = $6;
                                        $$ = (Node *) n;
                                }
-                       | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS SignedIconst
+                       | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
                                {
                                        AlterStatsStmt *n = makeNode(AlterStatsStmt);
 
@@ -6447,6 +6564,33 @@ AlterEnumStmt:
                                n->skipIfNewValExists = false;
                                $$ = (Node *) n;
                        }
+                | ALTER TYPE_P any_name DROP VALUE_P Sconst
+                       {
+                               /*
+                                * The following problems must be solved before this can be
+                                * implemented:
+                                *
+                                * - There must be no instance of the target value in
+                                *   any table.
+                                *
+                                * - The value must not appear in any catalog metadata,
+                                *   such as stored view expressions or column defaults.
+                                *
+                                * - The value must not appear in any non-leaf page of a
+                                *   btree (and similar issues with other index types).
+                                *   This is problematic because a value could persist
+                                *   there long after it's gone from user-visible data.
+                                *
+                                * - Concurrent sessions must not be able to insert the
+                                *   value while the preceding conditions are being checked.
+                                *
+                                * - Possibly more...
+                                */
+                               ereport(ERROR,
+                                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                errmsg("dropping an enum value is not implemented"),
+                                                parser_errposition(@4)));
+                       }
                 ;
 
 opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
@@ -10159,6 +10303,8 @@ operator_def_elem: ColLabel '=' NONE
                                                { $$ = makeDefElem($1, NULL, @1); }
                                   | ColLabel '=' operator_def_arg
                                                { $$ = makeDefElem($1, (Node *) $3, @1); }
+                                  | ColLabel
+                                               { $$ = makeDefElem($1, NULL, @1); }
                ;
 
 /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
@@ -10901,6 +11047,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_ROLLBACK;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | START TRANSACTION transaction_mode_list_or_empty
@@ -10909,6 +11056,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_START;
                                        n->options = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | COMMIT opt_transaction opt_transaction_chain
@@ -10918,6 +11066,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_COMMIT;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction opt_transaction_chain
@@ -10927,6 +11076,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_ROLLBACK;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | SAVEPOINT ColId
@@ -10935,6 +11085,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_SAVEPOINT;
                                        n->savepoint_name = $2;
+                                       n->location = @2;
                                        $$ = (Node *) n;
                                }
                        | RELEASE SAVEPOINT ColId
@@ -10943,6 +11094,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_RELEASE;
                                        n->savepoint_name = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | RELEASE ColId
@@ -10951,6 +11103,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_RELEASE;
                                        n->savepoint_name = $2;
+                                       n->location = @2;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction TO SAVEPOINT ColId
@@ -10959,6 +11112,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_TO;
                                        n->savepoint_name = $5;
+                                       n->location = @5;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction TO ColId
@@ -10967,6 +11121,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_TO;
                                        n->savepoint_name = $4;
+                                       n->location = @4;
                                        $$ = (Node *) n;
                                }
                        | PREPARE TRANSACTION Sconst
@@ -10975,6 +11130,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_PREPARE;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | COMMIT PREPARED Sconst
@@ -10983,6 +11139,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_COMMIT_PREPARED;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK PREPARED Sconst
@@ -10991,6 +11148,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_PREPARED;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                ;
@@ -11002,6 +11160,7 @@ TransactionStmtLegacy:
 
                                        n->kind = TRANS_STMT_BEGIN;
                                        n->options = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | END_P opt_transaction opt_transaction_chain
@@ -11011,6 +11170,7 @@ TransactionStmtLegacy:
                                        n->kind = TRANS_STMT_COMMIT;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                ;
@@ -11443,7 +11603,7 @@ AlterDomainStmt:
                                        $$ = (Node *) n;
                                }
                        /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
-                       | ALTER DOMAIN_P any_name ADD_P TableConstraint
+                       | ALTER DOMAIN_P any_name ADD_P DomainConstraint
                                {
                                        AlterDomainStmt *n = makeNode(AlterDomainStmt);
 
@@ -11614,35 +11774,44 @@ CreateConversionStmt:
 /*****************************************************************************
  *
  *             QUERY:
- *                             CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
- *                             CLUSTER [ (options) ] <qualified_name> [ USING <index_name> ]
- *                             CLUSTER [VERBOSE]
+ *                             CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
+ *                             CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
  *                             CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
  *
  *****************************************************************************/
 
 ClusterStmt:
-                       CLUSTER opt_verbose qualified_name cluster_index_specification
+                       CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
 
-                                       n->relation = $3;
-                                       n->indexname = $4;
-                                       n->params = NIL;
-                                       if ($2)
-                                               n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
+                                       n->relation = $5;
+                                       n->indexname = $6;
+                                       n->params = $3;
                                        $$ = (Node *) n;
                                }
-
-                       | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
+                       | CLUSTER '(' utility_option_list ')'
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
 
-                                       n->relation = $5;
-                                       n->indexname = $6;
+                                       n->relation = NULL;
+                                       n->indexname = NULL;
                                        n->params = $3;
                                        $$ = (Node *) n;
                                }
+                       /* unparenthesized VERBOSE kept for pre-14 compatibility */
+                       | CLUSTER opt_verbose qualified_name cluster_index_specification
+                               {
+                                       ClusterStmt *n = makeNode(ClusterStmt);
+
+                                       n->relation = $3;
+                                       n->indexname = $4;
+                                       n->params = NIL;
+                                       if ($2)
+                                               n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
+                                       $$ = (Node *) n;
+                               }
+                       /* unparenthesized VERBOSE kept for pre-17 compatibility */
                        | CLUSTER opt_verbose
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
@@ -11973,6 +12142,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = $2;
+                                               n->isall = false;
+                                               n->location = @2;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE PREPARE name
@@ -11980,6 +12151,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = $3;
+                                               n->isall = false;
+                                               n->location = @3;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE ALL
@@ -11987,6 +12160,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = NULL;
+                                               n->isall = true;
+                                               n->location = -1;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE PREPARE ALL
@@ -11994,6 +12169,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = NULL;
+                                               n->isall = true;
+                                               n->location = -1;
                                                $$ = (Node *) n;
                                        }
                ;
@@ -12334,6 +12511,7 @@ MergeStmt:
                        USING table_ref
                        ON a_expr
                        merge_when_list
+                       returning_clause
                                {
                                        MergeStmt  *m = makeNode(MergeStmt);
 
@@ -12342,6 +12520,7 @@ MergeStmt:
                                        m->sourceRelation = $6;
                                        m->joinCondition = $8;
                                        m->mergeWhenClauses = $9;
+                                       m->returningList = $10;
 
                                        $$ = (Node *) m;
                                }
@@ -12352,50 +12531,66 @@ merge_when_list:
                        | merge_when_list merge_when_clause             { $$ = lappend($1,$2); }
                ;
 
+/*
+ * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
+ * MATCHED [BY TARGET]. The first two cases match target tuples, and support
+ * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
+ * tuples, and only supports INSERT/DO NOTHING actions.
+ */
 merge_when_clause:
-                       WHEN MATCHED opt_merge_when_condition THEN merge_update
+                       merge_when_tgt_matched opt_merge_when_condition THEN merge_update
                                {
-                                       $5->matched = true;
-                                       $5->condition = $3;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $5;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN MATCHED opt_merge_when_condition THEN merge_delete
+                       | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
                                {
-                                       $5->matched = true;
-                                       $5->condition = $3;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $5;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN NOT MATCHED opt_merge_when_condition THEN merge_insert
+                       | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
                                {
-                                       $6->matched = false;
-                                       $6->condition = $4;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $6;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN MATCHED opt_merge_when_condition THEN DO NOTHING
+                       | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
                                {
                                        MergeWhenClause *m = makeNode(MergeWhenClause);
 
-                                       m->matched = true;
+                                       m->matchKind = $1;
                                        m->commandType = CMD_NOTHING;
-                                       m->condition = $3;
+                                       m->condition = $2;
 
                                        $$ = (Node *) m;
                                }
-                       | WHEN NOT MATCHED opt_merge_when_condition THEN DO NOTHING
+                       | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
                                {
                                        MergeWhenClause *m = makeNode(MergeWhenClause);
 
-                                       m->matched = false;
+                                       m->matchKind = $1;
                                        m->commandType = CMD_NOTHING;
-                                       m->condition = $4;
+                                       m->condition = $2;
 
                                        $$ = (Node *) m;
                                }
                ;
 
+merge_when_tgt_matched:
+                       WHEN MATCHED                                    { $$ = MERGE_WHEN_MATCHED; }
+                       | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
+               ;
+
+merge_when_tgt_not_matched:
+                       WHEN NOT MATCHED                                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
+                       | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
+               ;
+
 opt_merge_when_condition:
                        AND a_expr                              { $$ = $2; }
                        |                                               { $$ = NULL; }
@@ -13402,6 +13597,21 @@ table_ref:     relation_expr opt_alias_clause
                                        $2->alias = $4;
                                        $$ = (Node *) $2;
                                }
+                       | json_table opt_alias_clause
+                               {
+                                       JsonTable  *jt = castNode(JsonTable, $1);
+
+                                       jt->alias = $2;
+                                       $$ = (Node *) jt;
+                               }
+                       | LATERAL_P json_table opt_alias_clause
+                               {
+                                       JsonTable  *jt = castNode(JsonTable, $2);
+
+                                       jt->alias = $3;
+                                       jt->lateral = true;
+                                       $$ = (Node *) jt;
+                               }
                ;
 
 
@@ -13969,6 +14179,8 @@ xmltable_column_option_el:
                                { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
                        | NULL_P
                                { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
+                       | PATH b_expr
+                               { $$ = makeDefElem("path", $2, @1); }
                ;
 
 xml_namespace_list:
@@ -13997,6 +14209,152 @@ xml_namespace_el:
                                }
                ;
 
+json_table:
+                       JSON_TABLE '('
+                               json_value_expr ',' a_expr json_table_path_name_opt
+                               json_passing_clause_opt
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               json_on_error_clause_opt
+                       ')'
+                               {
+                                       JsonTable *n = makeNode(JsonTable);
+                                       char      *pathstring;
+
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       if (!IsA($5, A_Const) ||
+                                               castNode(A_Const, $5)->val.node.type != T_String)
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                                errmsg("only string constants are supported in JSON_TABLE path specification"),
+                                                                parser_errposition(@5)));
+                                       pathstring = castNode(A_Const, $5)->val.sval.sval;
+                                       n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
+                                       n->passing = $7;
+                                       n->columns = $10;
+                                       n->on_error = (JsonBehavior *) $12;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
+json_table_path_name_opt:
+                       AS name                 { $$ = $2; }
+                       | /* empty */   { $$ = NULL; }
+               ;
+
+json_table_column_definition_list:
+                       json_table_column_definition
+                               { $$ = list_make1($1); }
+                       | json_table_column_definition_list ',' json_table_column_definition
+                               { $$ = lappend($1, $3); }
+               ;
+
+json_table_column_definition:
+                       ColId FOR ORDINALITY
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_FOR_ORDINALITY;
+                                       n->name = $1;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename
+                               json_table_column_path_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_REGULAR;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
+                                       n->pathspec = (JsonTablePathSpec *) $3;
+                                       n->wrapper = $4;
+                                       n->quotes = $5;
+                                       n->on_empty = (JsonBehavior *) linitial($6);
+                                       n->on_error = (JsonBehavior *) lsecond($6);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename json_format_clause
+                               json_table_column_path_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_FORMATTED;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = (JsonFormat *) $3;
+                                       n->pathspec = (JsonTablePathSpec *) $4;
+                                       n->wrapper = $5;
+                                       n->quotes = $6;
+                                       n->on_empty = (JsonBehavior *) linitial($7);
+                                       n->on_error = (JsonBehavior *) lsecond($7);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename
+                               EXISTS json_table_column_path_clause_opt
+                               json_on_error_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_EXISTS;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
+                                       n->wrapper = JSW_NONE;
+                                       n->quotes = JS_QUOTES_UNSPEC;
+                                       n->pathspec = (JsonTablePathSpec *) $4;
+                                       n->on_empty = NULL;
+                                       n->on_error = (JsonBehavior *) $5;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | NESTED path_opt Sconst
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_NESTED;
+                                       n->pathspec = (JsonTablePathSpec *)
+                                               makeJsonTablePathSpec($3, NULL, @3, -1);
+                                       n->columns = $6;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | NESTED path_opt Sconst AS name
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_NESTED;
+                                       n->pathspec = (JsonTablePathSpec *)
+                                               makeJsonTablePathSpec($3, $5, @3, @5);
+                                       n->columns = $8;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
+path_opt:
+                       PATH
+                       | /* EMPTY */
+               ;
+
+json_table_column_path_clause_opt:
+                       PATH Sconst
+                               { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
+                       | /* EMPTY */
+                               { $$ = NULL; }
+               ;
+
 /*****************************************************************************
  *
  *     Type syntax
@@ -14069,6 +14427,7 @@ SimpleTypename:
                                        $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
                                                                                         makeIntConst($3, @3));
                                }
+                       | JsonType                                                              { $$ = $1; }
                ;
 
 /* We have a separate ConstTypename to allow defaulting fixed-length
@@ -14087,6 +14446,7 @@ ConstTypename:
                        | ConstBit                                                              { $$ = $1; }
                        | ConstCharacter                                                { $$ = $1; }
                        | ConstDatetime                                                 { $$ = $1; }
+                       | JsonType                                                              { $$ = $1; }
                ;
 
 /*
@@ -14455,6 +14815,13 @@ interval_second:
                                }
                ;
 
+JsonType:
+                       JSON
+                               {
+                                       $$ = SystemTypeName("json");
+                                       $$->location = @1;
+                               }
+               ;
 
 /*****************************************************************************
  *
@@ -14503,6 +14870,13 @@ a_expr:                c_expr                                                                  { $$ = $1; }
                                                                                           COERCE_SQL_SYNTAX,
                                                                                           @2);
                                }
+                       | a_expr AT LOCAL                                               %prec AT
+                               {
+                                       $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
+                                                                                          list_make1($1),
+                                                                                          COERCE_SQL_SYNTAX,
+                                                                                          -1);
+                               }
                /*
                 * These operators must be called out explicitly in order to make use
                 * of bison's automatic operator-precedence handling.  All other
@@ -14935,12 +15309,11 @@ a_expr:               c_expr                                                                  { $$ = $1; }
                        /*
                         * Required by SQL/JSON, but there are conflicts
                        | a_expr
-                               FORMAT_LA JSON json_encoding_clause_opt
+                               json_format_clause
                                IS  json_predicate_type_constraint
                                        json_key_uniqueness_constraint_opt              %prec IS
                                {
-                                       $3.location = @2;
-                                       $$ = makeJsonIsPredicate($1, $3, $5, $6, @1);
+                                       $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
                                }
                        */
                        | a_expr IS NOT
@@ -14954,13 +15327,12 @@ a_expr:               c_expr                                                                  { $$ = $1; }
                        /*
                         * Required by SQL/JSON, but there are conflicts
                        | a_expr
-                               FORMAT_LA JSON json_encoding_clause_opt
+                               json_format_clause
                                IS NOT
                                        json_predicate_type_constraint
                                        json_key_uniqueness_constraint_opt              %prec IS
                                {
-                                       $3.location = @2;
-                                       $$ = makeNotExpr(makeJsonIsPredicate($1, $3, $6, $7, @1), @1);
+                                       $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
                                }
                        */
                        | DEFAULT
@@ -15331,7 +15703,7 @@ func_expr: func_application within_group_clause filter_clause over_clause
                ;
 
 /*
- * As func_expr but does not accept WINDOW functions directly
+ * Like func_expr but does not accept WINDOW functions directly
  * (but they can still be contained in arguments for functions etc).
  * Use this when window expressions are not allowed, where needed to
  * disambiguate the grammar (e.g. in CREATE INDEX).
@@ -15649,7 +16021,7 @@ func_expr_common_subexpr:
                        | JSON_OBJECT '(' json_name_and_value_list
                                json_object_constructor_null_clause_opt
                                json_key_uniqueness_constraint_opt
-                               json_output_clause_opt ')'
+                               json_returning_clause_opt ')'
                                {
                                        JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
 
@@ -15660,7 +16032,7 @@ func_expr_common_subexpr:
                                        n->location = @1;
                                        $$ = (Node *) n;
                                }
-                       | JSON_OBJECT '(' json_output_clause_opt ')'
+                       | JSON_OBJECT '(' json_returning_clause_opt ')'
                                {
                                        JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
 
@@ -15674,7 +16046,7 @@ func_expr_common_subexpr:
                        | JSON_ARRAY '('
                                json_value_expr_list
                                json_array_constructor_null_clause_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
@@ -15689,7 +16061,7 @@ func_expr_common_subexpr:
                                select_no_parens
                                json_format_clause_opt
                                /* json_array_constructor_null_clause_opt */
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
@@ -15702,7 +16074,7 @@ func_expr_common_subexpr:
                                        $$ = (Node *) n;
                                }
                        | JSON_ARRAY '('
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
@@ -15713,7 +16085,100 @@ func_expr_common_subexpr:
                                        n->location = @1;
                                        $$ = (Node *) n;
                                }
-               ;
+                       | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
+                               {
+                                       JsonParseExpr *n = makeNode(JsonParseExpr);
+
+                                       n->expr = (JsonValueExpr *) $3;
+                                       n->unique_keys = $4;
+                                       n->output = NULL;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_SCALAR '(' a_expr ')'
+                               {
+                                       JsonScalarExpr *n = makeNode(JsonScalarExpr);
+
+                                       n->expr = (Expr *) $3;
+                                       n->output = NULL;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
+                               {
+                                       JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
+
+                                       n->expr = (JsonValueExpr *) $3;
+                                       n->output = (JsonOutput *) $4;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | MERGE_ACTION '(' ')'
+                               {
+                                       MergeSupportFunc *m = makeNode(MergeSupportFunc);
+
+                                       m->msftype = TEXTOID;
+                                       m->location = @1;
+                                       $$ = (Node *) m;
+                               }
+                       | JSON_QUERY '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_returning_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_QUERY_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = (JsonOutput *) $7;
+                                       n->wrapper = $8;
+                                       n->quotes = $9;
+                                       n->on_empty = (JsonBehavior *) linitial($10);
+                                       n->on_error = (JsonBehavior *) lsecond($10);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_EXISTS '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_on_error_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_EXISTS_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = NULL;
+                                       n->on_error = (JsonBehavior *) $7;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_VALUE '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_returning_clause_opt
+                               json_behavior_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_VALUE_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = (JsonOutput *) $7;
+                                       n->on_empty = (JsonBehavior *) linitial($8);
+                                       n->on_error = (JsonBehavior *) lsecond($8);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       ;
+
 
 /*
  * SQL/XML support
@@ -16438,6 +16903,77 @@ opt_asymmetric: ASYMMETRIC
                ;
 
 /* SQL/JSON support */
+json_passing_clause_opt:
+                       PASSING json_arguments                                  { $$ = $2; }
+                       | /*EMPTY*/                                                             { $$ = NIL; }
+               ;
+
+json_arguments:
+                       json_argument                                                   { $$ = list_make1($1); }
+                       | json_arguments ',' json_argument              { $$ = lappend($1, $3); }
+               ;
+
+json_argument:
+                       json_value_expr AS ColLabel
+                       {
+                               JsonArgument *n = makeNode(JsonArgument);
+
+                               n->val = (JsonValueExpr *) $1;
+                               n->name = $3;
+                               $$ = (Node *) n;
+                       }
+               ;
+
+/* ARRAY is a noise word */
+json_wrapper_behavior:
+                         WITHOUT WRAPPER                                       { $$ = JSW_NONE; }
+                       | WITHOUT ARRAY WRAPPER                         { $$ = JSW_NONE; }
+                       | WITH WRAPPER                                          { $$ = JSW_UNCONDITIONAL; }
+                       | WITH ARRAY WRAPPER                            { $$ = JSW_UNCONDITIONAL; }
+                       | WITH CONDITIONAL ARRAY WRAPPER        { $$ = JSW_CONDITIONAL; }
+                       | WITH UNCONDITIONAL ARRAY WRAPPER      { $$ = JSW_UNCONDITIONAL; }
+                       | WITH CONDITIONAL WRAPPER                      { $$ = JSW_CONDITIONAL; }
+                       | WITH UNCONDITIONAL WRAPPER            { $$ = JSW_UNCONDITIONAL; }
+                       | /* empty */                                           { $$ = JSW_UNSPEC; }
+               ;
+
+json_behavior:
+                       DEFAULT a_expr
+                               { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
+                       | json_behavior_type
+                               { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
+               ;
+
+json_behavior_type:
+                       ERROR_P         { $$ = JSON_BEHAVIOR_ERROR; }
+                       | NULL_P        { $$ = JSON_BEHAVIOR_NULL; }
+                       | TRUE_P        { $$ = JSON_BEHAVIOR_TRUE; }
+                       | FALSE_P       { $$ = JSON_BEHAVIOR_FALSE; }
+                       | UNKNOWN       { $$ = JSON_BEHAVIOR_UNKNOWN; }
+                       | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
+                       | EMPTY_P OBJECT_P      { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
+                       /* non-standard, for Oracle compatibility only */
+                       | EMPTY_P       { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
+               ;
+
+json_behavior_clause_opt:
+                       json_behavior ON EMPTY_P
+                               { $$ = list_make2($1, NULL); }
+                       | json_behavior ON ERROR_P
+                               { $$ = list_make2(NULL, $1); }
+                       | json_behavior ON EMPTY_P json_behavior ON ERROR_P
+                               { $$ = list_make2($1, $4); }
+                       | /* EMPTY */
+                               { $$ = list_make2(NULL, NULL); }
+               ;
+
+json_on_error_clause_opt:
+                       json_behavior ON ERROR_P
+                               { $$ = $1; }
+                       | /* EMPTY */
+                               { $$ = NULL; }
+               ;
+
 json_value_expr:
                        a_expr json_format_clause_opt
                        {
@@ -16447,10 +16983,34 @@ json_value_expr:
                        }
                ;
 
+json_format_clause:
+                       FORMAT_LA JSON ENCODING name
+                               {
+                                       int             encoding;
+
+                                       if (!pg_strcasecmp($4, "utf8"))
+                                               encoding = JS_ENC_UTF8;
+                                       else if (!pg_strcasecmp($4, "utf16"))
+                                               encoding = JS_ENC_UTF16;
+                                       else if (!pg_strcasecmp($4, "utf32"))
+                                               encoding = JS_ENC_UTF32;
+                                       else
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                                                errmsg("unrecognized JSON encoding: %s", $4)));
+
+                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
+                               }
+                       | FORMAT_LA JSON
+                               {
+                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
+                               }
+               ;
+
 json_format_clause_opt:
-                       FORMAT_LA JSON json_encoding_clause_opt
+                       json_format_clause
                                {
-                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, $3, @1);
+                                       $$ = $1;
                                }
                        | /* EMPTY */
                                {
@@ -16458,12 +17018,15 @@ json_format_clause_opt:
                                }
                ;
 
-json_encoding_clause_opt:
-                       ENCODING name                                   { $$ = makeJsonEncoding($2); }
-                       | /* EMPTY */                                   { $$ = JS_ENC_DEFAULT; }
+json_quotes_clause_opt:
+                       KEEP QUOTES ON SCALAR STRING_P          { $$ = JS_QUOTES_KEEP; }
+                       | KEEP QUOTES                                           { $$ = JS_QUOTES_KEEP; }
+                       | OMIT QUOTES ON SCALAR STRING_P        { $$ = JS_QUOTES_OMIT; }
+                       | OMIT QUOTES                                           { $$ = JS_QUOTES_OMIT; }
+                       | /* EMPTY */                                           { $$ = JS_QUOTES_UNSPEC; }
                ;
 
-json_output_clause_opt:
+json_returning_clause_opt:
                        RETURNING Typename json_format_clause_opt
                                {
                                        JsonOutput *n = makeNode(JsonOutput);
@@ -16476,21 +17039,35 @@ json_output_clause_opt:
                        | /* EMPTY */                                                   { $$ = NULL; }
                ;
 
+/*
+ * We must assign the only-JSON production a precedence less than IDENT in
+ * order to favor shifting over reduction when JSON is followed by VALUE_P,
+ * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
+ * fully reserved word.)  Because json_predicate_type_constraint is always
+ * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
+ * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
+ * really related to this syntax, but it's a convenient choice because it
+ * already has a precedence less than IDENT for other reasons.
+ */
 json_predicate_type_constraint:
-                       JSON                                                                    { $$ = JS_TYPE_ANY; }
+                       JSON                                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
                        | JSON VALUE_P                                                  { $$ = JS_TYPE_ANY; }
                        | JSON ARRAY                                                    { $$ = JS_TYPE_ARRAY; }
                        | JSON OBJECT_P                                                 { $$ = JS_TYPE_OBJECT; }
                        | JSON SCALAR                                                   { $$ = JS_TYPE_SCALAR; }
                ;
 
-/* KEYS is a noise word here */
+/*
+ * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
+ * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
+ * This prevents reducing them when the next token is KEYS.
+ */
 json_key_uniqueness_constraint_opt:
                        WITH UNIQUE KEYS                                                        { $$ = true; }
-                       | WITH UNIQUE                                                           { $$ = true; }
+                       | WITH UNIQUE                           %prec UNBOUNDED { $$ = true; }
                        | WITHOUT UNIQUE KEYS                                           { $$ = false; }
-                       | WITHOUT UNIQUE                                                        { $$ = false; }
-                       | /* EMPTY */                           %prec KEYS              { $$ = false; }
+                       | WITHOUT UNIQUE                        %prec UNBOUNDED { $$ = false; }
+                       | /* EMPTY */                           %prec UNBOUNDED { $$ = false; }
                ;
 
 json_name_and_value_list:
@@ -16536,7 +17113,7 @@ json_aggregate_func:
                                json_name_and_value
                                json_object_constructor_null_clause_opt
                                json_key_uniqueness_constraint_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonObjectAgg *n = makeNode(JsonObjectAgg);
@@ -16554,7 +17131,7 @@ json_aggregate_func:
                                json_value_expr
                                json_array_aggregate_order_by_clause_opt
                                json_array_constructor_null_clause_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayAgg *n = makeNode(JsonArrayAgg);
@@ -17065,6 +17642,7 @@ unreserved_keyword:
                        | COMMIT
                        | COMMITTED
                        | COMPRESSION
+                       | CONDITIONAL
                        | CONFIGURATION
                        | CONFLICT
                        | CONNECTION
@@ -17101,10 +17679,12 @@ unreserved_keyword:
                        | DOUBLE_P
                        | DROP
                        | EACH
+                       | EMPTY_P
                        | ENABLE_P
                        | ENCODING
                        | ENCRYPTED
                        | ENUM_P
+                       | ERROR_P
                        | ESCAPE
                        | EVENT
                        | EXCLUDE
@@ -17154,7 +17734,7 @@ unreserved_keyword:
                        | INSTEAD
                        | INVOKER
                        | ISOLATION
-                       | JSON
+                       | KEEP
                        | KEY
                        | KEYS
                        | LABEL
@@ -17184,6 +17764,7 @@ unreserved_keyword:
                        | MOVE
                        | NAME_P
                        | NAMES
+                       | NESTED
                        | NEW
                        | NEXT
                        | NFC
@@ -17201,6 +17782,7 @@ unreserved_keyword:
                        | OFF
                        | OIDS
                        | OLD
+                       | OMIT
                        | OPERATOR
                        | OPTION
                        | OPTIONS
@@ -17217,6 +17799,8 @@ unreserved_keyword:
                        | PARTITION
                        | PASSING
                        | PASSWORD
+                       | PATH
+                       | PLAN
                        | PLANS
                        | POLICY
                        | PRECEDING
@@ -17231,6 +17815,7 @@ unreserved_keyword:
                        | PROGRAM
                        | PUBLICATION
                        | QUOTE
+                       | QUOTES
                        | RANGE
                        | READ
                        | REASSIGN
@@ -17279,6 +17864,7 @@ unreserved_keyword:
                        | SIMPLE
                        | SKIP
                        | SNAPSHOT
+                       | SOURCE
                        | SQL_P
                        | STABLE
                        | STANDALONE_P
@@ -17290,6 +17876,7 @@ unreserved_keyword:
                        | STORAGE
                        | STORED
                        | STRICT_P
+                       | STRING_P
                        | STRIP_P
                        | SUBSCRIPTION
                        | SUPPORT
@@ -17297,6 +17884,7 @@ unreserved_keyword:
                        | SYSTEM_P
                        | TABLES
                        | TABLESPACE
+                       | TARGET
                        | TEMP
                        | TEMPLATE
                        | TEMPORARY
@@ -17312,6 +17900,7 @@ unreserved_keyword:
                        | UESCAPE
                        | UNBOUNDED
                        | UNCOMMITTED
+                       | UNCONDITIONAL
                        | UNENCRYPTED
                        | UNKNOWN
                        | UNLISTEN
@@ -17369,11 +17958,19 @@ col_name_keyword:
                        | INT_P
                        | INTEGER
                        | INTERVAL
+                       | JSON
                        | JSON_ARRAY
                        | JSON_ARRAYAGG
+                       | JSON_EXISTS
                        | JSON_OBJECT
                        | JSON_OBJECTAGG
+                       | JSON_QUERY
+                       | JSON_SCALAR
+                       | JSON_SERIALIZE
+                       | JSON_TABLE
+                       | JSON_VALUE
                        | LEAST
+                       | MERGE_ACTION
                        | NATIONAL
                        | NCHAR
                        | NONE
@@ -17605,6 +18202,7 @@ bare_label_keyword:
                        | COMMITTED
                        | COMPRESSION
                        | CONCURRENTLY
+                       | CONDITIONAL
                        | CONFIGURATION
                        | CONFLICT
                        | CONNECTION
@@ -17657,11 +18255,13 @@ bare_label_keyword:
                        | DROP
                        | EACH
                        | ELSE
+                       | EMPTY_P
                        | ENABLE_P
                        | ENCODING
                        | ENCRYPTED
                        | END_P
                        | ENUM_P
+                       | ERROR_P
                        | ESCAPE
                        | EVENT
                        | EXCLUDE
@@ -17731,8 +18331,15 @@ bare_label_keyword:
                        | JSON
                        | JSON_ARRAY
                        | JSON_ARRAYAGG
+                       | JSON_EXISTS
                        | JSON_OBJECT
                        | JSON_OBJECTAGG
+                       | JSON_QUERY
+                       | JSON_SCALAR
+                       | JSON_SERIALIZE
+                       | JSON_TABLE
+                       | JSON_VALUE
+                       | KEEP
                        | KEY
                        | KEYS
                        | LABEL
@@ -17761,6 +18368,7 @@ bare_label_keyword:
                        | MATERIALIZED
                        | MAXVALUE
                        | MERGE
+                       | MERGE_ACTION
                        | METHOD
                        | MINVALUE
                        | MODE
@@ -17770,6 +18378,7 @@ bare_label_keyword:
                        | NATIONAL
                        | NATURAL
                        | NCHAR
+                       | NESTED
                        | NEW
                        | NEXT
                        | NFC
@@ -17793,6 +18402,7 @@ bare_label_keyword:
                        | OFF
                        | OIDS
                        | OLD
+                       | OMIT
                        | ONLY
                        | OPERATOR
                        | OPTION
@@ -17813,7 +18423,9 @@ bare_label_keyword:
                        | PARTITION
                        | PASSING
                        | PASSWORD
+                       | PATH
                        | PLACING
+                       | PLAN
                        | PLANS
                        | POLICY
                        | POSITION
@@ -17830,6 +18442,7 @@ bare_label_keyword:
                        | PROGRAM
                        | PUBLICATION
                        | QUOTE
+                       | QUOTES
                        | RANGE
                        | READ
                        | REAL
@@ -17887,6 +18500,7 @@ bare_label_keyword:
                        | SMALLINT
                        | SNAPSHOT
                        | SOME
+                       | SOURCE
                        | SQL_P
                        | STABLE
                        | STANDALONE_P
@@ -17898,6 +18512,7 @@ bare_label_keyword:
                        | STORAGE
                        | STORED
                        | STRICT_P
+                       | STRING_P
                        | STRIP_P
                        | SUBSCRIPTION
                        | SUBSTRING
@@ -17910,6 +18525,7 @@ bare_label_keyword:
                        | TABLES
                        | TABLESAMPLE
                        | TABLESPACE
+                       | TARGET
                        | TEMP
                        | TEMPLATE
                        | TEMPORARY
@@ -17932,6 +18548,7 @@ bare_label_keyword:
                        | UESCAPE
                        | UNBOUNDED
                        | UNCOMMITTED
+                       | UNCONDITIONAL
                        | UNENCRYPTED
                        | UNIQUE
                        | UNKNOWN
@@ -18068,18 +18685,6 @@ makeColumnRef(char *colname, List *indirection,
 }
 
 
-static Node *
-makeStringConst(char *str, int location)
-{
-       A_Const    *n = makeNode(A_Const);
-
-       n->val.sval.type = T_String;
-       n->val.sval.sval = str;
-       n->location = location;
-
-       return (Node *) n;
-}
-
 
 static Node *
 makeFloatConst(char *str, int location)
@@ -18340,7 +18945,7 @@ insertSelectOptions(SelectStmt *stmt,
                                         parser_errposition(exprLocation(limitClause->limitCount))));
                stmt->limitCount = limitClause->limitCount;
        }
-       if (limitClause && limitClause->limitOption != LIMIT_OPTION_DEFAULT)
+       if (limitClause)
        {
                if (stmt->limitOption)
                        ereport(ERROR,
index c542cf75d05133d4211c4dd72e460e166d8efd73..fdb4e8106ab0d6cca44165fb006ab13e80f3de37 100644 (file)
@@ -6,8 +6,8 @@
  * gram.y
  *       POSTGRESQL BISON rules/actions
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -209,7 +209,6 @@ static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
 static void updateRawStmtEnd(RawStmt *rs, int end_location);
 static Node *makeColumnRef(char *colname, List *indirection,
                                                   int location, core_yyscan_t yyscanner);
-static Node *makeStringConst(char *str, int location);
 static Node *makeFloatConst(char *str, int location);
 static Node *makeBoolAConst(bool state, int location);
 static Node *makeBitStringConst(char *str, int location);
@@ -316,6 +315,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        struct SelectLimit *selectlimit;
        SetQuantifier setquantifier;
        struct GroupClause *groupclause;
+       MergeMatchKind mergematch;
        MergeWhenClause *mergewhen;
        struct KeyActions *keyactions;
        struct KeyAction *keyaction;
@@ -385,6 +385,8 @@ UpdateStmtShort
 %type <list>   alter_table_cmds alter_type_cmds
 %type <list>    alter_identity_column_option_list
 %type <defelt>  alter_identity_column_option
+%type <node>   set_statistics_value
+%type <str>            set_access_method_name
 
 %type <list>   createdb_opt_list createdb_opt_items copy_opt_list
                                transaction_mode_list
@@ -562,13 +564,14 @@ UpdateStmtShort
 %type <onconflict> opt_on_conflict
 %type <mergewhen>      merge_insert merge_update merge_delete
 
+%type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
 %type <node>   merge_when_clause opt_merge_when_condition
 %type <list>   merge_when_list
 
 %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
                                 SetResetClause FunctionSetResetClause
 
-%type <node>   TableElement TypedTableElement ConstraintElem TableFuncElement
+%type <node>   TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
 %type <node>   columnDef columnOptions
 %type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
 %type <node>   def_arg columnElem where_clause where_or_current_clause
@@ -614,7 +617,7 @@ UpdateStmtShort
 %type <list>   copy_options
 
 %type <typnam> Typename SimpleTypename ConstTypename
-                               GenericType Numeric opt_float
+                               GenericType Numeric opt_float JsonType
                                Character ConstCharacter
                                CharacterWithLength CharacterWithoutLength
                                ConstDatetime ConstInterval
@@ -639,7 +642,7 @@ UpdateStmtShort
 %type <keyword> col_name_keyword reserved_keyword
 %type <keyword> bare_label_keyword
 
-%type <node>   TableConstraint TableLikeClause
+%type <node>   DomainConstraint TableConstraint TableLikeClause
 %type <ival>   TableLikeOptionList TableLikeOption
 %type <str>            column_compression opt_column_compression column_storage opt_column_storage
 %type <list>   ColQualList
@@ -693,16 +696,30 @@ UpdateStmtShort
 %type <list>           hash_partbound
 %type <defelt>         hash_partbound_elem
 
-%type <node>   json_format_clause_opt
+%type <node>   json_format_clause
+                               json_format_clause_opt
                                json_value_expr
-                               json_output_clause_opt
+                               json_returning_clause_opt
                                json_name_and_value
                                json_aggregate_func
+                               json_argument
+                               json_behavior
+                               json_on_error_clause_opt
+                               json_table
+                               json_table_column_definition
+                               json_table_column_path_clause_opt
 %type <list>   json_name_and_value_list
                                json_value_expr_list
                                json_array_aggregate_order_by_clause_opt
-%type <ival>   json_encoding_clause_opt
+                               json_arguments
+                               json_behavior_clause_opt
+                               json_passing_clause_opt
+                               json_table_column_definition_list
+%type <str>            json_table_path_name_opt
+%type <ival>   json_behavior_type
                                json_predicate_type_constraint
+                               json_quotes_clause_opt
+                               json_wrapper_behavior
 %type <boolean>        json_key_uniqueness_constraint_opt
                                json_object_constructor_null_clause_opt
                                json_array_constructor_null_clause_opt
@@ -743,7 +760,7 @@ UpdateStmtShort
        CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
        CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
        CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
-       COMMITTED COMPRESSION CONCURRENTLY CONFIGURATION CONFLICT
+       COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
        CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
        COST CREATE CROSS CSV CUBE CURRENT_P
        CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
@@ -754,8 +771,8 @@ UpdateStmtShort
        DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
        DOUBLE_P DROP
 
-       EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
-       EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
+       EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ERROR_P ESCAPE
+       EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
        EXTENSION EXTERNAL EXTRACT
 
        FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
@@ -770,32 +787,33 @@ UpdateStmtShort
        INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
        INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
 
-       JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_OBJECT JSON_OBJECTAGG
+       JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
+       JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
 
-       KEY KEYS
+       KEEP KEY KEYS
 
        LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
        LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
        LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
 
-       MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE METHOD
+       MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
        MINUTE_P MINVALUE MODE MONTH_P MOVE
 
-       NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NFC NFD NFKC NFKD NO NONE
-       NORMALIZE NORMALIZED
+       NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
+       NONE NORMALIZE NORMALIZED
        NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
        NULLS_P NUMERIC
 
-       OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
+       OBJECT_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
        ORDER ORDINALITY OTHERS OUT_P OUTER_P
        OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
 
-       PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PGPOOL
-       PLACING PLANS POLICY
+       PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH PGPOOL
+       PLACING PLAN PLANS POLICY
        POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
        PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
 
-       QUOTE
+       QUOTE QUOTES
 
        RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING
        REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
@@ -805,16 +823,16 @@ UpdateStmtShort
        SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
        SEQUENCE SEQUENCES
        SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
-       SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P
-       START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRIP_P
+       SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
+       START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
        SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
 
-       TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
+       TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
        TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
        TREAT TRIGGER TRIM TRUE_P
        TRUNCATE TRUSTED TYPE_P TYPES_P
 
-       UESCAPE UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
+       UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
        UNLISTEN UNLOGGED UNTIL UPDATE USER USING
 
        VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
@@ -857,7 +875,6 @@ UpdateStmtShort
 
 
 /* Precedence: lowest to highest */
-%nonassoc      SET                             /* see relation_expr_opt_alias */
 %left          UNION EXCEPT
 %left          INTERSECT
 %left          OR
@@ -868,18 +885,23 @@ UpdateStmtShort
 %nonassoc      BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
 %nonassoc      ESCAPE                  /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
 
-/* SQL/JSON related keywords */
-%nonassoc      UNIQUE JSON
-%nonassoc      KEYS OBJECT_P SCALAR VALUE_P
-%nonassoc      WITH WITHOUT
-
 /*
- * To support target_el without AS, it used to be necessary to assign IDENT an
- * explicit precedence just less than Op.  While that's not really necessary
- * since we removed postfix operators, it's still helpful to do so because
- * there are some other unreserved keywords that need precedence assignments.
- * If those keywords have the same precedence as IDENT then they clearly act
- * the same as non-keywords, reducing the risk of unwanted precedence effects.
+ * Sometimes it is necessary to assign precedence to keywords that are not
+ * really part of the operator hierarchy, in order to resolve grammar
+ * ambiguities.  It's best to avoid doing so whenever possible, because such
+ * assignments have global effect and may hide ambiguities besides the one
+ * you intended to solve.  (Attaching a precedence to a single rule with
+ * %prec is far safer and should be preferred.)  If you must give precedence
+ * to a new keyword, try very hard to give it the same precedence as IDENT.
+ * If the keyword has IDENT's precedence then it clearly acts the same as
+ * non-keywords and other similar keywords, thus reducing the risk of
+ * unexpected precedence effects.
+ *
+ * We used to need to assign IDENT an explicit precedence just less than Op,
+ * to support target_el without AS.  While that's not really necessary since
+ * we removed postfix operators, we continue to do so because it provides a
+ * reference point for a precedence level that we can assign to other
+ * keywords that lack a natural precedence level.
  *
  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
  * opt_existing_window_name (see comment there).
@@ -897,15 +919,27 @@ UpdateStmtShort
  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
  * rather than reducing a conflicting rule that takes CUBE as a function name.
  * Using the same precedence as IDENT seems right for the reasons given above.
+ *
+ * SET is likewise assigned the same precedence as IDENT, to support the
+ * relation_expr_opt_alias production (see comment there).
+ *
+ * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
+ * the same precedence as IDENT.  This allows resolving conflicts in the
+ * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
+ * productions (see comments there).
+ *
+ * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
+ * precedence than PATH to fix ambiguity in the json_table production.
  */
-%nonassoc      UNBOUNDED               /* ideally would have same precedence as IDENT */
+%nonassoc      UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
 %nonassoc      IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
+                       SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
 %left          Op OPERATOR             /* multi-character ops and user-defined operators */
 %left          '+' '-'
 %left          '*' '/' '%'
 %left          '^'
 /* Unary Operators */
-%left          AT                              /* sets precedence for AT TIME ZONE */
+%left          AT                              /* sets precedence for AT TIME ZONE, AT LOCAL */
 %left          COLLATE
 %right         UMINUS
 %left          '[' ']'
@@ -2485,6 +2519,16 @@ alter_table_cmd:
                                        n->name = $3;
                                        $$ = (Node *) n;
                                }
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
+                       | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
+                               {
+                                       AlterTableCmd *n = makeNode(AlterTableCmd);
+
+                                       n->subtype = AT_SetExpression;
+                                       n->name = $3;
+                                       n->def = $8;
+                                       $$ = (Node *) n;
+                               }
                        /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
                        | ALTER opt_column ColId DROP EXPRESSION
                                {
@@ -2504,18 +2548,18 @@ alter_table_cmd:
                                        n->missing_ok = true;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
-                       | ALTER opt_column ColId SET STATISTICS SignedIconst
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
+                       | ALTER opt_column ColId SET STATISTICS set_statistics_value
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
                                        n->subtype = AT_SetStatistics;
                                        n->name = $3;
-                                       n->def = (Node *) makeInteger($6);
+                                       n->def = $6;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS <SignedIconst> */
-                       | ALTER opt_column Iconst SET STATISTICS SignedIconst
+                       /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
+                       | ALTER opt_column Iconst SET STATISTICS set_statistics_value
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
@@ -2527,7 +2571,7 @@ alter_table_cmd:
 
                                        n->subtype = AT_SetStatistics;
                                        n->num = (int16) $3;
-                                       n->def = (Node *) makeInteger($6);
+                                       n->def = $6;
                                        $$ = (Node *) n;
                                }
                        /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
@@ -2914,8 +2958,8 @@ alter_table_cmd:
                                        n->newowner = $3;
                                        $$ = (Node *) n;
                                }
-                       /* ALTER TABLE <name> SET ACCESS METHOD <amname> */
-                       | SET ACCESS METHOD name
+                       /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
+                       | SET ACCESS METHOD set_access_method_name
                                {
                                        AlterTableCmd *n = makeNode(AlterTableCmd);
 
@@ -3126,6 +3170,16 @@ alter_identity_column_option:
                                }
                ;
 
+set_statistics_value:
+                       SignedIconst                                    { $$ = (Node *) makeInteger($1); }
+                       | DEFAULT                                               { $$ = NULL; }
+               ;
+
+set_access_method_name:
+                       ColId                                                   { $$ = $1; }
+                       | DEFAULT                                               { $$ = NULL; }
+               ;
+
 PartitionBoundSpec:
                        /* a HASH partition */
                        FOR VALUES WITH '(' hash_partbound ')'
@@ -3498,10 +3552,18 @@ copy_opt_item:
                                {
                                        $$ = makeDefElem("force_not_null", (Node *) $4, @1);
                                }
+                       | FORCE NOT NULL_P '*'
+                               {
+                                       $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
+                               }
                        | FORCE NULL_P columnList
                                {
                                        $$ = makeDefElem("force_null", (Node *) $3, @1);
                                }
+                       | FORCE NULL_P '*'
+                               {
+                                       $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
+                               }
                        | ENCODING Sconst
                                {
                                        $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
@@ -3554,6 +3616,7 @@ copy_generic_opt_arg:
                        opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
                        | NumericOnly                                   { $$ = (Node *) $1; }
                        | '*'                                                   { $$ = (Node *) makeNode(A_Star); }
+                       | DEFAULT                       { $$ = (Node *) makeString("default"); }
                        | '(' copy_generic_opt_arg_list ')'             { $$ = (Node *) $2; }
                        | /* EMPTY */                                   { $$ = NULL; }
                ;
@@ -4270,6 +4333,60 @@ ConstraintElem:
                                }
                ;
 
+/*
+ * DomainConstraint is separate from TableConstraint because the syntax for
+ * NOT NULL constraints is different.  For table constraints, we need to
+ * accept a column name, but for domain constraints, we don't.  (We could
+ * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
+ * (which uses ColQualList) has for a long time accepted NOT NULL without a
+ * column name, so it makes sense that ALTER DOMAIN (which uses
+ * DomainConstraint) does as well.  None of these syntaxes are per SQL
+ * standard; we are just living with the bits of inconsistency that have built
+ * up over time.
+ */
+DomainConstraint:
+                       CONSTRAINT name DomainConstraintElem
+                               {
+                                       Constraint *n = castNode(Constraint, $3);
+
+                                       n->conname = $2;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | DomainConstraintElem                                  { $$ = $1; }
+               ;
+
+DomainConstraintElem:
+                       CHECK '(' a_expr ')' ConstraintAttributeSpec
+                               {
+                                       Constraint *n = makeNode(Constraint);
+
+                                       n->contype = CONSTR_CHECK;
+                                       n->location = @1;
+                                       n->raw_expr = $3;
+                                       n->cooked_expr = NULL;
+                                       processCASbits($5, @5, "CHECK",
+                                                                  NULL, NULL, &n->skip_validation,
+                                                                  &n->is_no_inherit, yyscanner);
+                                       n->initially_valid = !n->skip_validation;
+                                       $$ = (Node *) n;
+                               }
+                       | NOT NULL_P ConstraintAttributeSpec
+                               {
+                                       Constraint *n = makeNode(Constraint);
+
+                                       n->contype = CONSTR_NOTNULL;
+                                       n->location = @1;
+                                       n->keys = list_make1(makeString("value"));
+                                       /* no NOT VALID support yet */
+                                       processCASbits($3, @3, "NOT NULL",
+                                                                  NULL, NULL, NULL,
+                                                                  &n->is_no_inherit, yyscanner);
+                                       n->initially_valid = true;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
 opt_no_inherit:        NO INHERIT                                                      {  $$ = true; }
                        | /* EMPTY */                                                   {  $$ = false; }
                ;
@@ -4624,7 +4741,7 @@ stats_param:      ColId
  *****************************************************************************/
 
 AlterStatsStmt:
-                       ALTER STATISTICS any_name SET STATISTICS SignedIconst
+                       ALTER STATISTICS any_name SET STATISTICS set_statistics_value
                                {
                                        AlterStatsStmt *n = makeNode(AlterStatsStmt);
 
@@ -4633,7 +4750,7 @@ AlterStatsStmt:
                                        n->stxstattarget = $6;
                                        $$ = (Node *) n;
                                }
-                       | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS SignedIconst
+                       | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
                                {
                                        AlterStatsStmt *n = makeNode(AlterStatsStmt);
 
@@ -6468,6 +6585,33 @@ AlterEnumStmt:
                                n->skipIfNewValExists = false;
                                $$ = (Node *) n;
                        }
+                | ALTER TYPE_P any_name DROP VALUE_P Sconst
+                       {
+                               /*
+                                * The following problems must be solved before this can be
+                                * implemented:
+                                *
+                                * - There must be no instance of the target value in
+                                *   any table.
+                                *
+                                * - The value must not appear in any catalog metadata,
+                                *   such as stored view expressions or column defaults.
+                                *
+                                * - The value must not appear in any non-leaf page of a
+                                *   btree (and similar issues with other index types).
+                                *   This is problematic because a value could persist
+                                *   there long after it's gone from user-visible data.
+                                *
+                                * - Concurrent sessions must not be able to insert the
+                                *   value while the preceding conditions are being checked.
+                                *
+                                * - Possibly more...
+                                */
+                               ereport(ERROR,
+                                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                errmsg("dropping an enum value is not implemented"),
+                                                parser_errposition(@4)));
+                       }
                 ;
 
 opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
@@ -10180,6 +10324,8 @@ operator_def_elem: ColLabel '=' NONE
                                                { $$ = makeDefElem($1, NULL, @1); }
                                   | ColLabel '=' operator_def_arg
                                                { $$ = makeDefElem($1, (Node *) $3, @1); }
+                                  | ColLabel
+                                               { $$ = makeDefElem($1, NULL, @1); }
                ;
 
 /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
@@ -10922,6 +11068,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_ROLLBACK;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | START TRANSACTION transaction_mode_list_or_empty
@@ -10930,6 +11077,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_START;
                                        n->options = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | COMMIT opt_transaction opt_transaction_chain
@@ -10939,6 +11087,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_COMMIT;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction opt_transaction_chain
@@ -10948,6 +11097,7 @@ TransactionStmt:
                                        n->kind = TRANS_STMT_ROLLBACK;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | SAVEPOINT ColId
@@ -10956,6 +11106,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_SAVEPOINT;
                                        n->savepoint_name = $2;
+                                       n->location = @2;
                                        $$ = (Node *) n;
                                }
                        | RELEASE SAVEPOINT ColId
@@ -10964,6 +11115,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_RELEASE;
                                        n->savepoint_name = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | RELEASE ColId
@@ -10972,6 +11124,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_RELEASE;
                                        n->savepoint_name = $2;
+                                       n->location = @2;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction TO SAVEPOINT ColId
@@ -10980,6 +11133,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_TO;
                                        n->savepoint_name = $5;
+                                       n->location = @5;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK opt_transaction TO ColId
@@ -10988,6 +11142,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_TO;
                                        n->savepoint_name = $4;
+                                       n->location = @4;
                                        $$ = (Node *) n;
                                }
                        | PREPARE TRANSACTION Sconst
@@ -10996,6 +11151,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_PREPARE;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | COMMIT PREPARED Sconst
@@ -11004,6 +11160,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_COMMIT_PREPARED;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                        | ROLLBACK PREPARED Sconst
@@ -11012,6 +11169,7 @@ TransactionStmt:
 
                                        n->kind = TRANS_STMT_ROLLBACK_PREPARED;
                                        n->gid = $3;
+                                       n->location = @3;
                                        $$ = (Node *) n;
                                }
                ;
@@ -11023,6 +11181,7 @@ TransactionStmtLegacy:
 
                                        n->kind = TRANS_STMT_BEGIN;
                                        n->options = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                        | END_P opt_transaction opt_transaction_chain
@@ -11032,6 +11191,7 @@ TransactionStmtLegacy:
                                        n->kind = TRANS_STMT_COMMIT;
                                        n->options = NIL;
                                        n->chain = $3;
+                                       n->location = -1;
                                        $$ = (Node *) n;
                                }
                ;
@@ -11464,7 +11624,7 @@ AlterDomainStmt:
                                        $$ = (Node *) n;
                                }
                        /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
-                       | ALTER DOMAIN_P any_name ADD_P TableConstraint
+                       | ALTER DOMAIN_P any_name ADD_P DomainConstraint
                                {
                                        AlterDomainStmt *n = makeNode(AlterDomainStmt);
 
@@ -11635,35 +11795,44 @@ CreateConversionStmt:
 /*****************************************************************************
  *
  *             QUERY:
- *                             CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
- *                             CLUSTER [ (options) ] <qualified_name> [ USING <index_name> ]
- *                             CLUSTER [VERBOSE]
+ *                             CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
+ *                             CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
  *                             CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
  *
  *****************************************************************************/
 
 ClusterStmt:
-                       CLUSTER opt_verbose qualified_name cluster_index_specification
+                       CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
 
-                                       n->relation = $3;
-                                       n->indexname = $4;
-                                       n->params = NIL;
-                                       if ($2)
-                                               n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
+                                       n->relation = $5;
+                                       n->indexname = $6;
+                                       n->params = $3;
                                        $$ = (Node *) n;
                                }
-
-                       | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
+                       | CLUSTER '(' utility_option_list ')'
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
 
-                                       n->relation = $5;
-                                       n->indexname = $6;
+                                       n->relation = NULL;
+                                       n->indexname = NULL;
                                        n->params = $3;
                                        $$ = (Node *) n;
                                }
+                       /* unparenthesized VERBOSE kept for pre-14 compatibility */
+                       | CLUSTER opt_verbose qualified_name cluster_index_specification
+                               {
+                                       ClusterStmt *n = makeNode(ClusterStmt);
+
+                                       n->relation = $3;
+                                       n->indexname = $4;
+                                       n->params = NIL;
+                                       if ($2)
+                                               n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
+                                       $$ = (Node *) n;
+                               }
+                       /* unparenthesized VERBOSE kept for pre-17 compatibility */
                        | CLUSTER opt_verbose
                                {
                                        ClusterStmt *n = makeNode(ClusterStmt);
@@ -11994,6 +12163,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = $2;
+                                               n->isall = false;
+                                               n->location = @2;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE PREPARE name
@@ -12001,6 +12172,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = $3;
+                                               n->isall = false;
+                                               n->location = @3;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE ALL
@@ -12008,6 +12181,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = NULL;
+                                               n->isall = true;
+                                               n->location = -1;
                                                $$ = (Node *) n;
                                        }
                                | DEALLOCATE PREPARE ALL
@@ -12015,6 +12190,8 @@ DeallocateStmt: DEALLOCATE name
                                                DeallocateStmt *n = makeNode(DeallocateStmt);
 
                                                n->name = NULL;
+                                               n->isall = true;
+                                               n->location = -1;
                                                $$ = (Node *) n;
                                        }
                ;
@@ -12359,6 +12536,7 @@ MergeStmt:
                        USING table_ref
                        ON a_expr
                        merge_when_list
+                       returning_clause
                                {
                                        MergeStmt  *m = makeNode(MergeStmt);
 
@@ -12367,6 +12545,7 @@ MergeStmt:
                                        m->sourceRelation = $6;
                                        m->joinCondition = $8;
                                        m->mergeWhenClauses = $9;
+                                       m->returningList = $10;
 
                                        $$ = (Node *) m;
                                }
@@ -12377,50 +12556,66 @@ merge_when_list:
                        | merge_when_list merge_when_clause             { $$ = lappend($1,$2); }
                ;
 
+/*
+ * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
+ * MATCHED [BY TARGET]. The first two cases match target tuples, and support
+ * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
+ * tuples, and only supports INSERT/DO NOTHING actions.
+ */
 merge_when_clause:
-                       WHEN MATCHED opt_merge_when_condition THEN merge_update
+                       merge_when_tgt_matched opt_merge_when_condition THEN merge_update
                                {
-                                       $5->matched = true;
-                                       $5->condition = $3;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $5;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN MATCHED opt_merge_when_condition THEN merge_delete
+                       | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
                                {
-                                       $5->matched = true;
-                                       $5->condition = $3;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $5;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN NOT MATCHED opt_merge_when_condition THEN merge_insert
+                       | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
                                {
-                                       $6->matched = false;
-                                       $6->condition = $4;
+                                       $4->matchKind = $1;
+                                       $4->condition = $2;
 
-                                       $$ = (Node *) $6;
+                                       $$ = (Node *) $4;
                                }
-                       | WHEN MATCHED opt_merge_when_condition THEN DO NOTHING
+                       | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
                                {
                                        MergeWhenClause *m = makeNode(MergeWhenClause);
 
-                                       m->matched = true;
+                                       m->matchKind = $1;
                                        m->commandType = CMD_NOTHING;
-                                       m->condition = $3;
+                                       m->condition = $2;
 
                                        $$ = (Node *) m;
                                }
-                       | WHEN NOT MATCHED opt_merge_when_condition THEN DO NOTHING
+                       | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
                                {
                                        MergeWhenClause *m = makeNode(MergeWhenClause);
 
-                                       m->matched = false;
+                                       m->matchKind = $1;
                                        m->commandType = CMD_NOTHING;
-                                       m->condition = $4;
+                                       m->condition = $2;
 
                                        $$ = (Node *) m;
                                }
                ;
 
+merge_when_tgt_matched:
+                       WHEN MATCHED                                    { $$ = MERGE_WHEN_MATCHED; }
+                       | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
+               ;
+
+merge_when_tgt_not_matched:
+                       WHEN NOT MATCHED                                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
+                       | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
+               ;
+
 opt_merge_when_condition:
                        AND a_expr                              { $$ = $2; }
                        |                                               { $$ = NULL; }
@@ -13427,6 +13622,21 @@ table_ref:     relation_expr opt_alias_clause
                                        $2->alias = $4;
                                        $$ = (Node *) $2;
                                }
+                       | json_table opt_alias_clause
+                               {
+                                       JsonTable  *jt = castNode(JsonTable, $1);
+
+                                       jt->alias = $2;
+                                       $$ = (Node *) jt;
+                               }
+                       | LATERAL_P json_table opt_alias_clause
+                               {
+                                       JsonTable  *jt = castNode(JsonTable, $2);
+
+                                       jt->alias = $3;
+                                       jt->lateral = true;
+                                       $$ = (Node *) jt;
+                               }
                ;
 
 
@@ -13994,6 +14204,8 @@ xmltable_column_option_el:
                                { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
                        | NULL_P
                                { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
+                       | PATH b_expr
+                               { $$ = makeDefElem("path", $2, @1); }
                ;
 
 xml_namespace_list:
@@ -14022,6 +14234,152 @@ xml_namespace_el:
                                }
                ;
 
+json_table:
+                       JSON_TABLE '('
+                               json_value_expr ',' a_expr json_table_path_name_opt
+                               json_passing_clause_opt
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               json_on_error_clause_opt
+                       ')'
+                               {
+                                       JsonTable *n = makeNode(JsonTable);
+                                       char      *pathstring;
+
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       if (!IsA($5, A_Const) ||
+                                               castNode(A_Const, $5)->val.node.type != T_String)
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                                                errmsg("only string constants are supported in JSON_TABLE path specification"),
+                                                                parser_errposition(@5)));
+                                       pathstring = castNode(A_Const, $5)->val.sval.sval;
+                                       n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
+                                       n->passing = $7;
+                                       n->columns = $10;
+                                       n->on_error = (JsonBehavior *) $12;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
+json_table_path_name_opt:
+                       AS name                 { $$ = $2; }
+                       | /* empty */   { $$ = NULL; }
+               ;
+
+json_table_column_definition_list:
+                       json_table_column_definition
+                               { $$ = list_make1($1); }
+                       | json_table_column_definition_list ',' json_table_column_definition
+                               { $$ = lappend($1, $3); }
+               ;
+
+json_table_column_definition:
+                       ColId FOR ORDINALITY
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_FOR_ORDINALITY;
+                                       n->name = $1;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename
+                               json_table_column_path_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_REGULAR;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
+                                       n->pathspec = (JsonTablePathSpec *) $3;
+                                       n->wrapper = $4;
+                                       n->quotes = $5;
+                                       n->on_empty = (JsonBehavior *) linitial($6);
+                                       n->on_error = (JsonBehavior *) lsecond($6);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename json_format_clause
+                               json_table_column_path_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_FORMATTED;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = (JsonFormat *) $3;
+                                       n->pathspec = (JsonTablePathSpec *) $4;
+                                       n->wrapper = $5;
+                                       n->quotes = $6;
+                                       n->on_empty = (JsonBehavior *) linitial($7);
+                                       n->on_error = (JsonBehavior *) lsecond($7);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | ColId Typename
+                               EXISTS json_table_column_path_clause_opt
+                               json_on_error_clause_opt
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_EXISTS;
+                                       n->name = $1;
+                                       n->typeName = $2;
+                                       n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
+                                       n->wrapper = JSW_NONE;
+                                       n->quotes = JS_QUOTES_UNSPEC;
+                                       n->pathspec = (JsonTablePathSpec *) $4;
+                                       n->on_empty = NULL;
+                                       n->on_error = (JsonBehavior *) $5;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | NESTED path_opt Sconst
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_NESTED;
+                                       n->pathspec = (JsonTablePathSpec *)
+                                               makeJsonTablePathSpec($3, NULL, @3, -1);
+                                       n->columns = $6;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | NESTED path_opt Sconst AS name
+                               COLUMNS '(' json_table_column_definition_list ')'
+                               {
+                                       JsonTableColumn *n = makeNode(JsonTableColumn);
+
+                                       n->coltype = JTC_NESTED;
+                                       n->pathspec = (JsonTablePathSpec *)
+                                               makeJsonTablePathSpec($3, $5, @3, @5);
+                                       n->columns = $8;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+               ;
+
+path_opt:
+                       PATH
+                       | /* EMPTY */
+               ;
+
+json_table_column_path_clause_opt:
+                       PATH Sconst
+                               { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
+                       | /* EMPTY */
+                               { $$ = NULL; }
+               ;
+
 /*****************************************************************************
  *
  *     Type syntax
@@ -14094,6 +14452,7 @@ SimpleTypename:
                                        $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
                                                                                         makeIntConst($3, @3));
                                }
+                       | JsonType                                                              { $$ = $1; }
                ;
 
 /* We have a separate ConstTypename to allow defaulting fixed-length
@@ -14112,6 +14471,7 @@ ConstTypename:
                        | ConstBit                                                              { $$ = $1; }
                        | ConstCharacter                                                { $$ = $1; }
                        | ConstDatetime                                                 { $$ = $1; }
+                       | JsonType                                                              { $$ = $1; }
                ;
 
 /*
@@ -14480,6 +14840,13 @@ interval_second:
                                }
                ;
 
+JsonType:
+                       JSON
+                               {
+                                       $$ = SystemTypeName("json");
+                                       $$->location = @1;
+                               }
+               ;
 
 /*****************************************************************************
  *
@@ -14528,6 +14895,13 @@ a_expr:                c_expr                                                                  { $$ = $1; }
                                                                                           COERCE_SQL_SYNTAX,
                                                                                           @2);
                                }
+                       | a_expr AT LOCAL                                               %prec AT
+                               {
+                                       $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
+                                                                                          list_make1($1),
+                                                                                          COERCE_SQL_SYNTAX,
+                                                                                          -1);
+                               }
                /*
                 * These operators must be called out explicitly in order to make use
                 * of bison's automatic operator-precedence handling.  All other
@@ -14960,12 +15334,11 @@ a_expr:               c_expr                                                                  { $$ = $1; }
                        /*
                         * Required by SQL/JSON, but there are conflicts
                        | a_expr
-                               FORMAT_LA JSON json_encoding_clause_opt
+                               json_format_clause
                                IS  json_predicate_type_constraint
                                        json_key_uniqueness_constraint_opt              %prec IS
                                {
-                                       $3.location = @2;
-                                       $$ = makeJsonIsPredicate($1, $3, $5, $6, @1);
+                                       $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
                                }
                        */
                        | a_expr IS NOT
@@ -14979,13 +15352,12 @@ a_expr:               c_expr                                                                  { $$ = $1; }
                        /*
                         * Required by SQL/JSON, but there are conflicts
                        | a_expr
-                               FORMAT_LA JSON json_encoding_clause_opt
+                               json_format_clause
                                IS NOT
                                        json_predicate_type_constraint
                                        json_key_uniqueness_constraint_opt              %prec IS
                                {
-                                       $3.location = @2;
-                                       $$ = makeNotExpr(makeJsonIsPredicate($1, $3, $6, $7, @1), @1);
+                                       $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
                                }
                        */
                        | DEFAULT
@@ -15356,7 +15728,7 @@ func_expr: func_application within_group_clause filter_clause over_clause
                ;
 
 /*
- * As func_expr but does not accept WINDOW functions directly
+ * Like func_expr but does not accept WINDOW functions directly
  * (but they can still be contained in arguments for functions etc).
  * Use this when window expressions are not allowed, where needed to
  * disambiguate the grammar (e.g. in CREATE INDEX).
@@ -15674,7 +16046,7 @@ func_expr_common_subexpr:
                        | JSON_OBJECT '(' json_name_and_value_list
                                json_object_constructor_null_clause_opt
                                json_key_uniqueness_constraint_opt
-                               json_output_clause_opt ')'
+                               json_returning_clause_opt ')'
                                {
                                        JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
 
@@ -15685,7 +16057,7 @@ func_expr_common_subexpr:
                                        n->location = @1;
                                        $$ = (Node *) n;
                                }
-                       | JSON_OBJECT '(' json_output_clause_opt ')'
+                       | JSON_OBJECT '(' json_returning_clause_opt ')'
                                {
                                        JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
 
@@ -15699,7 +16071,7 @@ func_expr_common_subexpr:
                        | JSON_ARRAY '('
                                json_value_expr_list
                                json_array_constructor_null_clause_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
@@ -15714,7 +16086,7 @@ func_expr_common_subexpr:
                                select_no_parens
                                json_format_clause_opt
                                /* json_array_constructor_null_clause_opt */
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
@@ -15727,7 +16099,7 @@ func_expr_common_subexpr:
                                        $$ = (Node *) n;
                                }
                        | JSON_ARRAY '('
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
@@ -15738,7 +16110,100 @@ func_expr_common_subexpr:
                                        n->location = @1;
                                        $$ = (Node *) n;
                                }
-               ;
+                       | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
+                               {
+                                       JsonParseExpr *n = makeNode(JsonParseExpr);
+
+                                       n->expr = (JsonValueExpr *) $3;
+                                       n->unique_keys = $4;
+                                       n->output = NULL;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_SCALAR '(' a_expr ')'
+                               {
+                                       JsonScalarExpr *n = makeNode(JsonScalarExpr);
+
+                                       n->expr = (Expr *) $3;
+                                       n->output = NULL;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
+                               {
+                                       JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
+
+                                       n->expr = (JsonValueExpr *) $3;
+                                       n->output = (JsonOutput *) $4;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | MERGE_ACTION '(' ')'
+                               {
+                                       MergeSupportFunc *m = makeNode(MergeSupportFunc);
+
+                                       m->msftype = TEXTOID;
+                                       m->location = @1;
+                                       $$ = (Node *) m;
+                               }
+                       | JSON_QUERY '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_returning_clause_opt
+                               json_wrapper_behavior
+                               json_quotes_clause_opt
+                               json_behavior_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_QUERY_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = (JsonOutput *) $7;
+                                       n->wrapper = $8;
+                                       n->quotes = $9;
+                                       n->on_empty = (JsonBehavior *) linitial($10);
+                                       n->on_error = (JsonBehavior *) lsecond($10);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_EXISTS '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_on_error_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_EXISTS_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = NULL;
+                                       n->on_error = (JsonBehavior *) $7;
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       | JSON_VALUE '('
+                               json_value_expr ',' a_expr json_passing_clause_opt
+                               json_returning_clause_opt
+                               json_behavior_clause_opt
+                       ')'
+                               {
+                                       JsonFuncExpr *n = makeNode(JsonFuncExpr);
+
+                                       n->op = JSON_VALUE_OP;
+                                       n->context_item = (JsonValueExpr *) $3;
+                                       n->pathspec = $5;
+                                       n->passing = $6;
+                                       n->output = (JsonOutput *) $7;
+                                       n->on_empty = (JsonBehavior *) linitial($8);
+                                       n->on_error = (JsonBehavior *) lsecond($8);
+                                       n->location = @1;
+                                       $$ = (Node *) n;
+                               }
+                       ;
+
 
 /*
  * SQL/XML support
@@ -16463,6 +16928,77 @@ opt_asymmetric: ASYMMETRIC
                ;
 
 /* SQL/JSON support */
+json_passing_clause_opt:
+                       PASSING json_arguments                                  { $$ = $2; }
+                       | /*EMPTY*/                                                             { $$ = NIL; }
+               ;
+
+json_arguments:
+                       json_argument                                                   { $$ = list_make1($1); }
+                       | json_arguments ',' json_argument              { $$ = lappend($1, $3); }
+               ;
+
+json_argument:
+                       json_value_expr AS ColLabel
+                       {
+                               JsonArgument *n = makeNode(JsonArgument);
+
+                               n->val = (JsonValueExpr *) $1;
+                               n->name = $3;
+                               $$ = (Node *) n;
+                       }
+               ;
+
+/* ARRAY is a noise word */
+json_wrapper_behavior:
+                         WITHOUT WRAPPER                                       { $$ = JSW_NONE; }
+                       | WITHOUT ARRAY WRAPPER                         { $$ = JSW_NONE; }
+                       | WITH WRAPPER                                          { $$ = JSW_UNCONDITIONAL; }
+                       | WITH ARRAY WRAPPER                            { $$ = JSW_UNCONDITIONAL; }
+                       | WITH CONDITIONAL ARRAY WRAPPER        { $$ = JSW_CONDITIONAL; }
+                       | WITH UNCONDITIONAL ARRAY WRAPPER      { $$ = JSW_UNCONDITIONAL; }
+                       | WITH CONDITIONAL WRAPPER                      { $$ = JSW_CONDITIONAL; }
+                       | WITH UNCONDITIONAL WRAPPER            { $$ = JSW_UNCONDITIONAL; }
+                       | /* empty */                                           { $$ = JSW_UNSPEC; }
+               ;
+
+json_behavior:
+                       DEFAULT a_expr
+                               { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
+                       | json_behavior_type
+                               { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
+               ;
+
+json_behavior_type:
+                       ERROR_P         { $$ = JSON_BEHAVIOR_ERROR; }
+                       | NULL_P        { $$ = JSON_BEHAVIOR_NULL; }
+                       | TRUE_P        { $$ = JSON_BEHAVIOR_TRUE; }
+                       | FALSE_P       { $$ = JSON_BEHAVIOR_FALSE; }
+                       | UNKNOWN       { $$ = JSON_BEHAVIOR_UNKNOWN; }
+                       | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
+                       | EMPTY_P OBJECT_P      { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
+                       /* non-standard, for Oracle compatibility only */
+                       | EMPTY_P       { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
+               ;
+
+json_behavior_clause_opt:
+                       json_behavior ON EMPTY_P
+                               { $$ = list_make2($1, NULL); }
+                       | json_behavior ON ERROR_P
+                               { $$ = list_make2(NULL, $1); }
+                       | json_behavior ON EMPTY_P json_behavior ON ERROR_P
+                               { $$ = list_make2($1, $4); }
+                       | /* EMPTY */
+                               { $$ = list_make2(NULL, NULL); }
+               ;
+
+json_on_error_clause_opt:
+                       json_behavior ON ERROR_P
+                               { $$ = $1; }
+                       | /* EMPTY */
+                               { $$ = NULL; }
+               ;
+
 json_value_expr:
                        a_expr json_format_clause_opt
                        {
@@ -16472,10 +17008,34 @@ json_value_expr:
                        }
                ;
 
+json_format_clause:
+                       FORMAT_LA JSON ENCODING name
+                               {
+                                       int             encoding;
+
+                                       if (!pg_strcasecmp($4, "utf8"))
+                                               encoding = JS_ENC_UTF8;
+                                       else if (!pg_strcasecmp($4, "utf16"))
+                                               encoding = JS_ENC_UTF16;
+                                       else if (!pg_strcasecmp($4, "utf32"))
+                                               encoding = JS_ENC_UTF32;
+                                       else
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                                                errmsg("unrecognized JSON encoding: %s", $4)));
+
+                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
+                               }
+                       | FORMAT_LA JSON
+                               {
+                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
+                               }
+               ;
+
 json_format_clause_opt:
-                       FORMAT_LA JSON json_encoding_clause_opt
+                       json_format_clause
                                {
-                                       $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, $3, @1);
+                                       $$ = $1;
                                }
                        | /* EMPTY */
                                {
@@ -16483,12 +17043,15 @@ json_format_clause_opt:
                                }
                ;
 
-json_encoding_clause_opt:
-                       ENCODING name                                   { $$ = makeJsonEncoding($2); }
-                       | /* EMPTY */                                   { $$ = JS_ENC_DEFAULT; }
+json_quotes_clause_opt:
+                       KEEP QUOTES ON SCALAR STRING_P          { $$ = JS_QUOTES_KEEP; }
+                       | KEEP QUOTES                                           { $$ = JS_QUOTES_KEEP; }
+                       | OMIT QUOTES ON SCALAR STRING_P        { $$ = JS_QUOTES_OMIT; }
+                       | OMIT QUOTES                                           { $$ = JS_QUOTES_OMIT; }
+                       | /* EMPTY */                                           { $$ = JS_QUOTES_UNSPEC; }
                ;
 
-json_output_clause_opt:
+json_returning_clause_opt:
                        RETURNING Typename json_format_clause_opt
                                {
                                        JsonOutput *n = makeNode(JsonOutput);
@@ -16501,21 +17064,35 @@ json_output_clause_opt:
                        | /* EMPTY */                                                   { $$ = NULL; }
                ;
 
+/*
+ * We must assign the only-JSON production a precedence less than IDENT in
+ * order to favor shifting over reduction when JSON is followed by VALUE_P,
+ * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
+ * fully reserved word.)  Because json_predicate_type_constraint is always
+ * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
+ * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
+ * really related to this syntax, but it's a convenient choice because it
+ * already has a precedence less than IDENT for other reasons.
+ */
 json_predicate_type_constraint:
-                       JSON                                                                    { $$ = JS_TYPE_ANY; }
+                       JSON                                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
                        | JSON VALUE_P                                                  { $$ = JS_TYPE_ANY; }
                        | JSON ARRAY                                                    { $$ = JS_TYPE_ARRAY; }
                        | JSON OBJECT_P                                                 { $$ = JS_TYPE_OBJECT; }
                        | JSON SCALAR                                                   { $$ = JS_TYPE_SCALAR; }
                ;
 
-/* KEYS is a noise word here */
+/*
+ * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
+ * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
+ * This prevents reducing them when the next token is KEYS.
+ */
 json_key_uniqueness_constraint_opt:
                        WITH UNIQUE KEYS                                                        { $$ = true; }
-                       | WITH UNIQUE                                                           { $$ = true; }
+                       | WITH UNIQUE                           %prec UNBOUNDED { $$ = true; }
                        | WITHOUT UNIQUE KEYS                                           { $$ = false; }
-                       | WITHOUT UNIQUE                                                        { $$ = false; }
-                       | /* EMPTY */                           %prec KEYS              { $$ = false; }
+                       | WITHOUT UNIQUE                        %prec UNBOUNDED { $$ = false; }
+                       | /* EMPTY */                           %prec UNBOUNDED { $$ = false; }
                ;
 
 json_name_and_value_list:
@@ -16561,7 +17138,7 @@ json_aggregate_func:
                                json_name_and_value
                                json_object_constructor_null_clause_opt
                                json_key_uniqueness_constraint_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonObjectAgg *n = makeNode(JsonObjectAgg);
@@ -16579,7 +17156,7 @@ json_aggregate_func:
                                json_value_expr
                                json_array_aggregate_order_by_clause_opt
                                json_array_constructor_null_clause_opt
-                               json_output_clause_opt
+                               json_returning_clause_opt
                        ')'
                                {
                                        JsonArrayAgg *n = makeNode(JsonArrayAgg);
@@ -17090,6 +17667,7 @@ unreserved_keyword:
                        | COMMIT
                        | COMMITTED
                        | COMPRESSION
+                       | CONDITIONAL
                        | CONFIGURATION
                        | CONFLICT
                        | CONNECTION
@@ -17126,10 +17704,12 @@ unreserved_keyword:
                        | DOUBLE_P
                        | DROP
                        | EACH
+                       | EMPTY_P
                        | ENABLE_P
                        | ENCODING
                        | ENCRYPTED
                        | ENUM_P
+                       | ERROR_P
                        | ESCAPE
                        | EVENT
                        | EXCLUDE
@@ -17179,7 +17759,7 @@ unreserved_keyword:
                        | INSTEAD
                        | INVOKER
                        | ISOLATION
-                       | JSON
+                       | KEEP
                        | KEY
                        | KEYS
                        | LABEL
@@ -17209,6 +17789,7 @@ unreserved_keyword:
                        | MOVE
                        | NAME_P
                        | NAMES
+                       | NESTED
                        | NEW
                        | NEXT
                        | NFC
@@ -17226,6 +17807,7 @@ unreserved_keyword:
                        | OFF
                        | OIDS
                        | OLD
+                       | OMIT
                        | OPERATOR
                        | OPTION
                        | OPTIONS
@@ -17242,6 +17824,8 @@ unreserved_keyword:
                        | PARTITION
                        | PASSING
                        | PASSWORD
+                       | PATH
+                       | PLAN
                        | PLANS
                        | POLICY
                        | PRECEDING
@@ -17256,6 +17840,7 @@ unreserved_keyword:
                        | PROGRAM
                        | PUBLICATION
                        | QUOTE
+                       | QUOTES
                        | RANGE
                        | READ
                        | REASSIGN
@@ -17304,6 +17889,7 @@ unreserved_keyword:
                        | SIMPLE
                        | SKIP
                        | SNAPSHOT
+                       | SOURCE
                        | SQL_P
                        | STABLE
                        | STANDALONE_P
@@ -17315,6 +17901,7 @@ unreserved_keyword:
                        | STORAGE
                        | STORED
                        | STRICT_P
+                       | STRING_P
                        | STRIP_P
                        | SUBSCRIPTION
                        | SUPPORT
@@ -17322,6 +17909,7 @@ unreserved_keyword:
                        | SYSTEM_P
                        | TABLES
                        | TABLESPACE
+                       | TARGET
                        | TEMP
                        | TEMPLATE
                        | TEMPORARY
@@ -17337,6 +17925,7 @@ unreserved_keyword:
                        | UESCAPE
                        | UNBOUNDED
                        | UNCOMMITTED
+                       | UNCONDITIONAL
                        | UNENCRYPTED
                        | UNKNOWN
                        | UNLISTEN
@@ -17394,11 +17983,19 @@ col_name_keyword:
                        | INT_P
                        | INTEGER
                        | INTERVAL
+                       | JSON
                        | JSON_ARRAY
                        | JSON_ARRAYAGG
+                       | JSON_EXISTS
                        | JSON_OBJECT
                        | JSON_OBJECTAGG
+                       | JSON_QUERY
+                       | JSON_SCALAR
+                       | JSON_SERIALIZE
+                       | JSON_TABLE
+                       | JSON_VALUE
                        | LEAST
+                       | MERGE_ACTION
                        | NATIONAL
                        | NCHAR
                        | NONE
@@ -17630,6 +18227,7 @@ bare_label_keyword:
                        | COMMITTED
                        | COMPRESSION
                        | CONCURRENTLY
+                       | CONDITIONAL
                        | CONFIGURATION
                        | CONFLICT
                        | CONNECTION
@@ -17682,11 +18280,13 @@ bare_label_keyword:
                        | DROP
                        | EACH
                        | ELSE
+                       | EMPTY_P
                        | ENABLE_P
                        | ENCODING
                        | ENCRYPTED
                        | END_P
                        | ENUM_P
+                       | ERROR_P
                        | ESCAPE
                        | EVENT
                        | EXCLUDE
@@ -17756,8 +18356,15 @@ bare_label_keyword:
                        | JSON
                        | JSON_ARRAY
                        | JSON_ARRAYAGG
+                       | JSON_EXISTS
                        | JSON_OBJECT
                        | JSON_OBJECTAGG
+                       | JSON_QUERY
+                       | JSON_SCALAR
+                       | JSON_SERIALIZE
+                       | JSON_TABLE
+                       | JSON_VALUE
+                       | KEEP
                        | KEY
                        | KEYS
                        | LABEL
@@ -17786,6 +18393,7 @@ bare_label_keyword:
                        | MATERIALIZED
                        | MAXVALUE
                        | MERGE
+                       | MERGE_ACTION
                        | METHOD
                        | MINVALUE
                        | MODE
@@ -17795,6 +18403,7 @@ bare_label_keyword:
                        | NATIONAL
                        | NATURAL
                        | NCHAR
+                       | NESTED
                        | NEW
                        | NEXT
                        | NFC
@@ -17818,6 +18427,7 @@ bare_label_keyword:
                        | OFF
                        | OIDS
                        | OLD
+                       | OMIT
                        | ONLY
                        | OPERATOR
                        | OPTION
@@ -17838,7 +18448,9 @@ bare_label_keyword:
                        | PARTITION
                        | PASSING
                        | PASSWORD
+                       | PATH
                        | PLACING
+                       | PLAN
                        | PLANS
                        | POLICY
                        | POSITION
@@ -17855,6 +18467,7 @@ bare_label_keyword:
                        | PROGRAM
                        | PUBLICATION
                        | QUOTE
+                       | QUOTES
                        | RANGE
                        | READ
                        | REAL
@@ -17912,6 +18525,7 @@ bare_label_keyword:
                        | SMALLINT
                        | SNAPSHOT
                        | SOME
+                       | SOURCE
                        | SQL_P
                        | STABLE
                        | STANDALONE_P
@@ -17923,6 +18537,7 @@ bare_label_keyword:
                        | STORAGE
                        | STORED
                        | STRICT_P
+                       | STRING_P
                        | STRIP_P
                        | SUBSCRIPTION
                        | SUBSTRING
@@ -17935,6 +18550,7 @@ bare_label_keyword:
                        | TABLES
                        | TABLESAMPLE
                        | TABLESPACE
+                       | TARGET
                        | TEMP
                        | TEMPLATE
                        | TEMPORARY
@@ -17957,6 +18573,7 @@ bare_label_keyword:
                        | UESCAPE
                        | UNBOUNDED
                        | UNCOMMITTED
+                       | UNCONDITIONAL
                        | UNENCRYPTED
                        | UNIQUE
                        | UNKNOWN
@@ -18109,18 +18726,6 @@ makeTypeCast(Node *arg, TypeName *typename, int location)
 }
 #endif
 
-static Node *
-makeStringConst(char *str, int location)
-{
-       A_Const    *n = makeNode(A_Const);
-
-       n->val.sval.type = T_String;
-       n->val.sval.sval = str;
-       n->location = location;
-
-       return (Node *) n;
-}
-
 #ifndef pgpool_minimal_parser
 Node *
 makeStringConstCast(char *str, int location, TypeName *typename)
@@ -18402,7 +19007,7 @@ insertSelectOptions(SelectStmt *stmt,
                                         parser_errposition(exprLocation(limitClause->limitCount))));
                stmt->limitCount = limitClause->limitCount;
        }
-       if (limitClause && limitClause->limitOption != LIMIT_OPTION_DEFAULT)
+       if (limitClause)
        {
                if (stmt->limitOption)
                        ereport(ERROR,
index 9c11ea8e7659e86e39f8926941eea8ec60457c74..161282158b32b3fe9a2eb27da7965bf1b0e51eea 100644 (file)
@@ -4,8 +4,8 @@
  *       PostgreSQL's list of SQL keywords
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
index 74103605ff636a759ef34a81231a84f533d569c0..d4364dc270bde727888a186641a4482ed7488207 100644 (file)
@@ -4,8 +4,8 @@
  *       Key word lookup for PostgreSQL
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
index 62a01fa0201ca5abe7419b103e67ba58718c4066..9b16e1d1ce6b482a5b8b2a215bd6807ea66c1788 100644 (file)
@@ -5,8 +5,8 @@
  *
  * See comments in pg_list.h
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
index c8b806939eb18c2ed6834559256c2fbaa8e61977..cd1be5c830e6131ed9f5ff8cb03d8580c84da2ce 100644 (file)
@@ -4,8 +4,8 @@
  *       creator functions for various nodes. The functions here are for the
  *       most frequently created nodes.
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -538,6 +538,22 @@ makeFuncExpr(Oid funcid, Oid rettype, List *args,
        return funcexpr;
 }
 
+/*
+ * makeStringConst -
+ *     build a A_Const node of type T_String for given string
+ */
+Node *
+makeStringConst(char *str, int location)
+{
+       A_Const    *n = makeNode(A_Const);
+
+       n->val.sval.type = T_String;
+       n->val.sval.sval = str;
+       n->location = location;
+
+       return (Node *) n;
+}
+
 /*
  * makeDefElem -
  *     build a DefElem node
@@ -667,24 +683,19 @@ makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr,
 }
 
 /*
- *  * makeJsonEncoding -
- *   *    converts JSON encoding name to enum JsonEncoding
- *    */
-JsonEncoding
-makeJsonEncoding(char *name)
+ * makeJsonBehavior -
+ *   creates a JsonBehavior node
+ */
+JsonBehavior *
+makeJsonBehavior(JsonBehaviorType btype, Node *expr, int location)
 {
-    if (!pg_strcasecmp(name, "utf8"))
-        return JS_ENC_UTF8;
-    if (!pg_strcasecmp(name, "utf16"))
-        return JS_ENC_UTF16;
-    if (!pg_strcasecmp(name, "utf32"))
-        return JS_ENC_UTF32;
+       JsonBehavior *behavior = makeNode(JsonBehavior);
 
-    ereport(ERROR,
-            (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-             errmsg("unrecognized JSON encoding: %s", name)));
+       behavior->btype = btype;
+       behavior->expr = expr;
+       behavior->location = location;
 
-    return JS_ENC_DEFAULT;
+       return behavior;
 }
 
 /*
@@ -721,3 +732,39 @@ makeJsonIsPredicate(Node *expr, JsonFormat *format, JsonValueType item_type,
     return (Node *) n;
 }
 
+/*
+ * makeJsonTablePathSpec -
+ *     Make JsonTablePathSpec node from given path string and name (if any)
+ */
+JsonTablePathSpec *
+makeJsonTablePathSpec(char *string, char *name, int string_location,
+                      int name_location)
+{
+       JsonTablePathSpec *pathspec = makeNode(JsonTablePathSpec);
+
+       Assert(string != NULL);
+       pathspec->string = makeStringConst(string, string_location);
+       if (name != NULL)
+               pathspec->name = pstrdup(name);
+
+       pathspec->name_location = name_location;
+       pathspec->location = string_location;
+
+       return pathspec;
+}
+
+/*
+ * makeJsonTablePath -
+ *     Make JsonTablePath node for given path string and name
+ */
+JsonTablePath *
+makeJsonTablePath(Const *pathvalue, char *pathname)
+{
+       JsonTablePath *path = makeNode(JsonTablePath);
+
+       Assert(IsA(pathvalue, Const));
+       path->value = pathvalue;
+       path->name = pathname;
+
+       return path;
+}
index 1a0efecd68a2301111eada9d518f42e560253513..637dfbb96b22855847c413fd3201bfe644740af3 100644 (file)
@@ -3,8 +3,8 @@
  * outfuncs.c
  *       Output functions for Postgres tree nodes.
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
 #include "pg_trigger.h"
 #include "value.h"
 
+/* State flag that determines how nodeToStringInternal() should treat location fields */
+static bool write_location_fields = false;
+
 #define booltostr(x)  ((x) ? "true" : "false")
+#define SINGLE_QUOTE '\''
 
 void           _outNode(StringInfo str, void *obj);
 
@@ -36,6 +40,7 @@ static void _outAlias(StringInfo str, Alias *node);
 static void _outRangeVar(StringInfo str, RangeVar *node);
 static void _outVar(StringInfo str, Var *node);
 static void _outConst(StringInfo str, Const *node);
+static void _outSingleQuote(StringInfo str, const char *s);
 static void _outParam(StringInfo str, Param *node);
 static void _outAggref(StringInfo str, Aggref *node);
 static void _outGroupingFunc(StringInfo str, GroupingFunc *node);
@@ -348,6 +353,22 @@ outToken(StringInfo str, const char *s)
        }
 }
 
+static void
+_outSingleQuote(StringInfo str, const char *s)
+{
+       if (s == NULL || *s == '\0')
+       {
+               return;
+       }
+
+       while (*s)
+       {
+               if (*s == SINGLE_QUOTE)
+                       appendStringInfoChar(str, SINGLE_QUOTE);
+               appendStringInfoChar(str, *s++);
+       }
+}
+
 static void
 _outAlias(StringInfo str, Alias *node)
 {
@@ -421,16 +442,55 @@ _outGroupingFunc(StringInfo str, GroupingFunc *node)
 
 }
 
+static void
+_outWindowFuncRunCondition(StringInfo str, const WindowFuncRunCondition *node)
+{
+}
+
+static void
+_outMergeSupportFunc(StringInfo str, const MergeSupportFunc *node)
+{
+
+       if (IsA(node, MergeSupportFunc))
+       {
+               appendStringInfoString(str, "MERGE_ACTION()");
+       }
+}
+
 static void
 _outSubscriptingRef(StringInfo str, SubscriptingRef *node)
 {
+}
 
+static void
+_outJsonBehavior(StringInfo str, const JsonBehavior *node)
+{
 }
 
 static void
-_outFuncExpr(StringInfo str, FuncExpr *node)
+_outJsonExpr(StringInfo str, const JsonExpr *node)
+{
+
+}
+
+static void
+_outJsonTablePath(StringInfo str, const JsonTablePath *node)
 {
+}
 
+static void
+_outJsonTablePathScan(StringInfo str, const JsonTablePathScan *node)
+{
+}
+
+static void
+_outJsonTableSiblingJoin(StringInfo str, const JsonTableSiblingJoin *node)
+{
+}
+
+static void
+_outFuncExpr(StringInfo str, FuncExpr *node)
+{
 }
 
 static void
@@ -1340,6 +1400,31 @@ _outTriggerTransition(StringInfo str, TriggerTransition *node)
 {
 }
 
+static void
+_outJsonArgument(StringInfo str, const JsonArgument *node)
+{
+}
+
+static void
+_outJsonFuncExpr(StringInfo str, const JsonFuncExpr *node)
+{
+}
+
+static void
+_outJsonTablePathSpec(StringInfo str, const JsonTablePathSpec *node)
+{
+}
+
+static void
+_outJsonTable(StringInfo str, const JsonTable *node)
+{
+}
+
+static void
+_outJsonTableColumn(StringInfo str, const JsonTableColumn *node)
+{
+}
+
 static void
 _outReturnStmt(StringInfo str, ReturnStmt *node)
 {
@@ -1647,15 +1732,18 @@ static void
 _outMergeWhenClauses(StringInfo str, List *node)
 {
        ListCell   *temp;
+       char comma;
 
        foreach(temp, node)
        {
                MergeWhenClause *m = (MergeWhenClause *) lfirst(temp);
 
-               if (m->matched)
+               if (m->matchKind == MERGE_WHEN_MATCHED)
                        appendStringInfoString(str, " WHEN MATCHED ");
+               else if (m->matchKind == MERGE_WHEN_NOT_MATCHED_BY_SOURCE)
+                       appendStringInfoString(str, " WHEN NOT MATCHED BY SOURCE ");
                else
-                       appendStringInfoString(str, " WHEN NOT MATCHED ");
+                       appendStringInfoString(str, " WHEN NOT MATCHED BY TARGET ");
 
                if (m->condition)
                {
@@ -1670,13 +1758,71 @@ _outMergeWhenClauses(StringInfo str, List *node)
                        ListCell *s;
 
                        case CMD_UPDATE:
+                               comma = 0;
+                               appendStringInfo(str, "UPDATE SET ");
                                foreach(s, m->targetList)
                                {
                                        ResTarget *r = (ResTarget *) lfirst(s);
-                                       appendStringInfo(str, "UPDATE SET %s = ", r->name);
+
+                                       if (comma == 0)
+                                               comma = 1;
+                                       else
+                                               appendStringInfoString(str, ", ");
+
+                                       appendStringInfo(str, "\"%s\" = ", r->name);
                                        _outNode(str, r->val);
                                }
                                break;
+                       case CMD_INSERT:
+                               appendStringInfo(str, "INSERT ");
+                               if (m->targetList)
+                               {
+                                       comma = 0;
+                                       appendStringInfoString(str, "(");
+                                       foreach(s, m->targetList)
+                                       {
+                                               ResTarget *r = (ResTarget *) lfirst(s);
+
+                                               if (comma == 0)
+                                                       comma = 1;
+                                               else
+                                                       appendStringInfoString(str, ", ");
+
+                                               appendStringInfo(str, "\"%s\"", r->name);
+
+                                       }
+                                       appendStringInfoString(str, ") ");
+                               }
+
+                               if (m->override == OVERRIDING_SYSTEM_VALUE)
+                                       appendStringInfoString(str, "OVERRIDING SYSTEM VALUE ");
+                               else if (m->override == OVERRIDING_USER_VALUE)
+                                       appendStringInfoString(str, "OVERRIDING USER VALUE ");
+
+                               if (m->values)
+                               {
+                                       comma = 0;
+                                       appendStringInfo(str, "VALUES ");
+                                       appendStringInfoString(str, "(");
+
+                                       foreach(s, m->values)
+                                       {
+                                               if (comma == 0)
+                                                       comma = 1;
+                                               else
+                                                       appendStringInfoString(str, ", ");
+
+                                               _outNode(str, lfirst(s));
+                                       }
+                                       appendStringInfoString(str, ")");
+                               }
+                               break;
+                       case CMD_DELETE:
+                               appendStringInfo(str, "DELETE ");
+                               break;
+                       case CMD_NOTHING:
+                               appendStringInfo(str, "DO NOTHING ");
+                               break;
                        default:
                                break;
                }
@@ -1914,8 +2060,13 @@ _outString(StringInfo str, const String *node)
 static void
 _outBitString(StringInfo str, const BitString *node)
 {
-    /* internal representation already has leading 'b' */
-    appendStringInfoString(str, node->bsval);
+       /*
+        * The lexer will always produce a string starting with 'b' or 'x'.  There
+        * might be characters following that that need escaping, but outToken
+        * won't escape the 'b' or 'x'.  This is relied on by nodeTokenType.
+        */
+       Assert(node->bsval[0] == 'b' || node->bsval[0] == 'x');
+       outToken(str, node->bsval);
 }
 
 static void
@@ -2626,6 +2777,12 @@ _outMergeStmt(StringInfo str, MergeStmt *node)
        {
                _outMergeWhenClauses(str, node->mergeWhenClauses);
        }
+
+       if (node->returningList)
+       {
+               appendStringInfoString(str, " RETURNING ");
+               _outNode(str, node->returningList);
+       }
 }
 
 static void
@@ -2878,6 +3035,7 @@ _outCopyStmt(StringInfo str, CopyStmt *node)
        else
                appendStringInfoString(str, node->is_from == TRUE ? "STDIN " : "STDOUT ");
 
+
        if (server_version_num < 90000)
        {
                foreach(lc, node->options)
@@ -2940,7 +3098,7 @@ _outCopyStmt(StringInfo str, CopyStmt *node)
                /* version_num >= 90000 */
                if (node->options)
                {
-                       appendStringInfoString(str, "(");
+                       appendStringInfoString(str, "WITH (");
 
                        foreach(lc, node->options)
                        {
@@ -2953,18 +3111,35 @@ _outCopyStmt(StringInfo str, CopyStmt *node)
                                appendStringInfoString(str, " ");
 
                                if (strcmp(e->defname, "format") == 0
+                                       || strcmp(e->defname, "freeze") == 0
                                        || strcmp(e->defname, "oids") == 0
-                                       || strcmp(e->defname, "delimiter") == 0
-                                       || strcmp(e->defname, "null") == 0
                                        || strcmp(e->defname, "header") == 0
-                                       || strcmp(e->defname, "quote") == 0
-                                       || strcmp(e->defname, "escape") == 0)
+                                       || strcmp(e->defname, "on_error") == 0
+                                       || strcmp(e->defname, "log_verbosity") == 0)
                                        _outNode(str, e->arg);
-                               else if (strcmp(e->defname, "force_not_null") == 0)
+                               else if (strcmp(e->defname, "delimiter") == 0
+                                       || strcmp(e->defname, "null") == 0
+                                       || strcmp(e->defname, "default") == 0
+                                       || strcmp(e->defname, "quote") == 0
+                                       || strcmp(e->defname, "escape") == 0
+                                       || strcmp(e->defname, "encoding") == 0)
                                {
-                                       appendStringInfoString(str, "(");
-                                       _outIdList(str, (List *) e->arg);
-                                       appendStringInfoString(str, ")");
+                                       String     *value = (String *) e->arg;
+                                       appendStringInfoString(str, "'");
+                                       _outSingleQuote(str, value->sval);
+                                       appendStringInfoString(str, "'");
+                               }
+                               else if (strcmp(e->defname, "force_not_null") == 0
+                                       || strcmp(e->defname, "force_null") == 0)
+                               {
+                                       if (IsA(e->arg, A_Star))
+                                               appendStringInfoString(str, "*");
+                                       else if (IsA(e->arg, List))
+                                       {
+                                               appendStringInfoString(str, "(");
+                                               _outIdList(str, (List *) e->arg);
+                                               appendStringInfoString(str, ")");
+                                       }
                                }
                                else if (strcmp(e->defname, "force_quote") == 0)
                                {
@@ -5708,6 +5883,88 @@ _outXmlExpr(StringInfo str, XmlExpr *node)
        }
 }
 
+
+static void
+_outJsonFormat(StringInfo str, const JsonFormat *node)
+{
+}
+
+static void
+_outJsonReturning(StringInfo str, const JsonReturning *node)
+{
+}
+
+static void
+_outJsonValueExpr(StringInfo str, const JsonValueExpr *node)
+{
+}
+
+static void
+_outJsonConstructorExpr(StringInfo str, const JsonConstructorExpr *node)
+{
+}
+
+static void
+_outJsonIsPredicate(StringInfo str, const JsonIsPredicate *node)
+{
+}
+
+static void
+_outJsonOutput(StringInfo str, const JsonOutput *node)
+{
+}
+
+static void
+_outJsonKeyValue(StringInfo str, const JsonKeyValue *node)
+{
+}
+
+static void
+_outJsonParseExpr(StringInfo str, const JsonParseExpr *node)
+{
+}
+
+static void
+_outJsonScalarExpr(StringInfo str, const JsonScalarExpr *node)
+{
+}
+
+static void
+_outJsonSerializeExpr(StringInfo str, const JsonSerializeExpr *node)
+{
+}
+
+static void
+_outJsonObjectConstructor(StringInfo str, const JsonObjectConstructor *node)
+{
+}
+
+static void
+_outJsonArrayConstructor(StringInfo str, const JsonArrayConstructor *node)
+{
+}
+
+
+static void
+_outJsonArrayQueryConstructor(StringInfo str, const JsonArrayQueryConstructor *node)
+{
+}
+
+static void
+_outJsonAggConstructor(StringInfo str, const JsonAggConstructor *node)
+{
+}
+
+static void
+_outJsonObjectAgg(StringInfo str, const JsonObjectAgg *node)
+{
+}
+
+static void
+_outJsonArrayAgg(StringInfo str, const JsonArrayAgg *node)
+{
+}
+
 static void
 _outXmlSerialize(StringInfo str, XmlSerialize *node)
 {
@@ -5815,6 +6072,11 @@ _outPartitionRangeDatum(StringInfo str, PartitionRangeDatum *node)
 {
 }
 
+static void
+_outSinglePartitionSpec(StringInfo str, const SinglePartitionSpec *node)
+{
+}
+
 /*
  * _outNode -
  *       converts a Node into ascii string and append it to 'str'
@@ -5878,6 +6140,12 @@ _outNode(StringInfo str, void *obj)
                                /*
                                 * case T_WindowFunc: _outWindowFunc(str, obj); break;
                                 */
+                       case T_WindowFuncRunCondition:
+                               _outWindowFuncRunCondition(str, obj);
+                               break;
+                       case T_MergeSupportFunc:
+                               _outMergeSupportFunc(str, obj);
+                               break;
                        case T_SubscriptingRef:
                                _outSubscriptingRef(str, obj);
                                break;
@@ -5967,12 +6235,45 @@ _outNode(StringInfo str, void *obj)
                        case T_XmlExpr:
                                _outXmlExpr(str, obj);
                                break;
+                       case T_JsonFormat:
+                               _outJsonFormat(str, obj);
+                               break;
+                       case T_JsonReturning:
+                               _outJsonReturning(str, obj);
+                               break;
+                       case T_JsonValueExpr:
+                               _outJsonValueExpr(str, obj);
+                               break;
+                       case T_JsonConstructorExpr:
+                               _outJsonConstructorExpr(str, obj);
+                               break;
+                       case T_JsonIsPredicate:
+                               _outJsonIsPredicate(str, obj);
+                               break;
+                       case T_JsonBehavior:
+                               _outJsonBehavior(str, obj);
+                               break;
+                       case T_JsonExpr:
+                               _outJsonExpr(str, obj);
+                               break;
+                       case T_JsonTablePath:
+                               _outJsonTablePath(str, obj);
+                               break;
+                       case T_JsonTablePathScan:
+                               _outJsonTablePathScan(str, obj);
+                               break;
+                       case T_JsonTableSiblingJoin:
+                               _outJsonTableSiblingJoin(str, obj);
+                               break;
                        case T_NullTest:
                                _outNullTest(str, obj);
                                break;
                        case T_BooleanTest:
                                _outBooleanTest(str, obj);
                                break;
+                       case T_MergeAction:
+                               _outMergeAction(str, obj);
+                               break;
                        case T_CoerceToDomain:
                                _outCoerceToDomain(str, obj);
                                break;
@@ -6093,9 +6394,6 @@ _outNode(StringInfo str, void *obj)
                        case T_MergeWhenClause:
                                _outMergeWhenClauses(str, obj);
                                break;
-                       case T_MergeAction:
-                               _outMergeAction(str, obj);
-                               break;
                        case T_SetOperationStmt:
                                _outSetOperationStmt(str, obj);
                                break;
@@ -6184,6 +6482,54 @@ _outNode(StringInfo str, void *obj)
                        case T_TriggerTransition:
                                _outTriggerTransition(str, obj);
                                break;
+                       case T_JsonOutput:
+                               _outJsonOutput(str, obj);
+                               break;
+                       case T_JsonArgument:
+                               _outJsonArgument(str, obj);
+                               break;
+                       case T_JsonFuncExpr:
+                               _outJsonFuncExpr(str, obj);
+                               break;
+                       case T_JsonTablePathSpec:
+                               _outJsonTablePathSpec(str, obj);
+                               break;
+                       case T_JsonTable:
+                               _outJsonTable(str, obj);
+                               break;
+                       case T_JsonTableColumn:
+                               _outJsonTableColumn(str, obj);
+                               break;
+                       case T_JsonKeyValue:
+                               _outJsonKeyValue(str, obj);
+                               break;
+                       case T_JsonParseExpr:
+                               _outJsonParseExpr(str, obj);
+                               break;
+                       case T_JsonScalarExpr:
+                               _outJsonScalarExpr(str, obj);
+                               break;
+                       case T_JsonSerializeExpr:
+                               _outJsonSerializeExpr(str, obj);
+                               break;
+                       case T_JsonObjectConstructor:
+                               _outJsonObjectConstructor(str, obj);
+                               break;
+                       case T_JsonArrayConstructor:
+                               _outJsonArrayConstructor(str, obj);
+                               break;
+                       case T_JsonArrayQueryConstructor:
+                               _outJsonArrayQueryConstructor(str, obj);
+                               break;
+                       case T_JsonAggConstructor:
+                               _outJsonAggConstructor(str, obj);
+                               break;
+                       case T_JsonObjectAgg:
+                               _outJsonObjectAgg(str, obj);
+                               break;
+                       case T_JsonArrayAgg:
+                               _outJsonArrayAgg(str, obj);
+                               break;
                        case T_PartitionElem:
                                _outPartitionElem(str, obj);
                                break;
@@ -6196,6 +6542,9 @@ _outNode(StringInfo str, void *obj)
                        case T_PartitionRangeDatum:
                                _outPartitionRangeDatum(str, obj);
                                break;
+                       case T_SinglePartitionSpec:
+                               _outSinglePartitionSpec(str, obj);
+                               break;
 
                        case T_InsertStmt:
                                _outInsertStmt(str, obj);
@@ -6490,13 +6839,35 @@ _outNode(StringInfo str, void *obj)
 /*
  * nodeToString -
  *        returns the ascii representation of the Node as a palloc'd string
+ *
+ * write_loc_fields determines whether location fields are output with their
+ * actual value rather than -1.  The actual value can be useful for debugging,
+ * but for most uses, the actual value is not useful, since the original query
+ * string is no longer available.
  */
-char *
-nodeToString(const void *obj)
+static char *
+nodeToStringInternal(const void *obj, bool write_loc_fields)
 {
-       StringInfoData     str;
+       StringInfoData str;
+       bool            save_write_location_fields;
 
+       save_write_location_fields = write_location_fields;
+       write_location_fields = write_loc_fields;
+
+       /* see stringinfo.h for an explanation of this maneuver */
        initStringInfo(&str);
        _outNode(&str, (void *) obj);
+
+       write_location_fields = save_write_location_fields;
+
        return str.data;
 }
+
+/*
+ * Externally visible entry points
+ */
+char *
+nodeToString(const void *obj)
+{
+       return nodeToStringInternal(obj, false);
+}
index c4334c4e524adb4bcefe046a9e68e2608743c270..0cd5b95ee7e1db9c29108c266b1a5090ebba305c 100644 (file)
@@ -10,8 +10,8 @@
  * analyze.c and related files.
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
@@ -75,12 +75,12 @@ raw_parser(const char *str, RawParseMode mode, int len, bool *error, bool use_mi
        {
                /* this array is indexed by RawParseMode enum */
                static const int mode_token[] = {
-                       0,                                      /* RAW_PARSE_DEFAULT */
-                       MODE_TYPE_NAME,         /* RAW_PARSE_TYPE_NAME */
-                       MODE_PLPGSQL_EXPR,      /* RAW_PARSE_PLPGSQL_EXPR */
-                       MODE_PLPGSQL_ASSIGN1,   /* RAW_PARSE_PLPGSQL_ASSIGN1 */
-                       MODE_PLPGSQL_ASSIGN2,   /* RAW_PARSE_PLPGSQL_ASSIGN2 */
-                       MODE_PLPGSQL_ASSIGN3    /* RAW_PARSE_PLPGSQL_ASSIGN3 */
+                       [RAW_PARSE_DEFAULT] = 0,
+                       [RAW_PARSE_TYPE_NAME] = MODE_TYPE_NAME,
+                       [RAW_PARSE_PLPGSQL_EXPR] = MODE_PLPGSQL_EXPR,
+                       [RAW_PARSE_PLPGSQL_ASSIGN1] = MODE_PLPGSQL_ASSIGN1,
+                       [RAW_PARSE_PLPGSQL_ASSIGN2] = MODE_PLPGSQL_ASSIGN2,
+                       [RAW_PARSE_PLPGSQL_ASSIGN3] = MODE_PLPGSQL_ASSIGN3,
                };
 
                yyextra.have_lookahead = true;
@@ -676,11 +676,15 @@ parse_version(const char *versionString)
 
        cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev);
 
-       if (cnt < 2)
-               return -1;
-
        if (cnt == 2)
+       {
+               vrev = 0;
+       }
+       else if (cnt == 1)
+       {
+               vmin = 0;
                vrev = 0;
+       }
 
        return (100 * vmaj + vmin) * 100 + vrev;
 }
index b7f934b217021607963bb044289100b84ef901ea..03f86b5f1c3173c9cd37ad5482fab8de9cc670b4 100644 (file)
@@ -22,8 +22,8 @@
  * Postgres 9.2, this check is made automatically by the Makefile.)
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
@@ -219,16 +219,16 @@ extern void core_yyset_column(int column_no, yyscan_t yyscanner);
  * versions of Postgres failed to recognize -- as a comment if the input
  * did not end with a newline.
  *
- * XXX perhaps \f (formfeed) should be treated as a newline as well?
+ * non_newline_space tracks all the other space characters except newlines.
  *
  * XXX if you change the set of whitespace characters, fix scanner_isspace()
  * to agree.
  */
 
-space                  [ \t\n\r\f]
-horiz_space            [ \t\f]
-newline                        [\n\r]
-non_newline            [^\n\r]
+space                          [ \t\n\r\f\v]
+non_newline_space      [ \t\f\v]
+newline                                [\n\r]
+non_newline                    [^\n\r]
 
 comment                        ("--"{non_newline}*)
 
@@ -242,8 +242,8 @@ whitespace          ({space}+|{comment})
  */
 
 special_whitespace             ({space}+|{comment}{newline})
-horiz_whitespace               ({horiz_space}|{comment})
-whitespace_with_newline        ({horiz_whitespace}*{newline}{special_whitespace}*)
+non_newline_whitespace ({non_newline_space}|{comment})
+whitespace_with_newline        ({non_newline_whitespace}*{newline}{special_whitespace}*)
 
 quote                  '
 /* If we see {quote} then {quotecontinue}, the quoted string continues */
@@ -413,7 +413,7 @@ octfail                     0[oO]_?
 binfail                        0[bB]_?
 
 numeric                        (({decinteger}\.{decinteger}?)|(\.{decinteger}))
-numericfail            {decdigit}+\.\.
+numericfail            {decinteger}\.\.
 
 real                   ({decinteger}|{numeric})[Ee][-+]?{decinteger}
 realfail               ({decinteger}|{numeric})[Ee][-+]
@@ -425,8 +425,9 @@ bininteger_junk     {bininteger}{ident_start}
 numeric_junk   {numeric}{ident_start}
 real_junk              {real}{ident_start}
 
-param                  \${decinteger}
-param_junk             \${decinteger}{ident_start}
+/* Positional parameters don't accept underscores. */
+param                  \${decdigit}+
+param_junk             \${decdigit}+{ident_start}
 
 other                  .
 
@@ -570,7 +571,7 @@ other                       .
                                                ereport(ERROR,
                                                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                                                 errmsg("unsafe use of string constant with Unicode escapes"),
-                                                                errdetail("String constants with Unicode escapes cannot be used when standard_conforming_strings is off."),
+                                                                errdetail("String constants with Unicode escapes cannot be used when \"standard_conforming_strings\" is off."),
                                                                 lexer_errposition()));
                                        BEGIN(xus);
                                        startlit();
@@ -1439,6 +1440,8 @@ unescape_single_char(unsigned char c, core_yyscan_t yyscanner)
                        return '\r';
                case 't':
                        return '\t';
+               case 'v':
+                       return '\v';
                default:
                        /* check for backslash followed by non-7-bit-ASCII */
                        if (c == '\0' || IS_HIGHBIT_SET(c))
index 9d11cde36b418fa2aeb1e6031c8c9e239ec448fc..27df0468ab13c37918415fed2948690b0b5457c8 100644 (file)
@@ -3,8 +3,8 @@
  * scansup.c
  *       scanner support routines used by the core lexer
  *
- * Portions Copyright (c) 1996-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -127,6 +127,7 @@ scanner_isspace(char ch)
                ch == '\t' ||
                ch == '\n' ||
                ch == '\r' ||
+               ch == '\v' ||
                ch == '\f')
                return true;
        return false;
index 0e528394755a1922cf00dcd1e9879fb1ef475ae0..19e666b7cd5deb725596cad50d9aa2cc07ede514 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * Copyright (c) 2003-2023, PgPool Global Development Group
+ * Copyright (c) 2003-2024, PgPool Global Development Group
  * Copyright (c) 1983, 1995, 1996 Eric P. Allman
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
index 24884943e034a40581155db24d512edc115f6124..c35e5bacf37c21e52031bb185c209b74a51c08b1 100644 (file)
@@ -6,8 +6,8 @@
  * It can be used to buffer either ordinary C strings (null-terminated text)
  * or arbitrary binary data.  All storage is allocated with palloc().
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *       src/backend/lib/stringinfo.c
@@ -59,10 +59,16 @@ initStringInfo(StringInfo str)
  *
  * Reset the StringInfo: the data buffer remains valid, but its
  * previous content, if any, is cleared.
+ *
+ * Read-only StringInfos as initialized by initReadOnlyStringInfo cannot be
+ * reset.
  */
 void
 resetStringInfo(StringInfo str)
 {
+       /* don't allow resets of read-only StringInfos */
+       Assert(str->maxlen != 0);
+
        str->data[0] = '\0';
        str->len = 0;
        str->cursor = 0;
@@ -273,6 +279,9 @@ enlargeStringInfo(StringInfo str, int needed)
 {
        int                     newlen;
 
+       /* validate this is not a read-only StringInfo */
+       Assert(str->maxlen != 0);
+
        /*
         * Guard against out-of-range "needed" values.  Without this, we can get
         * an overflow or infinite loop in the following.
@@ -316,3 +325,19 @@ enlargeStringInfo(StringInfo str, int needed)
 
        str->maxlen = newlen;
 }
+
+/*
+ * destroyStringInfo
+ *
+ * Frees a StringInfo and its buffer (opposite of makeStringInfo()).
+ * This must only be called on palloc'd StringInfos.
+ */
+void
+destroyStringInfo(StringInfo str)
+{
+       /* don't allow destroys of read-only StringInfos */
+       Assert(str->maxlen != 0);
+
+       pfree(str->data);
+       pfree(str);
+}
index a689a1e28c0d131a330b4aa75e1cb38b8a9859ab..3b7ab09a839ec89fe8d3e6be6f507902e669409d 100644 (file)
@@ -4,8 +4,8 @@
  *       implementation of value nodes
  *
  *
- * Copyright (c) 2003-2023, PgPool Global Development Group
- * Copyright (c) 2003-2023, PostgreSQL Global Development Group
+ * Copyright (c) 2003-2024, PgPool Global Development Group
+ * Copyright (c) 2003-2024, PostgreSQL Global Development Group
  *
  *
  * IDENTIFICATION
index dee5e9ec36ac96652cd157eebf6ae87b73dff5b0..9dbae197c4af66e371922af7de7ef97d943f2d49 100644 (file)
 
 const pg_enc2name pg_enc2name_tbl[] =
 {
-       DEF_ENC2NAME(SQL_ASCII, 0),
-       DEF_ENC2NAME(EUC_JP, 20932),
-       DEF_ENC2NAME(EUC_CN, 20936),
-       DEF_ENC2NAME(EUC_KR, 51949),
-       DEF_ENC2NAME(EUC_TW, 0),
-       DEF_ENC2NAME(EUC_JIS_2004, 20932),
-       DEF_ENC2NAME(UTF8, 65001),
-       DEF_ENC2NAME(MULE_INTERNAL, 0),
-       DEF_ENC2NAME(LATIN1, 28591),
-       DEF_ENC2NAME(LATIN2, 28592),
-       DEF_ENC2NAME(LATIN3, 28593),
-       DEF_ENC2NAME(LATIN4, 28594),
-       DEF_ENC2NAME(LATIN5, 28599),
-       DEF_ENC2NAME(LATIN6, 0),
-       DEF_ENC2NAME(LATIN7, 0),
-       DEF_ENC2NAME(LATIN8, 0),
-       DEF_ENC2NAME(LATIN9, 28605),
-       DEF_ENC2NAME(LATIN10, 0),
-       DEF_ENC2NAME(WIN1256, 1256),
-       DEF_ENC2NAME(WIN1258, 1258),
-       DEF_ENC2NAME(WIN866, 866),
-       DEF_ENC2NAME(WIN874, 874),
-       DEF_ENC2NAME(KOI8R, 20866),
-       DEF_ENC2NAME(WIN1251, 1251),
-       DEF_ENC2NAME(WIN1252, 1252),
-       DEF_ENC2NAME(ISO_8859_5, 28595),
-       DEF_ENC2NAME(ISO_8859_6, 28596),
-       DEF_ENC2NAME(ISO_8859_7, 28597),
-       DEF_ENC2NAME(ISO_8859_8, 28598),
-       DEF_ENC2NAME(WIN1250, 1250),
-       DEF_ENC2NAME(WIN1253, 1253),
-       DEF_ENC2NAME(WIN1254, 1254),
-       DEF_ENC2NAME(WIN1255, 1255),
-       DEF_ENC2NAME(WIN1257, 1257),
-       DEF_ENC2NAME(KOI8U, 21866),
-       DEF_ENC2NAME(SJIS, 932),
-       DEF_ENC2NAME(BIG5, 950),
-       DEF_ENC2NAME(GBK, 936),
-       DEF_ENC2NAME(UHC, 0),
-       DEF_ENC2NAME(GB18030, 54936),
-       DEF_ENC2NAME(JOHAB, 0),
-       DEF_ENC2NAME(SHIFT_JIS_2004, 932)
+       [PG_SQL_ASCII] = DEF_ENC2NAME(SQL_ASCII, 0),
+       [PG_EUC_JP] = DEF_ENC2NAME(EUC_JP, 20932),
+       [PG_EUC_CN] = DEF_ENC2NAME(EUC_CN, 20936),
+       [PG_EUC_KR] = DEF_ENC2NAME(EUC_KR, 51949),
+       [PG_EUC_TW] = DEF_ENC2NAME(EUC_TW, 0),
+       [PG_EUC_JIS_2004] = DEF_ENC2NAME(EUC_JIS_2004, 20932),
+       [PG_UTF8] = DEF_ENC2NAME(UTF8, 65001),
+       [PG_MULE_INTERNAL] = DEF_ENC2NAME(MULE_INTERNAL, 0),
+       [PG_LATIN1] = DEF_ENC2NAME(LATIN1, 28591),
+       [PG_LATIN2] = DEF_ENC2NAME(LATIN2, 28592),
+       [PG_LATIN3] = DEF_ENC2NAME(LATIN3, 28593),
+       [PG_LATIN4] = DEF_ENC2NAME(LATIN4, 28594),
+       [PG_LATIN5] = DEF_ENC2NAME(LATIN5, 28599),
+       [PG_LATIN6] = DEF_ENC2NAME(LATIN6, 0),
+       [PG_LATIN7] = DEF_ENC2NAME(LATIN7, 0),
+       [PG_LATIN8] = DEF_ENC2NAME(LATIN8, 0),
+       [PG_LATIN9] = DEF_ENC2NAME(LATIN9, 28605),
+       [PG_LATIN10] = DEF_ENC2NAME(LATIN10, 0),
+       [PG_WIN1256] = DEF_ENC2NAME(WIN1256, 1256),
+       [PG_WIN1258] = DEF_ENC2NAME(WIN1258, 1258),
+       [PG_WIN866] = DEF_ENC2NAME(WIN866, 866),
+       [PG_WIN874] = DEF_ENC2NAME(WIN874, 874),
+       [PG_KOI8R] = DEF_ENC2NAME(KOI8R, 20866),
+       [PG_WIN1251] = DEF_ENC2NAME(WIN1251, 1251),
+       [PG_WIN1252] = DEF_ENC2NAME(WIN1252, 1252),
+       [PG_ISO_8859_5] = DEF_ENC2NAME(ISO_8859_5, 28595),
+       [PG_ISO_8859_6] = DEF_ENC2NAME(ISO_8859_6, 28596),
+       [PG_ISO_8859_7] = DEF_ENC2NAME(ISO_8859_7, 28597),
+       [PG_ISO_8859_8] = DEF_ENC2NAME(ISO_8859_8, 28598),
+       [PG_WIN1250] = DEF_ENC2NAME(WIN1250, 1250),
+       [PG_WIN1253] = DEF_ENC2NAME(WIN1253, 1253),
+       [PG_WIN1254] = DEF_ENC2NAME(WIN1254, 1254),
+       [PG_WIN1255] = DEF_ENC2NAME(WIN1255, 1255),
+       [PG_WIN1257] = DEF_ENC2NAME(WIN1257, 1257),
+       [PG_KOI8U] = DEF_ENC2NAME(KOI8U, 21866),
+       [PG_SJIS] = DEF_ENC2NAME(SJIS, 932),
+       [PG_BIG5] = DEF_ENC2NAME(BIG5, 950),
+       [PG_GBK] = DEF_ENC2NAME(GBK, 936),
+       [PG_UHC] = DEF_ENC2NAME(UHC, 949),
+       [PG_GB18030] = DEF_ENC2NAME(GB18030, 54936),
+       [PG_JOHAB] = DEF_ENC2NAME(JOHAB, 0),
+       [PG_SHIFT_JIS_2004] = DEF_ENC2NAME(SHIFT_JIS_2004, 932),
 };
 
 /* ----------
@@ -69,50 +69,50 @@ const pg_enc2name pg_enc2name_tbl[] =
  * This covers all encodings except MULE_INTERNAL, which is alien to gettext.
  * ----------
  */
-const pg_enc2gettext pg_enc2gettext_tbl[] =
-{
-       {PG_SQL_ASCII, "US-ASCII"},
-       {PG_UTF8, "UTF-8"},
-       {PG_LATIN1, "LATIN1"},
-       {PG_LATIN2, "LATIN2"},
-       {PG_LATIN3, "LATIN3"},
-       {PG_LATIN4, "LATIN4"},
-       {PG_ISO_8859_5, "ISO-8859-5"},
-       {PG_ISO_8859_6, "ISO_8859-6"},
-       {PG_ISO_8859_7, "ISO-8859-7"},
-       {PG_ISO_8859_8, "ISO-8859-8"},
-       {PG_LATIN5, "LATIN5"},
-       {PG_LATIN6, "LATIN6"},
-       {PG_LATIN7, "LATIN7"},
-       {PG_LATIN8, "LATIN8"},
-       {PG_LATIN9, "LATIN-9"},
-       {PG_LATIN10, "LATIN10"},
-       {PG_KOI8R, "KOI8-R"},
-       {PG_KOI8U, "KOI8-U"},
-       {PG_WIN1250, "CP1250"},
-       {PG_WIN1251, "CP1251"},
-       {PG_WIN1252, "CP1252"},
-       {PG_WIN1253, "CP1253"},
-       {PG_WIN1254, "CP1254"},
-       {PG_WIN1255, "CP1255"},
-       {PG_WIN1256, "CP1256"},
-       {PG_WIN1257, "CP1257"},
-       {PG_WIN1258, "CP1258"},
-       {PG_WIN866, "CP866"},
-       {PG_WIN874, "CP874"},
-       {PG_EUC_CN, "EUC-CN"},
-       {PG_EUC_JP, "EUC-JP"},
-       {PG_EUC_KR, "EUC-KR"},
-       {PG_EUC_TW, "EUC-TW"},
-       {PG_EUC_JIS_2004, "EUC-JP"},
-       {PG_SJIS, "SHIFT-JIS"},
-       {PG_BIG5, "BIG5"},
-       {PG_GBK, "GBK"},
-       {PG_UHC, "UHC"},
-       {PG_GB18030, "GB18030"},
-       {PG_JOHAB, "JOHAB"},
-       {PG_SHIFT_JIS_2004, "SHIFT_JISX0213"},
-       {0, NULL}
+const char *pg_enc2gettext_tbl[] =
+{
+       [PG_SQL_ASCII] = "US-ASCII",
+       [PG_UTF8] = "UTF-8",
+       [PG_MULE_INTERNAL] = NULL,
+       [PG_LATIN1] = "LATIN1",
+       [PG_LATIN2] = "LATIN2",
+       [PG_LATIN3] = "LATIN3",
+       [PG_LATIN4] = "LATIN4",
+       [PG_ISO_8859_5] = "ISO-8859-5",
+       [PG_ISO_8859_6] = "ISO_8859-6",
+       [PG_ISO_8859_7] = "ISO-8859-7",
+       [PG_ISO_8859_8] = "ISO-8859-8",
+       [PG_LATIN5] = "LATIN5",
+       [PG_LATIN6] = "LATIN6",
+       [PG_LATIN7] = "LATIN7",
+       [PG_LATIN8] = "LATIN8",
+       [PG_LATIN9] = "LATIN-9",
+       [PG_LATIN10] = "LATIN10",
+       [PG_KOI8R] = "KOI8-R",
+       [PG_KOI8U] = "KOI8-U",
+       [PG_WIN1250] = "CP1250",
+       [PG_WIN1251] = "CP1251",
+       [PG_WIN1252] = "CP1252",
+       [PG_WIN1253] = "CP1253",
+       [PG_WIN1254] = "CP1254",
+       [PG_WIN1255] = "CP1255",
+       [PG_WIN1256] = "CP1256",
+       [PG_WIN1257] = "CP1257",
+       [PG_WIN1258] = "CP1258",
+       [PG_WIN866] = "CP866",
+       [PG_WIN874] = "CP874",
+       [PG_EUC_CN] = "EUC-CN",
+       [PG_EUC_JP] = "EUC-JP",
+       [PG_EUC_KR] = "EUC-KR",
+       [PG_EUC_TW] = "EUC-TW",
+       [PG_EUC_JIS_2004] = "EUC-JP",
+       [PG_SJIS] = "SHIFT-JIS",
+       [PG_BIG5] = "BIG5",
+       [PG_GBK] = "GBK",
+       [PG_UHC] = "UHC",
+       [PG_GB18030] = "GB18030",
+       [PG_JOHAB] = "JOHAB",
+       [PG_SHIFT_JIS_2004] = "SHIFT_JISX0213",
 };
 
 
@@ -576,39 +576,6 @@ pg_utf2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
 }
 
 
-/*
- * Map a Unicode code point to UTF-8.  utf8string must have 4 bytes of
- * space allocated.
- */
-unsigned char *
-unicode_to_utf8(pg_wchar c, unsigned char *utf8string)
-{
-       if (c <= 0x7F)
-       {
-               utf8string[0] = c;
-       }
-       else if (c <= 0x7FF)
-       {
-               utf8string[0] = 0xC0 | ((c >> 6) & 0x1F);
-               utf8string[1] = 0x80 | (c & 0x3F);
-       }
-       else if (c <= 0xFFFF)
-       {
-               utf8string[0] = 0xE0 | ((c >> 12) & 0x0F);
-               utf8string[1] = 0x80 | ((c >> 6) & 0x3F);
-               utf8string[2] = 0x80 | (c & 0x3F);
-       }
-       else
-       {
-               utf8string[0] = 0xF0 | ((c >> 18) & 0x07);
-               utf8string[1] = 0x80 | ((c >> 12) & 0x3F);
-               utf8string[2] = 0x80 | ((c >> 6) & 0x3F);
-               utf8string[3] = 0x80 | (c & 0x3F);
-       }
-
-       return utf8string;
-}
-
 /*
  * Trivial conversion from pg_wchar to UTF-8.
  * caller should allocate enough space for "to"
@@ -1104,14 +1071,13 @@ ucs_wcwidth(pg_wchar ucs)
                {0x2E80, 0x2E99},
                {0x2E9B, 0x2EF3},
                {0x2F00, 0x2FD5},
-               {0x2FF0, 0x2FFB},
-               {0x3000, 0x303E},
+               {0x2FF0, 0x303E},
                {0x3041, 0x3096},
                {0x3099, 0x30FF},
                {0x3105, 0x312F},
                {0x3131, 0x318E},
                {0x3190, 0x31E3},
-               {0x31F0, 0x321E},
+               {0x31EF, 0x321E},
                {0x3220, 0x3247},
                {0x3250, 0x4DBF},
                {0x4E00, 0xA48C},
@@ -1217,34 +1183,6 @@ ucs_wcwidth(pg_wchar ucs)
        return 1;
 }
 
-/*
- * Convert a UTF-8 character to a Unicode code point.
- * This is a one-character version of pg_utf2wchar_with_len.
- *
- * No error checks here, c must point to a long-enough string.
- */
-pg_wchar
-utf8_to_unicode(const unsigned char *c)
-{
-       if ((*c & 0x80) == 0)
-               return (pg_wchar) c[0];
-       else if ((*c & 0xe0) == 0xc0)
-               return (pg_wchar) (((c[0] & 0x1f) << 6) |
-                                                  (c[1] & 0x3f));
-       else if ((*c & 0xf0) == 0xe0)
-               return (pg_wchar) (((c[0] & 0x0f) << 12) |
-                                                  ((c[1] & 0x3f) << 6) |
-                                                  (c[2] & 0x3f));
-       else if ((*c & 0xf8) == 0xf0)
-               return (pg_wchar) (((c[0] & 0x07) << 18) |
-                                                  ((c[1] & 0x3f) << 12) |
-                                                  ((c[2] & 0x3f) << 6) |
-                                                  (c[3] & 0x3f));
-       else
-               /* that is an invalid code on purpose */
-               return 0xffffffff;
-}
-
 static int
 pg_utf_dsplen(const unsigned char *s)
 {
@@ -2695,52 +2633,51 @@ pg_eucjp_increment(unsigned char *charptr, int length)
 /*
  *-------------------------------------------------------------------
  * encoding info table
- * XXX must be sorted by the same order as enum pg_enc (in mb/pg_wchar.h)
  *-------------------------------------------------------------------
  */
 const pg_wchar_tbl pg_wchar_table[] = {
-       {pg_ascii2wchar_with_len, pg_wchar2single_with_len, pg_ascii_mblen, pg_ascii_dsplen, pg_ascii_verifychar, pg_ascii_verifystr, 1},       /* PG_SQL_ASCII */
-       {pg_eucjp2wchar_with_len, pg_wchar2euc_with_len, pg_eucjp_mblen, pg_eucjp_dsplen, pg_eucjp_verifychar, pg_eucjp_verifystr, 3},  /* PG_EUC_JP */
-       {pg_euccn2wchar_with_len, pg_wchar2euc_with_len, pg_euccn_mblen, pg_euccn_dsplen, pg_euccn_verifychar, pg_euccn_verifystr, 2},  /* PG_EUC_CN */
-       {pg_euckr2wchar_with_len, pg_wchar2euc_with_len, pg_euckr_mblen, pg_euckr_dsplen, pg_euckr_verifychar, pg_euckr_verifystr, 3},  /* PG_EUC_KR */
-       {pg_euctw2wchar_with_len, pg_wchar2euc_with_len, pg_euctw_mblen, pg_euctw_dsplen, pg_euctw_verifychar, pg_euctw_verifystr, 4},  /* PG_EUC_TW */
-       {pg_eucjp2wchar_with_len, pg_wchar2euc_with_len, pg_eucjp_mblen, pg_eucjp_dsplen, pg_eucjp_verifychar, pg_eucjp_verifystr, 3},  /* PG_EUC_JIS_2004 */
-       {pg_utf2wchar_with_len, pg_wchar2utf_with_len, pg_utf_mblen, pg_utf_dsplen, pg_utf8_verifychar, pg_utf8_verifystr, 4},  /* PG_UTF8 */
-       {pg_mule2wchar_with_len, pg_wchar2mule_with_len, pg_mule_mblen, pg_mule_dsplen, pg_mule_verifychar, pg_mule_verifystr, 4},      /* PG_MULE_INTERNAL */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN1 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN2 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN3 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN4 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN5 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN6 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN7 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN8 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN9 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_LATIN10 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1256 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1258 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN866 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN874 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_KOI8R */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1251 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1252 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* ISO-8859-5 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* ISO-8859-6 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* ISO-8859-7 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* ISO-8859-8 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1250 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1253 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1254 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1255 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_WIN1257 */
-       {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},  /* PG_KOI8U */
-       {0, 0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifychar, pg_sjis_verifystr, 2},        /* PG_SJIS */
-       {0, 0, pg_big5_mblen, pg_big5_dsplen, pg_big5_verifychar, pg_big5_verifystr, 2},        /* PG_BIG5 */
-       {0, 0, pg_gbk_mblen, pg_gbk_dsplen, pg_gbk_verifychar, pg_gbk_verifystr, 2},    /* PG_GBK */
-       {0, 0, pg_uhc_mblen, pg_uhc_dsplen, pg_uhc_verifychar, pg_uhc_verifystr, 2},    /* PG_UHC */
-       {0, 0, pg_gb18030_mblen, pg_gb18030_dsplen, pg_gb18030_verifychar, pg_gb18030_verifystr, 4},    /* PG_GB18030 */
-       {0, 0, pg_johab_mblen, pg_johab_dsplen, pg_johab_verifychar, pg_johab_verifystr, 3},    /* PG_JOHAB */
-       {0, 0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifychar, pg_sjis_verifystr, 2} /* PG_SHIFT_JIS_2004 */
+       [PG_SQL_ASCII] = {pg_ascii2wchar_with_len, pg_wchar2single_with_len, pg_ascii_mblen, pg_ascii_dsplen, pg_ascii_verifychar, pg_ascii_verifystr, 1},
+       [PG_EUC_JP] = {pg_eucjp2wchar_with_len, pg_wchar2euc_with_len, pg_eucjp_mblen, pg_eucjp_dsplen, pg_eucjp_verifychar, pg_eucjp_verifystr, 3},
+       [PG_EUC_CN] = {pg_euccn2wchar_with_len, pg_wchar2euc_with_len, pg_euccn_mblen, pg_euccn_dsplen, pg_euccn_verifychar, pg_euccn_verifystr, 2},
+       [PG_EUC_KR] = {pg_euckr2wchar_with_len, pg_wchar2euc_with_len, pg_euckr_mblen, pg_euckr_dsplen, pg_euckr_verifychar, pg_euckr_verifystr, 3},
+       [PG_EUC_TW] = {pg_euctw2wchar_with_len, pg_wchar2euc_with_len, pg_euctw_mblen, pg_euctw_dsplen, pg_euctw_verifychar, pg_euctw_verifystr, 4},
+       [PG_EUC_JIS_2004] = {pg_eucjp2wchar_with_len, pg_wchar2euc_with_len, pg_eucjp_mblen, pg_eucjp_dsplen, pg_eucjp_verifychar, pg_eucjp_verifystr, 3},
+       [PG_UTF8] = {pg_utf2wchar_with_len, pg_wchar2utf_with_len, pg_utf_mblen, pg_utf_dsplen, pg_utf8_verifychar, pg_utf8_verifystr, 4},
+       [PG_MULE_INTERNAL] = {pg_mule2wchar_with_len, pg_wchar2mule_with_len, pg_mule_mblen, pg_mule_dsplen, pg_mule_verifychar, pg_mule_verifystr, 4},
+       [PG_LATIN1] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN2] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN3] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN4] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN5] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN6] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN7] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN8] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN9] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_LATIN10] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1256] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1258] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN866] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN874] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_KOI8R] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1251] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1252] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_ISO_8859_5] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_ISO_8859_6] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_ISO_8859_7] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_ISO_8859_8] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1250] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1253] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1254] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1255] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_WIN1257] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_KOI8U] = {pg_latin12wchar_with_len, pg_wchar2single_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifychar, pg_latin1_verifystr, 1},
+       [PG_SJIS] = {0, 0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifychar, pg_sjis_verifystr, 2},
+       [PG_BIG5] = {0, 0, pg_big5_mblen, pg_big5_dsplen, pg_big5_verifychar, pg_big5_verifystr, 2},
+       [PG_GBK] = {0, 0, pg_gbk_mblen, pg_gbk_dsplen, pg_gbk_verifychar, pg_gbk_verifystr, 2},
+       [PG_UHC] = {0, 0, pg_uhc_mblen, pg_uhc_dsplen, pg_uhc_verifychar, pg_uhc_verifystr, 2},
+       [PG_GB18030] = {0, 0, pg_gb18030_mblen, pg_gb18030_dsplen, pg_gb18030_verifychar, pg_gb18030_verifystr, 4},
+       [PG_JOHAB] = {0, 0, pg_johab_mblen, pg_johab_dsplen, pg_johab_verifychar, pg_johab_verifystr, 3},
+       [PG_SHIFT_JIS_2004] = {0, 0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifychar, pg_sjis_verifystr, 2},
 };
 
 /*
index 2033e9d11da8533ab8ac150090eb7ca000565d79..fcfea985ff407070c78ae47083e90ad5b5b24d0a 100644 (file)
@@ -770,43 +770,6 @@ MemoryContextAllocZero(MemoryContext context, Size size)
        return ret;
 }
 
-/*
- * MemoryContextAllocZeroAligned
- *             MemoryContextAllocZero where length is suitable for MemSetLoop
- *
- *     This might seem overly specialized, but it's not because newNode()
- *     is so often called with compile-time-constant sizes.
- */
-void *
-MemoryContextAllocZeroAligned(MemoryContext context, Size size)
-{
-       void       *ret;
-
-       AssertArg(MemoryContextIsValid(context));
-       AssertNotInCriticalSection(context);
-
-       if (!AllocSizeIsValid(size))
-               elog(ERROR, "invalid memory alloc request size %zu", size);
-
-       context->isReset = false;
-
-       ret = (*context->methods->alloc) (context, size);
-       if (ret == NULL)
-       {
-               MemoryContextStats(TopMemoryContext);
-               ereport(ERROR,
-                               (errcode(ERRCODE_OUT_OF_MEMORY),
-                                errmsg("out of memory"),
-                                errdetail("Failed on request of size %zu.", size)));
-       }
-
-       VALGRIND_MEMPOOL_ALLOC(context, ret, size);
-
-       MemSetLoop(ret, 0, size);
-
-       return ret;
-}
-
 /*
  * MemoryContextAllocExtended
  *             Allocate space within the specified context using the given flags.