Get pgvet running on your SQL files in just a few steps.
1
Install pgvet
Install using Go:
go install github.com/mnafees/pgvet@latest
The first build takes ~3 minutes due to CGO compilation. See the installation guide for details.
2
Create a sample SQL file
Create a file called test.sql with some SQL that has common issues:
test.sql
-- Sample queries with issues pgvet will catchSELECT * FROM users;SELECT id, email FROM users LIMIT 10;SELECT * FROM posts WHERE author_id NOT IN (SELECT user_id FROM banned_users);UPDATE users SET last_login = NOW();
3
Run pgvet
Run pgvet on your SQL file:
pgvet test.sql
You’ll see output like:
test.sql:2:8: warning: [select-star] SELECT * in outermost query is fragile — list columns explicitlytest.sql:4:39: warning: [limit-without-order] LIMIT without ORDER BY produces non-deterministic results (except LIMIT 1)test.sql:7:6: warning: [select-star] SELECT * in outermost query is fragile — list columns explicitlytest.sql:7:28: error: [not-in-subquery] NOT IN (SELECT ...) is broken when the subquery can return NULLs — use NOT EXISTS insteadtest.sql:10:1: warning: [update-without-where] UPDATE without WHERE updates every row in the table
4
Fix the issues
Update your SQL to fix the problems:
test.sql
-- Fixed queriesSELECT id, email, created_at FROM users;SELECT id, email FROM users ORDER BY created_at DESC LIMIT 10;SELECT * FROM posts WHERE NOT EXISTS ( SELECT 1 FROM banned_users WHERE user_id = posts.author_id);UPDATE users SET last_login = NOW() WHERE id = 123;
5
Verify the fixes
Run pgvet again to confirm all issues are resolved:
pgvet test.sql
Clean output means no issues were found. The exit code will be 0.