I need get data as text and return as array from postgresql function. I have a clips media table with files and for each clip id i wanna get all files from media clips. I created function like this:
CREATE OR REPLACE FUNCTION clips_media_array(INT)
RETURNS text[] AS $$
DECLARE
r clips_media%ROWTYPE;
t text[];
BEGIN
FOR r IN
SELECT file_name
FROM clips_media WHERE id_clips = $1 AND file_type = 2
LOOP
t := t.file_name;
END LOOP;
END;
$$
LANGUAGE plpgsql;
and i have an error:
ERROR: invalid input syntax for integer: "bfeO4RbZ5R1CUT8.jpg"
CONTEXT: PL/pgSQL function clips_media_array(integer) line 6 at FOR over SELECT rows
Could anyone help me with this ?
overin your code). But you neither need a loop nor a function for this. A simpleselect array_agg(file_name) from clips_media where ...will do just fine