0

I am changing pg-pool to cater cypher queries for Apache AGE and I have the following code, which takes the select statement. From that it gets the FROM clause, then from the FROM clause it gets the function names. So now I want that function arguments also. How would I do that. The code is as follows:

if (IsA(node, SelectStmt))
{
    SelectStmt *stmt = (SelectStmt *) node;
    List* fromClause = stmt->fromClause;

    ListCell   *fl;

    //Match the first cypher function call in the FROM clause. Could be multiple tables
    // e.g. FROM table1, table2, cypher(),table3....
    foreach(fl, fromClause)
    {
        Node       *n = lfirst(fl);
        if (IsA(n, RangeFunction))
        {
            RangeFunction *rf = (RangeFunction*) n;
            List* functions = rf->functions; 

            if (functions->length == 1)
            {
                List *sublist = (List *) lfirst(list_head(functions)); 
                FuncCall *fntree = (FuncCall *) lfirst(list_head(sublist));
                StringInfoData str;
                initStringInfo(&str);
                _outNode(&str,fntree->funcname);
                
                if (!strcmp("\"cypher\"",str.data)){
                    return true;
                }
            }
        }
    }
}

2 Answers2

0

The arguments are stored in FuncCall. Since you already have that, you can get them with

fntree->args

Note that your code only covers function calls in the top FROM list. What if there are subqueries?

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
0

FuncCall has a field args of type List* that stores all the function arguments.

Mohayu Din
  • 433
  • 9