我有这个功能。它没有完整,也没有做任何有意义的事情,但在写作的过程中,我一直收到这个错误:
ERROR: syntax error at or near "LOOP"
LINE 26: END LOOP;
任何人都可以查看我的代码,看看为什么?我的for循环语法对我来说很好。
CREATE FUNCTION assignGrades(prob numeric[], school_name text, school_id bigint) RETURNS void AS $$
DECLARE
num_grades integer ARRAY[6];
found_school school_probs%ROWTYPE;
num_students simulated_records%ROWTYPE;
num_students_int bigint;
random_record simulated_records%ROWTYPE;
BEGIN
SELECT INTO found_school * FROM school_probs WHERE school_code = school_id;--select the prob dist
SELECT INTO num_students * FROM simulated_records WHERE school = school_name;
SELECT COUNT(*) INTO num_students_int FROM simulated_records WHERE school = school_name;
num_grades[1] = num_students_int*found_school.probs[1];
num_grades[2] = num_students_int*found_school.probs[1];
num_grades[3] = num_students_int*found_school.probs[1];
num_grades[4] = num_students_int*found_school.probs[1];
num_grades[5] = num_students_int*found_school.probs[1];
num_grades[6] = num_students_int*found_school.probs[1];
FOR i IN 1..num_grades[1] LOOP
SELECT INTO random_record * FROM simulated_records WHERE school = school_name ORDER BY RANDOM() LIMIT 1;
IF random_record.grade IS NULL THEN
random_record.grade = 'A';
END LOOP;--syntax error here
END;
$$
LANGUAGE plpgsql
答案 0 :(得分:2)
你错过了
END IF;
一部分。