首页数据库PostgreSQL 序列增删改案例

PostgreSQL 序列增删改案例

时间2024-02-29 13:55:03发布访客分类数据库浏览270
导读:收集整理的这篇文章主要介绍了PostgreSQL 序列增删改案例,觉得挺不错的,现在分享给大家,也给大家做个参考。 创建序列CREATE SEQUENCE if not exists t...
收集整理的这篇文章主要介绍了PostgreSQL 序列增删改案例,觉得挺不错的,现在分享给大家,也给大家做个参考。

创建序列

CREATE SEQUENCE if not exists test_mergetable_id_seqINCREMENT 1MINVALUE 1MAXVALUE 999999999START 1CACHE 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;
    

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

您可能感兴趣的文章:
  • PostgreSQL Sequence序列的使用详解
  • postgresql 中的序列nextval详解
  • PostgreSQL 序列绑定字段与不绑定字段的区别说明
  • postgresql重置序列起始值的操作
  • postgresql 实现更新序列的起始值
  • postgresql修改自增序列操作
  • Postgresql数据库之创建和修改序列的操作

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: PostgreSQL 序列增删改案例
本文地址: https://pptw.com/jishu/632952.html
postgresql合并string c语言字符串类型如何赋值

游客 回复需填写必要信息