ALTER_PROCEDURE(7)
โจ ALTER PROCEDURE โจ
okay bestie, welcome to ALTER_PROCEDURE ๐
this is the page in the PostgreSQL 18.6 Documentation and it's literally all about changing the definition of a procedure. no cap, it's giving "glow-up for your stored procedure" energy.
๐ธ SYNOPSIS ๐ธ
ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
action [ ... ] [ RESTRICT ]
ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
RENAME TO new_name
ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
SET SCHEMA new_schema
ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
[ NO ] DEPENDS ON EXTENSION extension_name
where action is one of:
[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
SET configuration_parameter { TO | = } { value | DEFAULT }
SET configuration_parameter FROM CURRENT
RESET configuration_parameter
RESET ALL
๐ DESCRIPTION ๐
ALTER PROCEDURE changes the definition of a procedure. that's the whole vibe. you point it at a procedure and you tell it what to change. iconic behavior honestly.
okay so the rules of who's allowed to do this:
- you must own the procedure to use
ALTER PROCEDURE. it's your procedure, you get to alter it ๐ซถ - to change a procedure's schema, you must also have
CREATEprivilege on the new schema. both things. no skipping. - to alter the owner, you must be able to
SET ROLEto the new owning role, and that role must haveCREATEprivilege on the procedure's schema.
and the reason for all those restrictions? (this is the parenthetical, keep it, it's important) they enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the procedure. however, a superuser can alter ownership of any procedure anyway. main character energy only ๐
๐ PARAMETERS ๐
nameโ the name of an existing procedure, optionally schema-qualified. if you don't give an argument list, the name has to be unique in its schema. (no duplicates allowed, we're not doing that here ๐)argmodeโ the mode of an argument:IN,OUT,INOUT, orVARIADIC. if you justโฆ don't say anything, the default isIN.argnameโ the name of an argument. but real talk,ALTER PROCEDUREdoes not actually pay any attention to argument names, because only the argument data types are used to determine the procedure's identity. so cute, so ignored ๐argtypeโ the data type(s) of the procedure's arguments (optionally schema-qualified), if any. for the details of how the procedure is looked up using the argument data type(s), go seeDROP PROCEDURE(DROP_PROCEDURE(7)).new_nameโ the new name of the procedure. rebrand era โจnew_ownerโ the new owner of the procedure. heads up bestie: if the procedure is markedSECURITY DEFINER, it will subsequently execute as the new owner. so choose wisely ๐ซถnew_schemaโ the new schema for the procedure.extension_nameโ this form marks the procedure as dependent on the extension, or no longer dependent on the extension ifNOis specified. a procedure that's marked as dependent on an extension is dropped when the extension is dropped, even if cascade is not specified. and a procedure can depend upon multiple extensions, and will be dropped when any one of those extensions is dropped. it's a whole polycule of dependencies ๐ญ[ EXTERNAL ] SECURITY INVOKER/[ EXTERNAL ] SECURITY DEFINERโ change whether the procedure is a security definer or not. the key wordEXTERNALis ignored for SQL conformance. seeCREATE PROCEDURE(CREATE_PROCEDURE(7)) for more info about this capability.configuration_parameter/valueโ add or change the assignment to be made to a configuration parameter when the procedure is called. ifvalueisDEFAULTor, equivalently,RESETis used, the procedure-local setting is removed, so that the procedure executes with the value present in its environment. useRESET ALLto clear all procedure-local settings.SET FROM CURRENTsaves the value of the parameter that is current whenALTER PROCEDUREis executed, as the value to be applied when the procedure is entered.
see SET(7) and Chapter 19 for more info about allowed parameter names and values.
RESTRICTโ ignored, for conformance with the SQL standard. it's just there vibing ๐
๐ EXAMPLES ๐
want to rename the procedure insert_data with two arguments of type integer to insert_record? slay, do this:
ALTER PROCEDURE insert_data(integer, integer) RENAME TO insert_record;
want to change the owner of the procedure insert_data with two arguments of type integer to joe? here:
ALTER PROCEDURE insert_data(integer, integer) OWNER TO joe;
change the schema of the procedure insert_data with two arguments of type integer to accounting:
ALTER PROCEDURE insert_data(integer, integer) SET SCHEMA accounting;
mark the procedure insert_data(integer, integer) as being dependent on the extension myext:
ALTER PROCEDURE insert_data(integer, integer) DEPENDS ON EXTENSION myext;
adjust the search path that is automatically set for a procedure:
ALTER PROCEDURE check_password(text) SET search_path = admin, pg_temp;
disable automatic setting of search_path for a procedure:
ALTER PROCEDURE check_password(text) RESET search_path;
and then? the procedure will now execute with whatever search path is used by its caller. periodt.
๐ COMPATIBILITY ๐
this statement is partially compatible with the ALTER PROCEDURE statement in the SQL standard. the standard allows more properties of a procedure to be modified, but does not provide the ability to:
- rename a procedure
- make a procedure a security definer
- attach configuration parameter values to a procedure
- change the owner, schema, or volatility of a procedure
the standard also requires the RESTRICT key word, which is optional in PostgreSQL. so PostgreSQL is the chill one here ๐ฆ
๐ฅ SEE ALSO ๐ฅ
CREATE PROCEDURE(CREATE_PROCEDURE(7))DROP PROCEDURE(DROP_PROCEDURE(7))ALTER FUNCTION(ALTER_FUNCTION(7))ALTER ROUTINE(ALTER_ROUTINE(7))
and that's the whole page bestie, no notes ๐
this was the ALTER PROCEDURE(7) page from PostgreSQL 18.6, dated 2026. go alter something (that you own). mwah ๐โจ
๐ฆ 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