/ Published in: SQL
This kind of functions will be use full if we are migrating a database from one provider to another like from MS SQL Server to Postgresql.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
CREATE OR REPLACE FUNCTION YEAR (date1 DATE) RETURNS INTEGER AS $$ DECLARE YEAR_CONST CHARACTER VARYING(15) := 'year'; yearPart INTEGER := 0; yearPartInDoublePrecision DOUBLE PRECISION := 0; BEGIN yearPartInDoublePrecision := date_part(YEAR_CONST, date1); yearPart := CAST(yearPartInDoublePrecision AS INTEGER); RETURN yearPart; END; $$ LANGUAGE plpgsql;