Hi,
Having a query, I am trying to find out all the columns that need to be accessed (their varattno and vartype). I have access to a targetlist representing a tree like this. So, I am looking for a function that recursively traverses the tree and gives me the VARs. So, for SELECT a,b,b+c from tab; I am interested in [a,b]. Is such a function currently implemented in postgresql? How can I use it?
:targetlist (
{TARGETENTRY
:expr
{VAR
:varno 1
:varattno 1
:vartype 23
:vartypmod -1
:varcollid 0
:varlevelsup 0
:varnosyn 1
:varattnosyn 1
:location 7
}
:resno 1
:resname l_orderkey
:ressortgroupref 0
:resorigtbl 24805
:resorigcol 1
:resjunk false
}
{TARGETENTRY
:expr
{VAR
:varno 1
:varattno 2
:vartype 23
:vartypmod -1
:varcollid 0
:varlevelsup 0
:varnosyn 1
:varattnosyn 2
:location 18
}
:resno 2
:resname l_partkey
:ressortgroupref 0
:resorigtbl 24805
:resorigcol 2
:resjunk false
}
{TARGETENTRY
:expr
{OPEXPR
:opno 551
:opfuncid 177
:opresulttype 23
:opretset false
:opcollid 0
:inputcollid 0
:args (
{OPEXPR
:opno 551
:opfuncid 177
:opresulttype 23
:opretset false
:opcollid 0
:inputcollid 0
:args (
{VAR
:varno 1
:varattno 1
:vartype 23
:vartypmod -1
:varcollid 0
:varlevelsup 0
:varnosyn 1
:varattnosyn 1
:location 28
}
{VAR
:varno 1
:varattno 2
:vartype 23
:vartypmod -1
:varcollid 0
:varlevelsup 0
:varnosyn 1
:varattnosyn 2
:location 39
}
)
:location 38
}
{VAR
:varno 1
:varattno 3
:vartype 23
:vartypmod -1
:varcollid 0
:varlevelsup 0
:varnosyn 1
:varattnosyn 3
:location 49
}
)
:location 48
}
:resno 3
:resname ?column?
:ressortgroupref 0
:resorigtbl 0
:resorigcol 0
:resjunk false
}
)