How can I make this pseudo code to work in Postgresql:
create or replace function getf(arg character varying(255)) returns int
as $$
if arg = 'a' then return 1;
else return 2;
$$ language sql;
Based on argument I need to return some values and there is no other table I need to query. Just need to build a logic inside function. Tried to replace if with when clause, but could not figure out how to do it.
Thanks!
EXISTS()in the query, or even a lookup table. Functions are costly, see theimmutable strictoptions+remark in @Tometzky 's answer below.