Re: Getting the table ID - Mailing list pgsql-general

From David G. Johnston
Subject Re: Getting the table ID
Date
Msg-id CAKFQuwbJJJOx5M0Z6Xr4gVSSeCG6ayrxhJFi=Spf1q0KW5d3qA@mail.gmail.com
Whole thread Raw
In response to Getting the table ID  (Igor Korot <ikorot01@gmail.com>)
List pgsql-general
On Mon, Jul 18, 2022 at 8:11 PM Igor Korot <ikorot01@gmail.com> wrote:

There is a pg_namespace table - is this where the schema should come from?
If yes - how?
Looking at that table I don't see any unique fields...
Or is this something that is hidden?

Catalogs don't have all of the same metadata that user-space tables have.

"namespace" is the historical and internally used label for what we present to users as "schema"

In fact I'm trying to run following query:

SELECT c.oid FROM pg_class c, pg_namespace nc WHERE nc.oid =
c.relnamespace AND c.relname = ? AND nc.nspname = ?;

Then either relname or nspname caused the records to filter out because the join part of that where clause is correct.

I suggest you experiment using psql and literals so you can provide both actual queries and results more easily.  The whole self-contained script thing is very helpful.

You can also learn quite a bit by echoing queries in psql then using the various description metacommands that query these same catalogs - thus echoing the queries psql itself uses to answer this same question.

David J.

pgsql-general by date:

Previous
From: Igor Korot
Date:
Subject: Getting the table ID
Next
From: Christophe Pettus
Date:
Subject: Re: equivalent thing of mtr in mysql