Age Fucntion
От | brian stapel |
---|---|
Тема | Age Fucntion |
Дата | |
Msg-id | BAY107-W342B329D8DC7FBA42A01DA1B40@phx.gbl обсуждение исходный текст |
Ответы |
Re: Age Fucntion
|
Список | pgsql-novice |
Thanks for your time.
I'm having some difficulties with the age function. I need to calculate the difference in days between the current date and a value provided to a function via an argument. When I try to include my argument in the function, the function won't compile, if I replace my argument with a date value(replace dt_hiredate with '1/1/2007'), it compiles, and the function works as expected.
my code:
CREATE OR REPLACE FUNCTION "public"."function1" (dt_hiredate TIMESTAMP) RETURNS INTEGER AS
$body$
/* New function body */
DECLARE
BEGIN
return date_part('year',age(timestamp dt_hiredate))*365 + date_part('day',age(timestamp dt_hiredate));
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
Compile message:
ERROR: syntax error at or near "$1" at character 41
QUERY: SELECT date_part('year',age(timestamp $1 ))*365 + date_part('day',age(timestamp $2 ))
CONTEXT: SQL statement in PL/PgSQL function "function1" near line 5
View Athletes' Collections with Live Search. See it!
I'm having some difficulties with the age function. I need to calculate the difference in days between the current date and a value provided to a function via an argument. When I try to include my argument in the function, the function won't compile, if I replace my argument with a date value(replace dt_hiredate with '1/1/2007'), it compiles, and the function works as expected.
my code:
CREATE OR REPLACE FUNCTION "public"."function1" (dt_hiredate TIMESTAMP) RETURNS INTEGER AS
$body$
/* New function body */
DECLARE
BEGIN
return date_part('year',age(timestamp dt_hiredate))*365 + date_part('day',age(timestamp dt_hiredate));
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
Compile message:
ERROR: syntax error at or near "$1" at character 41
QUERY: SELECT date_part('year',age(timestamp $1 ))*365 + date_part('day',age(timestamp $2 ))
CONTEXT: SQL statement in PL/PgSQL function "function1" near line 5
View Athletes' Collections with Live Search. See it!
В списке pgsql-novice по дате отправления: