From: Tom Lane <tgl@sss.pgh.pa.us>
To: Aron Widforss <pgsql-general@antarkt.is>
Cc: pgsql-general@postgresql.org
Subject: Re: Find schema-qualified table name given unqualified name
Date: Tue, 19 Jun 2018 11:06:19 -0400
Message-ID: <20576.1529420779@sss.pgh.pa.us> (raw)
In-Reply-To: <1529418016.355123.1413189224.75962718@webmail.messagingengine.com>
References: <1529418016.355123.1413189224.75962718@webmail.messagingengine.com>
Aron Widforss <pgsql-general@antarkt.is> writes:
> I'm interested in finding a (any) unique identifier for a table given an unqualified name of the table. Is that feasible in SQL or a C function?
Something like this might help you:
select relnamespace::regnamespace from pg_class
where oid = 'mytablename'::regclass;
This will fail (not just return an empty set) if 'mytablename' isn't
resolvable, so you might need some hackery to cope with that. Also,
if you need it to work pre-9.5, you'll need to write an explicit
join to pg_namespace instead of relying on regnamespace.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql-general@antarkt.is
Subject: Re: Find schema-qualified table name given unqualified name
In-Reply-To: <20576.1529420779@sss.pgh.pa.us>
References: <1529418016.355123.1413189224.75962718@webmail.messagingengine.com> <20576.1529420779@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox