創建表
drop table test_create_table;
create table test_create_table (
id int8 not null primary key ,
user_id int8 not null,
user_name varchar(20) not null default '',
user_sex boolean
)
給主鍵設置自增(需要先設置sequence)
/*增加自增索引*/
create sequence id;
alter table test_create_table alter column id set default nextval('id');
添加索引
create unique index unq_user_id_user_name on test_create_table(user_id,user_name)
/*設置更新觸發器函數*/ create or replace function upd_timestamp() returns trigger as $$ begin new.update_time = current_timestamp; return new; end $$ language plpgsql; /*創建觸發器*/ create trigger trigger_test_study before update on test_create_table for each row execute procedure upd_timestamp();