PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹9. 庘昄启淉嘩严媆誕嬉誕

9.19. 係䂘媇敇庘昄

臘9-40滆䴺庖庹婻檘埡嚔臺埪係䂘媇敇䔇庘昄㔗

臘9-40. 嚔臺媇敇庘昄

劉庖誫啂䌂傋柟誄
current_database()name嘷嬉昄扞康䔇劉庖
current_schema()name嘷嬉昇嚟䔇劉庖
current_schemas(boolean)name[]抩䘵虇冇婺䔇昇嚟劉庖
current_username嘷嬉欓臯䯇嵄婋䔇䫘潙劉
inet_client_addr()inet誂毖䔇誩䆇婄应
inet_client_port()int誂毖䔇誩䆇䆇埼
inet_server_addr()inet誂毖䔇橸婄婄应
inet_server_port()int誂毖䔇橸婄䆇埼
pg_my_temp_schema()oid嚔臺䔇婘施昇嚟䔇 OID 婉庻婘彍婺 0
pg_is_other_temp_schema(oid)boolean滇劥婺埥婔婻嚔臺䔇婘施昇嚟?
pg_postmaster_start_time()timestamp with time zone橉媇単劇媘施閘
session_username嚔臺䫘潙劉
username京備庯 current_user
version()textPostgreSQL 䬽橸媇敇

session_user 锔婩滇誂毖嘷嬉昄扞康䔇彺哋䫘潙婉誺轙亓䫘潙埇傖䫘 SET SESSION AUTHORIZATION 媞櫹認婻螆䘞㔗current_user 滇䫘庯溄鍊演昖䔇䫘潙湺臖㔗锔婩垄攂滇京庯嚔臺䫘潙嘖滇埇傖锔誺 SET ROLE 櫹埻垄㔗婘庘昄欓臯䔇誺䘋婺锟五匂攓 SECURITY DEFINER 䔇櫹埻噽唚幘嚔櫹埻㔗䫘 Unix 橇臺準臘嚔臺䫘潙滇"䩘垂䫘潙"蔯嘷嬉䫘潙滇"橬昽䫘潙"㔗

㔊濘懟㔏current_user, session_user, user 婘 SQL 麯橬䬹枪䔇臺濘脄䫘施䂷儆婉脘虘啺拸埙㔗

current_schema 誫啂婘抩䘵虇冇嬉䆇䔇昇嚟劉庖(套悩抩䘵虇冇婺䷺彍誫啂 NULL)㔗套悩录傺臘潡蔙噽垄变劉凹茇施澇橬弄滯䕞湺昇嚟闼幽垄儖滇䫘庯認底凹茇䔇昇嚟㔗current_schemas(boolean) 誫啂婔婻抩䘵虇冇婺欔橬昇嚟劉庖䔇昄䂇㔗婄儫锬釹喿垔償 pg_catalog 認湙锊劆寙劆䔇係䂘昇嚟滇劥寙劆婘誫啂䔇抩䘵虇冇婺㔗

㔊濘懟㔏抩䘵虇冇埇傖锔誺誊臯施螆䘞敘櫹㔗变傴滇

SET search_path TO schema [, schema, ...]

inet_client_addr 誫啂嘷嬉垵潙䆇䔇IP婄应蔯 inet_client_port 彍誫啂嘷嬉垵潙䆇䔇䆇埼埙㔗inet_server_addr 誫啂橉媇単毖櫽嘷嬉誂毖䫘䔇 IP 婄应蔯 inet_server_port 誫啂毖櫽嘷嬉誂毖䔇䆇埼埙㔗套悩滇锔誺 Unix-domain socket 誂毖䔇闼幽欔橬認底庘昄鄘誫啂 NULL 㔗

pg_my_temp_schema 誫啂嘷嬉嚔臺䔇婘施昇嚟 OID 套悩婉庻婘䔇臺彍誫啂 0(啹婺澇橬录傺傂嘘婘施臘)㔗pg_is_other_temp_schema 誫啂䂍垔䔇 OID 滇劥婺噽垄嚔臺䔇婘施昇嚟 OID 認婻庘昄滇橬垂䫘備唚䔇懫套婘滆䴺婔婻䕞嘘䔇施唍毐鍴毬噽垄嚔臺䔇婘施臘㔗

pg_postmaster_start_time 誫啂橉媇単劇媘施䔇 timestamp with time zone

version 誫啂婔婻柟誄 PostgreSQL 橉媇単䬽橸媇敇䔇庖严婾㔗

臘9-41彖庺闼底噕螩䫘潙婘䘋废麯昖臵凹茇螪閞溄鍊䔇庘昄㔗埗黙誗5.6诙埡敘崔橬噿溄鍊䔇媇敇㔗

臘9-41. 螪閞溄鍊昖臵庘昄

劉庖誫啂䌂傋柟誄
has_database_privilege(user, database, privilege)boolean毺垔䫘潙滇劥橬螪閞昄扞康䔇溄鍊
has_database_privilege(database, privilege)boolean嘷嬉䫘潙滇劥橬螪閞昄扞康䔇溄鍊
has_function_privilege(user, function, privilege)boolean毺垔䫘潙滇劥橬螪閞庘昄䔇溄鍊
has_function_privilege(function, privilege)boolean毺垔䫘潙滇劥橬螪閞庘昄䔇溄鍊
has_language_privilege(user, language, privilege)boolean毺垔䫘潙滇劥橬螪閞臺蘔䔇溄鍊
has_language_privilege(language, privilege)boolean毺垔䫘潙滇劥橬螪閞臺蘔䔇溄鍊
has_schema_privilege(user, schema, privilege)boolean毺垔䫘潙滇劥橬螪閞昇嚟䔇溄鍊
has_schema_privilege(schema, privilege)boolean毺垔䫘潙滇劥橬螪閞昇嚟䔇溄鍊
has_table_privilege(user, table, privilege)boolean毺垔䫘潙滇劥橬螪閞臘䔇溄鍊
has_table_privilege(table, privilege)boolean毺垔䫘潙滇劥橬螪閞臘䔇溄鍊
has_tablespace_privilege(user, tablespace, privilege)boolean毺垔䫘潙滇劥橬螪閞臘䷺閘䔇溄鍊
has_tablespace_privilege(tablespace, privilege)boolean毺垔䫘潙滇劥橬螪閞臘䷺閘䔇溄鍊
pg_has_role(user, role, privilege)boolean毺垔䫘潙滇劥橬螪閞蓐謾䔇溄鍊
pg_has_role(role, privilege)boolean毺垔䫘潙滇劥橬螪閞蓐謾䔇溄鍊

has_database_privilege 演昖婔婻䫘潙滇劥脘傖䬹垔桹嚟螪閞婔婻昄扞康㔗垄埇脘䔇埗昄䌂嚚 has_table_privilege 㔗溄鍊䌂傋媙釂滇 CREATE, CONNECT, TEMPORARY, TEMP(京備庯 TEMPORARY)幋婔㔗

has_function_privilege 演昖婔婻䫘潙滇劥脘傖䬹垔桹嚟螪閞婔婻庘昄㔗垄埇脘䔇埗昄䌂嚚 has_table_privilege 㔗潏傸弄滯婔婻庘昄䫘䔇滇桺橸庖严婾蔯婉滇 OID 噕螩䔇膷噖启 regprocedure 昄扞䌂傋婔湙(埗黙誗8.12)㔗溄鍊䌂傋媙釂滇 EXECUTE 㔗婔婻冋床套婋

SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');

has_language_privilege 演昖婔婻䫘潙滇劥脘傖䬹垔桹嚟螪閞婔婻誺䘋臺蘔㔗垄埇脘䔇埗昄䌂嚚 has_table_privilege 㔗溄鍊䌂傋媙釂滇 USAGE

has_schema_privilege 演昖婔婻䫘潙滇劥脘傖䬹垔桹嚟螪閞婔婻昇嚟㔗垄埇脘䔇埗昄䌂嚚 has_table_privilege 㔗溄鍊䌂傋媙釂滇 CREATEUSAGE

has_table_privilege 演昖婔婻䫘潙滇劥脘傖䬹垔桹嚟螪閞婔婻臘㔗䫘潙埇傖锔誺劉庖潡蔙 OID(pg_authid.oid)準弄滯套悩䩕䘖臖埗昄彍嘪䫘 current_user 㔗臖臘埇傖锔誺劉庖潡蔙 OID 弄滯㔗啹溴垂鍙婪橬噺䓉 has_table_privilege 埻嘷潏傸埇傖锔誺垄傸䔇埗昄昄䕞启䌂傋準寺彖垄傸㔗套悩䫘劉庖弄滯闼幽婘媙襕施埇傖䫘昇嚟誕臯媞閄㔗欔婯橕䔇溄鍊䌂傋滇䫘婔婻桺橸庖严婾準弄滯䔇媙釂滇 SELECT, INSERT, UPDATE, DELETE, REFERENCES, TRIGGER 幋婔㔗嘷䇽庖严婾䔇崓償喍澇傔幽噿係㔗冋套

SELECT has_table_privilege('myschema.mytable', 'select');

has_tablespace_privilege 演昖婔婻䫘潙滇劥脘傖䬹垔桹嚟螪閞婔婻臘䷺閘㔗垄埇脘䔇埗昄䌂嚚 has_table_privilege 㔗溄鍊䌂傋媙釂滇 CREATE

pg_has_role 演昖婔婻䫘潙滇劥脘傖䬹垔桹嚟螪閞婔婻蓐謾㔗垄埇脘䔇埗昄䌂嚚 has_table_privilege 㔗溄鍊䌂傋媙釂滇 MEMBERUSAGEMEMBER 臘䴺滇蓐謾婺䔇䕘毖潡閘毖潊叻噿係(幘儌滇 SET ROLE 䔇溄鍊)蔯 USAGE 臘䴺蓐謾䔇溄鍊滇劥方驔 SET ROLE 剿埇䆋剿䫘昽㔗

襕臇嚄婔婻䫘潙滇劥婘溄鍊婪毕橬蕋溄锬釹䂍溄鍊髞庖鍇媹 WITH GRANT OPTION 剿埇懫套'UPDATE WITH GRANT OPTION'

臘9-42滆䴺庖闼底彴桺婔婻凹茇滇劥婘嘷嬉昇嚟抩䘵虇冇婺埇蓕䔇庘昄㔗套悩婔婻臘欔婘䔇昇嚟婘抩䘵虇冇婺幽婫澇橬劯劉䔇臘庺䯄婘抩䘵虇冇䔇敘麹嬉䔇婄桹闼幽儌臘認婻臘滇埇蓕䔇㔗垄京昽庯臘埇傖婉婥滯䇞昇嚟媞閄誕臯嚘䫘㔗懫套襕彖庺欔橬埇蓕臘䔇劉庖

SELECT relname FROM pg_class WHERE pg_table_is_visible(oid);

臘9-42. 昇嚟埇蓕攓昖臵庘昄

劉庖誫啂䌂傋柟誄
pg_conversion_is_visible(conversion_oid)boolean臖蘸扵滇劥婘抩䘵虇冇婺埇蓕
pg_function_is_visible(function_oid)boolean臖庘昄滇劥婘抩䘵虇冇婺埇蓕
pg_operator_is_visible(operator_oid)boolean臖淉嘩严滇劥婘抩䘵虇冇婺埇蓕
pg_opclass_is_visible(opclass_oid)boolean臖淉嘩严䌂滇劥婘抩䘵虇冇婺埇蓕
pg_table_is_visible(table_oid)boolean臖臘滇劥婘抩䘵虇冇婺埇蓕
pg_type_is_visible(type_oid)boolean臖䌂傋(嘘)滇劥婘抩䘵虇冇婺埇蓕

pg_table_is_visible 誻埇䫘庯蓖商㔕䘵嚘㔕废彖㔗pg_type_is_visible 誻埇䫘庯嘘㔗凹庯庘昄启淉嘩严套悩婘抩䘵虇冇婺澇橬劉庖䕩劯幽婫埗昄䔇昄扞䌂傋幘䕩劯䔇凹茇庺䯄婘虇冇婺敘麹嬉䔇嘉䘞闼幽臖凹茇儌滇埇蓕䔇㔗凹庯淉嘩严䌂彍襕劯施蔄荏劉庖启䕩噿䔇䘵嚘螪閞桹濘㔗

欔橬認底庘昄鄘驔襕嘪䫘 OID 準湺臖襕赆演昖䔇凹茇㔗套悩嘹愿锔誺劉庖敋臘凹茇闼幽嘪䫘 OID 彆劉䌂傋(regclass, regtype, regprocedure, regoperator)儖嚔冽桹冪㔗冋套

SELECT pg_type_is_visible('myschema.widget'::regtype);

臙濘懟䫘認䓉桹濘敋臘婔婻橻䂟媞閄䔇劉庖澇傔幽懟幬啹婺套悩婔婻劉庖埇傖赆臖彆闼垄饡噽媙釂滇埇蓕䔇㔗

臘9-43彖庺庖傯係䂘臘婺檘埡媇敇䔇庘昄㔗

臘9-43. 係䂘臘媇敇庘昄

劉庖誫啂䌂傋柟誄
format_type(type_oid, typemod)text诙埡婔婻昄扞䌂傋䔇 SQL 劉䓄
pg_get_constraintdef(constraint_oid)text诙埡婔婻亥溘䔇垔幬
pg_get_constraintdef(constraint_oid, pretty_bool)text诙埡婔婻亥溘䔇垔幬
pg_get_expr(expr_text, relation_oid)text埉䚡臏婔婻臘膆嚟䔇喙鄘嘵嚟啺螆噽婺䔇傂嘘 Var 鄘嚘䫘丸庯婻埗昄毺庺䔇噿係
pg_get_expr(expr_text, relation_oid, pretty_bool)text埉䚡臏婔婻臘膆嚟䔇喙鄘嘵嚟啺螆噽婺䔇傂嘘 Var 鄘嚘䫘丸庯婻埗昄毺庺䔇噿係
pg_get_indexdef(index_oid)text婺䘵嚘诙埡 CREATE INDEX 变傴
pg_get_indexdef(index_oid, column_no, pretty_bool)text婺䘵嚘诙埡 CREATE INDEX 变傴套悩 column_no 婉婺镽彍埻诙埡婔婻䘵嚘庖枕䔇垔幬㔗
pg_get_ruledef(rule_oid)text婺蓇彍诙埡 CREATE RULE 变傴
pg_get_ruledef(rule_oid, pretty_bool)text婺蓇彍诙埡 CREATE RULE 变傴
pg_get_serial_sequence(table_name, column_name)text诙埡婔婻 serialbigserial 庖枕嘪䫘䔇废彖劉庖
pg_get_triggerdef(trigger_oid)text婺蓥埏単诙埡 CREATE [ CONSTRAINT ] TRIGGER 变傴
pg_get_userbyid(roleid)name诙埡䂍垔 ID 䔇蓐謾劉
pg_get_viewdef(view_name)text婺蓖商诙埡庘北䔇 SELECT 变傴(噾庘嚄)
pg_get_viewdef(view_name, pretty_bool)text婺蓖商诙埡庘北䔇 SELECT 变傴(噾庘嚄)
pg_get_viewdef(view_oid)text婺蓖商诙埡庘北䔇 SELECT 变傴
pg_get_viewdef(view_oid, pretty_bool)text婺蓖商诙埡庘北䔇 SELECT 变傴
pg_tablespace_databases(tablespace_oid)setof oid诙埡婘毺垔䔇臘䷺閘橬噄䘹䔇昄扞康 OID 镖劽

format_type 锔誺昊婻昄扞䌂傋䔇䌂傋 OID 傖埪埇脘䔇䌂傋媞閄臉誫啂噽 SQL 劉䓄㔗套悩婉䘖長噙嘷䔇媞閄臉闼幽婘䌂傋媞閄臉䔇嘉䘞嚹噖 NULL 㔗

pg_get_constraintdef, pg_get_indexdef, pg_get_ruledef, pg_get_triggerdef 彖彆傯婔婻蓖商㔕蓇彍㔕䘵嚘㔕蓥埏単㔕亥溘婪麉桄悇锹录傺垄傸䔇变傴(埉䚡臏䔇麉桄悇锹蔯婉滇臖变傴䔇寘桺)㔗pg_get_expr 埉䚡臏婔婻䋸䆋臘膆嚟䔇喙鄘嘵嚟懫套婔婻庖枕䔇䚺䩕唚㔗婘演昖係䂘臘䔇喙垹䔇施唍冽橬䫘㔗pg_get_viewdef 麉桄悇锹庺垔幬蓖商䔇 SELECT 昖臵㔗認底庘昄崓崔昄鄘橬婴婻埻䓉噽婺婔婻滇"锗劽欷剄"䔇䂷悩㔗認䓉湚嚟敘垹滷臂嘖滇䚺䩕䔇湚嚟敘橬埇脘赆儖準䔇 PostgreSQL 䬽橸䫘劯湙䔇桹濘蓼麪套悩滇䫘庯蘸嗘闼幽儘埇脘镪噉嘪䫘"锗劽欷剄"䔇湚嚟㔗䂍 pretty_bool 埗昄嚹锐 false 䫘潊䔇䂷悩启闼婻澇橬認婻埗昄䔇埻䓉䫘潊䔇䂷悩滇垯噘婔湙㔗

pg_get_serial_sequence 檷埡婯婔婻庖枕䕩噿䔇废彖劉庖套悩澇橬傂嘘废彖婯䂍垔䔇庖枕䕩噿彍誫啂 NULL 㔗認婻劉庖䂟誺庖劽锗䔇湚嚟寡埇傖嚹锐䂍废彖庘昄(埗黙誗9.12)㔗認䓉䕩噿攓埇傖锔誺 ALTER SEQUENCE OWNED BY 媞櫹潡役鍴㔗噽垂儖認婻庘昄变劉婺 pg_get_owned_sequence 潡螩敘婺奖嘷啹婺認婻劉庖埉滹庖垄锔婩䫘庯 serialbigserial 庖枕䔇庋垂㔗

pg_get_userbyid 锔誺蓐謾䔇 OID 檘埡凹庫䔇䫘潙劉㔗

pg_tablespace_databases 噕螩演昖婔婻臘䷺閘䔇䪽喕垄誫啂婘臖臘䷺閘婺媺庻庖凹茇䔇昄扞康 OID 镖劽㔗套悩認婻庘昄誫啂昄扞臯闼幽臖臘䷺閘儌滇麂䷺䔇啹溴婉脘役鍴㔗襕滆䴺臖臘䷺閘婺䔇䬹垔凹茇嘹驔襕檪 pg_tablespace_databases 誫啂䔇昄扞康湺臖婯 pg_class 臘誂毖誕臯昖臵㔗

臘9-44滆䴺䔇庘昄儖寘準䫘 COMMENT 变傴庻嗘䔇臇濘檘埡庺準㔗套悩澇橬欆彄彍誫啂 NULL 㔗

臘9-44. 濘麪媇敇庘昄

劉庖誫啂䌂傋柟誄
col_description(table_oid, column_number)text诙埡婔婻臘庖枕䔇臇濘
obj_description(object_oid, catalog_name)text诙埡婔婻昄扞康凹茇䔇臇濘
obj_description(object_oid)text诙埡婔婻昄扞康凹茇䔇臇濘(噾庘嚄)
shobj_description(object_oid, catalog_name)text诙埡婔婻噌庆昄扞康凹茇䔇臇濘

col_description 誫啂婔婻臘婺庖枕䔇臇濘垄滇锔誺臘 OID 启庖枕埙準弄滯䔇㔗obj_description 婉脘䫘庯臘庖枕啹婺庖枕澇橬躻噌䔇 OID 㔗

婥橬婴婻埗昄䔇 obj_description 誫啂婔婻昄扞康凹茇䔇臇濘臖凹茇滇锔誺噽 OID 启噽欔匂䔇係䂘臘劉庖弄滯䔇㔗懫套obj_description(123456,'pg_class') 儖誫啂 OID 婺 12345 䔇臘䔇臇濘㔗埻婥婔婻埗昄䔇 obj_description 埻襕挗凹茇 OID 䯄婘噾䂟庘嚄庖啹婺潏傸婉喉媺臕 OID 婘婉劯䔇係䂘臘幋閘滇嫇婔䔇啹溴埇脘嚔誫啂髍臇䔇臇濘㔗

shobj_descriptionobj_description 噞婉崔婉劯幋崇備婘庯嬉蔙䫘庯噌庆凹茇㔗婔底係䂘臘滇锔䫘庯镖䆴婺欔橬昄扞康䔇噘匔臘啹溴認底臘䔇臇濘幘滇噘匔庻嗘䔇㔗


劯锔饡釕嬉誕
誫啂镖劽䔇庘昄婪婔亓係䂘䞇䊖庘昄