473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

table column information

Currently using Postgresql 7.2.4-5.80 with php 4.2.2.-8.0.8 on a redhat
8.0 system.

I am writing some php scripts where I want to generate a list of the
column names in a particular table that the user selects. I could take
the brute force method and hard code the column names but then every
time I add a new table or modify an existing one I would have to modify
the code. What I want is to have a generic function that given the
table name it will pull the column names for my use.

I need to get the table column names for several tables I have setup. I
know if I do a select * from tablename I can then use the pg_fieldname
function to pull the column names for all columns.

But I don't think I want to select the entire contents of the table
every time I want to get the names of the columns. I know this will
work but I think performance will be very poor.

Trying to find something the equivalent of doing a \d tablename in psql.
I did see a function to pull meta data but that is in a 4.3 version of
php.

I have also been trying to track down some information on the pga_layout
table. This appears to be a system table that might contain the
information I want but it does not list every table I have created. Not
sure what that is.

The books I have do not say much if anything about such system tables.

Any help or pointers would be appreciated.
--
Scot L. Harris <we***@cfl.rr.com>
---------------------------(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 23 '05 #1
4 2960
Hi,
Use getMetadata of java.sql.Connection. According to jdocs, the
DatabaseMetaData object can probably give you what you are looking for.

Carl <|};-)>

-----Original Message-----
From: pg*****************@postgresql.org
[mailto:pg*****************@postgresql.org] On Behalf Of Scot L. Harris
Sent: Sunday, May 16, 2004 1:22 PM
To: pg***********@postgresql.org
Subject: [GENERAL] table column information
Currently using Postgresql 7.2.4-5.80 with php 4.2.2.-8.0.8 on a redhat 8.0
system.

I am writing some php scripts where I want to generate a list of the column
names in a particular table that the user selects. I could take the brute
force method and hard code the column names but then every time I add a new
table or modify an existing one I would have to modify the code. What I
want is to have a generic function that given the table name it will pull
the column names for my use.

I need to get the table column names for several tables I have setup. I
know if I do a select * from tablename I can then use the pg_fieldname
function to pull the column names for all columns.

But I don't think I want to select the entire contents of the table every
time I want to get the names of the columns. I know this will work but I
think performance will be very poor.

Trying to find something the equivalent of doing a \d tablename in psql.
I did see a function to pull meta data but that is in a 4.3 version of php.
I have also been trying to track down some information on the pga_layout
table. This appears to be a system table that might contain the information
I want but it does not list every table I have created. Not sure what that
is.

The books I have do not say much if anything about such system tables.

Any help or pointers would be appreciated.


--
Scot L. Harris <we***@cfl.rr.com>
---------------------------(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

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

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

Nov 23 '05 #2
On Sun, 2004-05-16 at 16:58, Carl E. McMillin wrote:
Hi,
Use getMetadata of java.sql.Connection. According to jdocs, the
DatabaseMetaData object can probably give you what you are looking for.

Carl <|};-)>


Thanks, but I am using php 4.2.2 not java for this application.

--
Scot L. Harris <we***@cfl.rr.com>
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #3
Scot L. Harris wrote:
Currently using Postgresql 7.2.4-5.80 with php 4.2.2.-8.0.8 on a redhat
8.0 system.

I am writing some php scripts where I want to generate a list of the
column names in a particular table that the user selects. I could take
the brute force method and hard code the column names but then every
time I add a new table or modify an existing one I would have to modify
the code. What I want is to have a generic function that given the
table name it will pull the column names for my use.

I need to get the table column names for several tables I have setup. I
know if I do a select * from tablename I can then use the pg_fieldname
function to pull the column names for all columns.

But I don't think I want to select the entire contents of the table
every time I want to get the names of the columns. I know this will
work but I think performance will be very poor.

Trying to find something the equivalent of doing a \d tablename in psql.
I did see a function to pull meta data but that is in a 4.3 version of
php.

I have also been trying to track down some information on the pga_layout
table. This appears to be a system table that might contain the
information I want but it does not list every table I have created. Not
sure what that is.

The books I have do not say much if anything about such system tables.

Any help or pointers would be appreciated.


Hi,

You want to be querying the postgres catalog tables. See here for more info:

http://www.postgresql.org/docs/7.2/static/catalogs.html

The tables you want to look at are pg_class and pg_attribute. You will
want to query pg_class to get the oid of the table. Then you can query
pg_attribute using that oid to get the column names and types. This is
all the \d tablename does in psql, send a query to the db.

I cant remember exactly what you need to do but you can find out what
query psql sends to the backend by adding the -E parameter. For example:

psql -d tesdb -E

Then whenever psql fires off a query you can see it. So you could do:

psql -d testdb -R

testdb> \d sometable

And you will see what the query that you would need to execute to get
the column names ;-)

HTH
Nick

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #4
Wanted to thank everyone that responded. I have my application working
now just the way I wanted it. The pointers to the pg_class and
pg_attribute tables did the trick. And I will be reading some more on
the documentation that was pointed out.

Again thanks for the help.
--
Scot L. Harris <we***@cfl.rr.com>
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #5

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

Similar topics

2
by: sreddy | last post by:
I am trying to write a sql query on self referencing table. Just to brief ..Database is related to a Hiring department of the Qwest company. I need to generate a Report used by in HR...
36
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
3
by: EJH | last post by:
I have a Database that has three tables. One of the three is just a table that contains three fields and is filled with reference information. One field is 3-Digit(primary key), the next is...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: Mike | last post by:
We are using .NET 2.0 and intermittently egt the following errors on almost all our web pages. The error is not repoducable and cycling the worker process seems to temporarily fix the problems. ...
9
by: Hemant Shah | last post by:
How do I find out when the table was modified? When I look at syscat.tables it only lists creation time. -- Hemant Shah /"\ ASCII ribbon campaign E-mail:...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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,...
0
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...

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.