I have written a SQL function in PostgreSQL that accesses data from another table. On running the function, I am getting following error
relation table2 does not exist postgres
Here is the function that I am creating
CREATE OR REPLACE FUNCTION func(tbl1 table1)
RETURNS TABLE(a int, b text, c int, d text) AS $$
SELECT a, b, c, d
FROM table2
WHERE id = tbl1.user_id;
$$
language sql stable;
Working in case I change table2 to myschema.table2
What do I do? I do not want to add schema into the query. I want it to take whatever schema the function is in.