Idempotent query scripts