In postgres, once a function is created, can it ONLY be called in the same script where it was created, or can be saved in DB and I can access / call it another script as well?
My code is:
create or replace function roundfind(dates date) returns varchar
as $$
select
case
when dates between '2020-06-08' and '2020-11-14' then 'Round 1'
when dates between '2020-11-15' and '2021-02-17' then 'Round 2'
when dates between '2021-02-18' and '2021-04-28' then 'Round 3'
when dates between '2021-04-29' and '2021-07-16' then 'Round 4'
when dates between '2021-07-16' and '2021-10-03' then 'Round 5'
when dates between '2021-10-04' and '2021-11-30' then 'Round 6'
when dates between '2021-12-01' and '2022-02-01' then 'Round 7'
when dates between '2021-02-02' and '2022-03-28' then 'Round 8'
when dates >= '2022-03-29' then 'Round 9'
end;
$$
language sql;
CodePudding user response:
A function is automatically saved in the database. It is an object in the database just like a table, and you have to run DROP FUNCTION
to get rid of it. After you create the function, it can be used by everybody who has access to the function's schema.