From 262e1d285bb7665586c2c8651dc29c6860817a12 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 24 Dec 2006 22:48:12 +1300 Subject: [PATCH] New function for getting the last play date. --- dba/functions.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 dba/functions.sql diff --git a/dba/functions.sql b/dba/functions.sql new file mode 100644 index 0000000..a3c5a1a --- /dev/null +++ b/dba/functions.sql @@ -0,0 +1,15 @@ + +CREATE or REPLACE FUNCTION get_last_played( TEXT ) RETURNS TIMESTAMP AS ' +DECLARE + hash ALIAS FOR $1; + last_time TIMESTAMP; +BEGIN + -- ORDER BY hash_key and req_at makes index choice more sane. + SELECT req_at INTO last_time FROM played WHERE hash_key=hash + ORDER BY hash_key DESC, req_at DESC LIMIT 1; + IF NOT FOUND THEN + last_time := ''-infinity''; + END IF; + RETURN last_time; +END; +' LANGUAGE 'plpgsql' STRICT; -- 2.11.4.GIT