ALTER_PROCEDURE(7pg18)

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

โœจ 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 CREATE privilege on the new schema. both things. no skipping.
  • to alter the owner, you must be able to SET ROLE to the new owning role, and that role must have CREATE privilege 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, or VARIADIC. if you justโ€ฆ don't say anything, the default is IN.
  • argname โ€” the name of an argument. but real talk, ALTER PROCEDURE does 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 see DROP 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 marked SECURITY 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 if NO is 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 word EXTERNAL is ignored for SQL conformance. see CREATE 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. if value is DEFAULT or, equivalently, RESET is used, the procedure-local setting is removed, so that the procedure executes with the value present in its environment. use RESET ALL to clear all procedure-local settings. SET FROM CURRENT saves the value of the parameter that is current when ALTER PROCEDURE is 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 ๐Ÿ”ฅ


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