sprintf-style postgres query escaping and helper functions