ALTER_OPERATOR(7pg13)
β¨ 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; writeNONEif the operator has no left operand. yes,NONEis a valid mood here. πright_typeβ the data type of the operator's right operand; writeNONEif 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; writeNONEto remove existing selectivity estimator. so if you're over it, just sayNONE. πjoin_procβ the join selectivity estimator function for this operator; writeNONEto 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 π
CREATE OPERATOR(CREATE_OPERATOR(7))DROP OPERATOR(DROP_OPERATOR(7))
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
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-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