Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 042db01

Browse files
author
Nikita Glukhov
committed
Add SQL/JSON parsing
1 parent 439cd28 commit 042db01

File tree

10 files changed

+1144
-20
lines changed

10 files changed

+1144
-20
lines changed

src/backend/nodes/makefuncs.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "fmgr.h"
2121
#include "nodes/makefuncs.h"
2222
#include "nodes/nodeFuncs.h"
23+
#include "utils/errcodes.h"
2324
#include "utils/lsyscache.h"
2425

2526

@@ -611,3 +612,87 @@ makeGroupingSet(GroupingSetKind kind, List *content, int location)
611612
n->location = location;
612613
return n;
613614
}
615+
616+
/*
617+
* makeJsonValueExpr -
618+
* creates a JsonValueExpr node
619+
*/
620+
JsonValueExpr *
621+
makeJsonValueExpr(Expr *expr, JsonFormat format)
622+
{
623+
JsonValueExpr *jve = makeNode(JsonValueExpr);
624+
625+
jve->expr = expr;
626+
jve->format = format;
627+
628+
return jve;
629+
}
630+
631+
/*
632+
* makeJsonBehavior -
633+
* creates a JsonBehavior node
634+
*/
635+
JsonBehavior *
636+
makeJsonBehavior(JsonBehaviorType type, Node *default_expr)
637+
{
638+
JsonBehavior *behavior = makeNode(JsonBehavior);
639+
640+
behavior->btype = type;
641+
behavior->default_expr = default_expr;
642+
643+
return behavior;
644+
}
645+
646+
/*
647+
* makeJsonEncoding -
648+
* converts JSON encoding name to enum JsonEncoding
649+
*/
650+
JsonEncoding
651+
makeJsonEncoding(char *name)
652+
{
653+
if (!pg_strcasecmp(name, "utf8"))
654+
return JS_ENC_UTF8;
655+
if (!pg_strcasecmp(name, "utf16"))
656+
return JS_ENC_UTF16;
657+
if (!pg_strcasecmp(name, "utf32"))
658+
return JS_ENC_UTF32;
659+
660+
ereport(ERROR,
661+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
662+
errmsg("unrecognized JSON encoding: %s", name)));
663+
664+
return JS_ENC_DEFAULT;
665+
}
666+
667+
/*
668+
* makeJsonKeyValue -
669+
* creates a JsonKeyValue node
670+
*/
671+
Node *
672+
makeJsonKeyValue(Node *key, Node *value)
673+
{
674+
JsonKeyValue *n = makeNode(JsonKeyValue);
675+
676+
n->key = (Expr *) key;
677+
n->value = castNode(JsonValueExpr, value);
678+
679+
return (Node *) n;
680+
}
681+
682+
/*
683+
* makeJsonIsPredicate -
684+
* creates a JsonIsPredicate node
685+
*/
686+
Node *
687+
makeJsonIsPredicate(Node *expr, JsonFormat format, JsonValueType vtype,
688+
bool unique_keys)
689+
{
690+
JsonIsPredicate *n = makeNode(JsonIsPredicate);
691+
692+
n->expr = expr;
693+
n->format = format;
694+
n->vtype = vtype;
695+
n->unique_keys = unique_keys;
696+
697+
return (Node *) n;
698+
}

0 commit comments

Comments
 (0)