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

Commit 95b3ce0

Browse files
author
Nikita Glukhov
committed
Add SQL/JSON parsing
1 parent 3896e63 commit 95b3ce0

File tree

10 files changed

+1143
-20
lines changed

10 files changed

+1143
-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

@@ -628,3 +629,87 @@ makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
628629
v->va_cols = va_cols;
629630
return v;
630631
}
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

Comments
 (0)