I have a little function (used to be a part of a big one, but I've isolated the segment for this question):
CREATE OR REPLACE FUNCTION weird_date_issue_function() RETURNS INT AS
$BODY$
DECLARE
deleted_count INT := 0;
BEGIN
SELECT count(*)
INTO deleted_count
FROM user_verifications
WHERE verified = FALSE AND now() - create_date > INTERVAL '1 second';
RETURN deleted_count;
END;
$BODY$
LANGUAGE plpgsql;
The user_verification
indeed contains an unverified entry older than 1 second (for testing purposes).
When I call select weird_date_issue_function();
from my IDE, it returns 1.
But when I call it using jdbc.queryForObject("SELECT weird_date_issue_function()", Integer.class);
it returns 0.
But wait, that's not all. If I comment out the AND now() - create_date > INTERVAL '1 second';
part, I get 1 in my application as well. What is going on here?