U mean how to do it with pl function?
All information about database u can find in information_schema tables and views. With an IF statement and NOT FOUND 'constant' u can check if specified table contains given column. (see more on postgresql.org)
if you are using recent version of postgresql
and using plain SQL, just enclose it with savepoint
test@ws-dev:5432 test=> ALTER TABLE tbl DROP field;
ALTER TABLE
test@ws-dev:5432 test=*> SAVEPOINT test_1;
SAVEPOINT
test@ws-dev:5432 test=*> ALTER TABLE tbl DROP field;
ERROR: column "field" of relation "tbl" does not exist
test@ws-dev:5432 test=!> ROLLBACK TO SAVEPOINT test_1;
ROLLBACK
test@ws-dev:5432 test=*>
if it goes OK instead of ROLLBACK TO SAVEPOINT you do RELEASE SAVEPOINT
(in function, beside this method, you can use exceptions)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.