I'm learning PosgreSQL, i'm trying to call function get_color in a SELECT
statement inserting the column name of the table as parameter, but PostgreSQL version 9.6 (i've tried on 13.0 with the same result) returns me an UndefinedFunction error.
Here's the complete query code:
SELECT n
FROM pianokeys pn,
LATERAL get_color(pn.n) AS res;
CREATE OR REPLACE FUNCTION get_color(n integer) RETURNS text AS $$
BEGIN
IF((n % 88) % 2)
THEN
RETURN $b$black$b$;
ELSE
RETURN $w$white$w$;
END IF;
END;
$$
LANGUAGE plpgsql;
`
Here's the compiler error:
There was an error with the SQL query:
PG::UndefinedFunction: ERROR: function get_color(integer) does not exist
LINE 8: lateral get_color(pn.n) as res) AS "t1" LIMIT 1
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
What am i missing?