6.9 UDFs

6.59

create
or replace function tip_percentage(tip_column float, total_column float) 
returns numeric 
language plpgsql 
as $$ 

declare tip_percentage numeric;

begin if total_column = 0 then tip_percentage = 0;

elsif total_column is null then tip_percentage = 0;

elsif total_column > 0 then tip_percentage = tip_column / total_column;

end if;

return tip_percentage;

end;

$$

6.60

select
    total_amount,
    tip_amount,
    tip_percentage(tip_amount, total_amount)
from
    nyc_yellow_taxi_0601_0615_2016
order by
    pickup_datetime desc
limit
    10 offset 10000

6.61


6.62

select
    *
from
    find_311_text_match('food')
limit
    5