implement some sql functions