Add some sql functions and tests