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

2018-04-06 Thread 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

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

2018-04-06 Thread 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 parse

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

2018-04-06 Thread Ernst-Georg Schmid
Unfortunately it still crashes with Signal 11 even with a more strict check: if(parse->commandType == CMD_INSERT) { best regards, Ernst-Georg

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

2018-04-06 Thread Ernst-Georg Schmid
Hello, the crashing query is INSERT INTO blah.blahfasel (id) VALUES (1). But I'll check specifically for INSERTs now and try again. BTW: What exactly is a UTILITY command? Something like e.g. TRUNCATE or VACUUM? Best regards, Ernst-Georg

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

2018-04-06 Thread Ernst-Georg Schmid
Hello again, unfortunately this: >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. gives me a Signal 11. I can get the resultRelation and it is 1 (which matches the Documentatio

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

2018-04-05 Thread Ernst-Georg Schmid
Thank you David, so I am on the right track. >If you want the relation name from the OID then you'll need something >like get_rel_name(). Hm, lsyscache.c says for get_rel_name(): * NOTE: since relation name is not unique, be wary of code that uses this * for anything except preparing error

Get the name of the target Relation from Query struct?

2018-04-05 Thread Ernst-Georg Schmid
Hello, 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? And if yes, what would rtable give me as list entry? An OID or