PostgreSQL Custom Function to extract 4 digit year from passed in DATE TIME
Posted on 2007-10-09
In PostgeSQL, I want to create inline functions like I have in other RDBMS'.
I want to be able to pass in a Date and return the 4 digit year from this function. The code would be something like this.
CREATE FUNCTION getYear(TIMESTAMP) RETURNS char(4) AS
SELECT EXTRACT(YEAR FROM $1) LANGUAGE sql;
The use of the function would look something like this:
SELECT getYear("DateOfBirth") FROM emp;
I have tried to created a function several times, but keep getting errors, please help with my syntax handicap!