Implement on #to_sql and with unit test