title: Calling now() in a function
body: <p>One of our Postgres tables, called rep_event, has a timestamp column that indicates when each row was inserted.  But all of the rows have a timestamp value of 2000-01-01 00:00:00, so something isn't set up right.</p>
  
  <p>There is a function that inserts rows into the table, and it is the only code that inserts rows into that table - no other code inserts into that table.  (There also isn't any code that updates the rows in that table.)  Here is the definition of the function:</p>
  
  <pre><code>CREATE FUNCTION handle_event() RETURNS "trigger"
  AS $$
  BEGIN
      IF (TG_OP = 'DELETE') THEN
          INSERT INTO rep_event SELECT 'D', TG_RELNAME, OLD.object_id, now();
          RETURN OLD;
      ELSIF (TG_OP = 'UPDATE') THEN
          INSERT INTO rep_event SELECT 'U', TG_RELNAME, NEW.object_id, now();
          RETURN NEW;
      ELSIF (TG_OP = 'INSERT') THEN
          INSERT INTO rep_event SELECT 'I', TG_RELNAME, NEW.object_id, now();
          RETURN NEW;
      END IF;
      RETURN NULL;
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>Here is the table definition:</p>
  
  <pre><code>CREATE TABLE rep_event
  (
  operation character(1) NOT NULL,
  table_name text NOT NULL,
  object_id bigint NOT NULL,
  time_stamp timestamp without time zone NOT NULL
  )
  </code></pre>
  
  <p>As you can see, the now() function is called to get the current time.  Doing a "select now()" on the database returns the correct time, so is there an issue with calling now() from within a function?</p>