..of course... I didn't catch it... thanks.
 
That now works, but here is my real procedure, contructing the UNION of several lists groups into one single table:
 
CREATE PROCEDURE getListsGroups () returns table (id_grp string,  groupName string)  AS
BEGIN
    declare string VARIABLES.listsurl = 'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/User/Lists'; 
    declare string VARIABLES.listquery='
            select
            mup.id_list, mup.name_list
            from
            (call
                    comunicazioni2.invokeHTTP(
                            endpoint=>''' || listsurl || ''',
                            action=>''GET'',
                            headers=>jsonObject(''application/json'' as "Content-Type", ''application/json'' as "Accept",0 as  "Content-length")
                    )
            ) w,
            XMLTABLE(''/Items/Items'' passing JSONTOXML(''Items'', w.result) columns
            id_list string PATH ''idList'',
            name_list string PATH ''Name''
            ) mup;
        ';
    declare string VARIABLES.grpquery_pre='
            select
            mup.id_grp, mup.name_grp
            from
            (call
                    comunicazioni2.invokeHTTP(
                            endpoint=>''https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/';
    declare string VARIABLES.grpquery_post='/Groups'',
                            action=>''GET'',
                            headers=>jsonObject(''application/json'' as "Content-Type", ''application/json'' as "Accept",0 as  "Content-length")
                    )
            ) w,
            XMLTABLE(''/Items/Items'' passing JSONTOXML(''Items'', w.result) columns
            id_grp string PATH ''idGroup'',
            name_grp string PATH ''Name''
            ) mup
        ';
    EXECUTE IMMEDIATE listquery AS list_id string, list_name string INTO #temp;
    declare string VARIABLES.grpquery = '';
    LOOP ON (SELECT list_id, list_name from #temp) as lista           
    BEGIN
        IF (grpquery>'')
            BEGIN
                grpquery = grpquery || ' UNION ';
            END
   
        grpquery=grpquery || grpquery_pre || lista.list_id || grpquery_post;
   
    END
    grpquery=grpquery || ';';
    EXECUTE IMMEDIATE grpquery AS grp_id string, grp_name string;
END
 
and this, when executing
select * from (call getListsGroups()) as x
 
fails again, it seems to be escaping again, but it should not be, since all other iterations are escaped identically... I cannot understand why it seems to happen only at last iteration (list 1, the "lists" list is reversed), on line 99... could be a too long sql string? is there any limitation here? around 4000 characters?
 
[edit]
yes, it should be the string size limit... as in
Supported Types · Teiid Documentation
- confirmed: if I limit the "lists" query to 3 items, the union then works (since the final query string is less than 4000 chars long)
 
eg:
this (limited to 3 lists)
select * from (call getListsGroups()) as x
 
gives the same result as this
 
select * from (call getGroupList(7)) as x
UNION ALL
select * from (call getGroupList(6)) as x
UNION ALL
select * from (call getGroupList(5)) as x
 
should I use clob instead of string? but it seems I can't concatenate clobs as I do with strings...
[/edit]
 
Error: TEIID30168 Remote org.teiid.api.exception.query.QueryProcessingException: TEIID30168 Couldn't execute the dynamic SQL command "EXECUTE IMMEDIATE grpquery AS grp_id string, grp_name string" with the SQL statement "
    select
    mup.id_grp, mup.name_grp
    from 
    (call
            comunicazioni2.invokeHTTP(
                    endpoint=>'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/7/Groups',   
                    action=>'GET',
                    headers=>jsonObject('application/json' as "Content-Type", 'application/json' as "Accept",0 as  "Content-length")
            )
    ) w, 
    XMLTABLE('/Items/Items' passing JSONTOXML('Items', w.result) columns
    id_grp string PATH 'idGroup',
    name_grp string PATH 'Name'
    ) mup
UNION
    select
    mup.id_grp, mup.name_grp
    from 
    (call
            comunicazioni2.invokeHTTP(
                    endpoint=>'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/6/Groups',   
                    action=>'GET',
                    headers=>jsonObject('application/json' as "Content-Type", 'application/json' as "Accept",0 as  "Content-length")
            )
    ) w, 
    XMLTABLE('/Items/Items' passing JSONTOXML('Items', w.result) columns
    id_grp string PATH 'idGroup',
    name_grp string PATH 'Name'
    ) mup
UNION
    select
    mup.id_grp, mup.name_grp
    from 
    (call
            comunicazioni2.invokeHTTP(
                    endpoint=>'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/5/Groups',   
                    action=>'GET',
                    headers=>jsonObject('application/json' as "Content-Type", 'application/json' as "Accept",0 as  "Content-length")
            )
    ) w, 
    XMLTABLE('/Items/Items' passing JSONTOXML('Items', w.result) columns
    id_grp string PATH 'idGroup',
    name_grp string PATH 'Name'
    ) mup
UNION
    select
    mup.id_grp, mup.name_grp
    from 
    (call
            comunicazioni2.invokeHTTP(
                    endpoint=>'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/4/Groups',   
                    action=>'GET',
                    headers=>jsonObject('application/json' as "Content-Type", 'application/json' as "Accept",0 as  "Content-length")
            )
    ) w, 
    XMLTABLE('/Items/Items' passing JSONTOXML('Items', w.result) columns
    id_grp string PATH 'idGroup',
    name_grp string PATH 'Name'
    ) mup
UNION
    select
    mup.id_grp, mup.name_grp
    from 
    (call
            comunicazioni2.invokeHTTP(
                    endpoint=>'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/3/Groups',   
                    action=>'GET',
                    headers=>jsonObject('application/json' as "Content-Type", 'application/json' as "Accept",0 as  "Content-length")
            )
    ) w, 
    XMLTABLE('/Items/Items' passing JSONTOXML('Items', w.result) columns
    id_grp string PATH 'idGroup',
    name_grp string PATH 'Name'
    ) mup
UNION
    select
    mup.id_grp, mup.name_grp
    from 
    (call
            comunicazioni2.invokeHTTP(
                    endpoint=>'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/2/Groups',   
                    action=>'GET',
                    headers=>jsonObject('application/json' as "Content-Type", 'application/json' as "Accept",0 as  "Content-length")
            )
    ) w, 
    XMLTABLE('/Items/Items' passing JSONTOXML('Items', w.result) columns
    id_grp string PATH 'idGroup',
    name_grp string PATH 'Name'
    ) mup
UNION
    select
    mup.id_grp, mup.name_grp
    from 
    (call
            comunicazioni2.invokeHTTP(
                    endpoint=>'https://services.mailup.com/API/v1.1/Rest/ConsoleService.svc/Console/List/1/Groups',   
                    action=>'GET',
                    headers=>jsonObject('application/jso" due to: TEIID31100 Parsing error: Encountered ">jsonObject([*]'[*]" at line 99, column 117.
Was expecting: "char" | "date" | "time" | "timestamp" | "cast" | "convert" | "all" | "any" | "array_agg" | "case" ...
SQLState:  50000
ErrorCode: 30168