SQL versions of plotting routines