i created table with 4column with
create table conversation(
user_name varchar(200),
employer_name varchar(200),
message text,
date_sent timestamp
)
now i want alter date_sent column without remove it i want to set default value of current_timestamp for this column what i must do
CodePudding user response:
You can use
ALTER TABLE conversation ALTER COLUMN
date_sent SET DEFAULT current_timestamp;
create table conversation( user_name varchar(200), employer_name varchar(200), message text, date_sent timestamp );
ALTER TABLE conversation ALTER COLUMN date_sent SET DEFAULT current_timestamp;
insert into conversation (user_name) values ('me');
select * from conversation;
user_name | employer_name | message | date_sent :-------- | :------------ | :------ | :------------------------- me | null | null | 2022-04-01 09:38:13.674547
db<>fiddle here