user12990369
user12990369

Reputation:

Getting error when trying to change type DATE to DATETIME

I want to change my column type date to datetime. However, Im getting an error: syntax error at or near "DATETIME"

ALTER TABLE messages ALTER COLUMN date DATETIME;

I dont know why, im using PostgreSQL

Thanks!

Upvotes: 1

Views: 407

Answers (1)

user330315
user330315

Reputation:

As documented in the manual there is no datetime type in Postgres.

To change the type of a column you need to use the TYPE keyword after the column's name as documented in the manual

ALTER TABLE messages ALTER COLUMN "date" type timestamp;

Unrelated to your question, but you should avoid using keywords as column names.

Additionally "date" isn't a good name to begin with as it doesn't describe what kind of "date" that is. The "sent date"? The "receive date"? The "expiration date"?

Upvotes: 1

Related Questions