0

I have a stored procedure which accepts single varchar argument, I want to call this for each distinct id present in my table.

CREATE OR REPLACE FUNCTION updateData(i varchar(12)) RETURNS VOID AS $$
    BEGIN
      update employee set employee_number = nextval('d_employeeNumber_seq') where employee.age > 25 and employee.deptId = i;
     ALTER SEQUENCE d_employeeNumber_seq RESTART WITH 1;   
    END;
    $$ LANGUAGE plpgsql;

Now I want to call this updateData() for each department

something like select updateData() in (select distinct deptId from employee) [This isnt the correct syntax but i want to use something of this sort]

1
  • what you have is a function and not a stored procedure. Syntax to invoke stored procedure is different. Commented Aug 8, 2022 at 10:01

1 Answer 1

2

You would need a subquery and to pass the desired parameter:

select updateData(deptID)
from ( select distinct deptId  from employee) a
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was pretty straight forward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.