Query in SQL function still not schema-safe; add a couple