Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use

LTER 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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading