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

Commit f9e4061

Browse files
author
Nikita Glukhov
committed
Add .datetime() jsonpath item method
1 parent c83a3ea commit f9e4061

File tree

7 files changed

+948
-14
lines changed

7 files changed

+948
-14
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
124124
*(int32 *)(buf->data + offs) = chld;
125125
}
126126
break;
127+
case jpiDatetime:
128+
if (!item->value.arg)
129+
{
130+
int32 arg = 0;
131+
132+
appendBinaryStringInfo(buf, (char *) &arg, sizeof(arg));
133+
break;
134+
}
135+
/* fall through */
127136
case jpiFilter:
128137
case jpiIsUnknown:
129138
case jpiNot:
@@ -215,7 +224,6 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
215224
case jpiFloor:
216225
case jpiCeiling:
217226
case jpiDouble:
218-
case jpiDatetime:
219227
case jpiKeyValue:
220228
break;
221229
default:
@@ -540,7 +548,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
540548
appendBinaryStringInfo(buf, ".double()", 9);
541549
break;
542550
case jpiDatetime:
543-
appendBinaryStringInfo(buf, ".datetime()", 11);
551+
appendBinaryStringInfo(buf, ".datetime(", 10);
552+
if (v->content.arg)
553+
{
554+
jspGetArg(v, &elem);
555+
printJsonPathItem(buf, &elem, false, false);
556+
}
557+
appendStringInfoChar(buf, ')');
544558
break;
545559
case jpiKeyValue:
546560
appendBinaryStringInfo(buf, ".keyvalue()", 11);
@@ -636,7 +650,6 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
636650
case jpiFloor:
637651
case jpiCeiling:
638652
case jpiDouble:
639-
case jpiDatetime:
640653
case jpiKeyValue:
641654
case jpiLast:
642655
break;
@@ -678,6 +691,7 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
678691
case jpiPlus:
679692
case jpiMinus:
680693
case jpiFilter:
694+
case jpiDatetime:
681695
read_int32(v->content.arg, base, pos);
682696
break;
683697
case jpiIndexArray:
@@ -703,7 +717,8 @@ jspGetArg(JsonPathItem *v, JsonPathItem *a)
703717
v->type == jpiIsUnknown ||
704718
v->type == jpiExists ||
705719
v->type == jpiPlus ||
706-
v->type == jpiMinus
720+
v->type == jpiMinus ||
721+
v->type == jpiDatetime
707722
);
708723

709724
jspInitByBuffer(a, v->base, v->content.arg);

0 commit comments

Comments
 (0)