Search Postgresql Archives

conditional IF statements in postgresql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am writing a C program to access a PostgreSQL database, where 

I add a column if it doesn't exists in the table

or, update the column, if the column already exits.

Please suggest how to work with the conditional statements.

Thanks!

N.B. I wrote the following:

res = PQexec(conn, "IF COL_LENGTH('protein_sequence','comment') IS NULL");
PQclear(res);
if(res)
 {
     res = PQexec(conn, "ALTER TABLE protein_sequence ADD comment VARCHAR(500)");
     PQclear(res);
 }
 else
 {
     res = PQexec(conn, "UPDATE TABLE protein_sequence ADD comment VARCHAR(500)");
      PQclear(res);
 }

Is the code logically correct??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux