![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 366 Pomógł: 0 Dołączył: 2.01.2007 Ostrzeżenie: (0%) ![]() ![]() |
witam mam maly problem (albo czegos do konca nie rozumiem).
powiedzmy ze mamy tabele: 1sza: # create table test (test_id serial primary key not null, test char(10) not null, test2 char(10) not null); i 2ga ktora od niej dziedziczy: # create table aa (aa_id serial primary key not null, ulubione char(10)) inherits (test); w tym momencie do mojej drugiej tableli, tj. aa zostana przypisane kolumny z 1szej, tj. z test test_id | test | test2 | aa_id | ulubione ---------+------+-------+-------+---------- (0 rows) w tabeli aa trzymam 'ulubione' pozycje z tableli test. powiedzmy ze do obu tabel wstawie jakies przykladowe dane: test: test_id | test | test2 ---------+------------+------------ 1 | aa | bb 2 | cc | dd 3 | ee | ff aa: test_id | test | test2 | aa_id | ulubione ---------+------------+------------+-------+------------ 2 | cc | dd | 1 | zz gdy wydam komende: # select * from only test; spodziewalam sie otrzymac tylko te kolumny ktore wystepuja w test (czyli poza ta ktora jest rowniez w aa), jednak otrzymuje wszystkie, tj: test_id | test | test2 ---------+------------+------------ 1 | aa | bb 2 | cc | dd 3 | ee | ff (3 rows) ktos moglby naprowadzic mnie na prawidlowy zapis tudziez prawidlowy tok myslenia? pzdr! |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 366 Pomógł: 0 Dołączył: 2.01.2007 Ostrzeżenie: (0%) ![]() ![]() |
zatem zrobilam wg Twojego przykladu:
test=# create table rodzic (rodzic_id serial not null, rodzic char(10) not null, rodzic2 char(10) not null); ***(Single step mode: verify command)******************************************* create table rodzic (rodzic_id serial not null, rodzic char(10) not null, rodzic2 char(10) not null); ***(press return to proceed or enter x and return to cancel)******************** NOTICE: CREATE TABLE will create implicit sequence "rodzic_rodzic_id_seq" for serial column "rodzic.r odzic_id" CREATE TABLE test=# insert into rodzic (rodzic_id, rodzic, rodzic2) values (1, 'aa', 'AA'); ***(Single step mode: verify command)******************************************* insert into rodzic (rodzic_id, rodzic, rodzic2) values (1, 'aa', 'AA'); ***(press return to proceed or enter x and return to cancel)******************** INSERT 0 1 test=# insert into rodzic (rodzic_id, rodzic, rodzic2) values (2, 'bb', 'BB'); ***(Single step mode: verify command)******************************************* insert into rodzic (rodzic_id, rodzic, rodzic2) values (2, 'bb', 'BB'); ***(press return to proceed or enter x and return to cancel)******************** INSERT 0 1 test=# insert into rodzic (rodzic_id, rodzic, rodzic2) values (3, 'cc', 'CC'); ***(Single step mode: verify command)******************************************* insert into rodzic (rodzic_id, rodzic, rodzic2) values (3, 'cc', 'CC'); ***(press return to proceed or enter x and return to cancel)******************** INSERT 0 1 test=# alter table rodzic add constraint rodzic_pkey primary key (rodzic_id); ***(Single step mode: verify command)******************************************* alter table rodzic add constraint rodzic_pkey primary key (rodzic_id); ***(press return to proceed or enter x and return to cancel)******************** NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "rodzic_pkey" for table "rodzic" ALTER TABLE test=# select * from rodzic; ***(Single step mode: verify command)******************************************* select * from rodzic; ***(press return to proceed or enter x and return to cancel)******************** rodzic_id | rodzic | rodzic2 -----------+------------+------------ 1 | aa | AA 2 | bb | BB 3 | cc | CC (3 rows) test=# create table dziecko (dziecko_id serial primary key not null, ulubione char(10)) inherits (rodz ic); ***(Single step mode: verify command)******************************************* create table dziecko (dziecko_id serial primary key not null, ulubione char(10)) inherits (rodzic); ***(press return to proceed or enter x and return to cancel)******************** NOTICE: CREATE TABLE will create implicit sequence "dziecko_dziecko_id_seq" for serial column "dzieck o.dziecko_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "dziecko_pkey" for table "dziecko" CREATE TABLE test=# insert into dziecko (rodzic_id, rodzic, rodzic2, dziecko_id, ulubione) values (5, 'dd', 'DD', 2 , '44'); ***(Single step mode: verify command)******************************************* insert into dziecko (rodzic_id, rodzic, rodzic2, dziecko_id, ulubione) values (5, 'dd', 'DD', 2, '44') ; ***(press return to proceed or enter x and return to cancel)******************** INSERT 0 1 test=# insert into dziecko (rodzic_id, rodzic, rodzic2, dziecko_id, ulubione) values (3, 'cc', 'CC', 3 , 'dziecko'); ***(Single step mode: verify command)******************************************* insert into dziecko (rodzic_id, rodzic, rodzic2, dziecko_id, ulubione) values (3, 'cc', 'CC', 3, 'dzie cko'); ***(press return to proceed or enter x and return to cancel)******************** I TU GENERALNIE TROCHE INNEGO WYNIKU POWINNISMY SIE SPODZIEWAC.. Z TEGO CO ROZUMUJE, NIE POWINNO BYC 3CIEJ KOLUMNY GDYZ JEST ONA WSPOLNA DLA RODZICA I DZIECKA.. INSERT 0 1 test=# select * from only rodzic; ***(Single step mode: verify command)******************************************* select * from only rodzic; ***(press return to proceed or enter x and return to cancel)******************** rodzic_id | rodzic | rodzic2 -----------+------------+------------ 1 | aa | AA 2 | bb | BB 3 | cc | CC (3 rows) HMM, TO JAK? |
|
|
![]() ![]() |
![]() |
Aktualny czas: 12.10.2025 - 06:38 |