How To Write A Function In Postgresql