DROP_ROUTINE(7pg16)
π DROP_ROUTINE β bestie's guide to yeeting a routine
okay so real talk, this is DROP_ROUTINE from the PostgreSQL 16.15 docs, and it's genuinely one of the most underrated little commands out there. it removes a routine. that's the whole vibe. let's get into it π«Ά
β¨ SYNOPSIS β¨
DROP ROUTINE [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
[ CASCADE | RESTRICT ]
like, look at her. multi-routine capable. optional args. cascade or restrict. she's got range π₯
πΈ DESCRIPTION πΈ
DROP ROUTINE removes the definition of one or more existing routines. and when we say "routine", we mean it in the big-tent sense β the term "routine" includes aggregate functions, normal functions, and procedures. one command to drop them all, no cap π
for the actual deets on parameters, more examples, and further details, please go check under DROP AGGREGATE (DROP_AGGREGATE(7)), DROP FUNCTION (DROP_FUNCTION(7)), and DROP PROCEDURE (DROP_PROCEDURE(7)). she's the generalist, they're the specialists. iykyk π
π¦ NOTES π¦
okay this part is important, don't skip it, i'm serious:
- the lookup rules used by
DROP ROUTINEare fundamentally the same as forDROP PROCEDURE. in particular,DROP ROUTINEshares that command's behavior of considering an argument list that has noargmodemarkers to be possibly using the SQL standard's definition thatOUTarguments are included in the list. (DROP AGGREGATEandDROP FUNCTIONdo not do that, btw. they're different like that π) - in some cases where the same name is shared by routines of different kinds, it is possible for
DROP ROUTINEto fail with an ambiguity error even when a more specific command (DROP FUNCTION, etc.) would totally work. the fix? specify the argument type list more carefully. that also resolves such problems. slay β¨ - these lookup rules are also used by other commands that act on existing routines, such as
ALTER ROUTINEandCOMMENT ON ROUTINE. so like, knowing this is a whole personality trait at this point π§
π EXAMPLES π
okay so say you wanna drop the routine foo for type integer:
DROP ROUTINE foo(integer);
and the beautiful part? this command will work independent of whether foo is an aggregate, function, or procedure. it does not care. it does not ask questions. it just drops. iconic behavior honestly π
π COMPATIBILITY π
this command conforms to the SQL standard, with these PostgreSQL extensions:
- the standard only allows one routine to be dropped per command. (we said "actually, more." main character energy β)
- the
IF EXISTSoption is an extension. - the ability to specify argument modes and names is an extension, and the lookup rules differ when modes are given.
- user-definable aggregate functions are an extension.
π SEE ALSO π
DROP AGGREGATE(DROP_AGGREGATE(7))DROP FUNCTION(DROP_FUNCTION(7))DROP PROCEDURE(DROP_PROCEDURE(7))ALTER ROUTINE(ALTER_ROUTINE(7))
bestie heads up: note that there is no CREATE ROUTINE command. don't go looking for her, she's not coming to the function ππ
and that's the whole page! brought to you by the PostgreSQL 16.15 documentation, dated 2026 β go forth and drop responsibly, mwah ππ¦πΈ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-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