postgres if ,when及判断表是否存在的sql编写
判断表是否存在方法1:
SELECT case WHEN a.cc = THEN else END
FROM
(
select count(*) as cc from pg_class where relname = 'wo' --wo is table name,pg_class是pg自带的关键字
) as a
方法2:
用if判断,但有以下条件
The IF statement is part of the default procedural language PL/pgSQL. You need to create a function or execute an ad-hoc statement with the DO command.、
exist使用要求和if一样
DO
$do$
BEGIN
IF (select count(*) cc from pg_class where relname = 'wo') = 0 --一定要加括号
THEN
INSERT INTO wo VALUES (2);
ELSE
INSERT INTO wo VALUES (1);
END IF;
END
$do$
联合使用select 和insert的方法如下
create table language_ko(Key text,XML text);
insert into Language_ko(key,xml) (select "Key " as key,'<'||"Key"||'>'||"Korean"||'</'||"Key"||'>' as xml from "centralClient1")
postgres if ,when及判断表是否存在的sql编写的更多相关文章
- ORACLE创建表之前判断表是否存在与SQL Server 对比使用
在SQL Server 数据库中,我们在创建表之前删除表,有if exit()这样的语句,但是在oracle中却没有.如果直接使用drop table那么如果表不存在会报错,导致后续语句无法运行.因此 ...
- Sql 判断函数是否存在、sql判断表是否存在、sql判断存储过程是否存在、sql判断视图是否存在
--数据库是否存在 IF exists(SELECT * FROM master..sysdatabases WHERE name=N'库名') PRINT 'exists' ELSE PRINT ' ...
- [PostgreSql]PostgreSql调用函数及用IF EXISTS判断表是否存在
1.创建一个函数function1 -- FUNCTION: public.function1(character varying, integer) -- DROP FUNCTION public. ...
- oracle创建表之前判断表是否存在,如果存在则删除已有表
Mysql 创建表之前判断表是否存在,如果存在则删除已有表 DROP TABLE IF EXISTS sys_area; CREATE TABLE sys_area ( id int NOT NULL ...
- SqlServer主键外键添加及判断表是否存在
GO --判断表是否存在方式1 if object_id(N'EF_User',N'U') is null --判断表是否存在方式2 --if not exists (select * from db ...
- Sql Server 判断表或数据库是否存在
发布:thebaby 来源:脚本学堂 [大 中 小] 本文详细介绍了,在sql server中判断数据库或表是否存在的方法,有理论有实例,有需要的朋友可以参考下,一定有帮助的.原文地址:h ...
- Oracle删除表、字段之前判断表、字段是否存在
这篇文章主要介绍了Oracle删除表.字段之前判断表.字段是否存在的相关资料,需要的朋友可以参考下 在Oracle中若删除一个不存在的表,如 “DROP TABLE tableName”,则会提示: ...
- sql 判断表、列、视图等是否存在
1 判断数据库是否存在 if exists (select * from sys.databases where name = '数据库名') drop database [数据库名] 2 判 ...
- SQl 判断 表 视图 临时表等 是否存在
1.判断是否存在addOneArticle这个存储过程 if Exists(select name from sysobjects where NAME = 'addOneArticle' and t ...
随机推荐
- 阿里云API公共参数的获取
阿里云公共参数API https://help.aliyun.com/document_detail/50284.html?spm=5176.10695662.1996646101.searchcl ...
- 打开usb调试的方法
方法一: settings --> about tablet --> build number(疯狂点击) -->回退 developer options --> USB d ...
- Windows Server 2008 R2系统上安装SQLServer2012集群(简略)
4台服务器(1台AD.2台SQL服务器.1台iSCSI存储服务器) 9个IP(1个AD的IP.2个SQL服务器的IP.2个心跳IP.1个iSCSI存储服务器的IP.1个集群IP.1个DTC的IP.1个 ...
- easyui内嵌iframe问题解决
项目中使用easyui的tab页,每个tab页均内嵌iframe,现在要在tab页中控制新增一个同级别的tab页,记录如下: 首先是main.html主页面: <div class=" ...
- JavaScript(JS)计算某年某月的天数(月末)
方法1 /** * 获取某年月的天数 * @param year 年 * @param month 月(0-11) * @returns {number} 天数 */ var getDaysOfMon ...
- git记住提交密码的技巧
修改.git包里面的config文件,添加 [credential] helper = store
- Spring课程 Spring入门篇 5-4 advice应用(上)
1 解析 1.1 通知执行顺序 2 代码演练 1 解析 1.1 通知执行顺序 aop执行方式为:前置通知==>所要增强的方法==>后置通知==>最终通知 在出现异常时会进行:前置通知 ...
- 移动端布局注意事项与less
用Koala实现less的实时编译 1.下载Koala(Koala可以实现实时编译) 2.把CSS文件夹(如index.css,index.less)拖到Koala中 3.点击到需要编译的index. ...
- flask用session记录状态
html <form action="/login" method="POST"> <input type="text" ...
- webapi 开启gzip压缩
1.nuget安装Microsoft.AspNet.WebApi.Extensions.Compression.Server 2.global.asax.cs里引用System.Net.Http.Ex ...