I create two tables:
CREATE TABLE public.reader_speciality ( speciality_id SMALLSERIAL, value text, CONSTRAINT reader_speciality_pkey PRIMARY KEY (speciality_id) ) WITH ( OIDS=FALSE ); ALTER TABLE public.reader_speciality OWNER TO ""{userID}""; CREATE TABLE public.readers( reader_id SERIAL NOT NULL, fio text NOT NULL, speciality_id smallint, CONSTRAINT readers_speciality_id_fkey FOREIGN KEY(speciality_id) REFERENCES public.reader_speciality(speciality_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) WITH(OIDS= FALSE); ALTER TABLE public.readers OWNER TO ""{userID}""; readers has a speciality_id foreign key. Adding entries:
INSERT INTO reader_speciality (value) VALUES ('Физика'); INSERT INTO reader_speciality (value) VALUES ('Химия'); INSERT INTO readers (fio, speciality_id) VALUES ('Иванов Иван Иванович', 1); INSERT INTO readers (fio) VALUES ('Игорев Игорь Игоревич'); We look (the indexes are different, but this is not the point):
SELECT * FROM reader_speciality; SELECT * FROM readers; Now I try to give the value of the foreign key instead of the index, and something goes wrong:
SELECT readers.reader_id, readers.fio, reader_speciality.value FROM readers, reader_speciality WHERE (readers.speciality_id = reader_speciality.speciality_id OR readers.speciality_id IS NULL); How to make a request in this situation?


