PostgreSQL序列增删改案例创建序列
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;
--修改密码
drop table if exists useralter 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;
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。如有错误或未考虑完全的地⽅,望不吝赐教。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。