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 13:50:38
Message-ID: CAKJS1f8i+RhW8FXPgvTJP1JfVJHbhED1N4f4CtfEPehfVaGVBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 6 April 2018 at 01:20, Ernst-Georg Schmid
<ernst-georg(dot)schmid(at)bayer(dot)com> wrote:
>>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 messages.
>
> How do I get the schema name too, then?
>
> Call get_rel_namespace() and then get_rel_name() again with the Oid that was returned?

No, get_rel_name returns the relname from pg_class. What you need is
in pg_namespace:

namespace from relid: get_namespace_name(get_rel_namespace(relid))
relname from relid: get_rel_name(relid))));

If you're going to relation_open the rel, then you might want to use:

get_namespace_name(RelationGetNamespace(rel))

and

RelationGetRelationName(rel))));

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dmitry Dolgov 2018-04-05 13:51:20 Re: typcategory for regconfig
Previous Message Simon Riggs 2018-04-05 13:50:24 Re: Excessive PostmasterIsAlive calls slow down WAL redo