Postgresql 在您自己的sql函数中使用提取函数

Postgresql 在您自己的sql函数中使用提取函数,postgresql,postgresql-9.1,sql-function,Postgresql,Postgresql 9.1,Sql Function,我正在尝试在我的Postgres数据库中创建以下函数: create or replace function public.extract_hour(time_param timestamp with time zone) returns double precision language sql as $function$ SELECT EXTRACT(hour from timestamp time_param); $function$; 但我得到了以下错误: ERROR: syntax

我正在尝试在我的Postgres数据库中创建以下函数:

create or replace function public.extract_hour(time_param timestamp with time zone) returns double precision language sql as $function$
SELECT EXTRACT(hour from timestamp time_param);
$function$;
但我得到了以下错误:

ERROR:  syntax error at or near "time_param"

我尝试放置而不是
time_param
$0
,但出现了相同的错误。谁能告诉我怎么解决这个问题吗?

显然,您使用的是较旧版本的PostgreSQL(您忽略了提供)。自PostgreSQL 9.2以来,可以引用参数名称。在旧版本中,只能参考位置参数:

CREATE OR REPLACE FUNCTION public.extract_hour(time_param timestamptz)
  RETURNS double precision LANGUAGE sql AS
$function$
SELECT EXTRACT(hour from $1);
$function$;
创建或替换函数public.extract_hour(time_param timestamptz)
返回双精度语言sql作为
$function$
选择提取(小时从$1开始);
$function$
我还删除了放错位置的关键字
时间戳

而在PL/pgSQL函数中引用参数名称已经有很长一段时间了。