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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.