0

I'm trying to create the following function into my Postgres database:

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$;

but I get the following error:

ERROR:  syntax error at or near "time_param"

I tried to put instead of time_param $0, but the same error occur. Can somebody explain me how to solve that?

1 Answer 1

1

Obviously, you are using an older version of PostgreSQL (which you neglected to provide). Referring to parameter names is possible since PostgreSQL 9.2. In older versions you can only refer to positional parameters:

CREATE OR REPLACE FUNCTION public.extract_hour(time_param timestamptz)
  RETURNS double precision LANGUAGE sql AS
$function$
SELECT EXTRACT(hour from $1);
$function$;

Also I removed the misplaced keyword timestamp.

While referring to parameter names has been possible in PL/pgSQL functions for a long time now.
We fixed a documentation glitch to the opposite just recently.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.