Postgresql - Get Oid and relation name for relations created by the query
I got the solution.

I have the relid of the CTE. (in the example ss1, ss2 etc.)

From the relid I can get RangeTblEntry for each CTE using

RangeTblEntry *rt1 = ((RangeTblEntry *) list_nth(root-&gt;parse-&gt;rtable, (relid)-1));


For a CTE RangeTblEntry has a field ctename, which stores the name it's a CTE.

You can use rt1-&gt;ctename to get the CTE name.