Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:39:21+00:00 2026-05-23T14:39:21+00:00

One of our Postgres tables, called rep_event, has a timestamp column that indicates when

  • 0

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.

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:

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;

Here is the table definition:

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
)

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:39:22+00:00Added an answer on May 23, 2026 at 2:39 pm

    A simpler solution is to just modify your table definition to have NOW() be the default value:

    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 DEFAULT NOW()
    );
    

    Then you can get rid of the now() calls in your trigger.

    Also as a side note, I strongly suggest including the column ordering in your function… IOW;

    INSERT INTO rep_event (operation,table_name,object_id,time_stamp) SELECT ...
    

    This way if you ever add a new column or make other table changes that change the internal ordering of the tables, your function won’t suddenly break.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One of our clients has an old WinForms application that contains forms with a
One of our customers has a problem that we cannot reproduce. We programmatically copy
One of our clients has two very similar websites that we are performing lead
One of our sites has around 10,000 nodes. In each node, there is a
One of our weblogic 8.1s has suddenly started logging giant amounts of logs and
One of our providers are sometimes sending XML feeds that are tagged as UTF-8
One of our production apps has been on Amazon RDS (MySql) for a few
One of our clients has logged a very strange issue with us- We launched
One of our products uses a Javascript Rich text editor, which has the ability
One of our largest old VB6 apps has some code in it to allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.