Postgres Sql Using Function