-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
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;
+