Re: SQL:2023 JSON simplified accessor support - Mailing list pgsql-hackers

From jian he
Subject Re: SQL:2023 JSON simplified accessor support
Date
Msg-id CACJufxEt5bL-xYojenA7x1Fq=-DfhW3KGH=3Zz9TjJ1k95=uuQ@mail.gmail.com
Whole thread Raw
In response to Re: SQL:2023 JSON simplified accessor support  (Peter Eisentraut <peter@eisentraut.org>)
Responses Re: SQL:2023 JSON simplified accessor support
List pgsql-hackers
hi.

I have applied for 0001 to 0006.

static void
jsonb_subscript_transform(SubscriptingRef *sbsref,
                          List **indirection,
                          ParseState *pstate,
                          bool isSlice,
                          bool isAssignment)
{
    List       *upperIndexpr = NIL;
    ListCell   *idx;
    sbsref->refrestype = JSONBOID;
    sbsref->reftypmod = -1;
    if (jsonb_check_jsonpath_needed(*indirection))
    {
        sbsref->refjsonbpath =
            jsonb_subscript_make_jsonpath(pstate, indirection,
                                          &sbsref->refupperindexpr,
                                          &sbsref->reflowerindexpr);
        return;
    }
    foreach(idx, *indirection)
    {
        Node       *i = lfirst(idx);
        A_Indices  *ai;
        Node       *subExpr;
        Assert(IsA(i, A_Indices));
        ai = castNode(A_Indices, i);
        if (isSlice)
        {
            Node       *expr = ai->uidx ? ai->uidx : ai->lidx;
            ereport(ERROR,
                    (errcode(ERRCODE_DATATYPE_MISMATCH),
                     errmsg("jsonb subscript does not support slices"),
                     parser_errposition(pstate, exprLocation(expr))));
}

I am confused by the above error handling:
errmsg("jsonb subscript does not support slices").

we can do
select (jsonb '[1,2,3]')[0:1];
or
SELECT (jb).a[2:3].b FROM test_jsonb_dot_notation;

this is by definition, "slices"?
Anyway, I doubt this error handling will ever be reachable.

jsonb_check_jsonpath_needed checks whether the indirection contains is_slice,
but jsonb_subscript_transform already takes isSlice as an argument.
Maybe we can refactor it somehow.


T_String is a primitive node type with no subnodes.
typedef struct String
{
    pg_node_attr(special_read_write)
    NodeTag        type;
    char       *sval;
} String;
then in src/backend/nodes/nodeFuncs.c:
                    if (expr && !IsA(expr, String) && WALK(expr))
                        return true;
we can change it to
                    if (WALK(expr))
                        return true;
but in function expression_tree_walker_impl
we have to change it as

        case T_MergeSupportFunc:
        case T_String:
            /* primitive node types with no expression subnodes */
            break;



pgsql-hackers by date:

Previous
From: Melanie Plageman
Date:
Subject: Re: Simplify VM counters in vacuum code
Next
From: Melanie Plageman
Date:
Subject: Re: Vacuum ERRORs out considering freezing dead tuples from before OldestXmin