Processing Data in a Result Set
libpq provides functions, such as PQnfields, PQntuples, and PQfname, to help you properly parse and process the results of SELECT queries.
The following is an example (for details about the complete example, see Establishing a Database Connection, Executing SQL Statements, and Returning Results):
/* First, print out the attribute name. */ nFields = PQnfields(res); for (i = 0; i < nFields; i++) printf("%-15s", PQfname(res, i)); printf("\n\n"); /* Print lines. */ for (i = 0; i < PQntuples(res); i++) { for (j = 0; j < nFields; j++) printf("%-15s", PQgetvalue(res, i, j)); printf("\n"); } /* Release the memory of the result object to avoid memory leakage. */ PQclear(res);
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot