DROP FUNCTION without knowing the number/type of parameters?

后端 未结 7 874
面向向阳花
面向向阳花 2020-12-01 02:20

I keep all my functions in a text file with \'CREATE OR REPLACE FUNCTION somefunction\'. So if I add or change some function I just feed the file to psql.

7条回答
  •  甜味超标
    2020-12-01 02:36

    Here is the query I built on top of @Сухой27 solution that generates sql statements for dropping all the stored functions in a schema:

    WITH f AS (SELECT specific_schema || '.' || ROUTINE_NAME AS func_name 
            FROM information_schema.routines
            WHERE routine_type='FUNCTION' AND specific_schema='a3i')
    SELECT
        format('DROP FUNCTION %s(%s);',
          p.oid::regproc, pg_get_function_identity_arguments(p.oid))
    FROM pg_catalog.pg_proc p
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
    WHERE
        p.oid::regproc::text IN (SELECT func_name FROM f);
    

提交回复
热议问题