postgreSQL

PostgreSQL

docker run --name postgres \
    -e POSTGRES_PASSWORD=123456 \
    -p 5432:5432 \
    -d postgres

感觉和mysql没啥区别

SQL语言

插入

insert into table values(id,name,sex....)

吧查询结果插入表中

insert into table_1 select * from table_2;
吧table_2 的内容 插入到 table_1 中

更新

update table set name = lf where id = 1;

删除

delete from table where id =3;

数据类型

类型说明补充
smallint-32768 ~ 32767
int / integer-21E ~ 21E
real浮点数 6位十进制精度
numeric(m,n)任意精度 m 数据长度 n 小数点后精度注意:超出位会自动四舍五入
time8字节 10:50:05
date4字节 日期 1997-01-02
timestamp日期时间1998-01-02 10:20:02
char(n)/character(n)固定长度字符串,不足补空白
varchar(n)/character carying(n)可变长度
text变长字符串,无长度限制

函数

select concat( '-',A,'-' ) from table;
结果; -A-  字符拼接

数值函数

函数说明
avg平均
count列的行数
max列最大值哦
min列最小值
sum列求和

字符串函数

函数说明
length(s)字符串长度
concat(s1,s2…)字符串合并
ltrim(s)/rtrim(s)/trim(s)删除字符串空格函数
replace(s,s1,s2)字符串替换函数
substring(s,n,len)获取子串函数

日期时间函数

函数说明
extract(type from d)获取日期指定值函数
current_date获取当前日期函数
current_time获取当天时间函数
now获取当前日期函数时间
select my_data,
extract( year/month/day from my_date )//

自定义函数

[视频][https://www.bilibili.com/video/BV1av411r7yB?p=12&spm_id_from=pageDriver&vd_source=529975faf79e2de2d708a6f0c8898290]

运算符

算数运算符

+、-、*、/、%

比较运算符

=、<>/!=、>=、<=、>、<

运算符说明
least在两个或者多个参数时,返回最小值
greatest在有两个或多个参数时,返回最大值
between and判断一个值是否落在两个值之间
注意 select 2 between 1 and 3 (是包含1,2,3)
in判断是否时in 中的一个
like通配符匹配

逻辑运算符

not、and、or

运算符优先级

16612213966091

索引

索引名说明
B-Tree顺序索引
Hash简单比较
GiST一种索引架构
GIN反转索引,处理包含多个键的值
create index emp_name_index on employee(e_name); 创建索引  默认的是 BTree
drop index emp_name_index;   删除索引 

简单查询

null值最前

nulls first/last。吧null 前置/后置

select xxx from xxx
order by name asc nulss first;

limit

获取5条数据 忽略前4条

select * from xx limit 5 offset 4;

子查询

exists 中的查询有结果就返回 true

select * from xx where exists(select * from xxx where xxx);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值