记录碰到的postgresql和sqlserver的不同
1.sqlserver不区分大小写,脚本里基本都是小写,而表字段和表名基本是大写
pg默认将sql都转为小写,如果需要大写要用""括起来。
2.ISNULL() 变 COALESCE()
3.len变length
4.CHARINDEX(str1, str2) 变 POSITION(str1 in str2)
5.函数中返回值类型前用
RETURNS而不是RETURN
6.声明变量用
declare而不是as
7.在函数结尾需要声明执行语言
$$ LANGUAGE plpgsql;
8.函数中执行sql命令:
exec -> execute
9.函数内调用其他自定义函数使用:
call 变 perform
10.pg没有if exists
11.查函数
select count(routine_name) from information_schema.routines where routine_name = ‘函数名’ and routine_type = ‘FUNCTION’;
12.查字段
select count(*) from information_schema.columns WHERE table_schema = ‘public’ and table_name = ‘KMK’ and column_name = ‘fkmbh’;
13.查表
select * from information_schema.tables WHERE table_schema = ‘public’ and table_name = ‘KMK’
14.拼接字段
不用+ ,而是用 ||
15.查看序列
SELECT count(0) FROM pg_class where relkind = ‘S’ and relname = ‘seq_d’;
16.没有dual
直接select 0 就可以
17.没有rownum=1
用limit 1
18.查看pg当前在跑的命令
select * from pg_stat_activity order by state;
19.强制停止在跑命令
根据上条查出命令,得到pid
select pg_cancel_backend(pid);
更多推荐
所有评论(0)