Subject: Select statement error !!!!

From: "Vutharkar Goutham" <[email-masked]>
Date: Wed, 24 Sep 2003 10:27:04 +0000

Hello,

I am doing a simple program with PostgreSql wherein i am giving a select 
statement as an argument to PQexec like this

char query[1024];
strcpy(query,"Select * from Udp_Table");

res = PQexec(conn,query);

if(!res || PQresultStatus(res)! = PGRES_COMMAND_OK)
{
	fprintf(stderr,"Select Failed.\n");
	PQclear(res);
	exit(1);
}
now if i try to execute the above statement it is giving me always teh 
select failed message. I dont know where the problem is? But when i try to 
store some other query in array like update statement or insert statement or 
any other statement it is working and giving the results i want to see. But 
i dont know what is wrong with the select statement i think it should work 
isn't it? Can anybody out there please help me to solve this problem.

Thank You,

Goutham.V
  MSIT.

_________________________________________________________________
Get personal loans. It's hassle-free. 
http://server1.msn.co.in/msnleads/citibankpersonalloan/citibankploanjuly03.asp?type=txt 
It's approved instantly.

---

From: Oliver Elphick <[email-masked]>
Date: Wed, 24 Sep 2003 12:00:49 +0100

> select failed message.

In that statement you have a mixed case name for the table.  If it has a
mixed case name in the database too, the name needs to be enclosed in
double quotes.

-- 
Oliver Elphick                                [email-masked]
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "And we know that all things work together for good to 
      them that love God, to them who are the called  
      according to his purpose."            
                                   Romans 8:28

---

From: Tom Lane <[email-masked]>
Date: Wed, 24 Sep 2003 10:06:30 -0400

> 	fprintf(stderr,"Select Failed.\n");

The result status from a successful SELECT will be PGRES_TUPLES_OK;
PGRES_COMMAND_OK is only used for commands that do not return a tuple
set.

As commented nearby, it's not real clear that this query is succeeding,
anyway.  It would behoove you to print something more useful than
"Select Failed" in your failure path ... see PQresStatus() and
PQresultErrorMessage() for starters.

			regards, tom lane

PS: this does not belong on pgsql-docs.  pgsql-novice would be an
appropriate forum for first-time questions.