欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PostgreSQL 序列增刪改案例

 更新時間:2021年01月04日 11:44:15   作者:潘達(dá)小新  
這篇文章主要介紹了PostgreSQL 序列增刪改案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

創(chuàng)建序列

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; 

指定序列(給表的主鍵指定創(chuàng)建好的序列)

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

設(shè)置序列自增長從當(dāng)前最大值開始

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')

補(bǔ)充:pgsql的schema對用戶授權(quán),單個用戶跨schema增刪改查操作

--創(chuàng)建用戶

create user user1;

--修改密碼

alter user report with password 'password';

--授權(quán)查詢權(quán)限

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

修改search_path可跨schema操作

set search_path = "$user",user1,user2

--授權(quán)schema:schema1給user1權(quán)限 這個權(quán)限太大需要慎用

grant all on schema schema1 to user1;

--授權(quán)schema的表權(quán)限給user1 用戶權(quán)限太多需慎用

grant all on all tables in schema schema1 to user1;

--授權(quán)schema的表權(quán)限給user1 用戶權(quán)限太多需慎用

grant all on all tables in schema schema1 to user1;

--授權(quán)某個schema的單個表查權(quán)限

grant select on schema2.table1           to user1;

--收回所有授權(quán)

revoke all on all tables in schema schema1 from user1;

--為某個特定用戶設(shè)置search_path

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

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評論