sbdchd / squawk

🐘 linter for PostgreSQL, focused on migrations

Home Page:https://squawkhq.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positive with RLS Alter table

kaushalyap opened this issue Β· comments

... : warning: prefer-robust-stmts

ALTER TABLE IF EXISTS
tbl_name ENABLE ROW LEVEL SECURITY;

help: Consider wrapping in a transaction or adding a IF NOT EXISTS clause if the statement supports it.

@kaushalyap Can you provide a full example the replicates the issue? The provided example doesn't error.

echo 'ALTER TABLE IF EXISTS tbl_name ENABLE ROW LEVEL SECURITY;' | squawk
Found 0 issues in 1 file πŸŽ‰ 

I think I am running into the same issue. Tests on a single line work just fine there is a statement right before it fails:

$ echo 'ALTER TABLE IF EXISTS test ENABLE ROW LEVEL SECURITY;' | squawk        
Found 0 issues in 1 file πŸŽ‰
$ echo 'CREATE TABLE IF NOT EXISTS test();\nALTER TABLE IF EXISTS test ENABLE ROW LEVEL SECURITY;' | squawk
stdin:2:1: warning: prefer-robust-stmts

   2 | ALTER TABLE IF EXISTS test ENABLE ROW LEVEL SECURITY;

  help: Consider wrapping in a transaction or adding a IF NOT EXISTS clause if the statement supports it.

find detailed examples and solutions for each rule at https://squawkhq.com/docs/rules
$ squawk --version
squawk 1.1.2

Looks like a bug, thanks for the repro!