CREATE OR REPLACE FUNCTION setNewTermWeekly(INT8,DATE,DATE) RETURNS INT8 AS ' DECLARE in_id_doc ALIAS FOR $1; in_from ALIAS FOR $2; in_to ALIAS FOR $3; visit_time INT8; tmpint INT2; count INT8; my_row RECORD; BEGIN SELECT visit_time INTO visit_time FROM doctors WHERE id = cast(in_id_doc as INT8); IF NOT FOUND THEN return 1; END IF; tmpint := 1; LOOP IF tmpint > 7 THEN EXIT; END IF; FOR my_row IN SELECT id_type, cast(hour_from as int8) as hour_from, cast(hour_to as int8) FROM visits_hours WHERE id_doctor = cast(in_id_doc as INT8) AND day_num = tmpint ORDER BY hour_from LOOP --tutaj jest problem count := quote_ident(my_row.hour_from); --tutaj sie konczy LOOP INSERT INTO visits (id_doctor,day,hour) VALUES (in_id_doc,in_from+tmpint,count)); count := count + visit_time; IF count >= my_row.hour_to THEN EXIT; END IF; END LOOP; END LOOP; tmpint := tmpint + 1; END LOOP; END; ' LANGUAGE 'plpgsql';
SELECT setNewTermWeekly(cast(1 AS int8),cast(now() AS date),cast(now() AS date))
wywala taki błąd:
ERROR: mismatched parentheses
CONTEXT: compile of PL/pgSQL function "setnewtermweekly" near line 26