create or replace function user_lock(int4, int4, int4) returns int4 as
$$
  select case when pg_try_advisory_lock($1, $2) then 1 else 0 end;      
$$ language sql;
  
create or replace function user_unlock(int4, int4, int4) returns int4 as
$$
  select case when pg_advisory_unlock($1, $2) then 1 else 0 end;      
$$ language sql;
  
create or replace function user_write_lock(int4, int4, int4) returns int4 as
$$
  select case when pg_try_advisory_lock($1, $2) then 1 else 0 end;      
$$ language sql;  
  
create or replace function user_write_unlock(int4, int4, int4) returns int4 as
$$
  select case when pg_advisory_unlock($1, $2) then 1 else 0 end;      
$$ language sql;
  
create or replace function user_write_lock_oid(oid) returns int4 as
$$
  select case when pg_try_advisory_lock($1::bigint) then 1 else 0 end;      
$$ language sql;      
  
create or replace function user_write_lock_oid(int4) returns int4 as
$$
  select case when pg_try_advisory_lock($1::bigint) then 1 else 0 end;      
$$ language sql;        
  
create or replace function user_write_unlock_oid(oid) returns int4 as
$$
  select case when pg_advisory_unlock($1::bigint) then 1 else 0 end;      
$$ language sql;      
  
create or replace function user_write_unlock_oid(int4) returns int4 as
$$
  select case when pg_advisory_unlock($1::bigint) then 1 else 0 end;      
$$ language sql;          
  
create or replace function user_unlock_all() returns void as
$$
  begin
    select pg_advisory_unlock_all();  
    return;
  end;    
$$ language plpgsql;            
