This is a bit messy, but you can achieve the same effect with a stored procedure:
CREATE OR REPLACE PROCEDURE conditional_drop_proc(
schema_name VARCHAR,
proc_name VARCHAR,
arglist VARCHAR
)
AS $$
/*
Drop the procedure with the given name and arguments if it exists, don't fail if it doesn't.
@param schema_name: The schema in which the procedure lives.
@param proc_name: The name of the procedure to drop.
@param arglist: comma-separated list of arg types of the procedure. E.g. varchar,varchar,bool.
*/
DECLARE
sql_stmt VARCHAR(1000);
arg_buf VARCHAR(500);
curr_arg_type VARCHAR(50);
curr_arg_int INTEGER;
where_clause VARCHAR(500) := '';
arg_count INTEGER;
proc_cnt INTEGER;
BEGIN
arg_count := regexp_count(arglist, ',') + decode(char_length(arglist) > 0, TRUE, 1, 0);
/*
First check if the given procedure exist, and then drop it. To check if it exists, check:
* its name exists in the given schema
* the number of arguments passed matches
* the type of the arguments match
*/
arg_buf := regexp_replace(arglist, '[[:blank:]]', '');
FOR i IN 1..arg_count LOOP
-- Extract next arg
curr_arg_type := substring(
arg_buf,
1,
CASE
WHEN charindex(',', arg_buf) = 0
THEN char_length(arg_buf)
ELSE charindex(',', arg_buf) - 1
END
);
arg_buf := substring(arg_buf, charindex(',', arg_buf) + 1);
SELECT INTO curr_arg_int
oid
FROM pg_type
WHERE typname = curr_arg_type;
IF NOT FOUND THEN
RAISE EXCEPTION 'Could not find a type match for %', curr_arg_type;
END IF;
where_clause := where_clause || ' AND proc.proargtypes[' || i - 1 || '] = ' || curr_arg_int;
END LOOP;
sql_stmt := $stmt$
SELECT
1
from pg_proc proc
left join pg_namespace ns
ON proc.pronamespace = ns.oid
where
proc.proname = '$stmt$ || proc_name || $stmt$'
AND ns.nspname = '$stmt$ || schema_name || $stmt$'
AND proc.pronargs = $stmt$ || arg_count || $stmt
stmt$ || where_clause || $stmt
stmt$;
EXECUTE sql_stmt INTO proc_cnt;
IF (proc_cnt IS NOT NULL) THEN
sql_stmt := $stmt$
DROP PROCEDURE $stmt$ || schema_name || '.' || proc_name || '(' || arglist || ')' || $stmt
stmt$;
EXECUTE sql_stmt;
RAISE NOTICE 'Dropped procedure: %', sql_stmt;
ELSE
RAISE NOTICE 'Procedure %.%(%) does not exist, skipping.', schema_name, proc_name, arglist;
END IF;
END;
$$ LANGUAGE plpgsql;
Then just call it with:
CALL conditional_drop_proc('schema', 'proc_name', 'argtyp1,argtyp2,...');
Answer from kcdgkn on Stack OverflowAWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop function
DROP FUNCTION - Amazon Redshift
Removes a user-defined function (UDF) from the database.
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop table
DROP TABLE - Amazon Redshift
Existing Python UDFs will continue to function until June 30, 2026. For more information, see the blog post ... Removes a table from a database. If you are trying to empty a table of rows, without removing the table, use the DELETE or TRUNCATE command. DROP TABLE removes constraints that exist ...
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop procedure
DROP PROCEDURE - Amazon Redshift
Drops a procedure. To drop a procedure, both the procedure name and input argument data types, or signature, are required. Optionally, you can include the full argument data types, including OUT arguments.
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › alter table › alter table add and drop column examples
ALTER TABLE ADD and DROP COLUMN examples - Amazon Redshift
March 19, 2026 - Provides examples of how to add and drop a basic table column using the ALTER TABLE ADD and DROP COLUMN commands.
RazorSQL
razorsql.com › features › redshift_drop_constraint.html
Redshift Drop Constraint from a Redshift Table via the Alter Table Drop Constraint Command
The RazorSQL Redshift alter table tool includes a Drop Constraint option for dropping a constraint from an AWS Redshift database table. The drop constraint function allows the user to enter a constraint to drop from the table.
RazorSQL
razorsql.com › features › redshift_drop_column.html
Redshift Drop Column from a Redshift Table via the Alter Table Drop Column Command
The RazorSQL alter table tool for Amazon AWS Redshift includes a Drop Column option for dropping a column from a Redshift table. The drop column function allows the user to select a column to drop from the table.
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop view
DROP VIEW - Amazon Redshift
Clause that indicates to automatically drop objects that depend on the view, such as other views.
PopSQL
popsql.com › learn-sql › redshift › how-to-drop-a-view-in-redshift
How to Drop a View in Redshift - PopSQL
Redshift · MySQL · SQL Server · BigQuery · Snowflake · To drop a Redshift view, use the DROP VIEW command: DROP VIEW view_name; You can also add the IF EXISTS option to prevent errors when trying to drop a non-existent view.
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop model
DROP MODEL - Amazon Redshift
DROP MODEL also deletes all the associated prediction function that is derived from this model, all Amazon Redshift artifacts related to the model, and all Amazon S3 data related to the model.
Amazon Web Services
docs.amazonaws.cn › 亚马逊云科技 › amazon redshift › database developer guide › sql reference › sql commands › drop procedure
DROP PROCEDURE - Amazon Redshift
Drops a procedure. To drop a procedure, both the procedure name and input argument data types, or signature, are required. Optionally, you can include the full argument data types, including OUT arguments.
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop group
DROP GROUP - Amazon Redshift
Amazon Redshift will no longer support the creation of new Python UDFs starting Patch 198. Existing Python UDFs will continue to function until June 30, 2026. For more information, see the blog post ... Deletes a user group. This command isn't reversible. This command doesn't delete the individual users in a group. See DROP USER to delete an individual user.
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop database
DROP DATABASE - Amazon Redshift
3 days ago - To allow dropping the database, set the following variable and run the DROP DATABASE statement again. SET datashare_break_glass_session_var to 'ce8d280c10ad41'; ... In this case, Amazon Redshift generates a random one-time value to set the session variable to allow DROP DATABASE for a database that contains an AWS Data Exchange datashare.
Amazon Web Services
docs.amazonaws.cn › 亚马逊云科技 › amazon redshift › database developer guide › sql reference › sql commands › drop table
DROP TABLE - Amazon Redshift
If you would like to use Python UDFs, create the UDFs prior to that date. Existing Python UDFs will continue to function as normal. For more information, see the blog post ... Removes a table from a database. If you are trying to empty a table of rows, without removing the table, use the DELETE ...
AWS re:Post
repost.aws › knowledge-center › redshift-drop-object
Why can't I DROP an object in my Amazon Redshift cluster?
December 21, 2023 - Lock contention: A transaction is holding a lock on the object and causes the drop operation to hang. In Amazon Redshift, only the table owner, the schema owner, or a superuser can drop a table.
Amazon Web Services
docs.amazonaws.cn › 亚马逊云科技 › amazon redshift › database developer guide › sql reference › sql commands › drop schema
DROP SCHEMA - Amazon Redshift
Clause that indicates that if an external schema is dropped, drop the external database associated with the external schema, if one exists. If no external database exists, the command returns a message stating that no external database exists.
AWS
docs.aws.amazon.com › amazon redshift › database developer guide › sql reference › sql commands › drop schema
DROP SCHEMA - Amazon Redshift
Clause that indicates that if an external schema is dropped, drop the external database associated with the external schema, if one exists. If no external database exists, the command returns a message stating that no external database exists.