ALTER_OPERATOR(7pg13)

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

✨ ALTER OPERATOR ✨

okay so real talk β€” this is the ALTER OPERATOR(7) page from the PostgreSQL 13.23 Documentation, and it's literally the glow-up page for operators. bestie, if you've ever made a custom operator and then realized it needs a whole different owner, schema, or selectivity vibe, this is your moment. no cap. πŸ’…


πŸŽ€ NAME πŸŽ€

ALTER_OPERATOR β€” change the definition of an operator


πŸ¦‹ SYNOPSIS πŸ¦‹

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

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

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

like, three whole forms. pick your fighter. 🌈


🌸 DESCRIPTION 🌸

ALTER OPERATOR changes the definition of an operator. that's the whole assignment, and it ate. ✨

You must own the operator to use ALTER OPERATOR. periodt.

To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the operator's schema. 🫢 (these restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the operator β€” which, yeah, is exactly the kind of thing we're avoiding, thank you.) However, a superuser can alter ownership of any operator anyway. main character energy only. πŸ‘‘


πŸ’– PARAMETERS πŸ’–

  • name β€” the name (optionally schema-qualified) of an existing operator. iykyk, but schema-qualify it if you're being fancy.
  • left_type β€” the data type of the operator's left operand; write NONE if the operator has no left operand. yes, NONE is a valid mood here. πŸ™ˆ
  • right_type β€” the data type of the operator's right operand; write NONE if the operator has no right operand. same energy. πŸ’€
  • new_owner β€” the new owner of the operator. crown handoff. πŸ‘‘
  • new_schema β€” the new schema for the operator. relocation era. πŸ¦‹
  • res_proc β€” the restriction selectivity estimator function for this operator; write NONE to remove existing selectivity estimator. so if you're over it, just say NONE. πŸ’…
  • join_proc β€” the join selectivity estimator function for this operator; write NONE to remove existing selectivity estimator. same deal, bestie. πŸŽ€

πŸ”₯ EXAMPLES πŸ”₯

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

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

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

look at that. iconic. not me being obsessed with _int4. 😭


⭐ COMPATIBILITY ⭐

There is no ALTER OPERATOR statement in the SQL standard. we simply do not follow the rules. πŸ’€βœ¨


🌈 SEE ALSO 🌈


ngl, the ownership rules look dramatic, but they're there so you can't sneak around permissions by drop-and-recreate. respect the vibe check. 🧚

and that's the page, bestie β€” brought to you by PostgreSQL 13.23, dated 2025, for ALTER OPERATOR(7). go forth and alter responsibly. πŸ’œπŸŽ€

πŸ“¦ where this page comes from