Re: Get the name of the target Relation from Query struct?

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Ernst-Georg Schmid <ernst-georg(dot)schmid(at)bayer(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Get the name of the target Relation from Query struct?
Date: 2018-04-05 12:59:14
Message-ID: CAKJS1f8p9XvMzJ+vghHHVPdq8sUnhRsd1vxJZGRD+BO-78ws+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 5 April 2018 at 22:34, Ernst-Georg Schmid
<ernst-georg(dot)schmid(at)bayer(dot)com> wrote:
> I want to get the target Relation name for a UPDATE / INSERT / DELETE in a planner_hook. Do I understand struct Query correctly that:
>
> 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2018-04-05 13:17:48 Re: pgsql: Validate page level checksums in base backups
Previous Message Amit Langote 2018-04-05 12:54:41 Re: [HACKERS] Runtime Partition Pruning