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

Commit 04810d0

Browse files
author
Nikita Glukhov
committed
Add SQL/JSON parsing
1 parent 749375f commit 04810d0

File tree

10 files changed

+1130
-20
lines changed

10 files changed

+1130
-20
lines changed

src/backend/nodes/makefuncs.c

Lines changed: 70 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

@@ -628,3 +629,72 @@ makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
628629
v->va_cols = va_cols;
629630
return v;
630631
}
632+
633+
/*
634+
* makeJsonBehavior -
635+
* creates a JsonBehavior node
636+
*/
637+
JsonBehavior *
638+
makeJsonBehavior(JsonBehaviorType type, Node *default_expr)
639+
{
640+
JsonBehavior *behavior = makeNode(JsonBehavior);
641+
642+
behavior->btype = type;
643+
behavior->default_expr = default_expr;
644+
645+
return behavior;
646+
}
647+
648+
/*
649+
* makeJsonEncoding -
650+
* converts JSON encoding name to enum JsonEncoding
651+
*/
652+
JsonEncoding
653+
makeJsonEncoding(char *name)
654+
{
655+
if (!pg_strcasecmp(name, "utf8"))
656+
return JS_ENC_UTF8;
657+
if (!pg_strcasecmp(name, "utf16"))
658+
return JS_ENC_UTF16;
659+
if (!pg_strcasecmp(name, "utf32"))
660+
return JS_ENC_UTF32;
661+
662+
ereport(ERROR,
663+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
664+
errmsg("unrecognized JSON encoding: %s", name)));
665+
666+
return JS_ENC_DEFAULT;
667+
}
668+
669+
/*
670+
* makeJsonKeyValue -
671+
* creates a JsonKeyValue node
672+
*/
673+
Node *
674+
makeJsonKeyValue(Node *key, Node *value)
675+
{
676+
JsonKeyValue *n = makeNode(JsonKeyValue);
677+
678+
n->key = (Expr *) key;
679+
n->value = castNode(JsonValueExpr, value);
680+
681+
return (Node *) n;
682+
}
683+
684+
/*
685+
* makeJsonIsPredicate -
686+
* creates a JsonIsPredicate node
687+
*/
688+
Node *
689+
makeJsonIsPredicate(Node *expr, JsonFormat format, JsonValueType vtype,
690+
bool unique_keys)
691+
{
692+
JsonIsPredicate *n = makeNode(JsonIsPredicate);
693+
694+
n->expr = expr;
695+
n->format = format;
696+
n->vtype = vtype;
697+
n->unique_keys = unique_keys;
698+
699+
return (Node *) n;
700+
}

0 commit comments

Comments
 (0)