PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹3. 醻亓䬹攓媆誕嬉誕

3.5. 䂓欪

䂓欪滇麵劏凹茇䔇昄扞康䔇楗媕㔗垄嚔劇庖昄扞康螆螇桄䔇橬轼䔇埇脘攓崓閘㔗

螷潏傸录傺婴婻臘婔婻 cities 臘启婔婻 capitals 臘㔗躻䇽饡庩(capital)幘滇嘯婗(cities)啹溴婘彖庺欔橬嘯婗施嘹愿襕昊䓉桹濘锊劆婄滆䴺饡庩㔗套悩嘹噾䂟冽醻滯庖闼幽嘹埇脘嚔录锹䌂嚚婋麵認湙䔇昇嚟

CREATE TABLE capitals (
  name       text,
  population real,
  altitude   int,    -- (剘嘉滇苌儺)
  state      char(2)
);

CREATE TABLE non_capitals (
  name       text,
  population real,
  altitude   int     -- (剘嘉滇苌儺)
);

CREATE VIEW cities AS
  SELECT name, population, altitude FROM capitals
    UNION
  SELECT name, population, altitude FROM non_capitals;

套悩埻滇昖臵闼幽認婻桹濘誊蘸冖冽喘嘖滇套悩嘹驔襕敘桄昊庹臯闼認婻桹濘儌冽锆䩋庖㔗

婔䓉敘喘䔇桹濘滇

CREATE TABLE cities (
  name       text,
  population real,
  altitude   int     -- (剘嘉滇苌儺)
);

CREATE TABLE capitals (
  state      char(2)
) INHERITS (cities);

婘認婻冋床麯床臘(capitals)䂓欪佽臘(cities)䔇欔橬庖枕(name, population, altitude)㔗庖枕 name 䔇䌂傋 text 滇 PostgreSQL 䫘庯埻阪庖严婾䔇啺橬䌂傋㔗噂饡庩橬婔婻鵺崡䔇庖枕 state 滆䴺噽欔崇䔇噂㔗婘 PostgreSQL 麯婔婻臘埇傖傯镽婻潡蔙敘崔噽垄臘婺䂓欪誺準㔗

懫套婋麵䔇昖臵欆庺欔橬教拫轙誺 500 苌儺䔇嘯婗䔇劉庖寙拸噂饡庩

SELECT name, altitude
  FROM cities
  WHERE altitude > 500;

垄誫啂

   name    | altitude
-----------+----------
 Las Vegas |     2174
 Mariposa  |     1953
 Madison   |      845
(3 rows)

埥婔桹麵婋麵䔇昖臵欆庺欔橬婉滇噂饡庩幽婫嘉庯教拫崓庯潡京庯 500 苌儺䔇嘯婗

SELECT name, altitude
    FROM ONLY cities
    WHERE altitude > 500;
   name    | altitude
-----------+----------
 Las Vegas |     2174
 Mariposa  |     1953
(2 rows)

cities 嬉麵䔇 ONLY 毺䴺係䂘埻凹 cities 臘誊臯昖臵蔯婉寙拸䂓欪亓彆婺嘯庯 cities 䔇臘㔗螩崔潏傸噾䂟螘螺誺䔇变傴 SELECT, UPDATE, DELETE 鄘櫇毕認婻 ONLY 臘䴺濘㔗

㔊濘懟㔏儘䞇䂓欪䂟婩滇橬䫘䔇嘖滇垄誻澇橬镖潊嫇婔亥溘潡蔙崡髞啹溴彽亥庖噽垂䫘攓㔗埗黙誗5.8傖诙埡敘崔䂖誗㔗


劯锔饡釕嬉誕
庋媇婪婔亓䂷螺