From: | "Tjibbe Rijpma" <t(dot)b(dot)rijpma(at)student(dot)tudelft(dot)nl> |
---|---|
To: | <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: find column names from query |
Date: | 2005-01-24 08:55:13 |
Message-ID: | 001701c501f2$6b65bc30$0100a8c0@TJIBBE |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
I have the same kind of problem in PLpgsql.
But a solution for your problem in PHP can be the functions:
$int_colums = pg_num_fields($result);
for ( $col = 0; $col < $int_colums; $col++ ) {
$field_name = pg_field_name( $this->str_pg_result, $col);
echo '<td>' . $field_name . '</td>' ;
}
----- Original Message -----
From: Afton & Ray Still
To: PostgreSQL Novice
Sent: Monday, January 24, 2005 7:46
Subject: [NOVICE] find column names from query
Hello,
I'm trying to find a way to get the column names of a table, knowing only the table name. (I'm trying to display the contents of various hidden support tables to the DB administrator)
here's what's happening:
user picks a table name from a select list (HTML),
a SELECT * FROM selected_table ... query is sent (PHP)
nested for loops print out the table data (PHP and HTML)
works great to here, although I realize I'm cheating a little.
problem is the data has no column labels.
going through the documentation I found the following:
SELECT attname::regclass FROM pg_attribute WHERE attrelid = travel::regclass
I'm trying to get the attname, which should be the column name, from the pg_attribute "table"(or catalog?) when attrelid, which should be the table name, which I have.
trying this query in PgadminIII I get:
ERROR: cannot cast type name to regclass
I could go through and hardcode the table data into the application, but I'd prefer not to.
Any suggestions to make this work, or for better methods appreciated.
Ray
------------------------------------------------------------------------------
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 1/19/2005
------------------------------------------------------------------------------
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly
From | Date | Subject | |
---|---|---|---|
Next Message | Afton & Ray Still | 2005-01-24 14:12:25 | Re: find column names from query |
Previous Message | Michael Fuhr | 2005-01-24 08:42:41 | Re: find column names from query |