2023-10-01 19:14:39 +00:00
|
|
|
-- Deploy camper:to_price to pg
|
|
|
|
-- requires: roles
|
|
|
|
-- requires: schema_camper
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to camper, public;
|
|
|
|
|
|
|
|
create or replace function to_price(cents integer, decimal_digits integer default 2) returns text as
|
|
|
|
$$
|
|
|
|
declare
|
|
|
|
result text;
|
|
|
|
scale integer := 10^decimal_digits;
|
|
|
|
sign text := '';
|
|
|
|
begin
|
|
|
|
if cents < 0 then
|
|
|
|
sign := '-';
|
|
|
|
cents = -cents;
|
|
|
|
end if;
|
|
|
|
result = cents::text;
|
|
|
|
return sign || (cents / scale)::text || '.' || to_char(mod(cents, scale), rpad('FM', decimal_digits + 2, '0'));
|
|
|
|
end;
|
|
|
|
$$
|
|
|
|
language plpgsql
|
|
|
|
immutable;
|
|
|
|
|
|
|
|
comment on function to_price(integer, integer) is
|
|
|
|
'Converts the cents to a price representation, without currency and any other separater than decimal.';
|
|
|
|
|
|
|
|
revoke execute on function to_price(integer, integer) from public;
|
2023-10-06 11:23:20 +00:00
|
|
|
grant execute on function to_price(integer, integer) to guest;
|
2023-10-01 19:14:39 +00:00
|
|
|
grant execute on function to_price(integer, integer) to employee;
|
|
|
|
grant execute on function to_price(integer, integer) to admin;
|
|
|
|
|
|
|
|
commit;
|