0

I am trying to add a default timetable into my query with a chosen time, 09.00 o'clock. The type of the column was 'date', I changed it to 'timestamp', my assignment sais so. I don't know what to do now. I am very new to this and trying to understand queries with 'timestamp'.

This is what I have so far:

ALTER TABLE note
    ALTER COLUMN entered TYPE timestamp SET DEFAULT;

I don't know what to do next. Any help is appricieted!

Bosbes
  • 17
  • 4

1 Answers1

2

The ALTER COLUMN allows to provide an expression for the cast through the USING keyword. As you already have a date, you can convert it to a timestamp by adding a time:

ALTER TABLE note
    ALTER COLUMN entered TYPE timestamp using entered + time '09:00';

If you also want to set a default value to "today at 09:00" you can do that in the same statement:

ALTER TABLE note
    ALTER COLUMN entered TYPE TIMESTAMP USING entered + time '09:00', 
    ALTER COLUMN entered SET DEFAULT current_date + time '09:00';