helper functions for SQL query generation