Age Fucntion

From: brian stapel <brians_224(at)hotmail(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Age Fucntion
Date: 2007-01-16 20:02:10
Message-ID: BAY107-W342B329D8DC7FBA42A01DA1B40@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 41QUERY: 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
_________________________________________________________________
Fixing up the home? Live Search can help.
http://imagine-windowslive.com/search/kits/default.aspx?kit=improve&locale=en-US&source=wlmemailtaglinenov06

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2007-01-16 20:46:56 Re: Age Fucntion
Previous Message Chad Wagner 2007-01-13 14:25:06 Re: Moving an existing database from an old version?