postgreSql 使用笔记

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/haiyoung/article/details/83351887

postgreSql

postgreSql 自增主键计数器重置

select setval('table_name_seq',max_num+1,false);

postgreSql数据库中 表的自增主键映射 JPA

@Id  
@GeneratedValue(strategy = GenerationType.IDENTITY)  
private Integer id;  

postgresql数据库json字段查询

select x.variable::json->>'imageId' as imageId, x.status, y.image_name 
from task x join image y on x.variable::json->>'imageId' = y.image_id
where x.variable::json->>'imageId' is not null and x.status is not null and y.is_valid is true;

postgresql多表联合批量更新

update table_p as p 
set p_name = a.name,p_user = a.user_id,p_type = 'P02'
from (
select x.user_id,x.name,x.p_id from table_u x
join table_p y on x.p_id = y.p_id
) as a where p.p_id = a.p_id;

postgreSQL分页查询SQL

select * from table_name limit pagesize offset offsetNum ;  
-- 一般情况下: 
-- pagesize是固定的,即每页显示多少记录,而offsetNum则是需要我们去计算的。  
-- offsetNum=(当前页数-1)*pagesize (如果是第一页,假设每页显示10条数据,则是(1-1)*10,第二页则是(2-1)*10)  

查看postgresql当前连接

select * from pg_stat_activity;
-- 查询出来的信息中,只有当前查询用户的连接的详细信息

猜你喜欢

转载自blog.csdn.net/haiyoung/article/details/83351887