postgresql change table
--if cloumn exist
SELECT EXISTS (SELECT 1
FROM information_schema.columns
WHERE table_schema='ent' AND table_name='AdsPlatform' AND column_name='Name'); --add cloumn
ALTER TABLE finance."MappingInfo" ADD COLUMN IF NOT EXISTS "Active" boolean;
UPDATE finance."MappingInfo" SET "Active"=false where "Active" is null ;
ALTER TABLE finance."MappingInfo" ALTER COLUMN "Active" set NOT NULL;
--or
ALTER TABLE finance."MappingInfo" ALTER COLUMN "Active" Drop NOT NULL;
--remove column
ALTER TABLE finance."MappingInfo" DROP COLUMN IF EXISTS "WarnMsg";
--add column & set column value from another ALTER TABLE ent."AdsPlatform" ADD COLUMN IF NOT EXISTS "PlatfromSettlementParty" character varying(100); DO
$do$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema='ent' AND table_name='AdsPlatform' AND column_name='Name') THEN
UPDATE ent."AdsPlatform" SET "PlatfromSettlementParty"="Name" WHERE "PlatfromSettlementParty" is null;
ELSE
UPDATE ent."AdsPlatform" SET "PlatfromSettlementParty"= '' where "PlatfromSettlementParty" is null ;
END IF;
END
$do$ ALTER TABLE ent."AdsPlatform" ALTER COLUMN "PlatfromSettlementParty" set NOT NULL;
postgresql change table的更多相关文章
- PostgreSQL获取table名,字段名
PostgreSQL获取数据库中所有table名: SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg%' AND tablena ...
- PostgreSQL truncate table会释放索引的空间
apple=# create table test(id integer, info text); CREATE TABLE apple=# insert into test select gener ...
- PostgreSQL ALTER TABLE中改变数据类型时USING的用法<转>
在修改表字段类型的时候使用Using来进行显示的转换类型. 原文说明: SET DATA TYPE This form changes the type of a column of a table ...
- POSTGRESQL NO TABLE
POSTGRESQL EXTENDING SQL GRIGGER PROCEDURAL
- postgresql vacuum table
2down vote according to Documentation VACUUM reclaims storage occupied by dead tuples. But according ...
- centos7 pgpool+postgresql
安装postgresql CentOS7安装并配置PostgreSQL 安装pgpool rpm -ivh http://www.pgpool.net/yum/rpms/3.7/redhat/rhel ...
- How to speed up insertion performance in PostgreSQL
Disable any triggers on the table Drop indexes before starting the import, re-create them afterwards ...
- PostgreSQL的HA解决方案-2负载均衡(load balance)
一.部署说明 1.1 实施环境 本文档实验环境如下: PGSQL主机: 192.168.1.45 PGSQL备机: 192.168.1.50 软件和系统版本 Pgsql 版本: pgsql 9.2.4 ...
- 借助JavaScript中的时间函数改变Html中Table边框的颜色
借助JavaScript中的时间函数改变Html中Table边框的颜色 <html> <head> <meta http-equiv="Content-Type ...
随机推荐
- linux centos重置mysql密码教程
第一步 查看确定安装了mysql # rpm -qa|grep -i mysql 执行效果如下 第二步 重启mysql: # /etc/init.d/mysqld 截图如下 因为我已经开了,所以用re ...
- 查询和修改mysql最大连接数的方法
查询和修改mysql最大连接数的方法切换到mysql库里查询show variables like 'max_connections';show global status like 'Max_use ...
- make: *** /lib/modules/3.10.0-327.el7.x86_64/build: 没有那个文件或目录。 停止。
1.问题: [root@localhost]# make make -C /lib/modules/-.el7.x86_64/build M=/home/csri/poc/adore modules ...
- python docopt模块详解
python docopt模块详解 docopt 本质上是在 Python 中引入了一种针对命令行参数的形式语言,在代码的最开头使用 """ ""&q ...
- java中避免乱码
response.setContentType("text/html;charset=UTF-8"); 这个是在action中的 这个是在json中设置乱码的 contentTyp ...
- nvidia-docker
参考资料 https://github.com/NVIDIA/nvidia-docker/wiki/Installation#prerequisites https://github.com/NVID ...
- 算法竞赛入门经典训练指南——UVA 11300 preading the Wealth
A Communist regime is trying to redistribute wealth in a village. They have have decided to sit ever ...
- POJ 1308 Is It A Tree?和HDU 1272 小希的迷宫
POJ题目网址:http://poj.org/problem?id=1308 HDU题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1272 并查集的运用 ...
- Strom学习笔记2:Storm Maven Project-StromStack工程
1:IntelliJ新建Maven工程
- tomcat部署solr4.10
1.创建solrHome mkdir /opt/solrHome 2.拷贝solr基础数据 /example/solr/* /opt/solrHome 将contrib和dist两个目录拷贝到/opt ...