2

I have a postgres function which takes an integer, like this:

select public.delete_entry(value);

How can I call this multiple times passing different values? I have a list of 280 values, so I need to execute this 280 times, I could just go one by one and execute the function each time but I bet there's a better way

Thanks,

1 Answer 1

3

You can use a values() clause to provide the input parameters:

select delete_entry(v.id)
from (
  values (42), (100), (20), (13)
) as v(id);

If the values are consecutive, you can use generate_series()

select delete_entry(v.id)
from generate_series(1,280) as v(id);

If the IDs are already in a table, then just select from that table:

select delete_entry(the_column)
from the_table;
Sign up to request clarification or add additional context in comments.

2 Comments

I have these on a table, just one column with all the ids I need
Then it's even simpler: select public.delete_entry(column_name) from table_name

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.