I have created a function to delete multiple records.In our table contain id as type uuid.
We get the input is like array of ids.
CREATE OR REPLACE FUNCTION public.deletetVersion(item_list uuid[])
RETURNS TABLE(id uuid[])
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
RETURN QUERY
DELETE FROM version WHERE id = ANY(item_list);
END;
$BODY$;
SELECT * from deletetVersion(Array[‘b6ad1912-e4f1-4419-831a-c70df89ffd63′,’877898f0-2f3f-4890-a658-898e35ffee3a’])
But i got an error like:
Anyone please help me
ERROR: function deletetversion(text[]) does not exist
2
Answers
it is because the
is treated as text[]
try the following
as a parameter to your function
for example
In case of deletion
Your function should return either
setof uuid
– i.e. a table of uuid-s – oruuid[]
. I would prefer the first. You do not need PL/pgSQL, plain SQL is enough. So the function is:The version returning an array is a bit more complex:
And – as @Ibrahimshamma says – you may need to cast the argument to
uuid[]
.