ALTER_OPERATOR(7pg15)
β¨ 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; writeNONEif the operator has no left operand. yes,NONEis 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; writeNONEto remove existing selectivity estimator.join_procβ the join selectivity estimator function for this operator; writeNONEto 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 π
CREATE OPERATOR(CREATE_OPERATOR(7)) β make one β¨DROP OPERATOR(DROP_OPERATOR(7)) β unmake one π
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
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms