问题很简单。如何添加列x
到餐桌y
,但仅当x
列不存在?我找到了唯一的解决方案here https://stackoverflow.com/questions/9991043/how-can-i-test-if-a-column-exists-in-a-table-using-an-sql-statement如何检查列是否存在。
SELECT column_name
FROM information_schema.columns
WHERE table_name='x' and column_name='y';
With Postgres 9.6 https://www.postgresql.org/docs/9.6/static/sql-altertable.html这可以使用选项来完成if not exists
ALTER TABLE table_name ADD COLUMN IF NOT EXISTS column_name INTEGER;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)