Hi all, I have a small issue with a policy I did c...
# fleet
d
Hi all, I have a small issue with a policy I did create some months ago. We want to check the user count on all macOS devices (the policy should fail when more than 2 users). There was always a syntax error, but the query still did work. After the upgrade to the latest Fleet version, the save button is greyed out when the syntax is not ok, which is obviously intended. Do you have an idea why the syntax of my policy is not ok?
Copy code
SELECT COUNT(*) FROM (SELECT * FROM users WHERE SUBSTR(uuid,1,7) != 'FFFFEEE' AND shell != '/usr/bin/false' AND directory LIKE '/Users/%') HAVING COUNT(*) <= 2
Syntax Error:
Syntax error found near Single-quoted String Literal (WHERE Clause)
k
Taking a look at where this query is breaking down. I suspect it's related to the use of
HAVING
@Grant Bilstad Came up with a solution for you on this!
Copy code
SELECT 1
FROM (
SELECT COUNT(*) as user_count FROM users WHERE SUBSTR(uuid,1,7) != 'FFFFEEE' AND shell != '/usr/bin/false' AND directory LIKE '/Users/%'
)
WHERE user_count <= 2;
Trimmed it down just a bit:
Copy code
SELECT 1 WHERE 
(
SELECT COUNT(*)
FROM users 
WHERE SUBSTR(uuid,1,7) != 'FFFFEEE' 
AND shell != '/usr/bin/false' 
AND directory LIKE '/Users/%'
)
<= 2;
d
awesome! That worked, thanks @Kathy Satterlee 🙂