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 ...
随机推荐
- spring aop 执行顺序
aop 执行顺序: // @Before // @AfterThrowing order 值越小,执行时越靠前 // @After // @AfterReturning order 值越大,执行时越靠 ...
- java 泛型E T ?的区别
Java泛型中的标记符含义: E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Number ...
- [转载]时间显示插件 flipclock.js
<html> <head> <link rel="stylesheet" href="/assets/css/flipclock.css&q ...
- foreach嵌套遍历循环的问题
在foreach嵌套循环中使用==和equals的问题 JSONArray ja1= new JSONArray(); JSONArray ja2 = new JSONArray(); JSONObj ...
- 怎样从外网访问内网MongoDB数据库?
本地安装了一个MongoDB数据库,只能在局域网内访问到,怎样从外网也能访问到本地的MongoDB数据库呢?本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动MongoDB数据库 默认安装 ...
- ATM开学测试(未完成)
package ATM_design; //信1705-2 20173456 张浩 import java.util.*; import java.io.File; import java.io.Fi ...
- php实现共享内存进程通信函数之_shm
前面介绍了php实现共享内存的一个函数shmop,也应用到了项目中,不过shmop有局限性,那就是只支持字符串类型的:sem经过我的测试,是混合型,支持数组类型,可以直接存储,直接获取,少了多余的步骤 ...
- 如何用git将项目代码上传到github
注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...
- 树莓派安装cobbler,自动化安装CentOS
安装python.相关python模块.apache sudo apt-get install python python2.7 python-django python-netaddr python ...
- 本地win7ping VM linux ipv6地址问题
前述 在windows和linux同时安装ipv6之后,系统将会自动分配一个link-local(链接本地)地址也就是ifconfig -a看到的一行[inet6 addr: fe80::20c:29 ...