I am trying to create function Animals (for convenience purpose) that takes first letter of an animal name and returns the whole name of the animal from the list e.g. C=> Cow, Cat… The problem I am facing is that the string after the like function is being treated as a string (I want it to be input). The following didn’t work.
x
create function
Animalfun(input text) returns text
as $$
SELECT name
FROM Animals
WHERE name like 'input%';
$$ language sql;
select name from Animals where name = Animalfun('A');
Advertisement
Answer
Presumably, you want:
SELECT name FROM Animals WHERE name like input || '%'