dotaz na postgresql

Jan Serak sherry na pikebo.cz
Pondělí Prosinec 4 09:31:53 CET 2000


Tomas Pluskal wrote:
> 
> Preji hezky den,
> 
> mel bych takovyto dotaz ohledne PostgreSQL:
> 
> mam tabulku base, ktera obsahuje krom jineho sloupec ID, ktery chci, aby
> byl unikatni. Udelal jsem si tedy index (create unique index on base
> (id)). Z teto tabulky mam pak odvozene dalsi tabulky (create table
> xxx (...) inherits base), ktere zdedi i polozku ID. Problem je ale v tom,
> ze ja bych chtel mit ID unikatni i v ramci potomku. Ted napriklad muzu dat
> 
> insert into base (id) values (1);
> insert into xxx (id) values (1);
> 
> a select id from base* mi vyhodi
> |ID|
> ----
>  1
>  1
> 
> coz se mi nelibi, nicmene v dokumentaci jsem nenasel, jak to udelal jinak.
> Jde to nejak ?


Na http://www.postgresql.org/docs/user/sql-createtable.htm
se pise:

UNDER inherited_table

      The optional UNDER clause specifies a collection of table names from which
this table automatically inherits all fields. If any inherited field
      name appears more than once, Postgres reports an error. Postgres
automatically allows the created table to inherit functions on tables above it
      in the inheritance hierarchy. 

Dedi se tedy definice atributu (asi by bylo spravnejsi rici "kopiruji"). S daty
tabulky
se nedeje nic, jedna se o naprosto nezavisle tabulky. Unikatni klic udrzite jen
v jedne
jedine tabulce. Pokud to potrebujete mit ve vice tabulkach, nezbyva Vam nic
jineho, nez
to vyprogramovat v databazovych triggerech.

							Jan Serak


Další informace o konferenci Databases