Getting the table ID

Поиск
Список
Период
Сортировка
От Igor Korot
Тема Getting the table ID
Дата
Msg-id CA+FnnTzY4x=Ywq57QBdTWvddFBA-4sPD9AU36sj2uPE27N_qNw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Getting the table ID  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Getting the table ID  ("Walter Dörwald" <walter@livinglogic.de>)
Список pgsql-general
Hi, guys,

In the database theory each table is identified as "schema_name"."table_name".

When I tried to look at how to get the table id inside the PostgreSQL,
I saw that I needed to look at the pg_class table.

SELECT oid FROM pg_class WHERE relname = "table_name";

However that query will give a non-unique table id (see the first sentence).

So how do I get the table id based on the "schema_name.table_name"?

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?

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 = ?;

from my ODBC based program, but it returns 0 rows on SQLFetch.

I know PostgreSQL does not use '?' for query parameters
but I thought that since its an ODBC everything should work.

Nevertheless, all bindings were successful, but now rows are returned.

Is this query correct?

Thank you.



В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: postgis
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Getting the table ID