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;
--修改密码
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;
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
上一篇:使用mysql记录从url返回的http GET请求数据操作
栏 目:其它数据库
本文标题:PostgreSQL 序列增删改案例
本文地址:https://zz.feitang.co/shujuku/32723.html
您可能感兴趣的文章
- 12-22使用mysql记录从url返回的http GET请求数据操作
- 12-22详解sql中exists和in的语法与区别
- 12-22hive从mysql导入数据量变多的解决方案
- 12-22如何为PostgreSQL的表自动添加分区
- 12-22postgresql 实现得到时间对应周的周一案例
- 12-22sqoop export导出 map100% reduce0% 卡住的多种原因及解决
- 12-22mysql查询条件not in 和 in的区别及原因说明
- 12-22解决mysql使用not in 包含null值的问题
- 12-22解决从集合运算到mysql的not like找不出NULL的问题
- 12-22postgresql 实现多表关联删除


阅读排行
推荐教程
- 12-11mysql代码执行结构实例分析【顺序、分支、循环结构】
- 12-08添加mysql的用户名和密码是什么语句?
- 12-20PhpMyAdmin出现错误数据无法导出怎么办?
- 12-19Redis中实现查找某个值的范围
- 12-15浅析mysql迁移到clickhouse的5种方法
- 12-15CentOS7 64位下MySQL5.7安装与配置教程
- 12-14Mysql大型SQL文件快速恢复方案分享
- 12-14mysql 5.7.27 安装配置方法图文教程
- 12-13MySQL给新建用户并赋予权限最简单的方法
- 12-13关于MySQL索引的深入解析





