• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PostgreSQL 序列增删改案例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

创建序列

CREATE SEQUENCE if not exists test_mergetable_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 999999999
START 1
CACHE 1;
//或者: 
create sequence if not exists test_mergetable_id_seq increment by 1 minvalue 1 no maxvalue start with 1; 

指定序列(给表的主键指定创建好的序列)

alter table test_mergetable alter column "i_id" set default nextval('test_mergetable_id_seq');

设置序列自增长从当前最大值开始

SELECT setval('test_mergetable_id_seq', (SELECT MAX(i_id) FROM test_mergetable));
alter sequence test_mergetable_id_seq start with 12;

删除序列

drop sequence IF EXISTS test_mergetable_id_seq

查看序列

SELECT nextval('test_mergetable_id_seq')

补充:pgsql的schema对用户授权,单个用户跨schema增删改查操作

--创建用户

create user user1;

--修改密码

alter user report with password 'password';

--授权查询权限

grant usage on schema schema1 to user1;
grant usage on schema schema2 to user1;

修改search_path可跨schema操作

set search_path = "$user",user1,user2

--授权schema:schema1给user1权限 这个权限太大需要慎用

grant all on schema schema1 to user1;

--授权schema的表权限给user1 用户权限太多需慎用

grant all on all tables in schema schema1 to user1;

--授权schema的表权限给user1 用户权限太多需慎用

grant all on all tables in schema schema1 to user1;

--授权某个schema的单个表查权限

grant select on schema2.table1           to user1;

--收回所有授权

revoke all on all tables in schema schema1 from user1;

--为某个特定用户设置search_path

alter user user1 set search_path="$user",user1,user2;

以上为个人经验,希望能给大家一个参考,也希望大家多多支持极客世界。如有错误或未考虑完全的地方,望不吝赐教。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Oracle BULK COLLECT批量取数据解决方法发布时间:2022-02-08
下一篇:
linux centos7安装mysql8的教程发布时间:2022-02-08
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap