| From: | Julien Rouhaud <rjuju123(at)gmail(dot)com> | 
|---|---|
| To: | Walter Cai <walter(at)cs(dot)washington(dot)edu> | 
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> | 
| Subject: | Re: Retrieving Alias Name | 
| Date: | 2019-02-26 22:10:11 | 
| Message-ID: | CAOBaU_ae1s_XYU_a-AFeGnFrfy=b0MXEzVBHRWEkoK9Qiq7XGQ@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On Tue, Feb 26, 2019 at 10:48 PM Walter Cai <walter(at)cs(dot)washington(dot)edu> wrote:
>
> I'm currently using a (very rough) scheme to retrieve relation names from a PlannerInfo, and a RelOptInfo struct:
>
> PlannerInfo *root
> RelOptInfo *inner_rel
>
> //...
>
> RangeTblEntry *rte;
> int x = -1;
> while ((x = bms_next_member(inner_rel->relids, x)) >= 0)
> {
>     rte = root->simple_rte_array[x];
>     if (rte->rtekind == RTE_RELATION)
>     {
>         char *rel_name = get_rel_name(rte->relid);
>         // do stuff...
>     }
> }
>
> However, I now realize it would be better to access aliases as they appear in the SQL query. For instance, if the query contains "... FROM rel_name AS rel_alias ..." I would like to retrieve `rel_alias` instead of `rel_name`.
>
> Is it possible to derive the alias in a similar way?
You can use rte->eref->aliasname, which will contain the alias is one
was provided, otherwise the original name.  You can see RangeTblEntry
comment in include/nodes/parsenodes.h for more details.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2019-02-26 22:19:01 | Re: Allowing extensions to supply operator-/function-specific info | 
| Previous Message | Robert Haas | 2019-02-26 22:10:07 | Re: ATTACH/DETACH PARTITION CONCURRENTLY |