Page 1 of 1
How to get fields list of ANY query that returns no records
Posted: Mon Jul 31, 2006 2:22 pm
by martinwronski
Hi
Is it possible? If it is how to do it?
Example:
Query = SELECT em_login, em_name FROM employee
And table employee has no records.
So how to get column names: em_login, em_name?
Thx 4 ur help
Martin
Posted: Mon Jul 31, 2006 2:26 pm
by kbrown3074
describe employee
Posted: Mon Jul 31, 2006 3:01 pm
by martinwronski
thx, I know that
But I want to read that info from ANY query with multiple joins, subqueries, group by’s etc
is it possible?
psql returns column names event if there is no data returned but how to do this in php?
or how about this
SELECT em_login, em_salary * 12 AS year_salary FROM employee
how to find out that this query returns em_login/year_salary fields?
Posted: Tue Aug 01, 2006 7:43 am
by martinwronski
I have just found one way to do it by calling psql as an external program:
e.g.
exec("psql -h host -d database -U user -o \"$sFile\" -c \"$sQuery\"");
I have to generete psql results to file coz if I run psql with no -o switch it throws an exceptoion (under win2k).
also i have to remove all EOL to make it works fine:
$sQuery = str_replace("\n", ' ', $sQuery);
if anyone know the better way to do it please post it.
Posted: Tue Aug 01, 2006 7:46 am
by volka
Posted: Tue Aug 01, 2006 7:50 am
by feyd
psst, postgres..

Posted: Tue Aug 01, 2006 9:21 am
by volka
oops.
ok, it's pg_field_num and pg_field_name then

Posted: Wed Aug 02, 2006 3:29 am
by martinwronski
Works perfectly, thanks!
I got no bloody idea how i could miss this in pg/php documentation
