create table IF NOT EXISTS friends
(
name text primary key,
lives_in_city text
);
create table IF NOT EXISTS party_guests
(
guest_name text
constraint party_guests_pk
primary key
references friends
on update cascade on delete cascade,
chair_num int
);
insert into friends
values ('Вова', 'Волгоград'),
('Вася', 'Симферополь'),
('Петя', 'Дмитров'),
('Коля', 'Владивосток'),
('Саша', 'Москва'),
('Наташа', 'Сочи'),
('Даша', 'Иркутск') on conflict do nothing ;
insert into party_guests (guest_name, chair_num)
select name, row_number() over (partition by true)
from friends
where lives_in_city not in ('Иркутск', 'Сочи');
;
select name from friends where not exists(
select 1 from party_guests where party_guests.guest_name = friends.name
)