473,387 Members | 1,693 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,387 software developers and data experts.

how do i get field names of a table in postgresql?

Hi all,

I need to get the field names of a table in postgresql?

Like if a table called "employee" which has several fields like 'name','id','address','phone','workexperience'..et c..

I need to fetch the field names and print that into my output..

I have used the query called "show by column from employees"

Its not working...can some body help me to solve this problem.

thanks in advance...

Barani
Aug 13 '07 #1
4 3345
miller
1,089 Expert 1GB
Typically, the query one uses to obtain information about a SQL based table is "DESC employee".

Expand|Select|Wrap|Line Numbers
  1. my $sth = $dbh->prepare(q{DESC employee});
  2. $sth->execute or die $dbh->errstr;
  3. while (my $hashref = $sth->fetchrow_hashref) {
  4.     print $hashref->{Field}, "\n";
  5. }
  6. $sth->finish; undef $sth;
  7.  
-Miller
Aug 13 '07 #2
hi miller,
thanks for your help...Here is the code i have tried with your help...

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use CGI;
  3. use DBI;
  4.  
  5. $sth="dbi:Pg:dbname=barani";
  6. $dbh=DBI->connect("$sth","postgres","india")or die "can't connect$DBI::errstr\n\n";
  7.  
  8.  
  9. $sth = $dbh->prepare(q{DESC employee});
  10. $sth->execute or die $dbh->errstr;
  11. while ($hashref = $sth->fetchrow_hashref) {
  12.     print $hashref->{Field}, "\n";
  13. }
  14. $sth->finish; undef $sth;
  15.  
But i am getting the output as
"DBD::Pg::st execute failed: ERROR: parser: parse error at or near "DESC" at character 1 at empp.cgi line 10.
ERROR: parser: parse error at or near "DESC" at character 1 at empp.cgi line 10."

Please let me know how to solve this issue..

Barani
Aug 14 '07 #3
miller
1,089 Expert 1GB
You're going to have to ask the people in the PostgreSQL Forum what the proper query is for inspecting a tables format. It appears that "DESC table" doesn't work, but maybe they know an alternative.

- Miller
Aug 14 '07 #4
Thanks alot for your guidance Mr .miller..

Hope i will get more help from you..
Aug 14 '07 #5

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

Similar topics

3
by: Thierry B. | last post by:
Hi, from SQL*Plus, i use: DESCRIBE MyTable and I get this result (example): Nom NULL ? Type ----------------------------------------- --------...
1
by: Neil Zanella | last post by:
Hello, Consider the following PostgreSQL or Oracle SQL DDL code: CREATE TABLE fooTable ( foo INTEGER, PRIMARY KEY (foo) ); CREATE TABLE barTable (
4
by: Josué Maldonado | last post by:
Hello list, First of all, excuse me if this is not the right place to ask my question. Is there a way in postgresql to loop to all the fields of a given table and compare the OLD and NEW...
3
by: Neil Zanella | last post by:
Hello, I would like to ask the about the following... PostgreSQL allows tables resulting from subselects to be renamed with an optional AS keyword whereas Oracle 9 will report an error...
1
by: Don Leverton | last post by:
Hi Folks, I have been given a CD with approx 130 .xls files (bean-counters!) that I would like to import and merge to ONE table (tblTradeshow). The XL files are *similarly*, but not...
1
by: Wei Wang | last post by:
Hi, Sorry for asking the dynamic command question without thoroughly reading the documentation first. Thanks a lot for your reply, Richard. ;-) Now this may be a naive SQL question: Is there...
3
by: Justin Clift | last post by:
Hi all, I'm creating a centralised table to keep a log of changes in other tables. In thinking about the PL/pgSQL trigger to write and attach to the monitored tables (probably a row level...
2
by: Tim Vadnais | last post by:
Hi, My boss wants to add some logging functionality to some of our tables on update/delete/insert. I need to log who, when, table_name, field name, original value and new value for each record,...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.