|
20 | 20 | #include "fmgr.h"
|
21 | 21 | #include "nodes/makefuncs.h"
|
22 | 22 | #include "nodes/nodeFuncs.h"
|
| 23 | +#include "utils/errcodes.h" |
23 | 24 | #include "utils/lsyscache.h"
|
24 | 25 |
|
25 | 26 |
|
@@ -628,3 +629,87 @@ makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
|
628 | 629 | v->va_cols = va_cols;
|
629 | 630 | return v;
|
630 | 631 | }
|
| 632 | + |
| 633 | +/* |
| 634 | + * makeJsonValueExpr - |
| 635 | + * creates a JsonValueExpr node |
| 636 | + */ |
| 637 | +JsonValueExpr * |
| 638 | +makeJsonValueExpr(Expr *expr, JsonFormat format) |
| 639 | +{ |
| 640 | + JsonValueExpr *jve = makeNode(JsonValueExpr); |
| 641 | + |
| 642 | + jve->expr = expr; |
| 643 | + jve->format = format; |
| 644 | + |
| 645 | + return jve; |
| 646 | +} |
| 647 | + |
| 648 | +/* |
| 649 | + * makeJsonBehavior - |
| 650 | + * creates a JsonBehavior node |
| 651 | + */ |
| 652 | +JsonBehavior * |
| 653 | +makeJsonBehavior(JsonBehaviorType type, Node *default_expr) |
| 654 | +{ |
| 655 | + JsonBehavior *behavior = makeNode(JsonBehavior); |
| 656 | + |
| 657 | + behavior->btype = type; |
| 658 | + behavior->default_expr = default_expr; |
| 659 | + |
| 660 | + return behavior; |
| 661 | +} |
| 662 | + |
| 663 | +/* |
| 664 | + * makeJsonEncoding - |
| 665 | + * converts JSON encoding name to enum JsonEncoding |
| 666 | + */ |
| 667 | +JsonEncoding |
| 668 | +makeJsonEncoding(char *name) |
| 669 | +{ |
| 670 | + if (!pg_strcasecmp(name, "utf8")) |
| 671 | + return JS_ENC_UTF8; |
| 672 | + if (!pg_strcasecmp(name, "utf16")) |
| 673 | + return JS_ENC_UTF16; |
| 674 | + if (!pg_strcasecmp(name, "utf32")) |
| 675 | + return JS_ENC_UTF32; |
| 676 | + |
| 677 | + ereport(ERROR, |
| 678 | + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 679 | + errmsg("unrecognized JSON encoding: %s", name))); |
| 680 | + |
| 681 | + return JS_ENC_DEFAULT; |
| 682 | +} |
| 683 | + |
| 684 | +/* |
| 685 | + * makeJsonKeyValue - |
| 686 | + * creates a JsonKeyValue node |
| 687 | + */ |
| 688 | +Node * |
| 689 | +makeJsonKeyValue(Node *key, Node *value) |
| 690 | +{ |
| 691 | + JsonKeyValue *n = makeNode(JsonKeyValue); |
| 692 | + |
| 693 | + n->key = (Expr *) key; |
| 694 | + n->value = castNode(JsonValueExpr, value); |
| 695 | + |
| 696 | + return (Node *) n; |
| 697 | +} |
| 698 | + |
| 699 | +/* |
| 700 | + * makeJsonIsPredicate - |
| 701 | + * creates a JsonIsPredicate node |
| 702 | + */ |
| 703 | +Node * |
| 704 | +makeJsonIsPredicate(Node *expr, JsonFormat format, JsonValueType vtype, |
| 705 | + bool unique_keys) |
| 706 | +{ |
| 707 | + JsonIsPredicate *n = makeNode(JsonIsPredicate); |
| 708 | + |
| 709 | + n->expr = expr; |
| 710 | + n->format = format; |
| 711 | + n->vtype = vtype; |
| 712 | + n->unique_keys = unique_keys; |
| 713 | + |
| 714 | + return (Node *) n; |
| 715 | +} |
0 commit comments