【发布时间】:2016-06-02 00:12:26
【问题描述】:
我正在尝试编写我的第一个 PL/pgSQL 函数。目前,它只是应该返回传递给它的值中的字符数。
CREATE OR REPLACE FUNCTION public.cents(money)
RETURNS int
LANGUAGE plpgsql
LEAKPROOF
AS $function$
DECLARE
new_price money;
size int;
BEGIN
size := char_length(money);
RETURN size;
END;
$function$;
当我尝试使用 $66.66 进行测试时,我收到一个错误:
select cents($66.66);
ERROR: syntax error at or near ".66"
LINE 1: select cents($66.66);
^
如果我使用$66,我会得到一个不同的错误:
select cents($66);
ERROR: there is no parameter $66
LINE 1: select cents($66);
^
仅使用整数 66 给了我第三个错误:
select cents(66);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
我在这里做错了什么?
【问题讨论】:
标签: postgresql types plpgsql currency