473,480 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to read tables from database

32 New Member
I have to get all the table names that exist in a particular database in pgsql and print it in a html page.
How can i do this?
Mar 2 '07 #1
5 2336
michaelb
534 Recognized Expert Contributor
One way to get all user tables in Postgresql is to run this query:

Expand|Select|Wrap|Line Numbers
  1. SELECT c.relname as "Name"
  2.   FROM pg_catalog.pg_class c
  3.   LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
  4. WHERE c.relkind IN ('r','')
  5.   AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
  6.   AND pg_catalog.pg_table_is_visible(c.oid)
  7. ORDER BY 1
  8.  
If you have one of the latest versions of the server you can make use of
Information Schema

This would be a preferred approach.

All this implies that you need to submit your query using some client API, such as PHP, but if you open the psql session the command is simply
\d

Hope it helps.
Mar 2 '07 #2
michaelb
534 Recognized Expert Contributor
Forgot to mention: as far as making connection and processing query results using PHP you need to look here
Mar 2 '07 #3
anuragpj
32 New Member
One way to get all user tables in Postgresql is to run this query:

Expand|Select|Wrap|Line Numbers
  1. SELECT c.relname as "Name"
  2.   FROM pg_catalog.pg_class c
  3.   LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
  4. WHERE c.relkind IN ('r','')
  5.   AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
  6.   AND pg_catalog.pg_table_is_visible(c.oid)
  7. ORDER BY 1
  8.  
If you have one of the latest versions of the server you can make use of
Information Schema

This would be a preferred approach.

All this implies that you need to submit your query using some client API, such as PHP, but if you open the psql session the command is simply
\d

Hope it helps.
It is not working. It show this error
Warning: PostgreSQL query failed: ERROR: parser: parse error at or near "'" in /web/train06/myphp/ex.php on line 14. What is the problem?
How to display the table names?
Mar 6 '07 #4
michaelb
534 Recognized Expert Contributor
This sql works perfectly well for me.
I suspect that you may need to escape the single quotes in your PHP code.
Since you did not post any code snippets it is hard to pinpoint the problem.
Mar 6 '07 #5
ronverdonk
4,258 Recognized Expert Specialist
It is not working. It show this error
Warning: PostgreSQL query failed: ERROR: parser: parse error at or near "'" in /web/train06/myphp/ex.php on line 14. What is the problem?
How to display the table names?
Since you ask the question in the PHP forum, we can show you how to code Pgsql commands in php.

What you should know, as the pgsql programmer/user, is how the pgsql command to show the tables is constructed. Like in MySQL it is SHOW TABLES". There must be something alike in pgsql.

Ronald :cool:
Mar 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1963
by: Belinda | last post by:
Hello All I need to read a SQL Server table into a Web Page and within the Web Page to permit my users to make changes to the records, delete or add new records and then save the entire contents...
0
2748
by: Bennett Haselton | last post by:
I'm trying to port my MySQL tables for a database called "tracerlock" from one server to another. On the old server, in the /var/lib/mysql/tracerlock directory, there was a ".MYD", ".MYI" and...
3
12087
by: Silvio Lopes de Oliveira | last post by:
Hello, I have a C++ / MFC app which uses CDatabase and CRecordset to connect to a ODBC data source for a SQL Server 7 database. The application worked properly with a MySQL database, but after...
7
1782
by: Marty | last post by:
Hi, Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB. I have a problem to read/parse the dataset and I would like to know if I am using the right object to reach my...
24
41536
by: Bob Alston | last post by:
Anyone know a way to make all access to a linked table, in another Access MDB, read only? I really don't want all the hassle of implementing full access security. I can't do this at the server...
5
7523
by: ashley.ward | last post by:
I am attempting to write a program with VB 2005 Express Edition which accesses an Oracle 9 database and dumps the results of three SELECT queries into a spreadsheet file once every hour. ...
10
10218
by: Phil Stanton | last post by:
There are various hidden tables in Acees 2000 including MSysACEs The owner in Engine (I presume the Microsoft Jet Engine); I can't read the data or change the permissions. Any ideas Thanks ...
12
5443
by: Sean Davis | last post by:
I am working on a simple script to read from one database (oracle) and write to another (postgresql). I retrieve the data from oracle in chunks and drop the data to postgresql continuously. The...
2
8241
by: Bobby | last post by:
Hi, Not sure if this is Access, SQL or ODBC. I have a SQL database with an Access Front End. They are linked with ODBC. Occasionally (it's happened 3 times in 4 months) some of the linked tables...
6
8129
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
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
7032
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,...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6873
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
4471
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
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
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.