Rename column only if exists
问题 PostgreSQL does not allow ALTER TABLE t RENAME COLUMN IF EXISTS c1 TO c2 ...or anything like that. However, it's very convenient to be able to write scripts which modify DB structure which can be run again without first checking if it has already been run. How do I write a PostgreSQL function to do exactly this? 回答1: Better to have two functions, one calling the other: CREATE OR REPLACE FUNCTION column_exists(ptable TEXT, pcolumn TEXT) RETURNS BOOLEAN AS $BODY$ DECLARE result bool; BEGIN --