-2

I want to alter a table in sql by changing a row of the type date to a row of the type timestamp. I want to use the old values of type date and copy them to the new row of type timestamp. Furthermore I want to concat the timestamps with the time "12:00" (noon).

My try:

-- Create a temporary TIMESTAMP column
ALTER TABLE guest_group ADD COLUMN create_time_holder TIMESTAMP without time zone NULL;

-- Copy casted value over to the temporary column and set time to 12:00
UPDATE guest_group SET create_time_holder = arrival_date::TIMESTAMP without time zone AS "12:00";

The result should be a value (timestamp) containing the old date with the string "12:00"

2019-12-20 12:00

2
  • It's not clear whether you want 12 noon or 12 midnight. If you want midnight, then setting the time to 12:00 is incorrect. ISO timestamp standards use the 24 hour clock, meaning 00:00 is midnight. Commented Jun 9, 2019 at 0:39
  • I added the information you required to my post @jpmc26 Commented Jun 9, 2019 at 17:53

1 Answer 1

1

If you are using Postgres, I think this does what you want:

UPDATE guest_group
    SET create_time_holder = arrival_date::date + interval '12 hour';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.