473,500 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Command - To List Tables ?

Is there a SQL command I can issue which will list all the TABLES within
a database ?

Pete

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #1
9 130322
If you start psql with the -E option you can see the internal commands sent to
the backend. This can often give you a lot of hints as to the best way to
pull catalog data from a db:

jason=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN
'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************

So from this to get a list of tables you would execute the following in SQL:

select c.relname FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid);

This will give you tables only. If you wanted schema's and owners then you
would execute a similar variant to that thrown out by psql.

Rgds,

Jason

On Wed, 27 Aug 2003 08:37 pm, Peter Moscatt wrote:
Is there a SQL command I can issue which will list all the TABLES within
a database ?

Pete

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #2
On Wed, Aug 27, 2003 at 20:37:14 +1000,
Peter Moscatt <pg*******@optushome.com.au> wrote:
Is there a SQL command I can issue which will list all the TABLES within
a database ?


select datname from pg_database;

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #3
On Wed, 2003-08-27 at 05:37, Peter Moscatt wrote:
Is there a SQL command I can issue which will list all the TABLES within
a database ?


http://www.postgresql.org/docs/7.3/s...reference.html
http://www.postgresql.org/docs/7.3/s...ce-client.html
http://www.postgresql.org/docs/7.3/static/app-psql.html

OR

http://www.postgresql.org/docs/7.3/s...reference.html
http://www.postgresql.org/search.cgi...ist+all+tables
--
-----------------------------------------------------------------
Ron Johnson, Jr. ro***********@cox.net
Jefferson, LA USA

"Man, I'm pretty. Hoo Hah!"
Johnny Bravo
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #4
> Is there a SQL command I can issue which will list all the TABLES within
a database ?


select datname from pg_database;

--
WBR, sector119
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #5

On 27/08/2003 11:37 Peter Moscatt wrote:
Is there a SQL command I can issue which will list all the TABLES within
a database ?

Pete

select tablename from pg_tables

HTH

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants |
http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+---------------------------------------------+

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #6
On 27 Aug 2003 at 20:37, Peter Moscatt wrote:
Is there a SQL command I can issue which will list all the TABLES within
a database ?


\dt from psql

or select relname from pg_class;

Check the column name. There might be a typo there but pg_class is what you
are looking at.

Bye
Shridhar

--
There are certain things men must do to remain men. -- Kirk, "The Ultimate
Computer", stardate 4929.4
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #7
Carmen Gloria Sepulveda Dedes <cs********@atichile.com> writes:
Hello. I type \dt as user postgres, but it show only the tables within
public schema.
More accurately, it shows the tables visible in your schema search path.
I need to know all tables


\dt *.*

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #8
On Wed, Aug 27, 2003 at 08:09:16 -0500,
Bruno Wolff III <br***@wolff.to> wrote:
On Wed, Aug 27, 2003 at 20:37:14 +1000,
Peter Moscatt <pg*******@optushome.com.au> wrote:
Is there a SQL command I can issue which will list all the TABLES within
a database ?


select datname from pg_database;


This was an oops. I misread your question as asking for all databases,
not tables.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #9
On Wed, Aug 27, 2003 at 09:17:01AM -0400, Carmen Gloria Sepulveda Dedes wrote:
Hello. I type \dt as user postgres, but it show only the tables within
public schema. I need to know all tables (like v$_ or dba_ or user_
in oracle). How I do that?


You need to change your search_path. Use

SET search_path TO 'one-schema', 'another', ...

Then repeat your \dt

Or IIRC you can also use
\dt *.*

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"La espina, desde que nace, ya pincha" (Proverbio africano)

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4395
by: Wayne Wengert | last post by:
I am using VS.NET 2003, VB.NET, ADO.NET and an Access 2000 database. I want to display a list of all tables in an Access database. I want to put that list of table names in a listbox so the user...
3
38344
by: Davide Satta | last post by:
Where can i find a list of command of the standard library of c++ and the explanation of every single command? please help me -- Love & Peace Respect the Nature
1
5842
by: Mariusz Kaczmarczyk | last post by:
Hello, i can't find any matching answer for this question. How to construct SQL query to list all tables in current database? Let's say i use the default view. Or maybe there is better way in PHP...
2
7816
by: Pascal Deparis | last post by:
Hi, I've got a problem with the DB2 Command Line Processor, in V8, FP1. The databases have been created on an AIX server (version 4.3.3). Have a look at this: >db2 ? list DB21034E The...
3
19735
by: maricel | last post by:
Is there a way to list (using db2 command or catalogs) to list hierarchy of table parent & child relationship: 1) A list that shows which table should be deleted first,second,third... 2) A list...
0
1226
by: master | last post by:
Hi, I am new to SQL CE. How to get the list of tables in a database? Thanks for your help... DW
2
9143
by: Danny | last post by:
Hello, We imported a bunch of tables from a database and realized that the primary keys weren't copied to the destination db. In order to re- create the keys, we need to know which tables have...
0
1295
by: ebindia0041 | last post by:
Any help what is wrong with this code.. I am tring to FTP post a file by command prompt but it not work, system hang up.. commands are in my batch file... System.Diagnostics.ProcessStartInfo psi...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7188
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5491
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4924
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4614
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1432
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
317
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.