Создание
CREATE VIEW PaperSubmission AS
SELECT title, keyword, name AS conf_name, accepted
FROM Paper
JOIN Conference ON (Paper.conference_id = Conference.id);
Использование
SELECT * From PaperSubmission
WHERE conf_name = 'SIGMOD15';
Функции
SQL
+ императивные конструкции (переменные, условные операторы, циклы) CREATE OR REPLACE FUNCTION SubmitPaper(_title Text, _conference_id INT, _keywords TEXT[])
RETURNS VOID AS $$
DECLARE
_paper_id INT;
k TEXT;
BEGIN
INSERT INTO Paper(title)
VALUES (_title)
RETURNING id INTO _paper_id;
INSERT INTO PaperConference(paper_id, conference_id)
VALUES (_paper_id, _conference_id)
FOREACH k IN ARRAY _keywords LOOP
INSERT INTO PaperKeyword(paper_id, keyword_id)
SELECT _paper_id, Keyword.id
FROM Keyword
WHERE value = k;
END LOOP;
END;
$$ LANGUAGE plpgsql;