'Pass Array As Parameter Into A Stored Function postgresql
I wan to pass Array as parameter into a stored a stored function Postgresql, I wan to pass Employee Names as a parameter and get the ID of employee using select query pass it as a input to the delete query.
select * from links;
CREATE OR REPLACE FUNCTION testing(first_name varchar(255))
RETURNS INTEGER AS
$BODY$
DECLARE
emp_id INTEGER;
BEGIN
SELECT id into emp_id from links e where name = first_name;
DELETE FROM links WHERE id = emp_id;
return emp_id;
END
$BODY$
LANGUAGE plpgsql;
select * from testing('Google');
I could able to delete single record from table. now i want to pass as a parameter into my function to delete records.
Solution 1:[1]
Use an array as input (type text[]).
Then the whole operation becomes a single statement:
DELETE FROM links
WHERE name = ANY ($1)
RETURNING id;
Here, $1 is the placeholder for the array.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Laurenz Albe |

