dbTalk Databases Forums  

Retreiving database/table information

comp.databases.postgresql comp.databases.postgresql


Discuss Retreiving database/table information in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
karas (Offline)
Junior Member
 
Posts: 6
Join Date: May 2006

Default Retreiving database/table information - 02-05-2007 , 07:04 AM






Is there a way to retrieve data from database about specific table using some client interface in C or PHP? For example, if we have some table with few indexes and rules, how to check if an index or rule exists? How to check if a given table exists within a database?
PQexec() can't be used because it is a query function.

Reply With Quote
  #2  
Old   
jpd
 
Posts: n/a

Default Re: Retreiving database/table information - 02-05-2007 , 10:21 AM






Begin <karas.2ljbxz (AT) no-mx (DOT) forums.yourdomain.com.au>
On 2007-02-05, karas <karas.2ljbxz (AT) no-mx (DOT) forums.yourdomain.com.au> wrote:
Quote:
Is there a way to retrieve data from database about specific table
using some client interface in C or PHP?
Obviously, yes; the commandline utility does use libpq.


Quote:
For example, if we have some table with few indexes and rules, how
to check if an index or rule exists? How to check if a given table
exists within a database? -PQexec-() can't be used because it is a
query function.
There is an `information schema' documented in the manual that might
provide the information you are looking for. Chapter 32 of the 8.2
handbook. Say;

select * from information_schema.tables;

The specifics are left as an excercise. If that does not work for you,
you might have to query the postgresql specific system tables instead.


Oh, and you might consider not using someone's forum-to-usenet gateway
but using usenet directly instead. Some people do object to having their
usenet posts forum-ified that way. I don't like finding my usenet posts
redone as if on random forums that I never knew existed, for one.

It also invites posting habits that are frowned upon on usenet.


--
j p d (at) d s b (dot) t u d e l f t (dot) n l .
This message was originally posted on Usenet in plain text.
Any other representation, additions, or changes do not have my
consent and may be a violation of international copyright law.


Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Retreiving database/table information - 02-14-2007 , 05:32 AM



karas <karas.2ljbxz (AT) no-mx (DOT) forums.yourdomain.com.au> wrote:
Quote:
Is there a way to retrieve data from database about specific table using
some client interface in C or PHP? For example, if we have some table
with few indexes and rules, how to check if an index or rule exists?

You do things like that be querying tables in the information_schema
or pg_catalog.

e.g. to find out the name of all indexes for a specific table, you can

SELECT indexname FROM pg_catalog.pg_indexes
WHERE schemaname='schemaname' AND tablename='tablename'

Quote:
How to check if a given table exists within a database?
SELECT count(*)
FROM pg_catalog.pg_class JOIN pg_catalog.pg_namespace
ON (pg_class.relnamespace=pg_namespace.oid)
WHERE pg_class.relname='tablename' AND pg_namespace.nspname='schemaname'
AND pg_class.relkind='r'

Quote:
-PQexec-() can't be used because it is a query function.
What keeps you from using query functions? You'll have to explain in
greater detail.

Yours,
Laurenz Albe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.