Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Nasleđivanje tabela u PostgreSQL bazi podataka ====== PostgreSQL ima mehanizam za nasleđivanje između tabela ([[https://www.postgresql.org/docs/10/ddl-inherit.html|https://www.postgresql.org/docs/10/ddl-inherit.html]]) Primer roditeljske tabele cities i deteta capitals:<code> CREATE TABLE cities ( name text, population float, altitude int -- in feet ); CREATE TABLE capitals ( state char(2) ) INHERITS (cities); </code> * SELECT iz roditeljske table uvek vraća i slogove iz dece osim ako se ispred imena roditelja ne navede ključna reč ONLY npr. SELECT * FROM ONLY cities * ALTER roditeljske tabele (dodavanje/brisanje kolone) se prenosi i na decu, a obratno ne * INSERT u roditeljsku tabelu se ne prenosi u decu, a ni obratno * UPDATE zajedničke kolone u roditeljskoj tabeli se prenosi na decu, obratno ne Dokumentacija PostgreSQLa kaže da postoji 1 ograničenje tj. mana u konceptu nasleđivanja tabela, a to je: <code> A serious limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single tables, not to their inheritance children. </code> CKG Edit kb/pg/nasledjivanje_tabela.txt Last modified: 2019/11/14 12:50by nessa