On 5 April 2018 at 22:34, Ernst-Georg Schmid
<ernst-georg.schmid@bayer.com> wrote:
> I want to get the target Relation name for a UPDATE / INSERT / DELETE in a planner_hook. Do I understand struct Query
correctlythat:
>
> Query->resultRelation will be the index into Query->rtable to give me the target Relation?
Yes
> And if yes, what would rtable give me as list entry? An OID or a Relation or something else?
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.
If you want the relation name from the OID then you'll need something
like get_rel_name().
You'll probably also want to check the query->commandType to ensure
the command is one that will actually have a valid resultRelation.
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services