use the proper column name in pg_stat_activity for the postgres version
[xtuple] / foundation-database / public / functions / logout.sql
index 1626bf2..e571e66 100644 (file)
@@ -3,9 +3,16 @@ CREATE OR REPLACE FUNCTION logout() RETURNS integer AS $$
 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
-  PERFORM pg_advisory_unlock(datid::integer, procpid)
+  IF (compareversion('9.2.0') <= 0)
+  THEN
+    PERFORM pg_try_advisory_unlock(datid::integer, pid)
      FROM pg_stat_activity
-    WHERE(procpid = pg_backend_pid());
+    WHERE(pid = pg_backend_pid());
+  ELSE
+    PERFORM pg_advisory_unlock(datid::integer, procpid)
+       FROM pg_stat_activity
+      WHERE(procpid = pg_backend_pid());
+  END IF;
 
   RETURN 0;
 END;