sql - Syntax error at FOR LOOP -
sql - Syntax error at FOR LOOP -
i have function. it's not finish , doesn't meaningful yet, in process of writing i've been getting error:
error: syntax error @ or near "loop" line 26: end loop;
could @ code , see why?? loop syntax looks fine me.
create function assigngrades(prob numeric[], school_name text, school_id bigint) returns void $$ 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 found_school * school_probs school_code = school_id;--select prob dist select num_students * simulated_records school = school_name; select count(*) num_students_int simulated_records 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]; in 1..num_grades[1] loop select random_record * simulated_records school = school_name order random() limit 1; if random_record.grade null random_record.grade = 'a'; end loop;--syntax error here end; $$ language plpgsql
you have missed the
end if;
part.
sql postgresql plpgsql
Comments
Post a Comment