ALTER_OPERATOR(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’– ALTER OPERATOR โ€” the glow-up era ๐Ÿ’–

okay bestie, welcome to ALTER OPERATOR(7) from the PostgreSQL 18.6 Documentation โœจ this is the page where we learn how to change up an operator's whole situation โ€” new owner, new schema, new selectivity estimators, the works. no cap.


๐ŸŒธ 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 }
           | COMMUTATOR = com_op
           | NEGATOR = neg_op
           | HASHES
           | MERGES
          } [, ... ] )

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

ALTER OPERATOR changes the definition of an operator. it's giving operator makeover ๐Ÿ’œ

so like, you must own the operator to use ALTER OPERATOR. no owning, no altering, periodt.

and if you wanna change the owner? you gotta be able to SET ROLE to the new owning role, AND that role needs CREATE privilege on the operator's schema. why, you ask? because these restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the operator. makes sense bestie ๐Ÿซถ

BUT โ€” plot twist โ€” a superuser can alter ownership of any operator anyway ๐Ÿ‘‘ iconic.

๐ŸŽ€ PARAMETERS ๐ŸŽ€

  • name โ€” the name of an existing operator, optionally schema-qualified. the whole government name if you need it ๐Ÿ’…
  • left_type โ€” the data type of the operator's left operand. write NONE if the operator has no left operand. yes literally the word NONE, not a type, not vibes ๐Ÿซถ
  • right_type โ€” the data type of the operator's right operand.
  • new_owner โ€” the new owner of the operator. glow-up delivered ๐Ÿ“ฆโœจ
  • new_schema โ€” the new schema for the operator. moving out, moving on ๐Ÿฆ‹
  • 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.
  • com_op โ€” the commutator of this operator. heads up: can only be changed if the operator does not have an existing commutator.
  • neg_op โ€” the negator of this operator. same rule, bestie: can only be changed if the operator does not have an existing negator.
  • HASHES โ€” indicates this operator can support a hash join. can only be enabled and not disabled. one-way street, no take-backs ๐Ÿ”ฅ
  • MERGES โ€” indicates this operator can support a merge join. can only be enabled and not disabled. same energy ๐Ÿ’€

๐Ÿ’œ NOTES ๐Ÿ’œ

refer to Section 36.14 and Section 36.15 for further information ๐Ÿ“š

now this part is lowkey important so listen up:

since commutators come in pairs that are commutators of each other, ALTER OPERATOR SET COMMUTATOR will also set the commutator of the com_op to be the target operator. likewise, ALTER OPERATOR SET NEGATOR will also set the negator of the neg_op to be the target operator. it's mutual, it's reciprocal, it's a whole situationship ๐Ÿฅบ

and the consequence of all that? you must own the commutator or negator operator as well as the target operator. both of them. no skipping ๐Ÿ‘‘


๐ŸŒˆ 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 && (int[], int[]) SET (RESTRICT = _int_contsel, JOIN = _int_contjoinsel);

mark the && operator as being its own commutator:

ALTER OPERATOR && (int[], int[]) SET (COMMUTATOR = &&);

ate. no crumbs. ๐Ÿ’…


๐Ÿ“ COMPATIBILITY ๐Ÿ“

there is no ALTER OPERATOR statement in the SQL standard. we're off-script, we're original, we're built different ๐Ÿ˜Œ


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘


and that's the whole page bestie!! ๐Ÿงš this was PostgreSQL 18.6, dated 2026, and you absolutely slayed reading all of it. go forth and alter those operators responsibly ๐Ÿซถโœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from