SQL can't infer type