On Sat, Jul 5, 2014 at 11:06 AM, Madhurima Das <madhurima.das@xxxxxxxxx> wrote: > int main() > { > PGconn *conn; > PGresult *res; > int i=0,nFields=0,row=0,col=0; > > conn = PQconnectdb("dbname=test1 host=localhost user=postgres > password=yyy"); > if(PQstatus(conn) == CONNECTION_BAD) > { > fprintf(stderr, "Connection to database \"%s\" failed.\n", > PQerrorMessage(conn)); > fprintf(stderr, "%s", PQerrorMessage(conn)); > exit_nicely(conn); > } > > res = PQexec(conn, "IF COL_LENGTH('xxx','comment') IS NULL"); Call to PQclear is missing here or before the next call to PQexec. > if(res) > res = PQexec(conn, "ALTER TABLE xxx ADD comment VARCHAR(500)"); > else > res = PQexec(conn, "UPDATE TABLE xxx ADD comment VARCHAR(500)"); Same here. > res = PQexec(conn, "IF COL_LENGTH('xxx','id') IS NULL"); Same here. > if(res) > res = PQexec(conn, "ALTER TABLE xxx ADD id VARCHAR(50)"); > else > res = PQexec(conn, "UPDATE TABLE xxx ADD id VARCHAR(50)"); Same here. > res = PQexec(conn, "SELECT * FROM xxx"); > if((!res) || (PQresultStatus(res) != PGRES_TUPLES_OK)) > { > fprintf(stderr, "SELECT command did not return tuples properly\n"); > PQclear(res); > } > > PQclear(res); > PQfinish(conn); > > return 0; > } Btw, there is a lot of code duplication... -- Michael