UDF (user defined function) for postgresql lower version. ( ex 8.2 )