Re: Find schema-qualified table name given unqualified name

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Aron Widforss <pgsql-general(at)antarkt(dot)is>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Find schema-qualified table name given unqualified name
Date: 2018-06-19 15:06:19
Message-ID: 20576.1529420779@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Aron Widforss <pgsql-general(at)antarkt(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Louis Battuello 2018-06-19 15:20:10 Drop Default Privileges?
Previous Message Aron Widforss 2018-06-19 14:20:16 Find schema-qualified table name given unqualified name