您只能創建混凝土表FK參考 - 沒有意見,像information_schema.schemata
:
regress=> \dv information_schema.schemata
List of relations
Schema | Name | Type | Owner
--------------------+----------+------+----------
information_schema | schemata | view | postgres
(1 row)
底層pg_catalog.pg_namespace
表背視圖:
regress=> select pg_get_viewdef('information_schema.schemata');
pg_get_viewdef
-----------------------------------------------------------------------------------------------------
SELECT (current_database())::information_schema.sql_identifier AS catalog_name, +
(n.nspname)::information_schema.sql_identifier AS schema_name, +
(u.rolname)::information_schema.sql_identifier AS schema_owner, +
(NULL::character varying)::information_schema.sql_identifier AS default_character_set_catalog, +
(NULL::character varying)::information_schema.sql_identifier AS default_character_set_schema, +
(NULL::character varying)::information_schema.sql_identifier AS default_character_set_name, +
(NULL::character varying)::information_schema.character_data AS sql_path +
FROM pg_namespace n, +
pg_authid u +
WHERE ((n.nspowner = u.oid) AND pg_has_role(n.nspowner, 'USAGE'::text));
(1 row)
regress=> \dt pg_catalog.pg_namespace
List of relations
Schema | Name | Type | Owner
------------+--------------+-------+----------
pg_catalog | pg_namespace | table | postgres
(1 row)
...也沒有因爲PostgreSQL不支持系統表的外鍵引用:
regress=> CREATE TABLE blah (x text references pg_catalog.pg_namespace(nspname));
ERROR: permission denied: "pg_namespace" is a system catalog
所以......你不能。
據我所知,你不能在外鍵中引用*任何*系統表(並且此外:'information_schema'中的所有內容都是視圖,無論如何你都不能引用) –
@a_horse_with_no_name,謝謝你的提示!請張貼它作爲答案,可能它會是最好的。 –
您可以使用約束觸發器創建類似外鍵的東西,但它會比實際的FK慢得多。 –