Question about default values for timestamp

Currently in my db I am doing (setup a year or so ago)
createdAt: timestamp('created_at')
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
createdAt: timestamp('created_at')
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
for creating a default. However, I was looking at the docs and I see
timestamp1: timestamp('timestamp1').notNull().defaultNow(),
timestamp2: timestamp('timestamp2', { mode: 'string' })
.notNull()
.default(sql`now()`),
timestamp1: timestamp('timestamp1').notNull().defaultNow(),
timestamp2: timestamp('timestamp2', { mode: 'string' })
.notNull()
.default(sql`now()`),
What are the differences and which one should I be using nowadays?
1 Reply
aleclarson
aleclarson2mo ago
current_timestamp is standard sql, but now() is not. they are functionally equivalent in postgres

Did you find this page helpful?