write this more like the postgresql version