Re: How can I find the schema that a table belongs to? - Mailing list pgsql-general

From DM
Subject Re: How can I find the schema that a table belongs to?
Date
Msg-id AANLkTinP5B6LEdzq2WNDVXSF3n1hEbJsx=3yZK_1ALn2@mail.gmail.com
Whole thread Raw
In response to How can I find the schema that a table belongs to?  (Jerry LeVan <jerry.levan@mac.com>)
Responses Re: How can I find the schema that a table belongs to?  (DM <dm.aeqa@gmail.com>)
List pgsql-general
If your looking for Views then you could use pg_views ==> select * from pg_views limit 1;

Here is one more, there was a recent post same as your request, Please see the below email, hope this helps you

Tom Lane =================>
Thomas Kellerer <spam_eater@gmx.net> writes:
> Jerry LeVan, 19.01.2011 17:35:
>> So I guess the question is:
>> Given a bare table name, how can I recover the schema
>> qualified name with whatever the current search path happens
>> to be?

> SELECT table_schema
> FROM information_schema.tables
> WHERE table_name = 'your_table'
> ;

That's not going to work, at least not in the interesting case where you
have more than one candidate table --- that SELECT will list all of 'em.

In most cases the answer to this type of problem is "use regclass",
but regclass doesn't quite solve Jerry's problem because it won't
schema-qualify the name if the table is visible in the search path.
The best solution I can think of is

select nspname from pg_namespace n join pg_class c on n.oid = c.relnamespace
 where c.oid = 'my_table_name'::regclass;

which works but seems a bit brute-force.

                       regards, tom lane
- Hide quoted text -

==========================================>

On Wed, Jan 19, 2011 at 12:58 PM, Jerry LeVan <jerry.levan@mac.com> wrote:

On Jan 19, 2011, at 3:12 PM, DM wrote:

> one of the way to find out schema name is like below
>
> select * from pg_tables where tablename like '%xyz%';
>  schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers
> ------------+-----------+------------+------------+------------+----------+-------------
> (0 rows)
>
> ~Deepak
>

That does not work if the user entered a 'view' in the sql box.

Also a table/view could be in several schemas...

Jerry

pgsql-general by date:

Previous
From: "Edmundo Robles L."
Date:
Subject: undefined symbol PQconnectionNeedsPassword referenced by file pg_ctl.o
Next
From: DM
Date:
Subject: Re: How can I find the schema that a table belongs to?