ALTER_OPERATOR(7pg15)

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

✨ ALTER OPERATOR πŸ’…

okay so real quick β€” this is the ALTER OPERATOR page from the PostgreSQL 15.19 Documentation, and it's literally the glow-up manual for your operators. you ready bestie? πŸŽ€


🌸 NAME 🌸

ALTER_OPERATOR β€” change the definition of an operator

πŸ¦‹ SYNOPSIS πŸ¦‹

ALTER OPERATOR name ( { left_type | NONE } , right_type )
    OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }

ALTER OPERATOR name ( { left_type | NONE } , right_type )
    SET SCHEMA new_schema

ALTER OPERATOR name ( { left_type | NONE } , right_type )
    SET ( {  RESTRICT = { res_proc | NONE }
           | JOIN = { join_proc | NONE }
         } [, ... ] )

three whole forms, one iconic statement. pick your fighter ✨

πŸ’– DESCRIPTION πŸ’–

ALTER OPERATOR changes the definition of an operator. that's it, that's the whole vibe. giving a makeover to something that already exists πŸ’…

ngl, there's a catch: you must own the operator to use ALTER OPERATOR. like, it's yours, bestie.

and if you're changing the owner? then you also have to be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the operator's schema. the way that works is these restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the operator. so like, no sneaky shortcuts πŸ™ˆ

but fr fr β€” a superuser can alter ownership of any operator anyway. main character energy, no cap πŸ‘‘

🧚 PARAMETERS 🧚

  • name β€” the name of an existing operator (optionally schema-qualified). it's giving "who dis" but for your operator 🫢
  • left_type β€” the data type of the operator's left operand; write NONE if the operator has no left operand. yes, NONE is literally the way to say "no left operand" ⭐
  • right_type β€” the data type of the operator's right operand.
  • new_owner β€” the new owner of the operator. hand over the keys πŸ”₯
  • new_schema β€” the new schema for the operator. moving day! 🌈
  • res_proc β€” the restriction selectivity estimator function for this operator; write NONE to remove existing selectivity estimator.
  • join_proc β€” the join selectivity estimator function for this operator; write NONE to remove existing selectivity estimator.

lowkey both of those last two accept NONE to yeet the existing estimator, fyi πŸ“

πŸ”₯ EXAMPLES πŸ”₯

change the owner πŸ‘‘

change the owner of a custom operator a @@ b for type text:

ALTER OPERATOR @@ (text, text) OWNER TO joe;

swap the estimators πŸ’€

change the restriction and join selectivity estimator functions of a custom operator a && b for type int[]:

ALTER OPERATOR && (_int4, _int4) SET (RESTRICT = _int_contsel, JOIN = _int_contjoinsel);

ate. no crumbs. πŸŽ€

🌈 COMPATIBILITY 🌈

there is no ALTER OPERATOR statement in the SQL standard. we're built different, iykyk πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘


and that's a wrap, bestie 🫢 this page is from PostgreSQL 15.19, dated 2026 β€” go alter some operators, you're gonna slay πŸ’–πŸŒΈ

πŸ“¦ where this page comes from