Book Image

PostgreSQL Developer's Guide

By : Ibrar Ahmed, Asif Fayyaz, Amjad Shahzad
Book Image

PostgreSQL Developer's Guide

By: Ibrar Ahmed, Asif Fayyaz, Amjad Shahzad

Overview of this book

<p>PostgreSQL is an enterprise-level database that competes among proprietary database vendors, owing to its remarkable feature set and reliability without the expensive licensing overhead.</p> <p>This book is a comprehensive and pragmatic guide to developing databases in PostgreSQL. Beginning with a refresher of basic SQL skills, you will gradually be exposed to advanced concepts, such as learning how to program in native PostgreSQL procedural languages, implementing triggers, custom functions, and views. You will learn database optimization techniques such as query optimization and indexing while exploring extensive code examples. Lastly, you will explore foreign data wrappers, implementing extensibility, and improving maintainability.</p>
Table of Contents (19 chapters)
PostgreSQL Developer's Guide
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using status functions


There are some error-handling functions or status functions available to check the results of a function.

Using PQresultStatus

The PQresultStatus function sreturns the status of a command. This function is very important to get the result status after executing the query. This function is the base of the program logic, because a program should take action based on the result status. The syntax for PQtresultStatus is as follows:

ExecStatusType PQresultStatus(const PGresult *res);

The following is a code snippet to explain the PQresultStatus function:

/* Execute a query using PQexec */
result = PQexec(conn, "SELECT id, name FROM foo LIMIT 3");
switch(PQresultStatus(result))
{
  case PGRES_COMMAND_OK:
  /* Query successful and no data to return */
  break;
  case PGRES_TUPLES_OK:
  /* Query ok and data available */
  break;
  case PGRES_EMPTY_QUERY:
  /* Query string was empty */
  break;
  case PGRES_COPY_OUT:
  /* Data transfer from server side started */
  break;
  case...