ALTER_POLICY(7pg16)
π ALTER_POLICY (7pg16) β like, the whole glow-up guide for row-level security policies
okay bestie, so this page is ALTER POLICY from the PostgreSQL 16.15 docs and it's literally the manual for changing up a row-level security policy you already made. no cap, it's shorter than you'd think, but every single detail matters, so let's go π
β¨ SYNOPSIS β¨
here's the shape of it β two forms, both iconic:
ALTER POLICY name ON table_name RENAME TO new_name
ALTER POLICY name ON table_name
[ TO { role_name | PUBLIC | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...] ]
[ USING ( using_expression ) ]
[ WITH CHECK ( check_expression ) ]
like, the square brackets are optional bits, the curly braces are "pick one of these", and that [, ...] means "and you can keep adding more, queen". π
πΈ DESCRIPTION πΈ
okay so ALTER POLICY changes the definition of an existing row-level security policy. it's giving "makeover, not rebirth" β because, and this is the key part, ALTER POLICY only lets you modify:
- the set of roles the policy applies to, and
- the
USINGandWITH CHECKexpressions.
that's it, that's the whole menu. if you wanna change other properties of a policy β like which command it applies to, or whether it's permissive or restrictive β the policy has to be dropped and recreated. yeah, i know, annoying, but that's the rule. π
to use ALTER POLICY, you must own the table that the policy applies to. no ownership, no edits. sorry babe. π
now, in that second form of ALTER POLICY, the role list, using_expression, and check_expression each get replaced independently if you specify them. so if you omit one of those clauses, the corresponding part of the policy just stays exactly how it was. nothing gets wiped by accident, slay. β¨
π PARAMETERS π
nameβ the name of an existing policy you wanna alter. literally the one you're editing.table_nameβ the name of the table the policy is on. it can be optionally schema-qualified, so go ahead and be specific if you need to be.new_nameβ the new name for the policy. fresh name, same vibe.role_nameβ the role(s) the policy applies to. you can specify multiple roles at one time, no problem. and if you want it to apply to all roles, just usePUBLIC.using_expressionβ theUSINGexpression for the policy. for the full deets, seeCREATE POLICY(CREATE_POLICY(7)).check_expressionβ theWITH CHECKexpression for the policy. again,CREATE POLICY(CREATE_POLICY(7)) has the details.
π¦ COMPATIBILITY π¦
ALTER POLICY is a PostgreSQL extension. so like, it's a Postgres original, not a standard-SQL thing. iykyk π
π SEE ALSO π
CREATE POLICY(CREATE_POLICY(7))DROP POLICY(DROP_POLICY(7))
π«Ά and that's the whole page, bestie! written to match PostgreSQL 16.15, dated 2026, and filed under ALTER POLICY(7) β go forth and alter those policies, main character. πβ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms