diff options
author | Marko Kreen | 2010-10-27 14:57:39 +0000 |
---|---|---|
committer | Marko Kreen | 2010-11-02 13:41:48 +0000 |
commit | 78472afe1e8857f4ac3b36a1fa13ac4eccd40001 (patch) | |
tree | 275def89319aac50906ff442ae0e31f1e277cbcc | |
parent | 27617c203766fee1619561145207c4dcbbbd9c11 (diff) |
pgq.drop_queue: add force flag
-rw-r--r-- | sql/pgq/functions/pgq.drop_queue.sql | 42 |
1 files 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; + |