'question about altering date column in table with postgresSQL

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



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 a_horse_with_no_name