pgsql的一些语法
2020-12-29 16:50
225 查看
计算两个时间相差的天数
SELECT date_part('day',cast(now() as TIMESTAMP)-cast(create_time as TIMESTAMP)) FROM t_module_xxx;
create_time 是 timestamp 类型。可以通过date_part计算两个时间相差几天,几分钟,几秒钟等。
具体可以参考这篇文章。
可重复执行修改表结构语法
添加约束
alter table public.t_module_xxx drop constraint if EXISTS unique_xxxx; alter table public.t_module_xxx add constraint unique_xxxx unique(col1,col2);
建表语句
-- postgresql建议使用小写 drop table if exists public.t_module_xxx; drop sequence if exists seq_t_module_xxx; -- 创建序列 create sequence seq_t_module_xxx increment 1 minvalue 1 maxvalue 9223372036854775807 start 1 cache 1 cycle; -- 创建表 create table public.t_module_xxx ( order_id integer default nextval('seq_t_pcar_order') not null, user_id integer not null, loan_amount numeric(12, 2), loan_apply_no varchar(255), loan_apply_status varchar(2), loan_apply_time timestamp without time zone, loan_no varchar(255), loan_success_time timestamp without time zone, loan_status varchar(2), -- 金额类型 down_payment_amount numeric(12, 2), create_time timestamp without time zone default now(), update_time timestamp without time zone ); -- 创建注释 comment on table public.t_module_xxx is '订单表'; comment on column public.t_module_xxx.order_id is '主键'; --设置主键 alter table t_module_xxx add constraint pk_t_pcar_order primary key (order_id); -- 授权语句 grant select, insert, update, delete on public.t_module_xxx to xxxxxx; grant select on public.t_module_xxx to xxxxxx;
相关文章推荐
- [mysql使用(2)] mysql的一些语法与Oracle的差别
- C# 的一些语法特性
- 尖括号百分号的一些语法
- SQL语法的一些整理
- .NET中正则表达式的一些语法概述
- JS一些语法
- 编辑/etc/profile文件由于语法错误导致找不到一些常用命令
- 一些C++语法
- matlab的一些语法
- sql语句一些常用语法的积累
- 有关java语法需要注意地方的一些记录(一)
- Android.mk 中的一些语法
- hbase语法及一些问题的解决(其中有失误的地方,往体谅)
- Oracle数据库 中的基础的一些语法结构
- XPath语法使用的一些心得
- Unity3D Shader官方教程翻译(十八)----Shader语法 另外一些命令(分类)
- Swift3.0相对于2.3语法的一些变化
- FMX中一些delphi与C++ Builder语法的对比
- 基于sql语句的一些常用语法积累总结
- Oracle语法和SQL语法的一些区别