Skip to content

Instantly share code, notes, and snippets.

@shahidhk
Created August 28, 2018 11:39
Show Gist options
  • Select an option

  • Save shahidhk/624c094e21a241d25734362b7e533705 to your computer and use it in GitHub Desktop.

Select an option

Save shahidhk/624c094e21a241d25734362b7e533705 to your computer and use it in GitHub Desktop.
CREATE FUNCTION update_last_seen_timestamp_func() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.last_seen_at := now();
RETURN NEW;
END;
$$;
CREATE TRIGGER update_last_seen_timestamp_trigger
BEFORE INSERT OR UPDATE ON "user" FOR EACH ROW
EXECUTE PROCEDURE update_last_seen_timestamp_func();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment