List of table names of a DB

Lists: pgsql-hackers
From: Deepak S <in(dot)live(dot)in(at)live(dot)in>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: List of table names of a DB
Date: 2015-01-08 09:41:21
Message-ID: BLU182-W539047CBF4E25DA36DB1D0D3470@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello, I am unable to find the function which retrieves the 'list of names of the tables' used in a DB.
Reason: I need a mechanism by which I can extract the names of the tables used in a query which has been parsed. My plan is to check for a match of each word in the query with a list of names of the tables used in the current DB so that each hit confirms a 'table name' in the query in most cases.
Kindly help.Thanks in advance.
Deepak


From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Deepak S <in(dot)live(dot)in(at)live(dot)in>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: List of table names of a DB
Date: 2015-01-08 11:46:30
Message-ID: CAApHDvpXqY7U2c9PPptYyTjqQorzc6F+rWJKvWG1NAc+0NqSMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 8 January 2015 at 22:41, Deepak S <in(dot)live(dot)in(at)live(dot)in> wrote:

> Hello, I am unable to find the function which retrieves the 'list of
> names of the tables' used in a DB.
>
>
You may find what you want in: select table_name from
information_schema.tables;

http://www.postgresql.org/docs/9.4/static/infoschema-tables.html

> Reason: I need a mechanism by which I can extract the names of the tables
> used in a query which has been parsed. My plan is to check for a match of
> each word in the query with a list of names of the tables used in the
> current DB so that each hit confirms a 'table name' in the query in most
> cases.
>
>
This sounds rather flaky.

Maybe it would be better to just EXPLAIN the query and see if you get error
code 42P01
postgres=# \set VERBOSITY verbose
postgres=# explain select * from doesnotexist;
ERROR: 42P01: relation "doesnotexist" does not exist
LINE 1: explain select * from doesnotexist;

Unfortunately this won't help you much if you want to know all of the
tables that don't exist.

Also, just for the future, a question like this might be more suited for
the pgsql-general(at)postgresql(dot)org list.

Regards

David Rowley