Обсуждение: AW: Get the name of the target Relation from Query struct? SOLVED!

Поиск
Список
Период
Сортировка

AW: Get the name of the target Relation from Query struct? SOLVED!

От
Ernst-Georg Schmid
Дата:
Hello David,

actually Query->resultRelation is one based and Query->rtable is zero based.

So the correct call to list_nth is: list_nth(Query->rtable, Query->resultRelation - 1)

The comment "rtable index of target relation for INSERT/UPDATE/DELETE/MERGE; 0 for SELECT" on resultRelation in
parsenodes.h,Line 120 is misleading. It is _not_ a direct index into rtable, you have to subtract 1 first!
 

And now it works...checked against 9.6.8 and 10.3.

Best regards,

Ernst-Georg


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

От
Ashutosh Bapat
Дата:
Please don't break threads by changing subject line.

On Fri, Apr 6, 2018 at 3:42 PM, Ernst-Georg Schmid
<ernst-georg.schmid@bayer.com> wrote:
> Hello David,
>
> actually Query->resultRelation is one based and Query->rtable is zero based.
>
> So the correct call to list_nth is: list_nth(Query->rtable, Query->resultRelation - 1)

As I suggested in the other mail, please use rt_fetch() or
planner_rt_fetch() that's future-proof in case we change relids to be
something-other-than-one based (an unlikely event, but who knows).
-- 
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company


AW: Get the name of the target Relation from Query struct? SOLVED!

От
Ernst-Georg Schmid
Дата:
Hello,

> Please don't break threads by changing subject line.

> As I suggested in the other mail, please use rt_fetch() or

OK and OK.

Best regards,

Ernst-Georg