ALTER_POLICY(7pg15)

πŸ“¦ version 15.19, in opensuse-leap 16.0

πŸ’… ALTER POLICY πŸ’…

okay so bestie, welcome to the ALTER POLICY page from the PostgreSQL 15.19 Documentation β€” yes that's the manual we're in, ALTER POLICY(7), and no we are not skipping anything, we're gonna read it together 🫢


✨ NAME ✨

ALTER POLICY β€” change the definition of a row-level security policy. that's it, that's the vibe. you're editing a policy that already exists, not making a new one πŸ‘‘


🌸 SYNOPSIS 🌸

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 ) ]

two forms, both iconic, pick your fighter πŸŽ€


πŸ’– DESCRIPTION πŸ’–

so ALTER POLICY changes the definition of an existing row-level security policy. but listen β€” it's lowkey restrictive: ALTER POLICY only lets you modify the set of roles the policy applies to, plus the USING and WITH CHECK expressions. that's the whole menu, bestie 😭

want to change literally anything else about a policy β€” like which command it applies to, or whether it's permissive or restrictive? then you gotta DROP it and recreate it. no shortcuts, no glow-ups, periodt πŸ’€

to use ALTER POLICY, you must own the table that the policy applies to. own the table, get the keys πŸ‘‘

now, in the second form of ALTER POLICY, the role list, using_expression, and check_expression are replaced independently if specified. and when one of those clauses is omitted? the corresponding part of the policy stays exactly as it was. untouched. unbothered. main character energy 🌈


πŸŽ€ PARAMETERS πŸŽ€

  • name β€” the name of an existing policy you wanna alter. it's gotta exist already, we're not manifesting here ✨
  • table_name β€” the name (optionally schema-qualified) of the table that the policy is on. schema-qualified if you're feeling fancy πŸ’…
  • new_name β€” the new name for the policy. rebrand, slay πŸ¦‹
  • role_name β€” the role(s) to which the policy applies. you can specify multiple roles at one time, love a group chat. and to apply the policy to all roles, use PUBLIC πŸ’–
  • using_expression β€” the USING expression for the policy. see CREATE POLICY (CREATE_POLICY(7)) for the deets πŸ‘€
  • check_expression β€” the WITH CHECK expression for the policy. also see CREATE POLICY (CREATE_POLICY(7)) for the deets πŸ‘€

🧚 COMPATIBILITY 🧚

ALTER POLICY is a PostgreSQL extension. it's giving homegrown, it's giving original, no cap 🌸


⭐ SEE ALSO ⭐

read those too, bestie, they're the whole friend group πŸ”₯


fr fr though β€” if you're here to change anything besides roles, USING, or WITH CHECK, go read DROP POLICY / CREATE POLICY first, because ALTER POLICY will not do it for you πŸ™ˆ

k that's the whole page, you ate that πŸ“ mwah πŸ’œ β€” signed, sealed, delivered straight from PostgreSQL 15.19, dated 2026, ALTER POLICY(7) forever πŸ‘‘

πŸ“¦ where this page comes from