From 78472afe1e8857f4ac3b36a1fa13ac4eccd40001 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Wed, 27 Oct 2010 17:57:39 +0300 Subject: [PATCH] pgq.drop_queue: add force flag --- sql/pgq/functions/pgq.drop_queue.sql | 42 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/sql/pgq/functions/pgq.drop_queue.sql b/sql/pgq/functions/pgq.drop_queue.sql index 3819a914..09e024fe 100644 --- a/sql/pgq/functions/pgq.drop_queue.sql +++ b/sql/pgq/functions/pgq.drop_queue.sql @@ -1,34 +1,34 @@ -create or replace function pgq.drop_queue(x_queue_name text) +create or replace function pgq.drop_queue(x_queue_name text, x_force bool) returns integer as $$ -- ---------------------------------------------------------------------- --- Function: pgq.drop_queue(1) +-- Function: pgq.drop_queue(2) -- -- Drop queue and all associated tables. --- No consumers must be listening on the queue. -- +-- Parameters: +-- x_queue_name - queue name +-- x_force - ignore consumers -- ---------------------------------------------------------------------- declare tblname text; q record; num integer; begin - -- check ares - if x_queue_name is null then - raise exception 'Invalid NULL value'; - end if; - -- check if exists select * into q from pgq.queue - where queue_name = x_queue_name; + where queue_name = x_queue_name + for update; if not found then raise exception 'No such event queue'; end if; - -- check if no consumers - select count(*) into num from pgq.subscription - where sub_queue = q.queue_id; - if num > 0 then - raise exception 'cannot drop queue, consumers still attached'; + if not x_force then + -- check if no consumers + select count(*) into num from pgq.subscription + where sub_queue = q.queue_id; + if num > 0 then + raise exception 'cannot drop queue, consumers still attached'; + end if; end if; -- drop data tables @@ -54,3 +54,17 @@ begin end; $$ language plpgsql security definer; +create or replace function pgq.drop_queue(x_queue_name text) +returns integer as $$ +-- ---------------------------------------------------------------------- +-- Function: pgq.drop_queue(1) +-- +-- Drop queue and all associated tables. +-- No consumers must be listening on the queue. +-- +-- ---------------------------------------------------------------------- +begin + return pgq.drop_queue(x_queue_name, false); +end; +$$ language plpgsql strict; + -- 2.39.5