ALTER_OPERATOR(7)
๐ 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. writeNONEif the operator has no left operand. yes literally the wordNONE, 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. writeNONEto remove existing selectivity estimator.join_procโ the join selectivity estimator function for this operator. writeNONEto 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 ๐
CREATE OPERATOR(CREATE_OPERATOR(7))DROP OPERATOR(DROP_OPERATOR(7))
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
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms