Re: Get the name of the target Relation from Query struct? - Mailing list pgsql-hackers

From David Rowley
Subject Re: Get the name of the target Relation from Query struct?
Date
Msg-id CAKJS1f8p9XvMzJ+vghHHVPdq8sUnhRsd1vxJZGRD+BO-78ws+w@mail.gmail.com
Whole thread Raw
In response to Get the name of the target Relation from Query struct?  (Ernst-Georg Schmid <ernst-georg.schmid@bayer.com>)
Responses AW: Get the name of the target Relation from Query struct?
AW: Get the name of the target Relation from Query struct?
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: [HACKERS] Runtime Partition Pruning
Next
From: Alvaro Herrera
Date:
Subject: Re: pgsql: Validate page level checksums in base backups