Hello again,

unfortunately this:

>The list_nth(query->rtable, query->resultRelation) will give you a
>RangeTblEntry which has a property called relid, which is the
>Relation's OID as per pg_class.oid.

gives me a Signal 11.

I can get the resultRelation and it is 1 (which matches the Documentation that 
says that it would be 0 for a SELECT but I exclude SELECTs as you suggested).

But the list_nth() reliably crashes the backend with a Signal 11.

Here is the complete function:

static PlannedStmt *
limit_func(Query *parse, int cursorOptions, ParamListInfo boundParams)
{
        PlannedStmt *result;
        RangeTblEntry *rte;
        char *target_table;
        char *target_schema;

        /* this way we can daisy chain planner hooks if necessary */
        if (prev_planner_hook != NULL)
                result = (*prev_planner_hook) (parse, cursorOptions, 
boundParams);
        else
                result = standard_planner(parse, cursorOptions, boundParams);

    if(parse->commandType != CMD_SELECT) {
        int resultRelation = parse->resultRelation;

        rte = (RangeTblEntry *) list_nth(parse->rtable, resultRelation);

        //target_table = get_rel_name(rte->relid);

        //target_schema = get_namespace_name(get_rel_namespace(rte->relid));

        ereport(NOTICE, (errcode(ERRCODE_SUCCESSFUL_COMPLETION), errmsg("%i", 
resultRelation)));
    }

        return result;
}

If I comment out the line:        rte = (RangeTblEntry *) 
list_nth(parse->rtable, resultRelation);

it works and sends me the resultRelation to a NOTICE in the log output.

What am I doing wrong? It's a 10.3 on Ubuntu 16.04 compiled from sources. 
Everything else, e.g. multicorn and other extensions work, so I guess it must 
be my code and not a problem of the build system or PostgreSQL itself.

Best regards,

Ernst-Georg

Reply via email to