pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ian Barwick <ian.barwick@2ndquadrant.com>
To: Wells Oliver <wells.oliver@gmail.com>
To: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Dropping functions from pg_proc table w/ querry
Date: Wed, 30 Oct 2019 12:26:46 +0900
Message-ID: <6ebc3e08-a2e3-b8f9-773e-0bc24e79e75f@2ndquadrant.com> (raw)
In-Reply-To: <CAOC+FBWN5bf56SwUbnhbymt0c_bmS6+-C1aiPwNOPe089+DqHA@mail.gmail.com>
References: <CAOC+FBWN5bf56SwUbnhbymt0c_bmS6+-C1aiPwNOPe089+DqHA@mail.gmail.com>

On 2019/10/30 12:05, Wells Oliver wrote:
> I have this query:
> 
> select * from pg_proc where probin like '%someoldstuff%';
> 
> Which shows abou 20 functions I want dropped. Is there a quick convenient SQL query for dropping all of these? Can't quite figure it out.

Something like this should do the trick:

     DO
     $$
       DECLARE
         rec RECORD;
       BEGIN
         FOR rec IN
            SELECT n.nspname || '.' || p.proname || '(' || pg_catalog.pg_get_function_arguments(p.oid)  ||')' AS func
              FROM pg_catalog.pg_proc p
         LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
             WHERE p.proname LIKE 'foo%'
         LOOP
           RAISE NOTICE 'Dropping: %', rec.func;
           EXECUTE 'DROP FUNCTION ' || rec.func;
         END LOOP;
       END;
     $$;


Use at your own risk etc. etc.


Regards

Ian Barwick


-- 
  Ian Barwick                   https://www.2ndQuadrant.com/
  PostgreSQL Development, 24x7 Support, Training & Services





view thread (2+ messages)

Message-ID: <6ebc3e08-a2e3-b8f9-773e-0bc24e79e75f@2ndquadrant.com>
Permalink:  ../6ebc3e08-a2e3-b8f9-773e-0bc24e79e75f@2ndquadrant.com/
Also on:    postgresql.org/message-id/6ebc3e08-a2e3-b8f9-773e-0bc24e79e75f@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: ian.barwick@2ndquadrant.com, wells.oliver@gmail.com
  Subject: Re: Dropping functions from pg_proc table w/ querry
  In-Reply-To: <6ebc3e08-a2e3-b8f9-773e-0bc24e79e75f@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox