私はそれがエラーとして返され、特定のコースではなく、モジュールを呼び出すしようとしています:このpostgresqlクエリはどのようにテーブルとして返されますか?
CREATE OR REPLACE FUNCTION course_modules(_courseID integer)
RETURNS SETOF modules AS
$$
BEGIN
RETURN QUERY SELECT * FROM modules WHERE mod_id =(SELECT module_id from coursemodules WHERE course_id = _courseID);
END
$$
LANGUAGE 'plpgsql';
coursemoduleテーブル:表現
クエリとして使用サブクエリによって返さ複数の行を
CREATE TABLE coursemodules(
course_id integer references courses (id) ON DELETE CASCADE,
module_id integer references modules (mod_id) ON DELETE CASCADE
);
モジュール表
CREATE TABLE modules(
documents text NOT NULL,
mod_id serial primary key,
content text NOT NULL,
title varchar(50) NOT NULL
);
コース表
CREATE TABLE courses(
finishDate Date,
description text NOT NULL,
duration varchar(50) NOT NULL,
startDate Date,
id serial primary key,
courseName varchar(50) NOT NULL
);
'SELECT course_id、COUNT(*)courmoduleules GROUP BY course_id'を実行すると、' course_id'が繰り返される行が表示されます。 – Dai
'course_id'は' coursemodules'テーブルの主キーとして宣言されておらず、 'UNIQUE'制約もありません。 – Dai