You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT city, (temp_hi+temp_lo)/2AS temp_avg, dateFROM weather;
2.7 Aggregate Functions 聚合数据
SELECTmax(temp_lo) FROM weather;
SELECT city FROM weather WHERE temp_lo =max(temp_lo); WRONG, where里面不能用聚合属性
SELECT city FROM weather
WHERE temp_lo = (SELECTmax(temp_lo) FROM weather);
ALTERTABLE<table_name> OWNER TO <role_name>; /* 变更表,数据库的owner*/GRANTSELECTON<table_name> TO <role_name>; /* 允许某个用户查询某个表 */REVOKE ALL ON role2_s_table FROM wangx; /* 不允许wangx操作role2_s_table */REVOKEDELETEON<table_name> TO <role_name>; /* 删除用户的DELETE权限 */
select
table_name,
pg_size_pretty(pg_total_relation_size(quote_ident(table_name))),
pg_total_relation_size(quote_ident(table_name))
from information_schema.tables
where table_schema = 'public'
order by 3 desc;
basic
修改用户密码
ALTERUSER user_name WITH PASSWORD 'new_password';
允许用户查询某个数据表
GRANT CONNECT ON DATABASE <db> TO <role>;
GRANT USAGE ON SCHEMA public TO <role>;
GRANTSELECTON ALL TABLES IN SCHEMA public to <role>;
Database Roles
CREATE ROLE <name>;
DROP ROLE <name>;
SELECT rolname FROM pg_roles;
createtablestudents (
id integerprimary key generated by default as identity,
name char(3)
);
insert into students values (default, '1'); /* 1 */insert into students values (2, '1');
insert into students values (default, '1'); /* 报错, 因为2存在了 */