9

I've just created a Postgres database and table ('users'). My table has a created_at column of type:

TIMESTAMP WITH TIME ZONE NOT NULL;

I basically want to use this column to keep track of when a new user is created. Is there a way to have Postgres automatically update this with each insert or do I have to supply it a value for this on every insert?

(I want to say when using it before with Sequelize, it created this automatically - so wondering if this was done through Sequelize as a default when inserting).

Thank you!

2

1 Answer 1

20

You can declare a timestamp field to automatically be filled with the current time on INSERT by including the DEFAULT now() clause in your column definition.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.